vmm: Accept an externally-opened iommufd FD

The CLI `--platform` option now accepts `iommufd_fd=<n>` alongside the
existing `iommufd=on|off`.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
Assisted-by: Claude:Opus-4.7
This commit is contained in:
Bo Chen
2026-05-28 17:56:12 +00:00
committed by Rob Bradford
parent e4934de3c9
commit 867b5796a5
2 changed files with 88 additions and 14 deletions
+18
View File
@@ -159,6 +159,9 @@ pub struct PlatformConfig {
pub sev_snp: bool,
#[serde(default)]
pub iommufd: bool,
// FDs are not serialized and any deserialized value is invalid; see NetConfig::fds.
#[serde(default, deserialize_with = "deserialize_platformconfig_iommufd_fd")]
pub iommufd_fd: Option<i32>,
#[serde(default = "default_platformconfig_vfio_p2p_dma")]
pub vfio_p2p_dma: bool,
}
@@ -207,6 +210,21 @@ impl PlatformConfig {
}
}
fn deserialize_platformconfig_iommufd_fd<'de, D>(d: D) -> Result<Option<i32>, D::Error>
where
D: serde::Deserializer<'de>,
{
let invalid_fd: Option<i32> = Option::deserialize(d)?;
if invalid_fd.is_some() {
debug!(
"FD in 'PlatformConfig::iommufd_fd' won't be deserialized as it is most likely invalid now. Deserializing it as -1."
);
Ok(Some(-1))
} else {
Ok(None)
}
}
pub const DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT: u32 = 1;
fn default_pci_segment_aperture_weight() -> u32 {