diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index cb88fb8cc..1f1dd2f05 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1711,6 +1711,7 @@ impl DeviceManager { &id, handle.pci_common.pci_segment, handle.dma_handler, + handle.pci_common.pci_device_id, )?; // Track device BDF for Generic Initiator support @@ -1742,7 +1743,8 @@ impl DeviceManager { } if let Some(iommu_device) = iommu_device { - let dev_id = self.add_virtio_pci_device(iommu_device, &None, &iommu_id, 0, None)?; + let dev_id = + self.add_virtio_pci_device(iommu_device, &None, &iommu_id, 0, None, None)?; self.iommu_attached_devices = Some((dev_id, iommu_attached_devices)); } } @@ -3656,7 +3658,7 @@ impl DeviceManager { let pci_segment_id = 0x0_u16; let (pci_segment_id, pci_device_bdf, resources) = - self.pci_resources(&id, pci_segment_id)?; + self.pci_resources(&id, pci_segment_id, None)?; info!("Creating pvmemcontrol device: id = {id}"); let (pvmemcontrol_pci_device, pvmemcontrol_bus_device) = @@ -3922,8 +3924,11 @@ impl DeviceManager { id }; - let (pci_segment_id, pci_device_bdf, resources) = - self.pci_resources(&vfio_name, device_cfg.pci_common.pci_segment)?; + let (pci_segment_id, pci_device_bdf, resources) = self.pci_resources( + &vfio_name, + device_cfg.pci_common.pci_segment, + device_cfg.pci_common.pci_device_id, + )?; let mut needs_dma_mapping = false; @@ -4184,8 +4189,11 @@ impl DeviceManager { id }; - let (pci_segment_id, pci_device_bdf, resources) = - self.pci_resources(&vfio_user_name, device_cfg.pci_common.pci_segment)?; + let (pci_segment_id, pci_device_bdf, resources) = self.pci_resources( + &vfio_user_name, + device_cfg.pci_common.pci_segment, + device_cfg.pci_common.pci_device_id, + )?; let legacy_interrupt_group = if let Some(legacy_interrupt_manager) = &self.legacy_interrupt_manager { @@ -4301,6 +4309,7 @@ impl DeviceManager { virtio_device_id: &str, pci_segment_id: u16, dma_handler: Option>, + pci_device_id: Option, ) -> DeviceManagerResult { let id = format!("{VIRTIO_PCI_DEVICE_NAME_PREFIX}-{virtio_device_id}"); @@ -4309,7 +4318,7 @@ impl DeviceManager { node.children = vec![virtio_device_id.to_string()]; let (pci_segment_id, pci_device_bdf, resources) = - self.pci_resources(&id, pci_segment_id)?; + self.pci_resources(&id, pci_segment_id, pci_device_id)?; // Update the existing virtio node by setting the parent. if let Some(node) = self.device_tree.lock().unwrap().get_mut(virtio_device_id) { @@ -4446,7 +4455,7 @@ impl DeviceManager { info!("Creating pvpanic device {id}"); let (pci_segment_id, pci_device_bdf, resources) = - self.pci_resources(&id, pci_segment_id)?; + self.pci_resources(&id, pci_segment_id, None)?; let snapshot = snapshot_from_id(self.snapshot.as_ref(), id.as_str()); @@ -4484,7 +4493,7 @@ impl DeviceManager { info!("Creating ivshmem device {id}"); let (pci_segment_id, pci_device_bdf, resources) = - self.pci_resources(&id, pci_segment_id)?; + self.pci_resources(&id, pci_segment_id, None)?; let snapshot = snapshot_from_id(self.snapshot.as_ref(), id.as_str()); let ivshmem_ops = Arc::new(Mutex::new(IvshmemHandler { @@ -4529,6 +4538,7 @@ impl DeviceManager { &self, id: &str, pci_segment_id: u16, + pci_device_id: Option, ) -> DeviceManagerResult<(u16, PciBdf, Option>)> { // Look for the id in the device tree. If it can be found, that means // the device is being restored, otherwise it's created from scratch. @@ -4556,7 +4566,7 @@ impl DeviceManager { (pci_segment_id, pci_device_bdf, resources) } else { let pci_device_bdf = - self.pci_segments[pci_segment_id as usize].allocate_device_id(None)?; + self.pci_segments[pci_segment_id as usize].allocate_device_id(pci_device_id)?; (pci_segment_id, pci_device_bdf, None) }) @@ -5075,6 +5085,7 @@ impl DeviceManager { &id, handle.pci_common.pci_segment, handle.dma_handler, + handle.pci_common.pci_device_id, )?; // Update the PCIU bitmap