Add per-mdev override support

This commit is contained in:
Matt Bilker 2021-10-09 12:11:33 +00:00
parent b9a16c426e
commit 8921beccfd
No known key found for this signature in database
GPG Key ID: 69ADF8AEB6C8B5D1
2 changed files with 18 additions and 0 deletions

View File

@ -8,5 +8,6 @@ crate-type = ["cdylib"]
[dependencies]
libc = "0.2.102"
parking_lot = "0.11.2"
serde = { version = "1.0.130", features = ["derive"] }
toml = "0.5.8"

View File

@ -18,6 +18,7 @@ use std::path::PathBuf;
use std::str;
use libc::RTLD_NEXT;
use parking_lot::Mutex;
use serde::Deserialize;
mod dump;
@ -27,6 +28,8 @@ mod log;
use crate::format::{CStrFormat, HexFormat, StraightFormat};
use crate::log::{error, info};
static LAST_MDEV_UUID: Mutex<Option<Uuid>> = parking_lot::const_mutex(None);
/// Value of the "request" argument used by `nvidia-vgpud` and `nvidia-vgpu-mgr` when calling
/// ioctl to read the PCI device ID and type (and possibly other things) from the GPU.
const REQ_QUERY_GPU: c_ulong = 0xc020462a;
@ -139,6 +142,8 @@ struct VgpuConfig {
struct Config<'a> {
#[serde(borrow)]
profile: HashMap<&'a str, VgpuProfileOverride<'a>>,
#[serde(borrow)]
mdev: HashMap<&'a str, VgpuProfileOverride<'a>>,
}
#[derive(Deserialize)]
@ -316,6 +321,8 @@ pub unsafe extern "C" fn ioctl(fd: RawFd, request: c_ulong, argp: *mut c_void) -
OP_READ_START_CALL => {
let config = &*(io_data.result as *const VgpuStart);
info!("{:#?}", config);
*LAST_MDEV_UUID.lock() = Some(config.uuid);
}
_ => {}
}
@ -368,6 +375,7 @@ fn handle_profile_override(config: &mut VgpuConfig) -> bool {
};
let gpu_type = format!("nvidia-{}", config.gpu_type);
let mdev_uuid = LAST_MDEV_UUID.lock().take();
if let Some(config_override) = config_overrides.profile.get(gpu_type.as_str()) {
info!("Applying profile {} overrides", gpu_type);
@ -376,6 +384,15 @@ fn handle_profile_override(config: &mut VgpuConfig) -> bool {
return false;
}
}
if let Some(mdev_uuid) = mdev_uuid.map(|uuid| uuid.to_string()) {
if let Some(config_override) = config_overrides.mdev.get(mdev_uuid.as_str()) {
info!("Applying mdev UUID {} profile overrides", mdev_uuid);
if !apply_profile_override(config, &gpu_type, config_override) {
return false;
}
}
}
true
}