From d4f7f42800f4664fd1f2abd18f769efd51034a3c Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 7 Oct 2021 16:54:32 +0100 Subject: [PATCH] vmm: Add pci_segment option to DeviceConfig Signed-off-by: Rob Bradford --- vmm/src/config.rs | 27 +++++++++++++++++++++------ vmm/src/device_manager.rs | 5 ++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 2f38a7f9c..34b15badc 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -1654,14 +1654,16 @@ pub struct DeviceConfig { pub iommu: bool, #[serde(default)] pub id: Option, + #[serde(default)] + pub pci_segment: u16, } impl DeviceConfig { pub const SYNTAX: &'static str = - "Direct device assignment parameters \"path=,iommu=on|off,id=\""; + "Direct device assignment parameters \"path=,iommu=on|off,id=,pci_segment=\""; pub fn parse(device: &str) -> Result { let mut parser = OptionParser::new(); - parser.add("path").add("id").add("iommu"); + parser.add("path").add("id").add("iommu").add("pci_segment"); parser.parse(device).map_err(Error::ParseDevice)?; let path = parser @@ -1674,7 +1676,17 @@ impl DeviceConfig { .unwrap_or(Toggle(false)) .0; let id = parser.get("id"); - Ok(DeviceConfig { path, iommu, id }) + let pci_segment = parser + .convert::("pci_segment") + .map_err(Error::ParseDevice)? + .unwrap_or_default(); + + Ok(DeviceConfig { + path, + iommu, + id, + pci_segment, + }) } } @@ -2754,7 +2766,8 @@ mod tests { DeviceConfig { path: PathBuf::from("/path/to/device"), id: None, - iommu: false + iommu: false, + ..Default::default() } ); @@ -2763,7 +2776,8 @@ mod tests { DeviceConfig { path: PathBuf::from("/path/to/device"), id: None, - iommu: true + iommu: true, + ..Default::default() } ); @@ -2772,7 +2786,8 @@ mod tests { DeviceConfig { path: PathBuf::from("/path/to/device"), id: Some("mydevice0".to_owned()), - iommu: true + iommu: true, + ..Default::default() } ); diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index e658919c2..92c0c7e7e 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -2851,8 +2851,7 @@ impl DeviceManager { &mut self, device_cfg: &mut DeviceConfig, ) -> DeviceManagerResult<(u32, String)> { - // TODO: Fill with PCI segment ID from config when available - let pci_segment_id = 0; + let pci_segment_id = device_cfg.pci_segment; let pci_device_bdf = self.pci_segments[pci_segment_id as usize].next_device_bdf()?; let mut needs_dma_mapping = false; @@ -3435,7 +3434,7 @@ impl DeviceManager { let (device_id, device_name) = self.add_passthrough_device(device_cfg)?; // Update the PCIU bitmap - self.pci_segments[0].pci_devices_up |= 1 << (device_id >> 3); + self.pci_segments[device_cfg.pci_segment as usize].pci_devices_up |= 1 << (device_id >> 3); Ok(PciDeviceInfo { id: device_name,