From c021dda2677a36e679d5e5033ac22389e485976f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 7 Jun 2022 16:35:53 +0200 Subject: [PATCH] pci, vmm: Add migratable support to VFIO devices Based on recent changes to VfioPciDevice, the VFIO devices can now be migrated. Signed-off-by: Sebastien Boeuf --- pci/src/vfio.rs | 10 ++++++++-- vmm/src/device_manager.rs | 7 ++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 88ad93b30..91ca831f0 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -1153,6 +1153,7 @@ impl VfioPciDevice { legacy_interrupt_group: Option>, iommu_attached: bool, bdf: PciBdf, + restoring: bool, ) -> Result { let device = Arc::new(device); device.reset(); @@ -1185,8 +1186,13 @@ impl VfioPciDevice { vfio_wrapper: Arc::new(vfio_wrapper) as Arc, }; - common.parse_capabilities(bdf); - common.initialize_legacy_interrupt()?; + // No need to parse capabilities from the device if on the restore path. + // The initialization will be performed later when restore() will be + // called. + if !restoring { + common.parse_capabilities(bdf); + common.initialize_legacy_interrupt()?; + } let vfio_pci_device = VfioPciDevice { id, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 0d811f456..928a20edd 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -2978,10 +2978,6 @@ impl DeviceManager { device_cfg: &mut DeviceConfig, ) -> DeviceManagerResult<(PciBdf, String)> { let vfio_name = if let Some(id) = &device_cfg.id { - if self.device_tree.lock().unwrap().contains_key(id) { - return Err(DeviceManagerError::DeviceIdAlreadyInUse); - } - id.clone() } else { let id = self.next_device_name(VFIO_DEVICE_NAME_PREFIX)?; @@ -3090,6 +3086,7 @@ impl DeviceManager { legacy_interrupt_group, device_cfg.iommu, pci_device_bdf, + self.restoring, ) .map_err(DeviceManagerError::VfioPciCreate)?; @@ -3111,7 +3108,7 @@ impl DeviceManager { }) .map_err(DeviceManagerError::VfioMapRegion)?; - let mut node = device_node!(vfio_name); + let mut node = device_node!(vfio_name, vfio_pci_device); // Update the device tree with correct resource information. node.resources = new_resources;