From 20b9f95afda2963b654830d46eb9341bed40ef33 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 11 Feb 2022 09:33:55 +0000 Subject: [PATCH] vmm: Attach all devices from specified segments to the IOMMU Since the devices behind the IOMMU cannot be changed at runtime we offer the ability to place all devices on user chosen segments behind the IOMMU. This allows the hotplugging of devices behind the IOMMU provided that they are assigned to a segment that is located behind the iommu. Fixes: #911 Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 2c6eefec7..67280228b 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1246,6 +1246,20 @@ impl DeviceManager { let mut vfio_user_iommu_device_ids = self.add_user_devices()?; iommu_attached_devices.append(&mut vfio_user_iommu_device_ids); + // Add all devices from forced iommu segments + if let Some(platform_config) = self.config.lock().unwrap().platform.as_ref() { + if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() { + for segment in iommu_segments { + for device in 0..32 { + let bdf = PciBdf::new(*segment, 0, device, 0); + if !iommu_attached_devices.contains(&bdf) { + iommu_attached_devices.push(bdf); + } + } + } + } + } + if let Some(iommu_device) = iommu_device { let dev_id = self.add_virtio_pci_device(iommu_device, &None, iommu_id, 0)?; self.iommu_attached_devices = Some((dev_id, iommu_attached_devices));