From 7df7061610d468a171cb22ab5424900995167c3f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 7 Jun 2022 16:37:21 +0200 Subject: [PATCH] pci, vmm: Add migratable support to vfio-user devices Based on recent changes to VfioUserPciDevice, the vfio-user devices can now be migrated. Signed-off-by: Sebastien Boeuf --- pci/src/vfio_user.rs | 14 ++++++++++---- vmm/src/device_manager.rs | 10 ++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pci/src/vfio_user.rs b/pci/src/vfio_user.rs index 7a9de41b8..3eb4b53d6 100644 --- a/pci/src/vfio_user.rs +++ b/pci/src/vfio_user.rs @@ -69,6 +69,7 @@ impl VfioUserPciDevice { msi_interrupt_manager: Arc>, legacy_interrupt_group: Option>, bdf: PciBdf, + restoring: bool, ) -> Result { // This is used for the BAR and capabilities only let configuration = PciConfiguration::new( @@ -109,10 +110,15 @@ impl VfioUserPciDevice { vfio_wrapper: Arc::new(vfio_wrapper) as Arc, }; - common.parse_capabilities(bdf); - common - .initialize_legacy_interrupt() - .map_err(VfioUserPciDeviceError::InitializeLegacyInterrupts)?; + // 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() + .map_err(VfioUserPciDeviceError::InitializeLegacyInterrupts)?; + } Ok(Self { id, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 928a20edd..37d272056 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -358,9 +358,6 @@ pub enum DeviceManagerError { /// Could not give the PCI device ID back. PutPciDeviceId(pci::PciRootError), - /// Incorrect device ID as it is already used by another device. - DeviceIdAlreadyInUse, - /// No disk path was specified when one was expected NoDiskPath, @@ -3203,10 +3200,6 @@ impl DeviceManager { device_cfg: &mut UserDeviceConfig, ) -> DeviceManagerResult<(PciBdf, String)> { let vfio_user_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_USER_DEVICE_NAME_PREFIX)?; @@ -3244,6 +3237,7 @@ impl DeviceManager { self.msi_interrupt_manager.clone(), legacy_interrupt_group, pci_device_bdf, + self.restoring, ) .map_err(DeviceManagerError::VfioUserCreate)?; @@ -3288,7 +3282,7 @@ impl DeviceManager { }) .map_err(DeviceManagerError::VfioUserMapRegion)?; - let mut node = device_node!(vfio_user_name); + let mut node = device_node!(vfio_user_name, vfio_user_pci_device); // Update the device tree with correct resource information. node.resources = new_resources;