From 13972a0edf56abc1bf92f6ab2b76d7488264acf4 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Tue, 19 Aug 2025 22:01:03 +0000 Subject: [PATCH] vmm: Introduce option `--platform iommufd=on|off` This option allows user to configure VFIO device pass-through with iommufd (e.g. vfio cdev mode) or not (e.g. vfio legacy mode). Signed-off-by: Bo Chen --- vmm/src/api/openapi/cloud-hypervisor.yaml | 3 +++ vmm/src/config.rs | 12 ++++++++++-- vmm/src/vm_config.rs | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index 01106a257..7055c9788 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -794,6 +794,9 @@ components: sev_snp: type: boolean default: false + iommufd: + type: boolean + default: false MemoryZoneConfig: required: diff --git a/vmm/src/config.rs b/vmm/src/config.rs index e37809745..b04ba2749 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -804,7 +804,7 @@ impl PlatformConfig { let mut syntax = "Platform configuration parameters \ \"num_pci_segments=,iommu_segments=,\ iommu_address_width=,serial_number=,\ - uuid=,oem_strings=" + uuid=,oem_strings=,iommufd=on|off" .to_string(); if cfg!(feature = "tdx") { @@ -831,7 +831,8 @@ impl PlatformConfig { .add("iommu_address_width") .add("serial_number") .add("uuid") - .add("oem_strings"); + .add("oem_strings") + .add("iommufd"); #[cfg(feature = "tdx")] parser.add("tdx"); #[cfg(feature = "sev_snp")] @@ -858,6 +859,11 @@ impl PlatformConfig { .convert::("oem_strings") .map_err(Error::ParsePlatform)? .map(|v| v.0); + let iommufd = parser + .convert::("iommufd") + .map_err(Error::ParsePlatform)? + .unwrap_or(Toggle(false)) + .0; #[cfg(feature = "tdx")] let tdx = parser .convert::("tdx") @@ -877,6 +883,7 @@ impl PlatformConfig { serial_number, uuid, oem_strings, + iommufd, #[cfg(feature = "tdx")] tdx, #[cfg(feature = "sev_snp")] @@ -4824,6 +4831,7 @@ id=\"{id}\",pci_segment={pci_segment},queue_sizes={queue_sizes}" serial_number: None, uuid: None, oem_strings: None, + iommufd: false, #[cfg(feature = "tdx")] tdx: false, #[cfg(feature = "sev_snp")] diff --git a/vmm/src/vm_config.rs b/vmm/src/vm_config.rs index 88f8af4ac..cca72dde4 100644 --- a/vmm/src/vm_config.rs +++ b/vmm/src/vm_config.rs @@ -133,6 +133,8 @@ pub struct PlatformConfig { #[cfg(feature = "sev_snp")] #[serde(default)] pub sev_snp: bool, + #[serde(default)] + pub iommufd: bool, } pub const DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT: u32 = 1;