From 432eb5b70ad6c2db45758f15d81c85ee3b6c991b Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 11 Mar 2020 10:05:37 +0100 Subject: [PATCH] vmm: Free PCI BARs when unplugging PCI device Now that PciDevice trait has a dedicated function to remove the bars, the DeviceManager can invoke this function whenever a PCI device is unplugged from the VM. Signed-off-by: Sebastien Boeuf --- vmm/src/device_manager.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index eb4d087d8..df7194e92 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -135,6 +135,10 @@ pub enum DeviceManagerError { #[cfg(feature = "pci_support")] AllocateBars(pci::PciDeviceError), + /// Could not free the BARs associated with a PCI device. + #[cfg(feature = "pci_support")] + FreePciBars(pci::PciDeviceError), + /// Cannot register ioevent. RegisterIoevent(kvm_ioctls::Error), @@ -1861,6 +1865,13 @@ impl DeviceManager { return Ok(()); }; + // Free the allocated BARs + pci_device + .lock() + .unwrap() + .free_bars(&mut self.address_manager.allocator.lock().unwrap()) + .map_err(DeviceManagerError::FreePciBars)?; + // Remove the device from the PCI bus pci.lock() .unwrap()