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 <alex.lyn@antgroup.com>
This commit is contained in:
alex.lyn 2025-04-11 16:51:13 +08:00
parent af3c601a92
commit a42d16a6a4
2 changed files with 17 additions and 5 deletions

View File

@ -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"

View File

@ -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(())
}
}