From 8921beccfd3756f8fb04c60179443b43a0fa2303 Mon Sep 17 00:00:00 2001 From: Matt Bilker Date: Sat, 9 Oct 2021 12:11:33 +0000 Subject: [PATCH] Add per-mdev override support --- Cargo.toml | 1 + src/lib.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index bf51448..7355b1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 66f3060..12d1278 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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> = 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 }