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()