From 8ff3633782ffb919d3c343a754a34ca050baa75d Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 9 Apr 2020 13:15:18 +0100 Subject: [PATCH] vm-virtio: pci: Update the BARs used by the VirtioPciDevice In order to support freeing the memory that is allocated we need to make sure that we update the internal representation so that free_bars() can correctly free the memory if the device has its BARs moved. Signed-off-by: Rob Bradford --- vm-virtio/src/transport/pci_device.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vm-virtio/src/transport/pci_device.rs b/vm-virtio/src/transport/pci_device.rs index 76e048e28..330e45b53 100755 --- a/vm-virtio/src/transport/pci_device.rs +++ b/vm-virtio/src/transport/pci_device.rs @@ -787,6 +787,18 @@ impl PciDevice for VirtioPciDevice { Ok(()) } + fn move_bar(&mut self, old_base: u64, new_base: u64) -> result::Result<(), std::io::Error> { + // We only update our idea of the bar in order to support free_bars() above. + // The majority of the reallocation is done inside DeviceManager. + for (addr, _, _) in self.bar_regions.iter_mut() { + if (*addr).0 == old_base { + *addr = GuestAddress(new_base); + } + } + + Ok(()) + } + fn read_bar(&mut self, _base: u64, offset: u64, data: &mut [u8]) { match offset { o if o < COMMON_CONFIG_BAR_OFFSET + COMMON_CONFIG_SIZE => self.common_config.read(