Nova vGPU lifecycle FFI and the NVIDIA VFIO driver
Subsystems (7)
cover Nova vGPU lifecycle FFI and the NVIDIA VFIO driver
The NVIDIA vGPU VFIO driver is written in C and needs to invoke lifecycle operations owned by the Rust nova-core PF driver. VFIO open creates and boots a vGPU instance; reset resets it and scrubs guest VRAM, and close shuts it down and releases its resources.
The discussion about implementing the VFIO driver in Rust or C is still ongoing [2]. In the meantime, this series updates the patches to build on "Add Rust PCI SR-IOV support" [3] and addresses Alex Williamson's review comments [1, 2].
The first patch publishes these operations through NovaCoreVfApi in Nova's typed SR-IOV registration. Managed SR-IOV keeps the operations and their pinned context alive until the VF drivers have been removed.
The second patch adds the NVIDIA vGPU VFIO PCI variant. It uses the Nova interface when the VF's PF provides a compatible one and supports ordinary PCI passthrough otherwise. Configuration-space and BAR handling stay within the variant; this series does not modify VFIO core.
Changes in response to Alex Williamson's review [1, 2]:
- Restrict matching to NVIDIA 10de:2bb5 in the 3D display class (0302). PFs share this ID with VFs, so matched PFs and VFs without a compatible Nova interface use vfio-pci-core passthrough instead of being rejected by probe.
- Store the assigned PCI device ID in vconfig after enabling the device, so configuration reads use the core's virtualized value.
- Enforce the assigned BAR1 aperture for read, write and mmap, using the same limit reported by GET_REGION_INFO.
- Use reset_prepare/reset_done callbacks to cover configuration-space FLR as well as reset ioctls. Serialize instance open and close with the reset interval. Preserve firmware reset errors for reset ioctls and signal the VFIO error IRQ when configured. These callbacks cannot abort the PCI reset.
- Use SBDF naming and document the packed VF address. Remove the redundant VF check from open; probe selects the appropriate ops.
Subsystem ID reads remain in the variant's configuration handler because the core reads that field from hardware. The C driver preserves the existing VFIO drvdata contract and adds no VFIO-specific pointer to struct pci_dev.
The passthrough path uses vfio-pci-core defaults. This driver has its own enable_sriov parameter and does not inherit vfio-pci's other module options; full module-option parity remains open.
[1] https://lore.kernel.org/nova-gpu/[email protected]/
[2] https://lore.kernel.org/nova-gpu/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Zhi Wang (2):
gpu: nova-core: vgpu: export lifecycle operations to VFIO vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
MAINTAINERS | 1 + drivers/gpu/nova-core/driver.rs | 59 ++- drivers/gpu/nova-core/gpu.rs | 58 ++- drivers/gpu/nova-core/vgpu.rs | 7 + drivers/gpu/nova-core/vgpu/commands.rs | 11 +- drivers/gpu/nova-core/vgpu/fw/commands.rs | 1 + drivers/gpu/nova-core/vgpu/instance.rs | 153 ++++++- drivers/gpu/nova-core/vgpu/vgpu_api.rs | 235 ++++++++++ drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/Kconfig | 21 + drivers/vfio/pci/nvidia-vgpu/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/main.c | 509 ++++++++++++++++++++++ include/drm/nvidia_vgpu.h | 51 +++ rust/bindings/bindings_helper.h | 1 + 15 files changed, 1084 insertions(+), 29 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/vgpu_api.rs create mode 100644 drivers/vfio/pci/nvidia-vgpu/Kconfig create mode 100644 drivers/vfio/pci/nvidia-vgpu/Makefile create mode 100644 drivers/vfio/pci/nvidia-vgpu/main.c create mode 100644 include/drm/nvidia_vgpu.h
base-commit: 4c627824f040e6bd4a10bff4b1c353cdfaf1fc15
PATCH 1/2 gpu: nova-core: vgpu: export lifecycle operations to VFIO
VFIO open queries the VF's assigned vGPU type, allocates its resources, and boots the GSP plugin. Close destroys the instance, and reset resets the plugin and scrubs guest VRAM.
Expose these operations through NovaCoreVfApi, embedded in the PF's typed SR-IOV registration. Its C operations table borrows the API until VF removal. Keep instance locking, activation and teardown in VgpuManager.
Leave the C descriptor empty when vGPU mode is disabled so VF drivers can select their ordinary PCI passthrough path.
--- MAINTAINERS | 1 + drivers/gpu/nova-core/driver.rs | 59 ++++-- drivers/gpu/nova-core/gpu.rs | 58 +++++- drivers/gpu/nova-core/vgpu.rs | 7 + drivers/gpu/nova-core/vgpu/commands.rs | 11 +- drivers/gpu/nova-core/vgpu/fw/commands.rs | 1 + drivers/gpu/nova-core/vgpu/instance.rs | 153 +++++++++++++- drivers/gpu/nova-core/vgpu/vgpu_api.rs | 235 ++++++++++++++++++++++ include/drm/nvidia_vgpu.h | 51 +++++ rust/bindings/bindings_helper.h | 1 + 10 files changed, 548 insertions(+), 29 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/vgpu_api.rs create mode 100644 include/drm/nvidia_vgpu.h
MAINTAINERS +1 -0
@@ -8383,6 +8383,7 @@ C: irc://irc.oftc.net/nouveau T: git https://gitlab.freedesktop.org/drm/rust/kernel.git drm-rust-next F: Documentation/gpu/nova/ F: drivers/gpu/nova-core/ +F: include/drm/nvidia_vgpu.h DRM DRIVER FOR NVIDIA GPUS [RUST] M: Danilo Krummrich <[email protected]>
drivers/gpu/nova-core/driver.rs +46 -13
83 lines not on this page · raw message
drivers/gpu/nova-core/gpu.rs +48 -10
114 lines not on this page · raw message
drivers/gpu/nova-core/vgpu.rs +7 -0
@@ -31,6 +31,8 @@mod instance;mod log;mod scrubber; +#[cfg_attr(not( CONFIG_PCI_IOV ), expect(dead_code))] +pub (crate )mod vgpu_api;mod vram;/// vGPU state detected during GPU construction.
@@ -142,6 +144,11 @@ const fn total_channels(&self) -> u32 { self.total_channels } +/// Returns the live-instance registry. +fn instances (&self) -> &Mutex <VgpuInstances <'gpu>> { + &self.instances + } +fn fifo_engine_list (&self) -> &FifoEngineList { &self.fifo_engine_list }
drivers/gpu/nova-core/vgpu/commands.rs +10 -1
@@ -67,7 +67,6 @@ };/// Query the vGPU type assigned to a VF by its DBDF. -#[expect(dead_code)] pub (super )fn query_assigned_vf_type (cmdq: &Cmdq <'_>, dbdf:Dbdf ) ->Result <u32 > {let request = u64::from (dbdf.into_raw ()).to_le_bytes (); let response =
@@ -210,6 +209,16 @@ pub(super) fn set_plugin_bme( rpc.rpc_call_nvkv (dev, bar0, gfid,RpcMessage ::UpdateBmeState , &bme) } +/// Reset an active GSP plugin. +pub (super )fn reset_plugin ( + dev: &device::Device <device::Bound >, + bar:Bar0 <'_>, + gfid:Gfid , + rpc: &mut PluginRpc <'_, '_>, +) ->Result { + rpc.rpc_call (dev, bar, gfid,RpcMessage ::Reset , &[]) +} +/// Whether a failed allocation may still have transferred CHID ownership to firmware. pub (super )enum CeUtilsAllocError {/// A matching firmware response explicitly rejected the allocation.
drivers/gpu/nova-core/vgpu/fw/commands.rs +1 -0
@@ -33,6 +33,7 @@pub (in crate ::vgpu)enum RpcMessage {VersionNegotiation = bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_VERSION_NEGOTIATION ,SetupConfigParamsAndInit = bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_SETUP_CONFIG_PARAMS_AND_INIT , +Reset = bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_RESET ,UpdateBmeState = bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_UPDATE_BME_STATE , }
drivers/gpu/nova-core/vgpu/instance.rs +148 -5
220 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/vgpu_api.rs new file +235 -0
235 lines not on this page · raw message
include/drm/nvidia_vgpu.h new file +51 -0
51 lines not on this page · raw message
rust/bindings/bindings_helper.h +1 -0
@@ -37,6 +37,7 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_gpuvm.h> #include <drm/drm_ioctl.h> +#include <drm/nvidia_vgpu.h> #include <kunit/test.h> #include <linux/auxiliary_bus.h> #include <linux/bitmap.h>
PATCH 2/2 vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
In reply to Zhi WangNVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
Add a VFIO PCI variant with an override alias for NVIDIA 10de:2bb5 devices with class/subclass 0302. Leave the programming-interface byte unmasked so the generated alias ends in i*, as required by libvirt VFIO variant matching. PFs share this ID with their VFs. Use ordinary PCI passthrough unless a VF can borrow a compatible, complete Nova lifecycle interface through the typed SR-IOV descriptor. Both paths use VFIO PCI core defaults and support PASID attachment; generic passthrough also retains the core DMA-BUF export operation. Provide a driver-local enable_sriov option for PFs bound to this driver.
For vGPU instances, expose the firmware-selected device and subsystem IDs through configuration-space reads and constrain BAR1 region reporting, read, write, and mmap access to the assigned vGPU type's aperture. Coordinate firmware reset through PCI reset callbacks and serialize the entire reset window against instance open and close without retaining a mutex across a multi-device bus reset. Latch firmware reset failures until successful reopen, report them through the VFIO error IRQ and reset ioctls, and preserve core configuration-write return values.
--- drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/Kconfig | 21 ++ drivers/vfio/pci/nvidia-vgpu/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/main.c | 509 ++++++++++++++++++++++++++ 5 files changed, 536 insertions(+) create mode 100644 drivers/vfio/pci/nvidia-vgpu/Kconfig create mode 100644 drivers/vfio/pci/nvidia-vgpu/Makefile create mode 100644 drivers/vfio/pci/nvidia-vgpu/main.c
drivers/vfio/pci/Kconfig +2 -0
@@ -74,4 +74,6 @@ source "drivers/vfio/pci/qat/Kconfig" source "drivers/vfio/pci/xe/Kconfig" +source "drivers/vfio/pci/nvidia-vgpu/Kconfig" + endmenu
drivers/vfio/pci/Makefile +2 -0
@@ -24,3 +24,5 @@ obj-$(CONFIG_NVGRACE_GPU_VFIO_PCI) += nvgrace-gpu/ obj-$(CONFIG_QAT_VFIO_PCI) += qat/ obj-$(CONFIG_XE_VFIO_PCI) += xe/ + +obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia-vgpu/
drivers/vfio/pci/nvidia-vgpu/Kconfig new file +21 -0
@@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NVIDIA_VGPU_VFIO_PCI + tristate "VFIO support for the NVIDIA vGPU" + depends on NOVA_CORE && PCI_IOV + select VFIO_PCI_CORE + help + This option enables VFIO (Virtual Function I/O) support for + NVIDIA virtual GPUs (vGPU). It allows the assignment of a virtual + GPU instance to userspace applications via VFIO, typically used + with hypervisors such as KVM and device emulators like QEMU. + + Devices without an available Nova vGPU interface use ordinary PCI + passthrough. Both paths use the VFIO PCI core defaults; vfio-pci + module options do not apply. The enable_sriov parameter of this + driver controls SR-IOV configuration for PFs bound to it. + + The NVIDIA vGPU allows a physical GPU to be partitioned into + multiple virtual GPUs, each of which can be passed to a virtual + machine as a PCI device using the standard VFIO infrastructure. + + If you don't know what to do here, say N.
drivers/vfio/pci/nvidia-vgpu/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia-vgpu-vfio-pci.o +nvidia-vgpu-vfio-pci-y := main.o
drivers/vfio/pci/nvidia-vgpu/main.c new file +509 -0
509 lines not on this page · raw message