From 826e7b246eda5249126f2f910261f16ef81f9229 Mon Sep 17 00:00:00 2001 From: kharbranth Date: Thu, 5 May 2022 20:57:44 -0400 Subject: [PATCH 1/2] Allow unlocking VM migration/snapshot support This also requires NV_KVM_MIGRATION_UAPI to be set to 1 when building the `nvidia-vgpu-vfio` kernel module, hence why unlocking this feature is only conditionally enabled, since not everyone will want it. Signed-off-by: kharbranth --- src/config.rs | 7 +++++++ src/lib.rs | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index a8cf2b0..09b4ea1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,12 +7,18 @@ impl Defaults { const fn unlock() -> bool { true } + #[inline] + const fn unlock_migration() -> bool { + false + } } #[derive(Deserialize)] pub struct Config { #[serde(default = "Defaults::unlock")] pub unlock: bool, + #[serde(default = "Defaults::unlock_migration")] + pub unlock_migration: bool, } impl Default for Config { @@ -20,6 +26,7 @@ impl Default for Config { fn default() -> Self { Self { unlock: Defaults::unlock(), + unlock_migration: Defaults::unlock_migration(), } } } diff --git a/src/lib.rs b/src/lib.rs index 17fa886..af1e027 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,6 +75,9 @@ const OP_READ_PCI_ID: u32 = 0x20801801; /// `result` is a pointer to `VgpuConfig`. const OP_READ_VGPU_CFG: u32 = 0xa0820102; +/// `result` is a pointer to `bool`. +const OP_READ_VGPU_MIG_CAP: u32 = 0xa0810112; + /// `nvidia-vgpu-mgr` expects this value for a vGPU capable GPU. const DEV_TYPE_VGPU_CAPABLE: u32 = 3; @@ -340,10 +343,16 @@ pub unsafe extern "C" fn ioctl(fd: RawFd, request: c_ulong, argp: *mut c_void) - // Set device type to vGPU capable. *dev_type_ptr = DEV_TYPE_VGPU_CAPABLE; - } + }, + OP_READ_VGPU_MIG_CAP if CONFIG.unlock_migration => { + let mig_enabled: *mut bool = io_data.result.cast(); + + *mig_enabled = true; + }, _ => {} } + if io_data.status == STATUS_OK { match io_data.op_type { OP_READ_VGPU_CFG => { From a6d067f5594a9b12ef77320d81bddd322fcd4d09 Mon Sep 17 00:00:00 2001 From: kharbranth Date: Thu, 5 May 2022 21:07:14 -0400 Subject: [PATCH 2/2] Add documentation for unlocking VM migration/snapshotting Signed-off-by: kharbranth --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index a0161ff..f1d82c2 100644 --- a/README.md +++ b/README.md @@ -56,4 +56,13 @@ cuda_enabled = 1 frl_enabled = 0 ``` +If you want to enable VM migration or snapshotting, you must +recompile the `nvidia-vgpu-vfio` kernel module with `NV_KVM_MIGRATION_UAPI` +equal to 1. Then, create the file `/etc/vgpu_unlock/config.toml` and add the +following: + +```toml +unlock_migration = true +``` + Happy hacking!