vmm: DeviceConfig: Add fd field for an externally-opened vfio cdev

Add a new `fd: Option<i32>` field to DeviceConfig so a caller can
supply a pre-opened vfio cdev FD (e.g. /dev/vfio/devices/vfioN) in
addition to the existing sysfs path. The CLI `--device` option now
accepts `fd=<n>`, parsed alongside the existing options.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
Assisted-by: Claude:Opus-4.7
This commit is contained in:
Bo Chen
2026-04-28 03:49:20 +00:00
committed by Rob Bradford
parent bc5363823a
commit 0e4b98ae8e
2 changed files with 23 additions and 1 deletions
+18
View File
@@ -760,12 +760,30 @@ pub struct DeviceConfig {
pub pci_common: PciDeviceCommonConfig,
#[serde(default)]
pub path: Option<PathBuf>,
// FDs are not serialized and any deserialized value is invalid; see NetConfig::fds.
#[serde(default, deserialize_with = "deserialize_deviceconfig_fd")]
pub fd: Option<i32>,
#[serde(default)]
pub x_nv_gpudirect_clique: Option<u8>,
#[serde(default)]
pub x_exclude_mmap_bars: Vec<u64>,
}
fn deserialize_deviceconfig_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 'DeviceConfig' won't be deserialized as it is most likely invalid now. Deserializing it as -1."
);
Ok(Some(-1))
} else {
Ok(None)
}
}
impl ApplyLandlock for DeviceConfig {
fn apply_landlock(&self, landlock: &mut Landlock) -> LandlockResult<()> {
let path = self