mirror of
https://github.com/mbilker/vgpu_unlock-rs.git
synced 2025-06-08 13:28:23 +02:00
Add per-mdev override support
This commit is contained in:
parent
b9a16c426e
commit
8921beccfd
@ -8,5 +8,6 @@ crate-type = ["cdylib"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.102"
|
libc = "0.2.102"
|
||||||
|
parking_lot = "0.11.2"
|
||||||
serde = { version = "1.0.130", features = ["derive"] }
|
serde = { version = "1.0.130", features = ["derive"] }
|
||||||
toml = "0.5.8"
|
toml = "0.5.8"
|
||||||
|
17
src/lib.rs
17
src/lib.rs
@ -18,6 +18,7 @@ use std::path::PathBuf;
|
|||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use libc::RTLD_NEXT;
|
use libc::RTLD_NEXT;
|
||||||
|
use parking_lot::Mutex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
mod dump;
|
mod dump;
|
||||||
@ -27,6 +28,8 @@ mod log;
|
|||||||
use crate::format::{CStrFormat, HexFormat, StraightFormat};
|
use crate::format::{CStrFormat, HexFormat, StraightFormat};
|
||||||
use crate::log::{error, info};
|
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
|
/// 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.
|
/// ioctl to read the PCI device ID and type (and possibly other things) from the GPU.
|
||||||
const REQ_QUERY_GPU: c_ulong = 0xc020462a;
|
const REQ_QUERY_GPU: c_ulong = 0xc020462a;
|
||||||
@ -139,6 +142,8 @@ struct VgpuConfig {
|
|||||||
struct Config<'a> {
|
struct Config<'a> {
|
||||||
#[serde(borrow)]
|
#[serde(borrow)]
|
||||||
profile: HashMap<&'a str, VgpuProfileOverride<'a>>,
|
profile: HashMap<&'a str, VgpuProfileOverride<'a>>,
|
||||||
|
#[serde(borrow)]
|
||||||
|
mdev: HashMap<&'a str, VgpuProfileOverride<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[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 => {
|
OP_READ_START_CALL => {
|
||||||
let config = &*(io_data.result as *const VgpuStart);
|
let config = &*(io_data.result as *const VgpuStart);
|
||||||
info!("{:#?}", config);
|
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 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()) {
|
if let Some(config_override) = config_overrides.profile.get(gpu_type.as_str()) {
|
||||||
info!("Applying profile {} overrides", gpu_type);
|
info!("Applying profile {} overrides", gpu_type);
|
||||||
@ -376,6 +384,15 @@ fn handle_profile_override(config: &mut VgpuConfig) -> bool {
|
|||||||
return false;
|
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
|
true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user