From a42d16a6a4b00a1c16c8026447043e86731e7f6f Mon Sep 17 00:00:00 2001 From: "alex.lyn" Date: Fri, 11 Apr 2025 16:51:13 +0800 Subject: [PATCH] kata-types: Introduce pcie_switch_port in configuration (1) Introduce new field `pcie_switch_port` for switch ports. (2) Add related checking logics in vmms(dragonball, qemu) Fixes #10361 Signed-off-by: alex.lyn --- .../src/config/hypervisor/dragonball.rs | 1 + .../kata-types/src/config/hypervisor/mod.rs | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libs/kata-types/src/config/hypervisor/dragonball.rs b/src/libs/kata-types/src/config/hypervisor/dragonball.rs index 84cfab092a..089bc2672c 100644 --- a/src/libs/kata-types/src/config/hypervisor/dragonball.rs +++ b/src/libs/kata-types/src/config/hypervisor/dragonball.rs @@ -151,6 +151,7 @@ impl ConfigPlugin for DragonballConfig { if db.device_info.hotplug_vfio_on_root_bus || db.device_info.default_bridges > 0 || db.device_info.pcie_root_port > 0 + || db.device_info.pcie_switch_port > 0 { return Err(eother!( "dragonball hypervisor does not support PCI hotplug options" diff --git a/src/libs/kata-types/src/config/hypervisor/mod.rs b/src/libs/kata-types/src/config/hypervisor/mod.rs index ef7d9773d5..b5b0a26251 100644 --- a/src/libs/kata-types/src/config/hypervisor/mod.rs +++ b/src/libs/kata-types/src/config/hypervisor/mod.rs @@ -474,14 +474,18 @@ pub struct DeviceInfo { #[serde(default)] pub hotplug_vfio_on_root_bus: bool, - /// Before hot plugging a PCIe device, you need to add a pcie_root_port device. - /// - /// Use this parameter when using some large PCI bar devices, such as Nvidia GPU. - /// The value means the number of pcie_root_port. - /// This value is valid when hotplug_vfio_on_root_bus is true and machine_type is "q35" + /// This value of pcie_root_port device indicates that how many root ports to + /// be created when VM creation. + /// It's valid when hotplug_vfio_on_root_bus is true and machine_type is "q35". #[serde(default)] pub pcie_root_port: u32, + /// This value of pcie_switch_port device indicates that how many switch ports to + /// be created when VM creation. + /// It's valid when hotplug_vfio_on_root_bus is true, and machine_type is "q35". + #[serde(default)] + pub pcie_switch_port: u32, + /// Enable vIOMMU, default false /// /// Enabling this will result in the VM having a vIOMMU device. This will also add the @@ -520,6 +524,13 @@ impl DeviceInfo { self.default_bridges )); } + // It's not allowed to set PCIe RootPort and SwitchPort at the same time. + if self.pcie_root_port > 0 && self.pcie_switch_port > 0 { + return Err(eother!( + "Root Port and Switch Port set at the same time is forbidden." + )); + } + Ok(()) } }