mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user