From f71f6da907938aef6a90cf6df42889a8fa26a323 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 UserDeviceConfig Signed-off-by: Rob Bradford --- vmm/src/config.rs | 18 ++++++++++++++---- vmm/src/device_manager.rs | 5 ++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 34b15badc..32f48fbc0 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -1695,23 +1695,33 @@ pub struct UserDeviceConfig { pub socket: PathBuf, #[serde(default)] pub id: Option, + #[serde(default)] + pub pci_segment: u16, } impl UserDeviceConfig { - pub const SYNTAX: &'static str = "Userspace device socket=,id=\""; + pub const SYNTAX: &'static str = + "Userspace device socket=,id=,pci_segment=\""; pub fn parse(user_device: &str) -> Result { let mut parser = OptionParser::new(); - parser.add("socket").add("id"); + parser.add("socket").add("id").add("pci_segment"); parser.parse(user_device).map_err(Error::ParseUserDevice)?; let socket = parser .get("socket") .map(PathBuf::from) .ok_or(Error::ParseUserDeviceSocketMissing)?; - let id = parser.get("id"); + let pci_segment = parser + .convert::("pci_segment") + .map_err(Error::ParseUserDevice)? + .unwrap_or_default(); - Ok(UserDeviceConfig { socket, id }) + Ok(UserDeviceConfig { + socket, + id, + pci_segment, + }) } } #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Default)] diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 92c0c7e7e..c91685139 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -3063,8 +3063,7 @@ impl DeviceManager { &mut self, device_cfg: &mut UserDeviceConfig, ) -> 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 legacy_interrupt_group = @@ -3449,7 +3448,7 @@ impl DeviceManager { let (device_id, device_name) = self.add_vfio_user_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,