vmm: Add memory hotplug support to VFIO PCI devices

Extend the update_memory() method from DeviceManager so that VFIO PCI
devices can update their DMA mappings to the physical IOMMU, after a
memory hotplug has been performed.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-03-26 14:53:43 +01:00
parent cc67131ecc
commit 9e18177654

View File

@ -270,6 +270,10 @@ pub enum DeviceManagerError {
/// Cannot find a memory range for virtio-mem memory
VirtioMemRangeAllocation,
/// Failed updating guest memory for VFIO PCI device.
#[cfg(feature = "pci_support")]
UpdateMemoryForVfioPciDevice(VfioPciError),
}
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
@ -1886,6 +1890,22 @@ impl DeviceManager {
.map_err(DeviceManagerError::UpdateMemoryForVirtioDevice)?;
}
// Take care of updating the memory for VFIO PCI devices.
#[cfg(feature = "pci_support")]
{
for (_, any_device) in self.pci_devices.iter() {
if let Ok(vfio_pci_device) =
Arc::clone(any_device).downcast::<Mutex<VfioPciDevice>>()
{
vfio_pci_device
.lock()
.unwrap()
.update_memory(_new_region)
.map_err(DeviceManagerError::UpdateMemoryForVfioPciDevice)?;
}
}
}
Ok(())
}