Introduce NVIDIA vGPU manager and VFIO variant driver
Subsystems (8)
cover Introduce NVIDIA vGPU manager and VFIO variant driver
Add the nova-core support needed to create and manage NVIDIA vGPU instances, together with the NVIDIA vGPU VFIO variant driver that consumes the lifecycle interface.
The control path introduced by this series is:
+-----------------------+ +-----------------------+
| Linux guest | | Windows guest |
| NVIDIA guest driver | | NVIDIA guest driver |
+-----------+-----------+ +-----------+-----------+
| |
+-----------v-----------+ +-----------v-----------+
| QEMU (VFIO user) | | QEMU (VFIO user) |
+-----------+-----------+ +-----------+-----------+
+----------------+----------------+
|
+-------v-------+
| VFIO core |
+-------+-------+
|
+---------------------v---------------------+
| NVIDIA vGPU VFIO variant driver |
+---------------------+---------------------+
|
+---------------+----------------------+
| binds PCI VF | PF lifecycle API
| | open / close / reset
v v
+--------+--------+ +-------------+-------------+
| PCI VF(s) | | nova-core (PF driver) |
| (virtual GPU) | | vGPU Manager |
+--------+--------+ | VRAM / channels ... |
| +-------------+-------------+
| |
+-------------v--------------------------------------v----------------+
| NVIDIA physical GPU |
| VF resources PF / GSP / VRAM |
+---------------------------------------------------------------------+On the nova-core side, the PF driver owns the GPU firmware-facing part of vGPU management. It already detects vGPU mode before GSP boot and supplies the SR-IOV topology to the GPU System Processor firmware (GSP-RM). This series extends it to:
- Retain the firmware-reported VMMU segment size and FIFO engine ordering after GSP_INIT, together with nova-core's channel capacity.
- Add VramBlock and VramRegion ownership plus Bar1Map for bounded CPU mappings of VRAM-backed control structures.
- Query GSP-RM through its command queue for the vGPU type already assigned to a VF and its properties.
- Build a layout-validated, profile-wide pool of paired framebuffer and management-heap slots, reserve contiguous channel ranges, and keep live allocations in a per-PF instance registry.
- Use the typed r000 firmware bindings for control and response layouts, message IDs, and firmware-defined region sizes.
- Handle GMC transactions over the GSP queues, match GMC replies by command and sequence, dispatch interleaved RM RPCs from the shared GSP-to-CPU message queue, and consume stale GMC messages.
- Implement the GMCAPI bootload, shutdown, and cleanup operations with typed channel and resource maps for each plugin instance.
- Establish the BAR1-backed PluginRpc channel, negotiate its protocol, and send the VM configuration and plugin BME-state update.
- Use per-instance CeUtils channels to scrub guest framebuffer memory on allocation, reset, and shutdown. If ownership or completion is uncertain, keep the affected VRAM and channels out of the allocators.
- Expose the three per-instance plugin log buffers through debugfs with the header needed by nvlog_decoder.
- Keep resource locking, teardown, and rollback inside nova-core.
- Select the firmware-defined 48-VM WPR2 heap when a device advertises more than 32 VFs.
On the VFIO side, the NVIDIA vGPU VFIO variant driver:
- Binds only to an NVIDIA VF explicitly selected through driver_override.
- Derives the guest function ID (GFID) from the SR-IOV VF index and registers a vfio-pci-core device.
- Presents the vGPU PCI device and subsystem IDs returned by nova-core, and limits the reported framebuffer BAR size.
- Delegates the remaining PCI and VFIO operations to vfio-pci-core and uses the standard VFIO physical-device helpers for IOMMUFD.
The ownership boundary between the two drivers is visible at these lifecycle points:
- Open: after vfio_pci_core_enable(), the variant driver passes the PF returned by pci_physfn(vf), the GFID, the VF's PCI domain/bus/device/function (DBDF), and the calling process TGID to nvidia_vgpu_open(). nova-core validates the PF and GFID, creates and activates the instance, and returns the guest-visible PCI IDs and BAR1 size. On failure, the variant driver disables the vfio-pci-core device; on success, it calls vfio_pci_core_finish_enable().
- Reset: the variant driver first calls nvidia_vgpu_reset(). nova-core sends the plugin reset RPC and scrubs the guest framebuffer. Only after that succeeds is VFIO_DEVICE_RESET passed to vfio-pci-core for the PCI function reset.
- Close: the variant driver invokes the void nvidia_vgpu_close() interface to request plugin shutdown, framebuffer scrubbing, and resource release from nova-core, then closes the vfio-pci-core device.
The cross-module interface is therefore limited to three GPL-only symbols in NOVA_CORE_VGPU: nvidia_vgpu_open(), nvidia_vgpu_close(), and nvidia_vgpu_reset().
This is a ground-up rework of the earlier vGPU RFC [1]. In particular, the vGPU manager has been moved from the VFIO driver into the nova-core implementation, and the VFIO side no longer carries copies of RM firmware headers. The VFIO driver attaches to the VF and uses its PF's nova-core state for management, as discussed in that thread.
The patches are organized as follows:
1-4 Initialize VgpuManager and add the memory and firmware building
blocks.
5-8 Allocate instances and implement GMC, plugin boot, and RPC. 9-10 Scrub guest framebuffer memory and expose plugin diagnostics. 11-12 Export the lifecycle API and add its VFIO consumer. 13 Select the larger WPR2 heap for 48-VF devices.
The series is based on the nova-core r000 GSP, memory-management, SR-IOV, Rust bitmap/id-pool, and PCI abstraction work. The exact base commit is recorded below, and the complete prerequisite stack is available in [2].
[1] https://lore.kernel.org/kvm/[email protected]/
[2] https://github.com/zhiwang-nvidia/nova-core/tree/zhi/nova-vgpu-wip-nova-gsp-20260902
Alok Kumar (1):
gpu: nova-core: vgpu: add VRAM slot allocator
Zhi Wang (12):
gpu: nova-core: vgpu: add post-GSP-boot vGPU initialization
gpu: nova-core: mm: add VramBlock and Bar1Map
gpu: nova-core: vgpu: add r000 plugin bindings
gpu: nova-core: vgpu: add instance create/destroy
gpu: nova-core: gsp: add GMC transaction helpers
gpu: nova-core: vgpu: add vGPU bootload
gpu: nova-core: vgpu: implement PluginRpc channel and config params
gpu: nova-core: vgpu: scrub guest framebuffer memory with CeUtils
gpu: nova-core: vgpu: export plugin log buffers via debugfs
gpu: nova-core: vgpu: export lifecycle operations to VFIO vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
gpu: nova-core: reserve the 48-VM WPR2 heap
drivers/gpu/nova-core/driver.rs | 42 +- drivers/gpu/nova-core/fb.rs | 2 +- drivers/gpu/nova-core/gpu.rs | 184 +++-- drivers/gpu/nova-core/gpu/channel.rs | 3 + drivers/gpu/nova-core/gsp.rs | 29 +- drivers/gpu/nova-core/gsp/boot.rs | 13 +- drivers/gpu/nova-core/gsp/cmdq.rs | 356 +++++++-- drivers/gpu/nova-core/gsp/commands.rs | 78 +- drivers/gpu/nova-core/gsp/fw.rs | 63 +- drivers/gpu/nova-core/gsp/fw/commands.rs | 185 ++++- .../gpu/nova-core/gsp/fw/r000_00/bindings.rs | 175 +++++ drivers/gpu/nova-core/gsp/hal/gh100.rs | 2 +- drivers/gpu/nova-core/gsp/hal/tu102.rs | 2 +- drivers/gpu/nova-core/mm.rs | 6 +- drivers/gpu/nova-core/mm/bar_user.rs | 183 ++++- drivers/gpu/nova-core/mm/vram.rs | 187 +++++ drivers/gpu/nova-core/nova_core_exports.c | 5 + drivers/gpu/nova-core/vgpu.rs | 91 --- drivers/gpu/nova-core/vgpu/bootload.rs | 162 ++++ drivers/gpu/nova-core/vgpu/consts.rs | 33 + drivers/gpu/nova-core/vgpu/fw.rs | 490 ++++++++++++ drivers/gpu/nova-core/vgpu/fw/commands.rs | 28 + drivers/gpu/nova-core/vgpu/instance.rs | 705 ++++++++++++++++++ drivers/gpu/nova-core/vgpu/log.rs | 167 +++++ drivers/gpu/nova-core/vgpu/mod.rs | 170 +++++ drivers/gpu/nova-core/vgpu/plugin_rpc.rs | 274 +++++++ drivers/gpu/nova-core/vgpu/scrubber.rs | 474 ++++++++++++ drivers/gpu/nova-core/vgpu/vfio.rs | 282 +++++++ drivers/gpu/nova-core/vgpu/vram.rs | 140 ++++ drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/Kconfig | 16 + drivers/vfio/pci/nvidia-vgpu/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/main.c | 253 +++++++ include/drm/nvidia_vgpu.h | 28 + rust/bindings/bindings_helper.h | 1 + 36 files changed, 4536 insertions(+), 299 deletions(-) create mode 100644 drivers/gpu/nova-core/mm/vram.rs delete mode 100644 drivers/gpu/nova-core/vgpu.rs create mode 100644 drivers/gpu/nova-core/vgpu/bootload.rs create mode 100644 drivers/gpu/nova-core/vgpu/consts.rs create mode 100644 drivers/gpu/nova-core/vgpu/fw.rs create mode 100644 drivers/gpu/nova-core/vgpu/fw/commands.rs create mode 100644 drivers/gpu/nova-core/vgpu/instance.rs create mode 100644 drivers/gpu/nova-core/vgpu/log.rs create mode 100644 drivers/gpu/nova-core/vgpu/mod.rs create mode 100644 drivers/gpu/nova-core/vgpu/plugin_rpc.rs create mode 100644 drivers/gpu/nova-core/vgpu/scrubber.rs create mode 100644 drivers/gpu/nova-core/vgpu/vfio.rs create mode 100644 drivers/gpu/nova-core/vgpu/vram.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: a1dc9fdea9ab15e5df1bd6af1f6de2e40079f02d
Signature · 1 line
2.53.0
PATCH 1/13 gpu: nova-core: vgpu: add post-GSP-boot vGPU initialization
GSP-RM does not expose the parameters needed to divide resources among vGPU instances until GSP_INIT completes. Before this point VgpuManager only knows whether vGPU mode is enabled, so it cannot provide the engine topology, VMMU alignment, or channel capacity required by instance management.
Decode the VMMU segment size and ordered FIFO engine table from the typed GSP_INIT NVKV response. Retain only host-driven engines while preserving hardware FIFO order. After a successful GSP_INIT, initialize the manager with these values and the 2048-channel capacity, but retain them only when vGPU mode is enabled.
Move VgpuManager into Gpu and let it borrow the pinned ChannelIdPool. Create that pool with the same channel capacity, order the Gpu fields so the manager is dropped before the memory manager, GSP resources, and its channel pool, and pass it separately to GSP boot so unload resources do not retain a manager reference. Keep a copy of the detected mode in the GPU-owned GSP runtime data instead of passing it through the HAL calls.
--- drivers/gpu/nova-core/gpu.rs | 53 ++++++--- drivers/gpu/nova-core/gpu/channel.rs | 3 + drivers/gpu/nova-core/gsp.rs | 12 +- drivers/gpu/nova-core/gsp/boot.rs | 13 ++- drivers/gpu/nova-core/gsp/commands.rs | 33 ++++++ drivers/gpu/nova-core/gsp/fw/commands.rs | 36 ++++++ drivers/gpu/nova-core/gsp/hal/gh100.rs | 2 +- drivers/gpu/nova-core/gsp/hal/tu102.rs | 2 +- drivers/gpu/nova-core/vgpu.rs | 91 --------------- drivers/gpu/nova-core/vgpu/mod.rs | 139 +++++++++++++++++++++++ 10 files changed, 274 insertions(+), 110 deletions(-) delete mode 100644 drivers/gpu/nova-core/vgpu.rs create mode 100644 drivers/gpu/nova-core/vgpu/mod.rs
drivers/gpu/nova-core/gpu.rs +40 -13
@@ -53,6 +53,11 @@mod channel;mod hal; +pub (crate )use self::channel::{ +ChannelIdPool , +TOTAL_CHANNELS ,// +}; +macro_rules! define_chipset { ({ $($variant:ident = $value:expr),* $(,)* }) => {
@@ -291,8 +296,6 @@ struct GspResources<'gpu> {// TODO: use different resource types for each boot method, and make the relevant Gsp methods // generic against them. fsp: Option<Fsp<'gpu>>, - /// vGPU state detected before GSP boot. - vgpu: VgpuManager,/// GSP runtime data. #[pin] gsp: Gsp,
@@ -304,6 +307,10 @@ struct GspResources<'gpu> {#[pin_data] pub (crate )struct Gpu <'gpu> { spec:Spec , +/// vGPU state and firmware parameters. +/// +/// Declared before MM and BAR1 so live instances are torn down before their resources. + vgpu:VgpuManager <'gpu>,/// GPU memory manager owning memory management resources. /// /// Must be kept declared *before* `gsp_resources`, so that its components are dropped while
@@ -314,6 +321,11 @@ pub(crate) struct Gpu<'gpu> {/// GSP and its resources. #[pin] gsp_resources: GspResources<'gpu>, +/// Channel ID pool borrowed by the vGPU manager and its live instances. +/// +/// Declared after `vgpu` so the manager is dropped before the pool. +#[pin] + chid_pool: ChannelIdPool,/// System memory page required for flushing all pending GPU-side memory writes done through /// PCIE into system memory, via sysmembar (A GPU-initiated HW memory-barrier operation). ///
@@ -342,7 +354,6 @@ fn drop(self: Pin<&mut Self>) { gsp_falcon: &*this.gsp_falcon, sec2_falcon: &*this.sec2_falcon, fsp: this.fsp.as_mut(), - vgpu: &*this.vgpu, }, bundle, )
@@ -402,6 +413,18 @@ pub(crate) fn new(// Initialize this early because `gsp_resources` depends on it. sysmem_flush: SysmemFlush::register(dev, bar, spec.chipset)?, + chid_pool <- ChannelIdPool::new(cv!(TOTAL_CHANNELS as usize)), + +// TODO: Use `&chid_pool` self-referential pin-init syntax once available. +// +// SAFETY: `chid_pool` is initialized before this expression and lives at a pinned +// stable address. Field order drops `vgpu` before `chid_pool`, including unwind of +// an incomplete initializer. + vgpu: VgpuManager::new( + // SAFETY: The lifetime and drop-order rationale above covers this borrow. + unsafe { &*core::ptr::from_ref(chid_pool.as_ref().get_ref()) }, + ), + gsp_resources <-try_pin_init! (GspResources { device: pdev,
@@ -420,22 +443,26 @@ pub(crate) fn new( fsp: Fsp::try_new(dev, bar, spec.chipset)?, - vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()), + _: { + vgpu.detect_state (pdev, spec.chipset, fsp.as_mut ()); + }, - gsp <- Gsp::new(pdev, spec.chipset), + gsp <- Gsp::new(pdev, spec.chipset, vgpu.state()),// This member must be initialized last, so the unload bundle can never be dropped // from outside of the constructed `GspResources`, ensuring that the unload sequence // is properly run in case of failure. - boot_result: gsp.boot(GspBootContext { - pdev, - bar, - chipset: spec.chipset, - gsp_falcon, - sec2_falcon, - fsp: fsp.as_mut (), + boot_result: gsp.boot( +GspBootContext { + pdev, + bar, + chipset: spec.chipset, + gsp_falcon, + sec2_falcon, + fsp: fsp.as_mut (), + }, vgpu, - })?, + )?, }), _: {
drivers/gpu/nova-core/gpu/channel.rs +3 -0
@@ -21,6 +21,9 @@ }, // }; +/// Total channel ID capacity available to vGPU instances. +pub (crate )const TOTAL_CHANNELS :u32 =2048 ; +/// Pool for tracking reservations of channel IDs. #[pin_data] pub (crate )struct ChannelIdPool {
drivers/gpu/nova-core/gsp.rs +10 -2
@@ -60,7 +60,7 @@ fw::GspArgumentsPadded, // }, num, - vgpu::VgpuManager, // + vgpu::VgpuState, // };pub (crate )const GSP_PAGE_SHIFT :usize =12 ;
@@ -79,7 +79,6 @@ pub(crate) struct GspBootContext<'ctx, 'gpu> { pub(crate) gsp_falcon: &'ctx Falcon<'gpu, GspFalcon>, pub(crate) sec2_falcon: &'ctx Falcon<'gpu, Sec2Falcon>, pub(crate) fsp: Option<&'ctx mut Fsp<'gpu>>, - pub(crate) vgpu: &'ctx VgpuManager, }impl <'ctx, 'gpu>GspBootContext <'ctx, 'gpu> {
@@ -282,6 +281,8 @@ struct LogBuffers {pub (crate )struct Gsp {/// Preloaded GSP firmware TLV metadata used during boot. gsp_tlv: kernel::firmware::Firmware , +/// vGPU mode detected before GSP boot. + vgpu_state:VgpuState ,/// Libos arguments. pub (crate ) libos:Coherent <[LibosMemoryRegionInitArgument ]>,/// Log buffers for all LIBOS3 tasks, exposed via debugfs.
@@ -300,6 +301,7 @@ impl Gsp {pub (crate )fn new ( pdev: &pci::Device <device::Bound >, chipset:Chipset , + vgpu_state:VgpuState , ) ->impl PinInit <Self ,Error > + '_ { pin_init::pin_init_scope (move || {let dev = pdev.as_ref ();
@@ -323,6 +325,7 @@ pub(crate) fn new( Ok(try_pin_init!(Self { gsp_tlv, + vgpu_state, cmdq: Arc::pin_init(Cmdq::new(dev), GFP_KERNEL)?, rm_state_monitor: Coherent::zeroed(dev, GFP_KERNEL)?, rmargs: Coherent::init(
@@ -398,6 +401,11 @@ pub(crate) fn new( }) } +/// Returns the vGPU mode detected for this boot. +pub (crate )const fn vgpu_state (&self) ->VgpuState { + self.vgpu_state + } +/// Returns a shared handle to the GSP command queue. pub (crate )fn cmdq (&self) ->Arc <Cmdq > { self.cmdq.clone ()
drivers/gpu/nova-core/gsp/boot.rs +11 -2
@@ -37,6 +37,7 @@ gsp::GspFirmware, radix3::Radix3, // }, + gpu::TOTAL_CHANNELS, gsp::{ cmdq::{Cmdq ,
@@ -52,7 +53,8 @@ }, // }, num, - regs, // + regs, + vgpu::VgpuManager, // };impl super ::Gsp {
@@ -72,6 +74,7 @@ impl super::Gsp {pub (crate )fn boot ( self:Pin <&mut Self >,mut ctx:super ::GspBootContext <'_, '_>, + vgpu: &mut VgpuManager <'_>, ) ->Result <super ::BootResult > {let pdev = ctx.pdev;let bar = ctx.bar;
@@ -128,7 +131,7 @@ pub(crate) fn boot(// the registry keys ride inside that one request. Its reply is also what says GSP-RM has // finished starting, and the load-and-execute events it raises first are dispatched as // they arrive. -let init_payload = commands::build_gsp_init_payload (pdev, chipset, ctx.vgpu.state ())?; +let init_payload = commands::build_gsp_init_payload (pdev, chipset, self.vgpu_state ())?;// Only the chipsets that raise `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` are shipped a // `gen_bootloader.tlv`, so requesting it elsewhere fails the whole boot with `ENOENT`. let bootloader =if super ::hal::uses_generic_bootloader (chipset) {
@@ -155,6 +158,12 @@ pub(crate) fn boot( ) })?; + vgpu.init ( + &static_info.fifo_engine_list, + static_info.vmmu_segment_size, +TOTAL_CHANNELS , + ); + Ok(super::BootResult::new( unload_guard.dismiss().1, static_info,
drivers/gpu/nova-core/gsp/commands.rs +33 -0
@@ -49,6 +49,19 @@ vgpu::VgpuState, // }; +/// Upper bound on entries in the hardware FIFO engine table. +pub (crate )const MAX_FIFO_ENGINES :usize =64 ; + +/// Bit mask for `NVGMC_SC_ENGINE_FLAGS_IS_HOST_DRIVEN` (bits 0:0). +const ENGINE_FLAGS_IS_HOST_DRIVEN :u32 =1 <<0 ; + +/// Ordered list of host-driven GMC engine IDs from the hardware FIFO engine table. +#[derive( Copy , Clone )] +pub (crate )struct FifoEngineList { +pub (crate ) gmc_ids: [u32 ;MAX_FIFO_ENGINES ], +pub (crate ) count:usize , +} +/// The static GPU configuration, as decoded from the `GSP_INIT` reply. pub (crate )struct GetGspStaticInfoReply { gpu_name: [u8 ;64 ],
@@ -58,6 +71,10 @@ pub(crate) struct GetGspStaticInfoReply { pub(crate) usable_fb_regions: KVec<Range<u64>>,/// Exclusive end of the FB physical address space. pub(crate) total_fb_end: u64, +/// VMMU segment size reported by GSP-RM, in bytes. + pub(crate) vmmu_segment_size: u64, +/// Ordered host-driven FIFO engine GMC IDs. + pub(crate) fifo_engine_list: FifoEngineList, }/// Error type for [`GetGspStaticInfoReply::gpu_name`].
@@ -289,12 +306,28 @@ fn decode_gsp_info(words: &[u64]) -> Result<GetGspStaticInfoReply> { usable_fb_regions.push (region,GFP_KERNEL )?; }let total_fb_end = decoded.total_fb_end ().ok_or (EINVAL )?; +let vmmu_segment_size = decoded.vmmu_segment_size (); +let fifo_count = decoded.fifo_engine_count (); +let raw_ids = decoded.fifo_engine_gmc_ids (); +let raw_flags = decoded.fifo_engine_flags (); +let mut fifo_engine_list =FifoEngineList { + gmc_ids: [0 ;MAX_FIFO_ENGINES ], + count:0 , + }; +for indexin 0 ..fifo_count { +if raw_flags[index] &ENGINE_FLAGS_IS_HOST_DRIVEN !=0 { + fifo_engine_list.gmc_ids[fifo_engine_list.count] = raw_ids[index]; + fifo_engine_list.count +=1 ; + } + }Ok (GetGspStaticInfoReply { gpu_name, bar1_pde_base: decoded.bar1_pde_base (), usable_fb_regions, total_fb_end, + vmmu_segment_size, + fifo_engine_list, }) }
drivers/gpu/nova-core/gsp/fw/commands.rs +36 -0
@@ -26,6 +26,7 @@ Encodeable, Encoder, Index, + Indexed, Key, KeyId, Required, //
@@ -295,6 +296,14 @@ pub(crate) struct GspInitResponseSchema => GspInitResponse { fb_regions: Accumulated<FbRegionSchema>, bar1_pde_base: Required<u64, { Self::BAR1_PDE_BASE_KEY }>, vmmu_segment_size: Key<u64, { Self::VMMU_SEGMENT_SIZE_KEY }>, + fifo_engine_count: Key<u32, { Self::FIFO_ENGINE_COUNT_KEY }>, + fifo_engine_gmc_ids: Indexed< + u32, + { GspInitResponse::MAX_FIFO_ENGINES }, + { Self::FIFO_ENGINE_GMC_ENGINE_ID_KEY }, + >, + fifo_engine_flags: + Indexed<u32, { GspInitResponse::MAX_FIFO_ENGINES }, { Self::FIFO_ENGINE_FLAGS_KEY }>, } }
@@ -303,6 +312,9 @@ impl GspInitResponseSchema {const GPU_NAME_STRING_KEY :KeyId =0x2000 ;const BAR1_PDE_BASE_KEY :KeyId =0x1020 ;const VMMU_SEGMENT_SIZE_KEY :KeyId =0x1050 ; +const FIFO_ENGINE_COUNT_KEY :KeyId =0x0500 ; +const FIFO_ENGINE_GMC_ENGINE_ID_KEY :KeyId =0x0501 ; +const FIFO_ENGINE_FLAGS_KEY :KeyId =0x0502 ; }/// Payload of the `GSP_INIT` response.
@@ -312,10 +324,14 @@ pub(crate) struct GspInitResponse { fb_regions: KVVec<FbRegion>, bar1_pde_base: u64, vmmu_segment_size: u64, + fifo_engine_count: u32, + fifo_engine_gmc_ids: [u32; Self::MAX_FIFO_ENGINES], + fifo_engine_flags: [u32; Self::MAX_FIFO_ENGINES], }impl GspInitResponse {pub (crate )const MAX_GPU_NAME_LEN :usize =64 ; +const MAX_FIFO_ENGINES :usize =64 ;/// A region with no tag is general-purpose memory. A tagged region is reserved for a /// firmware-internal use that the tag identifies.
@@ -358,6 +374,26 @@ pub(crate) fn total_fb_end(&self) -> Option<u64> { .max()? .checked_add (1 ) } + +/// Returns the VMMU segment size reported by GSP-RM. +pub (crate )const fn vmmu_segment_size (&self) ->u64 { + self.vmmu_segment_size + } + +/// Returns the count of FIFO engines reported by GSP-RM. +pub (crate )fn fifo_engine_count (&self) ->usize { + (self.fifo_engine_countas usize ).min (Self ::MAX_FIFO_ENGINES ) + } + +/// Returns the raw array of GMC engine IDs from the FIFO engine table. +pub (crate )fn fifo_engine_gmc_ids (&self) -> &[u32 ;Self ::MAX_FIFO_ENGINES ] { + &self.fifo_engine_gmc_ids + } + +/// Returns the raw array of per-engine flags from the FIFO engine table. +pub (crate )fn fifo_engine_flags (&self) -> &[u32 ;Self ::MAX_FIFO_ENGINES ] { + &self.fifo_engine_flags + } }nvkv_decode! {
drivers/gpu/nova-core/gsp/hal/gh100.rs +1 -1
@@ -151,7 +151,7 @@ fn boot(let chipset = ctx.chipset;let gsp_falcon = ctx.gsp_falcon; -let fb_sizes =FbSizes ::new (chipset, ctx.bar, ctx.vgpu.state ())?; +let fb_sizes =FbSizes ::new (chipset, ctx.bar, gsp.vgpu_state ())?;dev_dbg! (dev,"{:#x?}\n" , fb_sizes); let wpr_meta =
drivers/gpu/nova-core/gsp/hal/tu102.rs +1 -1
@@ -259,7 +259,7 @@ fn boot(let gsp_falcon = ctx.gsp_falcon;let sec2_falcon = ctx.sec2_falcon; -let fb_ranges =FbRanges ::new (chipset, bar, gsp_fw, ctx.vgpu.state ())?; +let fb_ranges =FbRanges ::new (chipset, bar, gsp_fw, gsp.vgpu_state ())?;dev_dbg! (dev,"{:#x?}\n" , fb_ranges);// Declared before the unload guard so that if Booter fails while running, SEC2 is reset
drivers/gpu/nova-core/vgpu.rs deleted +0 -91
91 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/mod.rs new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
2.53.0
Alexandre Courbot
maintainerRe: [PATCH 01/13] gpu: nova-core: vgpu: add post-GSP-boot vGPU initialization
Hi Zhi,
Quoted 12 lines · Zhi Wang
GSP-RM does not expose the parameters needed to divide resources among vGPU instances until
GSP_INITcompletes. Before this point VgpuManager only knows whether vGPU mode is enabled, so it cannot provide the engine topology, VMMU alignment, or channel capacity required by instance management.Decode the VMMU segment size and ordered FIFO engine table from the typed
GSP_INITNVKV response. Retain only host-driven engines while preserving hardware FIFO order. After a successfulGSP_INIT, initialize the manager with these values and the 2048-channel capacity, but retain them only when vGPU mode is enabled.
Quoted 6 lines
Move VgpuManager into Gpu and let it borrow the pinned ChannelIdPool. Create that pool with the same channel capacity, order the Gpu fields so the manager is dropped before the memory manager, GSP resources, and its channel pool, and pass it separately to GSP boot so unload resources do not retain a manager reference. Keep a copy of the detected mode in the GPU-owned GSP runtime data instead of passing it through the HAL calls.
The commit log reads like this patch tries to group several things together. The diff below makes it even more clear:
<...>
Quoted 2 lines
drivers/gpu/nova-core/vgpu.rs | 91 --------------- drivers/gpu/nova-core/vgpu/mod.rs | 139 +++++++++++++++++++++++
This moves code around while adding features to the moved block, making it very difficult to understand what happens looking at the diff. Typically when you need to do what you will want to split into two or more patches: one that is purely mechanical and moves the original code to its destination, ideally without any change, and then the changes you want to apply, one per patch.
In this case though there is probably no need for the move at all: even if you plan on adding sub-modules to vgpu, the main module can stay in vgpu.rs. Sub-modules can then be named vgpu/foo.rs, vgpu/bar.rs, and it will work just fine. Actually I think that's the preferred way of organizing modules in R4L.
Generally speaking, let's keep mechanical changes, refactorings, plumbing and only then new features each as separate patches. Not only does this make it easier to review, it also will give you a better perspective of your own code and make possible optimizations/reorderings visible that are not obvious is everything is clumped together.
PATCH 2/13 gpu: nova-core: mm: add VramBlock and Bar1Map
In reply to Zhi WangGPU page table setup and VRAM-backed control structures require the driver to allocate physical VRAM and map it into the BAR1 aperture for CPU access. These operations are common to both the base driver and vGPU paths.
VramBlock owns a buddy allocator allocation. Shared VramRegion views keep that allocation alive while callers select byte ranges within a larger preallocated block. Bar1Map retains one such region while mapping the containing pages and bounds all CPU accesses to the requested view. The mapping must be explicitly destroyed to release GPU VA resources and invalidate PTEs.
Keep BarUser inline in Gpu and let short-lived BarUserAccess objects borrow it. Bar1Map owns its mapped VA range and borrows the driver-owned BAR1 mapping; explicit destruction returns the VA through BarUser and GpuMm. Its MMIO accessors remain runtime checked because BAR1 and the logical mapping have runtime sizes.
--- drivers/gpu/nova-core/gpu.rs | 20 ++- drivers/gpu/nova-core/mm.rs | 6 +- drivers/gpu/nova-core/mm/bar_user.rs | 143 ++++++++++++++++++-- drivers/gpu/nova-core/mm/vram.rs | 187 +++++++++++++++++++++++++++ 4 files changed, 329 insertions(+), 27 deletions(-) create mode 100644 drivers/gpu/nova-core/mm/vram.rs
drivers/gpu/nova-core/gpu.rs +9 -11
@@ -317,7 +317,8 @@ pub(crate) struct Gpu<'gpu> {/// the GSP is still operational. mm: GpuMm<'gpu>,/// BAR1 user interface for CPU access to GPU virtual memory. - bar_user: Arc<BarUser<'gpu>>, +#[pin] + bar_user: BarUser<'gpu>,/// GSP and its resources. #[pin] gsp_resources: GspResources<'gpu>,
@@ -508,19 +509,16 @@ pub(crate) fn new( },// Create BAR1 user interface for CPU access to GPU virtual memory. - bar_user: { + bar_user <- {let info = &gsp_resources.boot_result.static_info;let pdb_addr =VramAddress ::from_raw (info.bar1_pde_base);let bar1_idx =crate ::driver::bar1_resource_index (pdev)?;let bar1_size = pdev.resource_len (bar1_idx)?; -Arc ::pin_init ( -BarUser ::new ( - pdb_addr, - gsp_resources.spec.chipset, - bar1_size, - bar1, - )?, -GFP_KERNEL , +BarUser ::new ( + pdb_addr, + gsp_resources.spec.chipset, + bar1_size, + bar1, )? }, })
@@ -543,7 +541,7 @@ pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bou dev, this.mm, regions, - this.bar_user, + this.bar_user.as_ref().get_ref(), info.bar1_pde_base, this.spec.chipset, ) {
drivers/gpu/nova-core/mm.rs +3 -3
@@ -67,6 +67,7 @@ macro_rules! impl_pfn_bounded {mod regs;pub (super )mod tlb;pub (super )mod vmm; +pub (crate )mod vram;/// GPU Memory Manager - owns all core MM components. ///
@@ -298,8 +299,7 @@ pub(crate) mod selftest {use kernel::{ device, - sizes::SizeConstants , - sync::Arc ,// + sizes::SizeConstants ,// };use super ::*;
@@ -309,7 +309,7 @@ pub(crate) fn run( dev: &device::Device<device::Bound>, mm: &mut GpuMm<'_>, usable_fb_regions: &[Range<u64>], - bar_user: &Arc<bar_user::BarUser<'_>>, + bar_user: &bar_user::BarUser<'_>, bar1_pdb: u64, chipset: Chipset, ) -> Result {
drivers/gpu/nova-core/mm/bar_user.rs +130 -13
199 lines not on this page · raw message
drivers/gpu/nova-core/mm/vram.rs new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH 02/13] gpu: nova-core: mm: add VramBlock and Bar1Map
On 2026-09-05 at 18:11 +1000, Zhi Wang <[email protected]> wrote...
Quoted 12 lines
GPU page table setup and VRAM-backed control structures require the driver to allocate physical VRAM and map it into the BAR1 aperture for CPU access. These operations are common to both the base driver and vGPU paths.
VramBlock owns a buddy allocator allocation. Shared VramRegion views keep that allocation alive while callers select byte ranges within a larger preallocated block. Bar1Map retains one such region while mapping the containing pages and bounds all CPU accesses to the requested view. The mapping must be explicitly destroyed to release GPU VA resources and invalidate PTEs.
Quoted 5 lines
Keep BarUser inline in Gpu and let short-lived BarUserAccess objects borrow it. Bar1Map owns its mapped VA range and borrows the driver-owned BAR1 mapping; explicit destruction returns the VA through BarUser and GpuMm. Its MMIO accessors remain runtime checked because BAR1 and the logical mapping have runtime sizes.
This patch seems to be doing three different things that build on top of each other, so it would be a bit easier to review if it was split up into three patches. One patch adding the VRAM allocator, one dealing with the shared VramRegion views and another to do the actual BAR1 mappings.
Quoted 8 lines
Signed-off-by Zhi Wang <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 20 ++- drivers/gpu/nova-core/mm.rs | 6 +- drivers/gpu/nova-core/mm/bar_user.rs | 143 ++++++++++++++++++-- drivers/gpu/nova-core/mm/vram.rs | 187 +++++++++++++++++++++++++++ 4 files changed, 329 insertions(+), 27 deletions(-) create mode 100644 drivers/gpu/nova-core/mm/vram.rs
[...]
drivers/gpu/nova-core/mm/vram.rs line 121
Quoted 3 lines
drivers/gpu/nova-core/mm/vram.rs new file +3
-0+/// Allocate an exact VRAM range relative to a usable region's buddy base. +pub (crate )fn alloc_vram_range ( + mm: &GpuMm<'_>,
Given this operates on GpuMm I think it might be better if this was a method implemented on GpuMm.
drivers/gpu/nova-core/mm/vram.rs line 133
Quoted 12 lines
drivers/gpu/nova-core/mm/vram.rs new file +12
-0+ range: Range<u64>, + align: u64, +) -> Result<Arc<VramBlock>> { +let page_size = u64::try_from (PAGE_SIZE ).map_err (|_|EOVERFLOW )?; +let size = range + .end + .checked_sub (range.start) + .filter (|size| *size !=0 ) + .ok_or (EINVAL )?; +if !range.start.is_multiple_of (page_size) || !size.is_multiple_of (page_size) { +return Err (EINVAL ); + }
I think these should already be checked in gpu_buddy_alloc_blocks() so no need to repeat the same checks here.
drivers/gpu/nova-core/mm/vram.rs line 141
Quoted 8 lines
drivers/gpu/nova-core/mm/vram.rs new file +8
-0+ +let align = align.max (page_size); +let align_usize = usize::try_from (align).map_err (|_|EOVERFLOW )?; +let min_block_size =Alignment ::new_checked (align_usize).ok_or (EINVAL )?; +let buddy = mm.buddy (); +if range.end > buddy.size () { +return Err (ENOSPC ); + }
Ditto.
Quoted 25 lines
drivers/gpu/nova-core/mm/vram.rs new file +25
-0+let blocks =KBox ::pin_init ( + buddy.alloc_blocks ( +GpuBuddyAllocMode ::Range (range.clone ()), + size, + min_block_size, +GpuBuddyAllocFlags ::default (), + ), +GFP_KERNEL , + )?; + +let mut address =None ; +let mut allocation_end =None ; +let mut covered =0u64 ; +for blockin blocks.as_ref ().iter () { +let block_address = block.offset (); +let block_size = block.size (); +let block_end = block_address.checked_add (block_size).ok_or (EOVERFLOW )?; + address =Some (address.map_or (block_address, |start:u64 | start.min (block_address))); + allocation_end =Some (allocation_end.map_or (block_end, |end:u64 | end.max (block_end))); + covered = covered.checked_add (block_size).ok_or (EOVERFLOW )?; + } + +let address = address.ok_or (ENOMEM )?; +let allocation_end = allocation_end.ok_or (ENOMEM )?; +let expected_address = buddy
drivers/gpu/nova-core/mm/vram.rs line 177
Quoted 10 lines
drivers/gpu/nova-core/mm/vram.rs new file +10
-0+ .base_offset() + .checked_add (range.start) + .ok_or (EOVERFLOW )?; +if address != expected_address + || covered != size + || allocation_end.checked_sub (address).ok_or (EIO )? != size + || !address.is_multiple_of (align) + { +return Err (EIO ); + }
What is the purpose of these checks? Do we ever expect to hit any of these errors?
Thanks.
Quoted 12 lines
drivers/gpu/nova-core/mm/vram.rs new file +9
-0+Ok (Arc ::new ( +VramBlock { + _blocks: blocks, + address, + size, + }, +GFP_KERNEL , + )?) +}Signature · 1 line
2.53.0
PATCH 3/13 gpu: nova-core: vgpu: add VRAM slot allocator
In reply to Zhi WangFrom: Alok Kumar <[email protected]>
vGPU profiles need fixed-size framebuffer and plugin management-heap regions for each instance. Allocating them independently fragments VRAM and does not preserve a stable profile-wide layout.
Add a standalone slot allocator that reserves one exact VRAM range and tracks assignments in a bitmap. Validate the profile layout and reject an allocation request whose layout differs from the active pool.
Lay out all framebuffer slots first and all management-heap slots second, pairing them by bitmap index. Require the framebuffer stride and pool base to satisfy the profile VMMU-segment alignment.
Keep the pool in an Arc<VramBlock> and return checked VramRegion views for each slot. This lets consumers map a subrange while retaining the complete buddy allocation for as long as any view remains alive.
--- drivers/gpu/nova-core/vgpu/mod.rs | 1 + drivers/gpu/nova-core/vgpu/vram.rs | 142 +++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 drivers/gpu/nova-core/vgpu/vram.rs
drivers/gpu/nova-core/vgpu/mod.rs +1 -0
@@ -22,6 +22,7 @@ };mod hal; +mod vram;/// vGPU state detected during GPU construction. #[derive( Debug , Clone , Copy )]
drivers/gpu/nova-core/vgpu/vram.rs new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 4/13 gpu: nova-core: vgpu: add r000 plugin bindings
In reply to Zhi WangThe vGPU plugin communication area and RPC protocol are defined by the r000 firmware interface. Keeping local copies of that ABI risks letting the host driver drift from the firmware layout.
Extend the existing r000 binding set with the nova-core subset of dev_vgpu_gsp_shared.h. The bindings expose the control and response region types, message IDs, and firmware-defined region sizes. Keep the raw declarations private and expose only the symbols needed by the vGPU plugin communication layer.
--- .../gpu/nova-core/gsp/fw/r000_00/bindings.rs | 173 ++++++++++++++++++ drivers/gpu/nova-core/vgpu/fw.rs | 2 + drivers/gpu/nova-core/vgpu/mod.rs | 1 + 3 files changed, 176 insertions(+) create mode 100644 drivers/gpu/nova-core/vgpu/fw.rs
drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs +173 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. #[repr( C )] #[derive( Default )]
@@ -857,3 +858,175 @@ pub struct rpc_unloading_guest_driver_v1F_07 { pub __bindgen_padding_0: [u8; 2usize], pub newLevel: u32_, } +pub const GSP_PLUGIN_BOOTLOADED :u32 =1315261039 ; +pub const VGPU_CPU_GSP_CTRL_BUFF_VERSION :u32 =2 ; +pub const VGPU_CPU_GSP_CTRL_BUFF_REGION_SIZE :u32 =4096 ; +pub const VGPU_CPU_GSP_RESPONSE_BUFF_REGION_SIZE :u32 =4096 ; +pub const VGPU_CPU_GSP_MESSAGE_BUFF_REGION_SIZE :u32 =4096 ; +pub const VGPU_CPU_GSP_MIGRATION_BUFF_REGION_SIZE :u32 =2097152 ; +pub const VGPU_CPU_GSP_ERROR_BUFF_REGION_SIZE :u32 =4096 ; +pub const VGPU_CPU_GSP_INIT_TASK_LOG_BUFF_REGION_SIZE :u32 =131072 ; +pub const VGPU_CPU_GSP_VGPU_TASK_LOG_BUFF_REGION_SIZE :u32 =262144 ; +pub const VGPU_CPU_GSP_KERNEL_TASK_LOG_BUFF_REGION_SIZE :u32 =65536 ; +pub const VGPU_CPU_GSP_GUEST_RPC_TRACE_BUFF_REGION_SIZE :u32 =65536 ; +pub const VGPU_CPU_GSP_COMMUNICATION_BUFF_TOTAL_SIZE :u32 =2637824 ; +pub type VGPU_CPU_GSP_BOOL =u32_ ; +#[repr( C )] +#[derive( Debug , Default , Copy , Clone , MaybeZeroable )] +pub struct VGPU_CPU_GSP_VGX_VERSION { +pub major_number:u32_ , +pub minor_number:u32_ , +} +#[repr( C )] +#[derive( Debug , Copy , Clone , MaybeZeroable )] +pub struct VGPU_CPU_GSP_GUEST_INFO { +pub vgx_version:VGPU_CPU_GSP_VGX_VERSION , +pub guest_driver_version_buffer_length:u32_ , +pub guest_version_buffer_length:u32_ , +pub guest_title_buffer_length:u32_ , +pub guest_changelist_number:u32_ , +pub guest_driver_version_buffer: [ffi::c_char ;256usize ], +pub guest_version_buffer: [ffi::c_char ;256usize ], +pub guest_title_buffer: [ffi::c_char ;256usize ], +pub guest_branch_buffer: [ffi::c_char ;256usize ], +} +impl Default for VGPU_CPU_GSP_GUEST_INFO { +fn default () ->Self { +let mut s = ::core::mem::MaybeUninit ::<Self >::uninit (); +unsafe { + ::core::ptr::write_bytes (s.as_mut_ptr (),0 ,1 ); + s.assume_init () + } + } +} +#[repr( C )] +#[derive( Copy , Clone , MaybeZeroable )] +pub union VGPU_CPU_GSP_CTRL_BUFF_REGION { +pub buf: [u8_ ;4096usize ], +pub __bindgen_anon_1:VGPU_CPU_GSP_CTRL_BUFF_REGION__bindgen_ty_1 , +} +#[repr( C )] +#[derive( Debug , Default , Copy , Clone , MaybeZeroable )] +pub struct VGPU_CPU_GSP_CTRL_BUFF_REGION__bindgen_ty_1 { +pub version:u32_ , +pub message_type:u32_ , +pub message_seq_num:u32_ , +pub __bindgen_padding_0: [u8 ;4usize ], +pub response_buff_offset:u64_ , +pub message_buff_offset:u64_ , +pub migration_buff_offset:u64_ , +pub error_buff_offset:u64_ , +pub guest_rpc_trace_buff_offset:u64_ , +pub migration_buf_cpu_access_offset:u32_ , +pub is_migration_in_progress:u8_ , +pub __bindgen_padding_1: [u8 ;3usize ], +pub error_buff_cpu_get_idx:u32_ , +pub guest_rpc_trace_buff_cpu_get_idx:u32_ , +pub attached_vgpu_count:u32_ , +pub is_gr_init_done:u8_ , +pub __bindgen_padding_2: [u8 ;3usize ], +pub host_info: [VGPU_CPU_GSP_CTRL_BUFF_REGION__bindgen_ty_1__bindgen_ty_1 ;16usize ], +} +#[repr( C )] +#[derive( Debug , Default , Copy , Clone , MaybeZeroable )] +pub struct VGPU_CPU_GSP_CTRL_BUFF_REGION__bindgen_ty_1__bindgen_ty_1 { +pub vgpu_type_id:u32_ , +pub host_gpu_pci_id:u32_ , +pub pci_dev_id:u32_ , +pub vgpu_uuid: [u8_ ;16usize ], +} +impl Default for VGPU_CPU_GSP_CTRL_BUFF_REGION { +fn default () ->Self { +let mut s = ::core::mem::MaybeUninit ::<Self >::uninit (); +unsafe { + ::core::ptr::write_bytes (s.as_mut_ptr (),0 ,1 ); + s.assume_init () + } + } +} +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_VERSION_NEGOTIATION :MESSAGE =1 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_SETUP_CONFIG_PARAMS_AND_INIT :MESSAGE =2 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_RESET :MESSAGE =3 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MIGRATION_STOP_WORK :MESSAGE =4 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MIGRATION_CANCEL_STOP :MESSAGE =5 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MIGRATION_SAVE_STATE :MESSAGE =6 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MIGRATION_CANCEL_SAVE :MESSAGE =7 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MIGRATION_RESTORE_STATE :MESSAGE =8 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MIGRATION_RESTORE_DEFERRED_STATE :MESSAGE =9 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MIGRATION_RESUME_WORK :MESSAGE =10 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_CONSOLE_VNC_STATE :MESSAGE =11 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_VF_BAR0_REG_ACCESS :MESSAGE =12 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_UPDATE_BME_STATE :MESSAGE =13 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_RESET_MIGRATION_BUFFER_PTR :MESSAGE =14 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_RELEASE_CLIENT_DATABASE :MESSAGE =15 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_CHECK_IS_ALIVE :MESSAGE =16 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_SEND_STATIC_INFO :MESSAGE =17 ; +pub const MESSAGE_NV_VGPU_CPU_RPC_MSG_MAX :MESSAGE =18 ; +pub type MESSAGE = ffi::c_uint ; +#[repr( C )] +#[derive( Debug , Default , Copy , Clone , MaybeZeroable )] +pub struct VGPU_CPU_GSP_DISPLAYLESS_SURFACE { +pub sequence_update_start:u64_ , +pub sequence_update_end:u64_ , +pub effective_fb_page_size:u32_ , +pub rect_width:u32_ , +pub rect_height:u32_ , +pub surface_width:u32_ , +pub surface_height:u32_ , +pub surface_size:u32_ , +pub surface_offset:u32_ , +pub surface_format:u32_ , +pub surface_kind:u32_ , +pub surface_pitch:u32_ , +pub surface_type:u32_ , +pub surface_block_height:u8_ , +pub __bindgen_padding_0: [u8 ;3usize ], +pub is_blanking_enabled:VGPU_CPU_GSP_BOOL , +pub is_flip_pending:VGPU_CPU_GSP_BOOL , +pub is_free_pending:VGPU_CPU_GSP_BOOL , +pub is_memory_blocklinear:VGPU_CPU_GSP_BOOL , +} +#[repr( C )] +#[derive( Copy , Clone , MaybeZeroable )] +pub union VGPU_CPU_GSP_RESPONSE_BUFF_REGION { +pub buf: [u8_ ;4096usize ], +pub __bindgen_anon_1:VGPU_CPU_GSP_RESPONSE_BUFF_REGION__bindgen_ty_1 , +} +#[repr( C )] +#[derive( Debug , Copy , Clone , MaybeZeroable )] +pub struct VGPU_CPU_GSP_RESPONSE_BUFF_REGION__bindgen_ty_1 { +pub message_seq_num_received:u32_ , +pub message_seq_num_processed:u32_ , +pub result_code:u32_ , +pub guest_rpc_version:u32_ , +pub migration_buf_gsp_access_offset:u32_ , +pub migration_state_save_complete:u32_ , +pub is_migration_allowed:VGPU_CPU_GSP_BOOL , +pub __bindgen_padding_0: [u8 ;4usize ], +pub surface: [VGPU_CPU_GSP_DISPLAYLESS_SURFACE ;4usize ], +pub error_buff_gsp_put_idx:u32_ , +pub grid_license_state:u32_ , +pub guest_os_type:u32_ , +pub frl_config:u32_ , +pub guest_info:VGPU_CPU_GSP_GUEST_INFO , +pub is_guest_info_populated:VGPU_CPU_GSP_BOOL , +pub guest_rpc_trace_buff_gsp_put_idx:u32_ , +} +impl Default for VGPU_CPU_GSP_RESPONSE_BUFF_REGION__bindgen_ty_1 { +fn default () ->Self { +let mut s = ::core::mem::MaybeUninit ::<Self >::uninit (); +unsafe { + ::core::ptr::write_bytes (s.as_mut_ptr (),0 ,1 ); + s.assume_init () + } + } +} +impl Default for VGPU_CPU_GSP_RESPONSE_BUFF_REGION { +fn default () ->Self { +let mut s = ::core::mem::MaybeUninit ::<Self >::uninit (); +unsafe { + ::core::ptr::write_bytes (s.as_mut_ptr (),0 ,1 ); + s.assume_init () + } + } +}
drivers/gpu/nova-core/vgpu/fw.rs new file +2 -0
@@ -0,0 +1,2 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
drivers/gpu/nova-core/vgpu/mod.rs +1 -0
@@ -21,6 +21,7 @@ gsp::commands::FifoEngineList, // }; +mod fw;mod hal;mod vram;
Signature · 1 line
2.53.0
PATCH 5/13 gpu: nova-core: vgpu: add instance create/destroy
In reply to Zhi WangAdd the instance registry and the resources needed for an individual vGPU. Allocate paired framebuffer and management-heap regions from a profile-wide VRAM slot pool, and reserve channel IDs through ChannelIdPool.
Keep mandatory allocations as non-optional fields, enforce profile-specific instance limits, and group the firmware identity into an InstanceInfo. Add typed NVKV GMCAPI helpers for querying the VF assignment and vGPU properties.
Make VgpuManager own the instance registry. Each registry entry keeps the instance's channel reservation and VRAM regions allocated until the entry is removed.
--- drivers/gpu/nova-core/gpu.rs | 72 +++--- drivers/gpu/nova-core/gsp.rs | 1 + drivers/gpu/nova-core/gsp/boot.rs | 4 +- drivers/gpu/nova-core/gsp/cmdq.rs | 63 +++++ drivers/gpu/nova-core/gsp/commands.rs | 11 + drivers/gpu/nova-core/gsp/fw.rs | 8 + drivers/gpu/nova-core/gsp/fw/commands.rs | 44 ++-- drivers/gpu/nova-core/mm/vram.rs | 3 + drivers/gpu/nova-core/vgpu/consts.rs | 12 + drivers/gpu/nova-core/vgpu/instance.rs | 288 +++++++++++++++++++++++ drivers/gpu/nova-core/vgpu/mod.rs | 48 ++-- 11 files changed, 486 insertions(+), 68 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/consts.rs create mode 100644 drivers/gpu/nova-core/vgpu/instance.rs
drivers/gpu/nova-core/gpu.rs +39 -33
@@ -49,12 +49,12 @@ vgpu::VgpuManager, // }; -#[cfg_attr(not( CONFIG_KUNIT = "y" ), expect(dead_code))] mod channel;mod hal;pub (crate )use self::channel::{ChannelIdPool , +ChannelIdReservation ,TOTAL_CHANNELS ,// };
@@ -310,6 +310,7 @@ pub(crate) struct Gpu<'gpu> {/// vGPU state and firmware parameters. /// /// Declared before MM and BAR1 so live instances are torn down before their resources. +#[pin] vgpu: VgpuManager<'gpu>,/// GPU memory manager owning memory management resources. ///
@@ -421,50 +422,55 @@ pub(crate) fn new(// SAFETY: `chid_pool` is initialized before this expression and lives at a pinned // stable address. Field order drops `vgpu` before `chid_pool`, including unwind of // an incomplete initializer. - vgpu: VgpuManager::new( + vgpu <-VgpuManager ::new (// SAFETY: The lifetime and drop-order rationale above covers this borrow. unsafe { &*core::ptr::from_ref (chid_pool.as_ref ().get_ref ()) }, ), - gsp_resources <-try_pin_init! (GspResources { - device: pdev, + gsp_resources <- { +let mut vgpu = vgpu; +try_pin_init! (GspResources { + device: pdev, - spec: *spec, + spec: *spec, - bar, + bar, - gsp_falcon:Falcon ::new ( - dev, - spec.chipset, - bar - ) - .inspect (|falcon| falcon.clear_swgen0_intr ())?, + gsp_falcon:Falcon ::new ( + dev, + spec.chipset, + bar + ) + .inspect (|falcon| falcon.clear_swgen0_intr ())?, - sec2_falcon:Falcon ::new (dev, spec.chipset, bar)?, + sec2_falcon:Falcon ::new (dev, spec.chipset, bar)?, - fsp:Fsp ::try_new (dev, bar, spec.chipset)?, + fsp:Fsp ::try_new (dev, bar, spec.chipset)?, - _: { - vgpu.detect_state (pdev, spec.chipset, fsp.as_mut ()); - }, + _: { + vgpu.as_mut ().detect_state (pdev, spec.chipset, fsp.as_mut ()); + }, - gsp <-Gsp ::new (pdev, spec.chipset, vgpu.state ()), - -// This member must be initialized last, so the unload bundle can never be dropped -// from outside of the constructed `GspResources`, ensuring that the unload sequence -// is properly run in case of failure. - boot_result: gsp.boot ( -GspBootContext { - pdev, - bar, - chipset: spec.chipset, - gsp_falcon, - sec2_falcon, - fsp: fsp.as_mut (), + gsp <-Gsp ::new (pdev, spec.chipset, vgpu.as_ref ().state ()), + +// This member must be initialized last, so the unload bundle can never be +// dropped from outside of the constructed `GspResources`, ensuring that the +// unload sequence is properly run in case of failure. + boot_result: { + gsp.boot ( +GspBootContext { + pdev, + bar, + chipset: spec.chipset, + gsp_falcon, + sec2_falcon, + fsp: fsp.as_mut (), + }, + vgpu.as_mut (), + )? }, - vgpu, - )?, - }), + }) + }, _: {// The `GSP_INIT` reply already carried this.
drivers/gpu/nova-core/gsp.rs +1 -0
@@ -32,6 +32,7 @@mod regs;pub (crate )use fw::{ + vgpu_bindings,GspFmcBootParams ,GspFwWprMeta ,LibosMemoryRegionInitArgument ,
drivers/gpu/nova-core/gsp/boot.rs +2 -2
@@ -74,7 +74,7 @@ impl super::Gsp {pub (crate )fn boot ( self:Pin <&mut Self >,mut ctx:super ::GspBootContext <'_, '_>, - vgpu: &mut VgpuManager <'_>, +mut vgpu:Pin <&mut VgpuManager <'_>>, ) ->Result <super ::BootResult > {let pdev = ctx.pdev;let bar = ctx.bar;
@@ -158,7 +158,7 @@ pub(crate) fn boot( ) })?; - vgpu.init ( + vgpu.as_mut ().init ( &static_info.fifo_engine_list, static_info.vmmu_segment_size, TOTAL_CHANNELS,
drivers/gpu/nova-core/gsp/cmdq.rs +63 -0
75 lines not on this page · raw message
drivers/gpu/nova-core/gsp/commands.rs +11 -0
@@ -49,6 +49,11 @@ vgpu::VgpuState, // }; +pub (crate )use fw::commands::{ +Dbdf , +VgpuProperties ,// +}; +/// Upper bound on entries in the hardware FIFO engine table. pub (crate )const MAX_FIFO_ENGINES :usize =64 ;
@@ -281,6 +286,12 @@ fn nvkv_words(payload_0: &[u8], payload_1: &[u8]) -> Result<KVVec<u64>> {Ok (out) } +/// Decodes a byte-oriented GMC vGPU-properties response with the typed NVKV schema. +pub (crate )fn decode_vgpu_properties (payload: &[u8 ]) ->Result <KBox <VgpuProperties >> { +let words =nvkv_words (payload, &[])?; +VgpuProperties ::decode (&words) +} +/// Decodes the static GPU configuration from an NVKV stream. /// /// # Errors
drivers/gpu/nova-core/gsp/fw.rs +8 -0
@@ -4,6 +4,14 @@pub (crate )mod commands;mod r000_00; +/// Raw firmware declarations used by vGPU management. +pub (crate )mod vgpu_bindings { +pub (crate )use super ::r000_00::{ +GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE , +GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES ,// + }; +} +// Alias to avoid repeating the version number with every use. use r000_00as bindings;
drivers/gpu/nova-core/gsp/fw/commands.rs +26 -18
66 lines not on this page · raw message
drivers/gpu/nova-core/mm/vram.rs +3 -0
@@ -86,16 +86,19 @@ fn new(backing: Arc<VramBlock>, range: Range<u64>) -> Result<Self> { }/// Return the physical address of the first byte in this region. +#[expect(dead_code)] pub (crate )const fn address (&self) ->u64 { self.address }/// Return the region size in bytes. +#[expect(dead_code)] pub (crate )const fn size (&self) ->u64 { self.size }/// Return a checked subregion relative to this region. +#[expect(dead_code)] pub (crate )fn subregion (&self, range:Range <u64 >) ->Result <Self > {let size = range .end
drivers/gpu/nova-core/vgpu/consts.rs new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +/// Development OpenRM GMC command identifiers used by vGPU management. +pub (crate )mod gmc { +use crate ::gsp::vgpu_bindingsas bindings; + +pub (crate )const VGPU_MGMT_QUERY_PROPERTIES :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES ; +pub (crate )const VGPU_MGMT_QUERY_ASSIGNED_VF :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE ; +}
drivers/gpu/nova-core/vgpu/instance.rs new file +288 -0
288 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/mod.rs +33 -15
111 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 6/13 gpu: nova-core: gsp: add GMC transaction helpers
In reply to Zhi WangMatch GMC replies to requests by both the masked command identifier and sequence number instead of accepting the next GMC message as the reply. Use one deadline while stale responses and interleaved messages are consumed.
Pass the GMC sequence through event dispatch, and add helpers for status-only replies and commands completed by asynchronous events.
A GMC transaction holds the shared command queue lock while waiting. Consume and dispatch a valid interleaved RM RPC frame instead of treating it as malformed GMC framing, then continue waiting for the GMC message.
The GSP-to-CPU queue carries both RM RPC and GMC messages. The threaded drain predates GMC support and parses every pending entry as RM RPC. Consequently, an asynchronous GMC message fails RPC framing validation, poisons the queue, and leaves the CPU read pointer stuck on that entry.
Use the common classifier for both wire formats. It consumes and dispatches valid RM RPC messages while returning GMC messages to the caller. Advance the read pointer for returned GMC messages so the drain can continue.
The drain holds the command queue lock, so no synchronous GMC transaction can be waiting for a returned message at the same time. Such a message is therefore unsolicited or stale and can be consumed without dispatch.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 311 ++++++++++++++++++-------- drivers/gpu/nova-core/gsp/commands.rs | 30 ++- drivers/gpu/nova-core/gsp/fw.rs | 22 ++ 3 files changed, 265 insertions(+), 98 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +221 -90
@@ -52,6 +52,7 @@ driver::Bar0, gsp::{ fw::{ +GmcApiHeader ,GmcCommand ,GspGmcMsgElement ,GspMsgElement ,
@@ -648,8 +649,8 @@ fn receive_msg<M: MessageFromGsp>(&self, bar: Bar0<'_>, timeout: Delta) -> Resul self.inner.lock ().receive_msg (bar, timeout,None ) } -/// Receives one GMC element from the GSP and passes its command id, the `max_resp_or_status` -/// field, and the raw payload slices to `handler`. +/// Receives one GMC element from the GSP and passes its header and raw payload slices to +/// `handler`. /// /// This method may sleep while waiting. The [`CmdqInner`] mutex stays locked across the wait /// and across the `handler` call, so `handler` must not call back into this [`Cmdq`].
@@ -659,7 +660,7 @@ pub(crate) fn receive_gmc_and_dispatch<R>( &self, bar: Bar0<'_>, timeout: Delta, - handler: impl FnOnce(u32, u32, &[u8], &[u8]) -> (Option<R>, QueuePointers), + handler: impl FnOnce(&GmcApiHeader, &[u8], &[u8]) -> (Option<R>, QueuePointers), ) -> Result<Option<R>> { self.inner .lock()
@@ -686,9 +687,10 @@ pub(crate) fn send_gmc_no_wait( self.inner .lock () .send_gmc (bar, command_id, payload, max_response_size) + .map (|_| ()) } -/// Sends a GMC API command and waits for its response. +/// Sends a GMC API command and waits for its matching response. /// /// The queue stays locked for the complete transaction. A single deadline bounds all queue /// elements observed while waiting.
@@ -698,26 +700,59 @@ pub(crate) fn send_gmc_and_receive( command_id: u32, payload: &[u8], max_response_size: u32, + ) -> Result<GmcResponse> { + self.send_gmc_and_receive_timeout( + bar, + command_id, + payload, + max_response_size, + Self::RECEIVE_TIMEOUT, + ) + } + + /// Sends a GMC API command and waits up to `timeout` for its matching response. + pub(crate) fn send_gmc_and_receive_timeout( + &self, + bar: Bar0<'_>, + command_id: u32, + payload: &[u8], + max_response_size: u32, + timeout: Delta, ) -> Result<GmcResponse> { let mut inner = self.inner.lock(); - inner.send_gmc(bar, command_id, payload, max_response_size)?; + let expected_sequence = inner.send_gmc(bar, command_id, payload, max_response_size)?; + let dev = inner.dev.clone(); - let deadline = Instant::<Monotonic>::now() + Self::RECEIVE_TIMEOUT; + let deadline = Instant::<Monotonic>::now() + timeout; loop { let remaining = deadline - Instant::<Monotonic>::now(); if remaining.is_negative() { return Err(ETIMEDOUT); } - let response = inner.receive_gmc_and_dispatch( + let response = match inner.receive_gmc_and_dispatch( bar, remaining, - |received_command, status, payload_0, payload_1| { - if received_command != command_id { + |header, payload_0, payload_1| { + if !header.is_response_to(command_id, expected_sequence) { + let kind = if header.is_response() { + "response" + } else { + "event" + }; + dev_dbg!( + &dev, + "GSP GMC: skip {} seq {} cmd {:#x}; want response seq {} cmd {:#x}\n", + kind, + header.sequence_number(), + header.command_id(), + expected_sequence, + command_id, + ); return (None, QueuePointers::Unchanged); } - let response = (|| { + let response: Result<GmcResponse> = (|| { let mut payload = KVec::with_capacity( payload_0 .len()
@@ -728,14 +763,18 @@ pub(crate) fn send_gmc_and_receive( payload.extend_from_slice (payload_0,GFP_KERNEL )?; payload.extend_from_slice (payload_1,GFP_KERNEL )?;Ok (GmcResponse { - status, + status: header.max_resp_or_status, payload, }) })(); (Some (response),QueuePointers ::Unchanged ) }, - )?; + ) { + Ok(response) => response, + Err(ERANGE) => continue, + Err(error) => return Err(error), + };if let Some (response) = response {return response;
@@ -743,6 +782,81 @@ pub(crate) fn send_gmc_and_receive( } } +/// Sends a synchronous GMC command and checks its status-only reply. +pub (crate )fn send_gmc_and_check_status ( + &self, + bar:Bar0 <'_>, + command_id:u32 , + payload: &[u8 ], + ) ->Result { +let response = self.send_gmc_and_receive (bar, command_id, payload,0 )?; +if response.status ==0 { +Ok (()) + }else { +Err (EIO ) + } + } + +/// Sends an asynchronous GMC command and waits atomically for its event. +/// +/// The command queue remains locked from the send through the matching +/// event, preventing another transaction from consuming its completion. +/// Interleaved GMC events are passed to `handler`; responses are consumed +/// while waiting. The timeout is shared by the complete operation. +pub (crate )fn send_gmc_and_wait_event ( + &self, + bar:Bar0 <'_>, + command_id:u32 , + payload: &[u8 ], + timeout:Delta , +mut predicate:impl FnMut (u32 ,u32 ,u64 , &[u8 ], &[u8 ]) ->Result <bool >, +mut handler:impl FnMut (u32 ,u32 ,u64 , &[u8 ], &[u8 ]) ->Result , + ) ->Result { +let mut inner = self.inner.lock (); + inner.send_gmc (bar, command_id, payload,0 )?; +let deadline =Instant ::<Monotonic >::now () + timeout; + +loop { +let remaining = deadline -Instant ::<Monotonic >::now (); +if remaining.is_negative () { +return Err (ETIMEDOUT ); + } + +let matched =match inner.receive_gmc_and_dispatch ( + bar, + remaining, + |header, payload_0, payload_1| { +let result:Result <bool > = (|| { +if header.is_response () { +return Ok (false ); + } + +let command = header.command_id (); +let status = header.max_resp_or_status; +let sequence = header.sequence_number (); +if predicate (command, status, sequence, payload_0, payload_1)? { +return Ok (true ); + } + +handler (command, status, sequence, payload_0, payload_1)?; +Ok (false ) + })(); + (Some (result),QueuePointers ::Unchanged ) + }, + ) { +Ok (matched) => matched, +Err (ERANGE ) =>continue , +Err (error) =>return Err (error), + }; + +if let Some (matched) = matched { +if matched? { +return Ok (()); + } + } + } + } +/// Waits for an unsolicited GSP event of type `M`, dispatching any other event that arrives /// first. ///
@@ -772,8 +886,8 @@ pub(crate) fn await_msg<M: MessageFromGsp>(&self, bar: Bar0<'_>) -> Result<M>/// Drains and dispatches every message currently pending in the GSP-to-CPU queue. /// -/// Routes each message the GSP has already posted through [`CmdqInner::dispatch_event`] and -/// returns without waiting for more. +/// Dispatches pending RM RPC messages as events, consumes pending GMC messages, and returns +/// without waiting for more. /// /// # Errors ///
@@ -936,9 +1050,10 @@ fn send_gmc( command_id: u32, payload: &[u8], max_response_size: u32, - ) -> Result { + ) -> Result<u64> {let rpc_seq = self.rpc_seq; self.rpc_seq = self.rpc_seq.wrapping_add (1 ); +let sequence = u64::from (rpc_seq);let dst = self.gsp_mem.allocate_command ::<GspGmcMsgElement >( bar,
@@ -946,12 +1061,8 @@ fn send_gmc( Self::ALLOCATE_TIMEOUT, )?; -let msg_element =GspGmcMsgElement ::init ( - command_id, - u64::from (rpc_seq), - payload.len (), - max_response_size, - ); +let msg_element = +GspGmcMsgElement ::init (command_id, sequence, payload.len (), max_response_size);// SAFETY: `dst.header` points to a valid, writable `GspGmcMsgElement` region. unsafe { msg_element.__init (core::ptr::from_mut (dst.header))?;
@@ -963,7 +1074,7 @@ fn send_gmc(dev_dbg! ( &self.dev,"GSP GMC: send: seq# {}, command={}, length=0x{:x}\n" , - rpc_seq, + sequence,GmcCommand (command_id), dst.header.length (), );
@@ -971,7 +1082,7 @@ fn send_gmc(let elem_count = dst.header.element_count ();DmaGspMem ::advance_cpu_write_ptr_v2 (bar, elem_count); -Ok (()) +Ok (sequence) }/// Wait for a message to become available on the message queue.
@@ -1022,6 +1133,12 @@ fn wait_for_msg(&self, bar: Bar0<'_>, timeout: Delta) -> Result<GspMessage<'_>>return Err (e); } +if !header.is_rm_rpc () { +dev_err! (&self.dev,"GSP RPC: receive: invalid NVDM type\n" ); + self.poisoned.set (true ); +return Err (EIO ); + } +let payload_length = header.payload_length ();// Check that the driver read area is large enough for the message.
@@ -1084,6 +1201,26 @@ fn advance_rx_event_seq(&mut self, function: Result<MsgFunction, u32>) { } } +/// Consumes and dispatches the RM RPC element currently at the queue head. +fn consume_and_dispatch_rpc (&mut self, bar:Bar0 <'_>) ->Result { +let (function, seq, length) = { +let message = self.wait_for_msg (bar,Delta ::ZERO )?; + + ( + message.header.function (), + message.header.sequence (), + message.header.length (), + ) + }; + + self.log_received (function, seq, length); +let pages = u32::try_from (length.div_ceil (GSP_PAGE_SIZE ))?; +DmaGspMem ::advance_cpu_read_ptr_v2 (bar, pages); + self.advance_rx_event_seq (function); + self.dispatch_event (function, seq); +Ok (()) + } +/// Receive a message from the GSP. /// /// The expected message type is given by the `M` generic parameter. With `expected_seq` set,
@@ -1203,32 +1340,22 @@ fn dispatch_event(&self, function: Result<MsgFunction, u32>, seq: u32) {/// Drains and dispatches all messages currently pending in the GSP-to-CPU queue. /// -/// Processes whatever the GSP has already posted, dispatching each message as an event, and -/// stops once the queue is empty. There is no awaited reply during a drain, so every message -/// is routed to [`Self::dispatch_event`]. +/// RM RPC messages are dispatched as events. GMC messages are unsolicited while the drain owns +/// the command queue lock, so they are consumed without dispatch. /// /// # Errors /// /// Returns the receive error that stopped the drain, in particular the `EIO` of a queue -/// poisoned by corrupt framing (see [`Self::wait_for_msg`]). +/// poisoned by framing that is invalid for both GMC and RM RPC (see +/// [`Self::receive_gmc_and_dispatch`]). fn drain (&mut self, bar:Bar0 <'_>) ->Result {while !self.gsp_mem.driver_read_area_v2 (bar).0 .is_empty () { -// A message is available, so this returns without waiting. -let msg = self.wait_for_msg (bar,Delta ::ZERO )?; -let function = msg.header.function (); -let seq = msg.header.sequence (); -let length = msg.header.length (); - - self.log_received (function, seq, length); - -let pages = u32::try_from (length.div_ceil (GSP_PAGE_SIZE )).map_err (|_| { -dev_err! (&self.dev,"GSP drain: message length overflow\n" ); -EIO - })?; - -DmaGspMem ::advance_cpu_read_ptr_v2 (bar, pages); - self.advance_rx_event_seq (function); - self.dispatch_event (function, seq); +match self.receive_gmc_and_dispatch ::<()>(bar,Delta ::ZERO , |_, _, _| { + (None ,QueuePointers ::Unchanged ) + }) { +Ok (_) |Err (ERANGE ) => {} +Err (error) =>return Err (error), + } }Ok (())
@@ -1269,7 +1396,14 @@ fn wait_for_gmc_msg(&self, bar: Bar0<'_>, timeout: Delta) -> Result<GmcMessage<' };// Checked before any length field is read, since bad framing leaves them untrusted. -if let Err (e) = header.validate_framing () { +let framing = header.validate_common_framing ().and_then (|()| { +if header.is_gmc_api () { + header.validate_framing () + }else { +Ok (()) + } + }); +if let Err (e) = framing {dev_err! ( &self.dev,"GSP GMC: receive: bad MCTP framing, declared length {}\n" ,
@@ -1306,12 +1440,11 @@ fn wait_for_gmc_msg(&self, bar: Bar0<'_>, timeout: Delta) -> Result<GmcMessage<' }) } -/// Receive the next GMC event from the GSP and dispatch it through a handler. +/// Receive the next GMC element from the GSP and dispatch it through a handler. /// -/// The handler receives the GMC command id, the header's `max_resp_or_status` field, and the -/// raw payload slices that follow the [`super::fw::GmcApiHeader`] (two slices because the -/// circular buffer may wrap). It returns `None` for an element it does not handle, paired -/// with the [`QueuePointers`] state it left behind. +/// The handler receives the GMC header and the raw payload slices that follow it (two slices +/// because the circular buffer may wrap). It returns `None` for an element it does not handle, +/// paired with the [`QueuePointers`] state it left behind. /// /// `max_resp_or_status` is a union: GSP-RM writes an `NV_STATUS` there when the element is a /// response, and the maximum response size when it is a request. Only a handler that knows
@@ -1320,23 +1453,29 @@ fn wait_for_gmc_msg(&self, bar: Bar0<'_>, timeout: Delta) -> Result<GmcMessage<'/// Where [`Self::receive_msg`] keys on [`MsgFunction`], this keys on the GMC command id, /// which is the form the r000 firmware uses for boot events. /// -/// Returns `Ok(None)` when nothing claimed the element, either because it is not a GMC -/// element or because the handler declined it. The read pointer is advanced past the element -/// on every path except a handler reporting [`QueuePointers::Reset`], which has already -/// returned both pointers to zero. +/// Returns `Ok(None)` when the handler declines a GMC element. A valid interleaved RM RPC +/// element is consumed and dispatched before this method returns `ERANGE`. The read pointer is +/// advanced past the element on every path except a handler reporting [`QueuePointers::Reset`], +/// which has already returned both pointers to zero. /// /// # Errors /// /// - `ETIMEDOUT` if `timeout` has elapsed before any message becomes available. /// - `EIO` if the queue is poisoned or the element fails framing validation (see /// [`Self::wait_for_gmc_msg`]). +/// - `ERANGE` if a valid interleaved RM RPC element was consumed and dispatched. fn receive_gmc_and_dispatch <R >( &mut self, bar:Bar0 <'_>, timeout:Delta , - handler:impl FnOnce (u32 ,u32 , &[u8 ], &[u8 ]) -> (Option <R >,QueuePointers ), + handler:impl FnOnce (&GmcApiHeader , &[u8 ], &[u8 ]) -> (Option <R >,QueuePointers ), ) ->Result <Option <R >> {let message = self.wait_for_gmc_msg (bar, timeout)?; +if !message.header.is_gmc_api () { + self.consume_and_dispatch_rpc (bar)?; +return Err (ERANGE ); + } +let header = message.header;let length = header.length ();
@@ -1345,45 +1484,37 @@ fn receive_gmc_and_dispatch<R>(let cpu_write_ptr =DmaGspMem ::cpu_write_ptr_v2 (bar);let cpu_read_ptr =DmaGspMem ::cpu_read_ptr_v2 (bar); -// The RPC and GMC elements share every field through `nvdm_header`, so `gmc` holds an -// RPC header rather than a GMC one unless the NVDM type says otherwise. -let (result, queue_pointers) =if !header.is_gmc_api () { -dev_warn! (&self.dev,"GSP GMC: dropping non-GMC queue element\n" ); - (None ,QueuePointers ::Unchanged ) - }else if num::u32_as_usize (header.gmc.size) != header.payload_length () { -// GSP-RM sends the element as the GMC header plus `size` bytes, so the two lengths -// describe the same payload and a handler cannot tell which one to believe. -dev_err! ( - &self.dev, -"GSP GMC: payload is {} bytes, transport declares {}\n" , - header.gmc.size, - header.payload_length (), - ); - (None ,QueuePointers ::Unchanged ) - }else { -let command_id = header.gmc.command_id (); -let kind =if header.gmc.is_response () { -"response" +let (result, queue_pointers) = +if num::u32_as_usize (header.gmc.size) != header.payload_length () { +// GSP-RM sends the element as the GMC header plus `size` bytes, so the two lengths +// describe the same payload and a handler cannot tell which one to believe. +dev_err! ( + &self.dev, +"GSP GMC: payload is {} bytes, transport declares {}\n" , + header.gmc.size, + header.payload_length (), + ); + (None ,QueuePointers ::Unchanged ) }else { -"event" - }; +let command_id = header.gmc.command_id (); +let sequence = header.gmc.sequence_number (); +let kind =if header.gmc.is_response () { +"response" + }else { +"event" + }; -dev_dbg! ( - &self.dev, -"GSP GMC: {}: seq# {}, command={}, length=0x{:x}\n" , - kind, - header.gmc.sequence_number (), -GmcCommand (command_id), - length, - ); +dev_dbg! ( + &self.dev, +"GSP GMC: {}: seq# {}, command={}, length=0x{:x}\n" , + kind, + sequence, +GmcCommand (command_id), + length, + ); -handler ( - command_id, - header.gmc.max_resp_or_status, - message.contents.0 , - message.contents.1 , - ) - }; +handler (&header.gmc, message.contents.0 , message.contents.1 ) + };let pages = u32::try_from (length.div_ceil (GSP_PAGE_SIZE ))?;
drivers/gpu/nova-core/gsp/commands.rs +22 -8
@@ -13,6 +13,10 @@ device, pci, prelude::*, + time::{ + Instant, + Monotonic, // + }, transmute::AsBytes, // };
@@ -219,20 +223,27 @@ pub(crate) fn gsp_init( GSP_INIT_MAX_RESPONSE_SIZE, )?; +let deadline =Instant ::<Monotonic >::now () +Cmdq ::RECEIVE_TIMEOUT ; loop { - let reply = cmdq.receive_gmc_and_dispatch( - bar, - Cmdq::RECEIVE_TIMEOUT, - |command_id, max_resp_or_status, payload_0, payload_1| { - if command_id == GMCAPI_CMD_GSP_INIT { + let remaining = deadline - Instant::<Monotonic>::now(); + if remaining.is_negative() { + return Err(ETIMEDOUT); + } + + let reply = + match cmdq.receive_gmc_and_dispatch(bar, remaining, |header, payload_0, payload_1| { + let command_id = header.command_id(); + if header.is_response() && command_id == GMCAPI_CMD_GSP_INIT { ( Some(decode_gsp_init_reply( - max_resp_or_status, + header.max_resp_or_status, payload_0, payload_1, )), QueuePointers::Unchanged, ) + } else if header.is_response() { + (None, QueuePointers::Unchanged) } else { // A boot event. Keep waiting for the reply unless handling it failed. match on_boot_event(command_id, payload_0) {
@@ -242,8 +253,11 @@ pub(crate) fn gsp_init( Err(e) => (Some(Err(e)), QueuePointers::Reset), } } - }, - )?; + }) { + Ok(reply) => reply, + Err(ERANGE) => continue, + Err(error) => return Err(error), + };if let Some (reply) = reply {return reply;
drivers/gpu/nova-core/gsp/fw.rs +22 -0
@@ -596,6 +596,11 @@ pub(crate) fn validate_framing(&self) -> Result { ) } +/// Returns `true` if the NVDM header routes this element to the RM RPC dispatcher. +pub (crate )fn is_rm_rpc (&self) ->bool { + self.nvdm_header.validate (NvdmType ::RmRpc ) + } +// Returns the sequence number of the message. pub (crate )fn sequence (&self) ->u32 { self.rpc.sequence
@@ -735,6 +740,13 @@ pub(crate) fn is_response(&self) -> bool { self.command &GMCAPI_COMMAND_FLAGS_RESPONSE !=0 } +/// Returns `true` if this header is the response to `command_id` and `sequence`. +pub (crate )fn is_response_to (&self, command_id:u32 , sequence:u64 ) ->bool { + self.is_response () + && self.command_id () == (command_id &GMCAPI_COMMAND_ID_MASK ) + && self.sequence == sequence + } +/// Returns [`Self::sequence`] with the GSP-initiated-event bit cleared. pub (crate )fn sequence_number (&self) ->u64 { self.sequence & !GMC_EVENT_SEQUENCE_BASE
@@ -911,6 +923,16 @@ pub(crate) fn validate_framing(&self) -> Result { ) } +pub (crate )fn validate_common_framing (&self) ->Result { +validate_mctp_framing ( + self.mctp_magic, + self.mctp_payload_size, + self.mctp_header, + self.nvdm_header, + core::mem::offset_of!(Self , gmc), + ) + } +/// Returns `true` if the NVDM header routes this element to the GSP's GMC dispatch. /// /// A [`GspMsgElement`] and a [`GspGmcMsgElement`] share every field through `nvdm_header`,
Signature · 1 line
2.53.0
PATCH 7/13 gpu: nova-core: vgpu: add vGPU bootload
In reply to Zhi WangImplement the GMCAPI VGPU_BOOTLOAD command that boots the GSP plugin for a vGPU instance, together with the VGPU_SHUTDOWN and VGPU_CLEANUP teardown sequence.
Encode the typed channel map, framebuffer, management heap and log locations, then poll the PluginRpc BAR1 marker for boot completion.
--- drivers/gpu/nova-core/gsp/commands.rs | 2 + drivers/gpu/nova-core/gsp/fw.rs | 18 ++- drivers/gpu/nova-core/gsp/fw/commands.rs | 60 +++++++ drivers/gpu/nova-core/mm/vram.rs | 3 - drivers/gpu/nova-core/vgpu/bootload.rs | 162 +++++++++++++++++++ drivers/gpu/nova-core/vgpu/consts.rs | 8 + drivers/gpu/nova-core/vgpu/fw.rs | 193 +++++++++++++++++++++++ drivers/gpu/nova-core/vgpu/instance.rs | 100 ++++++++++-- drivers/gpu/nova-core/vgpu/mod.rs | 2 + drivers/gpu/nova-core/vgpu/plugin_rpc.rs | 65 ++++++++ drivers/gpu/nova-core/vgpu/vram.rs | 2 - 11 files changed, 598 insertions(+), 17 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/bootload.rs create mode 100644 drivers/gpu/nova-core/vgpu/plugin_rpc.rs
drivers/gpu/nova-core/gsp/commands.rs +2 -0
@@ -54,6 +54,8 @@ };pub (crate )use fw::commands::{ + encode_vgpu_bootload, +ChannelMapEntry ,Dbdf ,VgpuProperties ,// };
drivers/gpu/nova-core/gsp/fw.rs +17 -1
@@ -7,8 +7,24 @@/// Raw firmware declarations used by vGPU management. pub (crate )mod vgpu_bindings {pub (crate )use super ::r000_00::{ +GMCAPI_COMMANDS_GMCAPI_CMD_BOOTLOAD_GSP_VGPU_PLUGIN_TASK , +GMCAPI_COMMANDS_GMCAPI_CMD_CLEANUP_GSP_VGPU_PLUGIN_RESOURCES ,GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE , -GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES ,// +GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES , +GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK , +GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK_COMPLETE , +GSP_PLUGIN_BOOTLOADED , +VGPU_CPU_GSP_COMMUNICATION_BUFF_TOTAL_SIZE , +VGPU_CPU_GSP_CTRL_BUFF_REGION , +VGPU_CPU_GSP_CTRL_BUFF_REGION_SIZE , +VGPU_CPU_GSP_ERROR_BUFF_REGION_SIZE , +VGPU_CPU_GSP_GUEST_RPC_TRACE_BUFF_REGION_SIZE , +VGPU_CPU_GSP_INIT_TASK_LOG_BUFF_REGION_SIZE , +VGPU_CPU_GSP_KERNEL_TASK_LOG_BUFF_REGION_SIZE , +VGPU_CPU_GSP_MESSAGE_BUFF_REGION_SIZE , +VGPU_CPU_GSP_MIGRATION_BUFF_REGION_SIZE , +VGPU_CPU_GSP_RESPONSE_BUFF_REGION_SIZE , +VGPU_CPU_GSP_VGPU_TASK_LOG_BUFF_REGION_SIZE ,// }; }
drivers/gpu/nova-core/gsp/fw/commands.rs +60 -0
72 lines not on this page · raw message
drivers/gpu/nova-core/mm/vram.rs +0 -3
@@ -86,19 +86,16 @@ fn new(backing: Arc<VramBlock>, range: Range<u64>) -> Result<Self> { }/// Return the physical address of the first byte in this region. -#[expect(dead_code)] pub (crate )const fn address (&self) ->u64 { self.address }/// Return the region size in bytes. -#[expect(dead_code)] pub (crate )const fn size (&self) ->u64 { self.size }/// Return a checked subregion relative to this region. -#[expect(dead_code)] pub (crate )fn subregion (&self, range:Range <u64 >) ->Result <Self > {let size = range .end
drivers/gpu/nova-core/vgpu/bootload.rs new file +162 -0
162 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/consts.rs +8 -0
@@ -9,4 +9,12 @@ pub(crate) mod gmc { bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES ;pub (crate )const VGPU_MGMT_QUERY_ASSIGNED_VF :u32 = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE ; +pub (crate )const BOOTLOAD :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_BOOTLOAD_GSP_VGPU_PLUGIN_TASK ; +pub (crate )const SHUTDOWN :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK ; +pub (crate )const SHUTDOWN_COMPLETE :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK_COMPLETE ; +pub (crate )const CLEANUP :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_CLEANUP_GSP_VGPU_PLUGIN_RESOURCES ; }
drivers/gpu/nova-core/vgpu/fw.rs +193 -0
195 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/instance.rs +89 -11
164 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/mod.rs +2 -0
@@ -3,8 +3,10 @@use core::num::NonZero ; +pub (crate )mod bootload;pub (crate )mod consts;pub (crate )mod instance; +pub (crate )mod plugin_rpc;pub (crate )use self::instance::VgpuInstances ;
drivers/gpu/nova-core/vgpu/plugin_rpc.rs new file +65 -0
65 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/vram.rs +0 -2
@@ -3,8 +3,6 @@//! VRAM slot allocation for vGPU instances. -#![expect(dead_code)] -use kernel::{ bitmap::BitmapVec , prelude::*,
Signature · 1 line
2.53.0
PATCH 8/13 gpu: nova-core: vgpu: implement PluginRpc channel and config params
In reply to Zhi WangExtend PluginRpc from a boot-ready poller into the BAR1-backed RPC channel used by the vGPU plugin.
Initialize the control and response regions, publish NVKV-encoded messages through the message region, ring the VF doorbell, and match responses by sequence number. Negotiate the protocol, send the VM configuration, and enable bus mastering after the plugin starts.
Keep raw firmware message IDs in fw/commands.rs and retain ownership of the communication mapping in PluginRpc so teardown can release it after firmware cleanup.
--- drivers/gpu/nova-core/gsp/commands.rs | 2 + drivers/gpu/nova-core/gsp/fw.rs | 6 + drivers/gpu/nova-core/gsp/fw/commands.rs | 45 +++++ drivers/gpu/nova-core/mm/bar_user.rs | 11 ++ drivers/gpu/nova-core/vgpu/consts.rs | 7 + drivers/gpu/nova-core/vgpu/fw.rs | 192 +++++++++++++++++++- drivers/gpu/nova-core/vgpu/fw/commands.rs | 29 +++ drivers/gpu/nova-core/vgpu/instance.rs | 30 +++- drivers/gpu/nova-core/vgpu/plugin_rpc.rs | 209 +++++++++++++++++++++- 9 files changed, 519 insertions(+), 12 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/fw/commands.rs
drivers/gpu/nova-core/gsp/commands.rs +2 -0
@@ -54,6 +54,8 @@ };pub (crate )use fw::commands::{ + encode_plugin_config_params, + encode_plugin_set_bme, encode_vgpu_bootload,ChannelMapEntry ,Dbdf ,
drivers/gpu/nova-core/gsp/fw.rs +6 -0
@@ -14,15 +14,21 @@ pub(crate) mod vgpu_bindings { GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK, GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK_COMPLETE, GSP_PLUGIN_BOOTLOADED, + MESSAGE_NV_VGPU_CPU_RPC_MSG_RESET, + MESSAGE_NV_VGPU_CPU_RPC_MSG_SETUP_CONFIG_PARAMS_AND_INIT, + MESSAGE_NV_VGPU_CPU_RPC_MSG_UPDATE_BME_STATE, + MESSAGE_NV_VGPU_CPU_RPC_MSG_VERSION_NEGOTIATION, VGPU_CPU_GSP_COMMUNICATION_BUFF_TOTAL_SIZE, VGPU_CPU_GSP_CTRL_BUFF_REGION, VGPU_CPU_GSP_CTRL_BUFF_REGION_SIZE, + VGPU_CPU_GSP_CTRL_BUFF_VERSION, VGPU_CPU_GSP_ERROR_BUFF_REGION_SIZE, VGPU_CPU_GSP_GUEST_RPC_TRACE_BUFF_REGION_SIZE, VGPU_CPU_GSP_INIT_TASK_LOG_BUFF_REGION_SIZE, VGPU_CPU_GSP_KERNEL_TASK_LOG_BUFF_REGION_SIZE, VGPU_CPU_GSP_MESSAGE_BUFF_REGION_SIZE, VGPU_CPU_GSP_MIGRATION_BUFF_REGION_SIZE, + VGPU_CPU_GSP_RESPONSE_BUFF_REGION, VGPU_CPU_GSP_RESPONSE_BUFF_REGION_SIZE, VGPU_CPU_GSP_VGPU_TASK_LOG_BUFF_REGION_SIZE, // };
drivers/gpu/nova-core/gsp/fw/commands.rs +45 -0
57 lines not on this page · raw message
drivers/gpu/nova-core/mm/bar_user.rs +11 -0
@@ -141,6 +141,12 @@ pub(crate) fn try_read32(&self, offset: usize) -> Result<u32> { self.bar_user.bar1.try_read32 (off) } +/// Write an 8-bit value at the given offset. +pub (crate )fn try_write8 (&self, value:u8 , offset:usize ) ->Result { +let off = self.bar_offset (offset)?; + self.bar_user.bar1.try_write8 (value, off) + } +/// Write a 32-bit value at the given offset. pub (crate )fn try_write32 (&self, value:u32 , offset:usize ) ->Result {let off = self.bar_offset (offset)?;
@@ -270,6 +276,11 @@ pub(crate) fn try_read32(&self, offset: usize) -> Result<u32> { .try_read32(self.bar_offset(offset, size_of::<u32>())?) } +pub (crate )fn try_write8 (&self, value:u8 , offset:usize ) ->Result { + self.bar1 + .try_write8 (value, self.bar_offset (offset,size_of ::<u8 >())?) + } +pub (crate )fn try_write32 (&self, value:u32 , offset:usize ) ->Result { self.bar1 .try_write32 (value, self.bar_offset (offset,size_of ::<u32 >())?)
drivers/gpu/nova-core/vgpu/consts.rs +7 -0
@@ -18,3 +18,10 @@ pub(crate) mod gmc {pub (crate )const CLEANUP :u32 = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_CLEANUP_GSP_VGPU_PLUGIN_RESOURCES ; } + +/// vGPU plugin RPC values not provided by the firmware bindings. +pub (crate )mod plugin_rpc { +pub (crate )const DOORBELL_STRIDE :u32 =32 ; +pub (crate )const DOORBELL_VECTOR :u32 =17 ; +pub (crate )const NV_VIRTUAL_FUNCTION_PRIV_DOORBELL :usize =0xb8_0000 +0x2200 ; +}
drivers/gpu/nova-core/vgpu/fw.rs +186 -6
263 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/fw/commands.rs new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +use crate ::gsp::vgpu_bindingsas bindings; + +/// State observed in the response buffer for an expected RPC sequence. +pub (crate )enum RpcResponse { +/// Firmware has not completed the expected sequence. +Pending { +/// Last sequence completed by firmware. + sequence:u32 , + }, +/// Firmware has completed the expected sequence. +Complete { +/// Firmware result code. + status:u32 , + }, +} + +/// Message types supported by the nova-core plugin RPC channel. +#[derive( Clone , Copy )] +#[repr( u32 )] +pub (crate )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 , +#[expect(dead_code)] +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 +27 -3
@@ -34,7 +34,10 @@ }, consts::gmc, fw::CommBufferRegion, - plugin_rpc::PluginRpc, + plugin_rpc::{ + PluginConfigParams, + PluginRpc, // + }, vram::{VgpuVramLayout ,VgpuVramSlot ,
@@ -353,7 +356,11 @@ pub(crate) fn query_vgpu_type(cmdq: &Cmdq, bar: Bar0<'_>, type_id: u32) -> ResulOk (VgpuType ::from_properties (&properties)) } -/// Bootload the GSP plugin for an allocated instance. +/// Start the vGPU plugin and establish its RPC channel. +/// +/// Ask GSP to create the plugin task, wait for its BAR1 ready marker, +/// initialize the shared RPC buffers, negotiate the protocol, send the +/// instance configuration, and enable bus mastering. #[expect(dead_code)] pub (crate )fn activate_instance ( dev: &device::Device<device::Bound>,
@@ -362,5 +369,22 @@ pub(crate) fn activate_instance( instance: &mut VgpuInstance<'_>, fifo_engine_list: &FifoEngineList, ) -> Result { -bootload (dev, cmdq, bar, instance, fifo_engine_list) +bootload (dev, cmdq, bar, instance, fifo_engine_list)?; + +let params =PluginConfigParams ::new ( + [0 ;16 ], + instance.dbdf, + instance.vgpu_type.vgpu_type_id, + instance.vm_pid, + u32::try_from (instance.chids.len ()).map_err (|_|EOVERFLOW )?, + instance.num_plugin_channels, + ); +let gfid = instance.gfid; +let rpc = &mut instance.plugin_rpc; + rpc.init_rpc ()?; + rpc.negotiate_rpc_version (dev, bar, gfid)?; + rpc.send_config_params (dev, bar, gfid, ¶ms)?; + rpc.set_bme (dev, bar, gfid,true )?; + +Ok (()) }
drivers/gpu/nova-core/vgpu/plugin_rpc.rs +206 -3
251 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 9/13 gpu: nova-core: vgpu: scrub guest framebuffer memory with CeUtils
In reply to Zhi WangA vGPU framebuffer can retain guest data when an instance is reused. Add a per-instance Copy Engine utility, CeUtils, that asks GSP-RM to scrub the framebuffer and verifies completion through a hardware semaphore page.
Scrub a framebuffer immediately after allocating it and after shutting an instance down, before returning its VRAM to the allocator. Reserve the last channel ID in each instance range for CeUtils and report the remaining channel count to the plugin.
If firmware ownership or scrub completion cannot be established, retain the affected channel IDs and VRAM instead of allowing another instance to reuse them.
--- drivers/gpu/nova-core/gsp/fw.rs | 4 + .../gpu/nova-core/gsp/fw/r000_00/bindings.rs | 1 + drivers/gpu/nova-core/vgpu/consts.rs | 6 + drivers/gpu/nova-core/vgpu/instance.rs | 141 +++++- drivers/gpu/nova-core/vgpu/mod.rs | 1 + drivers/gpu/nova-core/vgpu/scrubber.rs | 474 ++++++++++++++++++ 6 files changed, 615 insertions(+), 12 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/scrubber.rs
drivers/gpu/nova-core/gsp/fw.rs +4 -0
@@ -13,11 +13,15 @@ pub(crate) mod vgpu_bindings { GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES, GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK, GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK_COMPLETE, + GMCAPI_COMMANDS_GMCAPI_CMD_VGPU_MGR_ALLOC_GSP_CEUTILS, + GMCAPI_COMMANDS_GMCAPI_CMD_VGPU_MGR_FREE_GSP_CEUTILS, + GMCAPI_COMMANDS_GMCAPI_CMD_VGPU_MGR_SCRUB_GUEST_FB, GSP_PLUGIN_BOOTLOADED, MESSAGE_NV_VGPU_CPU_RPC_MSG_RESET, MESSAGE_NV_VGPU_CPU_RPC_MSG_SETUP_CONFIG_PARAMS_AND_INIT, MESSAGE_NV_VGPU_CPU_RPC_MSG_UPDATE_BME_STATE, MESSAGE_NV_VGPU_CPU_RPC_MSG_VERSION_NEGOTIATION, + NV_ADDR_FBMEM, VGPU_CPU_GSP_COMMUNICATION_BUFF_TOTAL_SIZE, VGPU_CPU_GSP_CTRL_BUFF_REGION, VGPU_CPU_GSP_CTRL_BUFF_REGION_SIZE,
drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs +1 -0
@@ -858,6 +858,7 @@ pub struct rpc_unloading_guest_driver_v1F_07 { pub __bindgen_padding_0: [u8; 2usize], pub newLevel: u32_, } +pub const NV_ADDR_FBMEM :u32 =2 ;pub const GSP_PLUGIN_BOOTLOADED :u32 =1315261039 ;pub const VGPU_CPU_GSP_CTRL_BUFF_VERSION :u32 =2 ;pub const VGPU_CPU_GSP_CTRL_BUFF_REGION_SIZE :u32 =4096 ;
drivers/gpu/nova-core/vgpu/consts.rs +6 -0
@@ -17,6 +17,12 @@ pub(crate) mod gmc { bindings::GMCAPI_COMMANDS_GMCAPI_CMD_SHUTDOWN_GSP_VGPU_PLUGIN_TASK_COMPLETE ;pub (crate )const CLEANUP :u32 = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_CLEANUP_GSP_VGPU_PLUGIN_RESOURCES ; +pub (crate )const SCRUB_GUEST_FB :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_VGPU_MGR_SCRUB_GUEST_FB ; +pub (crate )const ALLOC_GSP_CEUTILS :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_VGPU_MGR_ALLOC_GSP_CEUTILS ; +pub (crate )const FREE_GSP_CEUTILS :u32 = + bindings::GMCAPI_COMMANDS_GMCAPI_CMD_VGPU_MGR_FREE_GSP_CEUTILS ; }/// vGPU plugin RPC values not provided by the firmware bindings.
drivers/gpu/nova-core/vgpu/instance.rs +129 -12
229 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/mod.rs +1 -0
@@ -7,6 +7,7 @@pub (crate )mod consts;pub (crate )mod instance;pub (crate )mod plugin_rpc; +pub (crate )mod scrubber;pub (crate )use self::instance::VgpuInstances ;
drivers/gpu/nova-core/vgpu/scrubber.rs new file +474 -0
474 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 10/13 gpu: nova-core: vgpu: export plugin log buffers via debugfs
In reply to Zhi WangExpose the three per-VM GSP plugin log buffers (init, vgpu, kernel) through debugfs so that nvlog_decoder can decode them at runtime.
Each log file is backed by VRAM in the management heap and read via BAR1 MMIO. A self-describing header (architecture + build ID) is prepended so decoding tools need no out-of-band metadata.
Make gpu.spec and gpu.build_id accessible to instance creation, and promote LOG_BUFFER_HEADER_SIZE / build_log_buffer_header to pub(crate) for reuse by the vGPU log module.
--- drivers/gpu/nova-core/driver.rs | 42 ++++-- drivers/gpu/nova-core/gpu.rs | 10 +- drivers/gpu/nova-core/gsp.rs | 16 ++- drivers/gpu/nova-core/mm/bar_user.rs | 61 ++++++--- drivers/gpu/nova-core/vgpu/fw.rs | 117 +++++++++++++++- drivers/gpu/nova-core/vgpu/instance.rs | 79 ++++++++++- drivers/gpu/nova-core/vgpu/log.rs | 167 +++++++++++++++++++++++ drivers/gpu/nova-core/vgpu/mod.rs | 1 + drivers/gpu/nova-core/vgpu/plugin_rpc.rs | 6 + 9 files changed, 458 insertions(+), 41 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/log.rs
drivers/gpu/nova-core/driver.rs +28 -14
@@ -6,6 +6,7 @@ Bound, Core, // }, + devres::Devres, io::resource, pci, pci::{
@@ -15,9 +16,12 @@ }, prelude::*, sizes::SZ_16M, - sync::atomic::{ - Atomic, - Relaxed, // + sync::{ + atomic::{ + Atomic, + Relaxed, // + }, + Arc, // }, types::ForLt, };
@@ -35,18 +39,28 @@#[pin_data] pub (crate )struct NovaCore <'bound> { +/// Auxiliary DRM-device registration. +/// +/// Declared first so consumers are unregistered before the interrupt and GPU resources are +/// torn down. +#[allow(clippy::type_complexity)] + _reg: auxiliary::Registration <'bound,ForLt! (())>,/// GSP event interrupt registration. /// -/// Declared first so it is dropped first: `free_irq` runs (waiting out any in-flight handler) -/// before the GSP is unloaded (`gpu`) or the BAR mapping is released (`bar`). +/// Declared before the GPU and BAR resources so `free_irq` runs (waiting out any in-flight +/// handler) before the GSP is unloaded (`gpu`) or the BAR mapping is released (`bar`). #[pin] _gsp_irq:GspIrq <'bound>,#[pin] pub (crate ) gpu:Gpu <'bound>, bar: pci::Bar <'bound,BAR0_SIZE >, - bar1:Bar1 <'bound>, -#[allow(clippy::type_complexity)] - _reg: auxiliary::Registration <'bound,ForLt! (())>, +/// Device-managed BAR1 mapping shared with debugfs readers. +/// +/// Debugfs file backing types must be `'static`, so readers cannot retain +/// the lifetime-bound [`Bar1`] reference used before log export was added. +/// [`Devres`] revokes access during unbind, while [`Arc`] keeps the handle +/// alive until all scoped readers have drained. + bar1:Arc <Devres <Bar1 <'static>>>,/// Self-referential borrow of `vectors`, so this does not have to be repeated in the /// constructor. Will go away with self-referential pin-init. vectors_ref: &'boundSubtreeVectors <'bound>,
@@ -129,17 +143,17 @@ fn probe<'bound>(// is dropped after all fields that use `vectors_ref` (struct field drop order). vectors_ref: unsafe { &*core::ptr::from_ref(vectors.as_ref().get_ref()) }, bar: pdev.iomap_region_sized::<BAR0_SIZE>(0, c"nova-core/bar0")?, - bar1: { - let bar1_idx = bar1_resource_index(pdev)?; - pdev.iomap_region (bar1_idx,c"nova-core/bar1" )? - }, + bar1: Arc::new( + pdev.iomap_region(bar1_resource_index(pdev)?, c"nova-core/bar1")? + .into_devres()?, + GFP_KERNEL, + )?,// TODO: Use self-referential pin-init syntax once available. gpu <-Gpu ::new ( pdev,// SAFETY: `bar` is initialized above, pinned, and outlives `gpu`. unsafe { &*core::ptr::from_ref (bar) }, -// SAFETY: `bar1` is initialized above, pinned, and outlives `gpu`. -unsafe { &*core::ptr::from_ref (bar1) }, + bar1.clone (), vectors_ref, ),// Quiesce the interrupt tree before registering the handler below.
drivers/gpu/nova-core/gpu.rs +9 -1
@@ -4,6 +4,7 @@use kernel::{ device, + devres::Devres , dma::Device , fmt, gpu::buddy::GpuBuddyParams ,
@@ -31,6 +32,7 @@ Falcon, // }, fb::SysmemFlush, + firmware, fsp::Fsp, gsp::{ self,
@@ -374,10 +376,16 @@ pub(crate) fn cmdq(&self) -> Arc<Cmdq> { self.gsp_resources.gsp.cmdq () } +/// Returns the firmware build identifier, if one was reported. +#[expect(dead_code)] +pub (crate )fn build_id (&self) ->Option <firmware::BuildId > { + self.gsp_resources.gsp.build_id () + } +pub (crate )fn new ( pdev: &'gpu pci::Device <device::Core <'_>>, bar:Bar0 <'gpu>, - bar1: &'gpuBar1 <'gpu>, + bar1:Arc <Devres <Bar1 <'static>>>, vectors: &'gpuSubtreeVectors <'gpu>, ) ->impl PinInit <Self ,Error > + 'gpu {let dev = pdev.as_ref ();
drivers/gpu/nova-core/gsp.rs +14 -2
@@ -116,7 +116,10 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {/// This header makes each dump self-describing so that decoding tools can /// identify the firmware build, GPU architecture, and metadata format without /// out-of-band information. -const LOG_BUFFER_HEADER_SIZE :usize =0x48 ; +/// +/// `0x48` is the offset of `data` in `LIBOS_LOG_NVLOG_BUFFER_V2`, as defined +/// by Open RM's `uproc/os/common/include/liblogdecode.h`. +pub (crate )const LOG_BUFFER_HEADER_SIZE :usize =0x48 ;/// Build a log buffer header from GPU and firmware metadata. ///
@@ -130,7 +133,7 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {/// 0x20 buildId[32] /// 0x40 flags (u32) = 1 (packed metadata) /// 0x44 reserved (u32) = 0 -fn build_log_buffer_header ( +pub (crate )fn build_log_buffer_header ( chipset:Chipset , build_id: &BuildId , task_prefix: &str,
@@ -411,6 +414,15 @@ pub(crate) const fn vgpu_state(&self) -> VgpuState {pub (crate )fn cmdq (&self) ->Arc <Cmdq > { self.cmdq.clone () } + +/// Returns the firmware build identifier, if one was reported. +pub (crate )fn build_id (&self) ->Option <BuildId > { +Tlv ::new (self.gsp_tlv.data ()) + .ok ()? + .get_bytes (b"BLID" ) + .ok () + .and_then (BuildId ::from_raw) + } }/// Opaque bundle required to unload the GSP. Created by [`Gsp::boot`], consumed by [`Gsp::unload`].
drivers/gpu/nova-core/mm/bar_user.rs +42 -19
158 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/fw.rs +116 -1
137 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/instance.rs +75 -4
143 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/log.rs new file +167 -0
167 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/mod.rs +1 -0
@@ -6,6 +6,7 @@pub (crate )mod bootload;pub (crate )mod consts;pub (crate )mod instance; +pub (crate )mod log;pub (crate )mod plugin_rpc;pub (crate )mod scrubber;
drivers/gpu/nova-core/vgpu/plugin_rpc.rs +6 -0
@@ -27,6 +27,7 @@ }, vgpu::fw::{CommBufferRegion , +MappedPluginLogBuffers ,PluginLogRegions ,RpcMessage ,RpcResponse ,//
@@ -92,6 +93,11 @@ pub(crate) fn plugin_logs(&self) -> Result<PluginLogRegions> { self.comm.plugin_logs () } +/// Return revocable BAR1 views of the plugin logs. +pub (crate )fn mapped_plugin_logs (&self) ->Result <MappedPluginLogBuffers > { + self.comm.mapped_plugin_logs () + } +/// Poll the control buffer until the plugin publishes its boot marker. pub (crate )fn wait_plugin_ready (&self, dev: &device::Device <device::Bound >) ->Result {let start =Instant ::<Monotonic >::now ();
Signature · 1 line
2.53.0
PATCH 11/13 gpu: nova-core: vgpu: export lifecycle operations to VFIO
In reply to Zhi WangThe NVIDIA vGPU VFIO variant driver needs nova-core to create, reset, and destroy firmware-backed vGPU instances on behalf of virtual functions.
Add an internal C interface for these operations and implement its entry points in Rust. The open operation queries the profile assigned to the VF and creates and activates an instance. Close and reset run the corresponding teardown and reinitialization sequences.
Keep registry locking, allocation, activation, publication, and rollback inside VgpuManager so the VFIO caller does not coordinate manager state. Extend the existing C export shim to publish the three GPL-only symbols in the NOVA_CORE_VGPU namespace, and use the Rust #[export] attribute to verify their signatures against the C declarations at build time.
--- drivers/gpu/nova-core/gpu.rs | 55 ++++- drivers/gpu/nova-core/nova_core_exports.c | 5 + drivers/gpu/nova-core/vgpu/fw/commands.rs | 1 - drivers/gpu/nova-core/vgpu/instance.rs | 145 ++++++++++- drivers/gpu/nova-core/vgpu/mod.rs | 11 +- drivers/gpu/nova-core/vgpu/vfio.rs | 282 ++++++++++++++++++++++ include/drm/nvidia_vgpu.h | 28 +++ rust/bindings/bindings_helper.h | 1 + 8 files changed, 504 insertions(+), 24 deletions(-) create mode 100644 drivers/gpu/nova-core/vgpu/vfio.rs create mode 100644 include/drm/nvidia_vgpu.h
drivers/gpu/nova-core/gpu.rs +43 -12
@@ -1,6 +1,9 @@// SPDX-License-Identifier: GPL-2.0 -use core::ops::Range ; +use core::{ + num::NonZero , + ops::Range ,// +};use kernel::{ device,
@@ -9,6 +12,7 @@ fmt, gpu::buddy::GpuBuddyParams, io::Io, + new_mutex, num::Bounded, pci, prelude::*,
@@ -17,7 +21,10 @@ SizeConstants, SZ_4K, // }, - sync::Arc, + sync::{ +Arc , +Mutex ,// + }, };use crate ::{
@@ -318,7 +325,8 @@ pub(crate) struct Gpu<'gpu> {/// /// Must be kept declared *before* `gsp_resources`, so that its components are dropped while /// the GSP is still operational. - mm: GpuMm<'gpu>, +#[pin] + mm: Mutex<GpuMm<'gpu>>,/// BAR1 user interface for CPU access to GPU virtual memory. #[pin] bar_user: BarUser<'gpu>,
@@ -377,11 +385,30 @@ pub(crate) fn cmdq(&self) -> Arc<Cmdq> { }/// Returns the firmware build identifier, if one was reported. -#[expect(dead_code)] pub (crate )fn build_id (&self) ->Option <firmware::BuildId > { self.gsp_resources.gsp.build_id () } +pub (crate )fn vgpu_manager (&self) -> &VgpuManager <'gpu> { + &self.vgpu + } + +pub (crate )fn vgpu_total_vfs (&self) ->Option <NonZero <u16 >> { + self.vgpu.total_vfs () + } + +pub (crate )fn mm (&self) -> &Mutex <GpuMm <'gpu>> { + &self.mm + } + +pub (crate )fn bar_user (&self) -> &BarUser <'gpu> { + &self.bar_user + } + +pub (crate )fn bar0 (&self) ->Bar0 <'gpu> { + self.gsp_resources.bar + } +pub (crate )fn new ( pdev: &'gpu pci::Device <device::Core <'_>>, bar: Bar0<'gpu>,
@@ -505,7 +532,7 @@ pub(crate) fn new( },// Create GPU memory manager owning memory management resources. - mm: { + mm <- {let info = &gsp_resources.boot_result.static_info;let usable_vram = info.usable_fb_regions.first ().ok_or (ENODEV )?; let buddy_params = GpuBuddyParams {
@@ -514,12 +541,15 @@ pub(crate) fn new( chunk_size: Alignment::new::<SZ_4K>(), }; -GpuMm ::new ( - bar, - gsp_resources.spec.chipset, - buddy_params, -VramAddress ::from_raw (info.total_fb_end), - )? +new_mutex! ( +GpuMm ::new ( + bar, + gsp_resources.spec.chipset, + buddy_params, +VramAddress ::from_raw (info.total_fb_end), + )?, +"nova-core::gpu-mm" , + ) },// Create BAR1 user interface for CPU access to GPU virtual memory.
@@ -550,10 +580,11 @@ pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bou .boot_result .static_info;let regions = &info.usable_fb_regions; +let mut mm = this.mm.lock (); if let Err(err) = crate::mm::selftest::run( dev, - this.mm, + &mut mm, regions, this.bar_user.as_ref().get_ref(), info.bar1_pde_base,
drivers/gpu/nova-core/nova_core_exports.c +5 -0
@@ -8,8 +8,13 @@* dependencies natively. */ +#include <drm/nvidia_vgpu.h> #include <linux/export.h> +EXPORT_SYMBOL_NS_GPL (nvidia_vgpu_open,"NOVA_CORE_VGPU" ); +EXPORT_SYMBOL_NS_GPL (nvidia_vgpu_close,"NOVA_CORE_VGPU" ); +EXPORT_SYMBOL_NS_GPL (nvidia_vgpu_reset,"NOVA_CORE_VGPU" ); +#define EXPORT_SYMBOL_RUST_GPL (sym) extern int sym; EXPORT_SYMBOL_GPL(sym)#include "exports_nova_core_generated.h"
drivers/gpu/nova-core/vgpu/fw/commands.rs +0 -1
@@ -23,7 +23,6 @@ pub(crate) enum RpcResponse {pub (crate )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 , -#[expect(dead_code)] 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 +136 -9
226 lines not on this page · raw message
drivers/gpu/nova-core/vgpu/mod.rs +9 -2
@@ -9,6 +9,7 @@pub (crate )mod log;pub (crate )mod plugin_rpc;pub (crate )mod scrubber; +mod vfio;pub (crate )use self::instance::VgpuInstances ;
@@ -124,6 +125,14 @@ pub(crate) fn state(&self) -> VgpuState { self.state } +/// Returns the number of VFs available to an enabled vGPU boot. +pub (crate )fn total_vfs (&self) ->Option <NonZero <u16 >> { +match self.state { +VgpuState ::Disabled =>None , +VgpuState ::Enabled { total_vfs } =>Some (total_vfs), + } + } +/// Initializes the runtime parameters returned by GSP_INIT. pub (crate )fn init ( self: Pin<&mut Self>,
@@ -140,7 +149,6 @@ pub(crate) fn init( }/// Returns the live-instance registry. -#[expect(dead_code)] pub (crate )fn instances (&self) -> &Mutex <VgpuInstances <'gpu>> { &self.instances }
@@ -156,7 +164,6 @@ pub(crate) const fn total_channels(&self) -> Option<u32> { }/// Returns the ordered FIFO engine list provided by GSP_INIT. -#[expect(dead_code)] pub (crate )fn fifo_engine_list (&self) ->Result <&FifoEngineList > { self.fifo_engine_list.as_ref ().ok_or (ENODEV ) }
drivers/gpu/nova-core/vgpu/vfio.rs new file +282 -0
282 lines not on this page · raw message
include/drm/nvidia_vgpu.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +#ifndef __DRM_NVIDIA_VGPU_H__ +#define __DRM_NVIDIA_VGPU_H__ + +#include <linux/types.h> + +struct pci_dev ; + +/** +* struct nvidia_vgpu_type_info - vGPU type descriptor returned by open +* @pci_dev_id: PCI device ID to present to the guest +* @pci_subsys_id: PCI subsystem ID to present to the guest +* @bar1_length: BAR1 aperture size in MiB +*/ +struct nvidia_vgpu_type_info { +u32 pci_dev_id; +u32 pci_subsys_id; +u64 bar1_length; +}; + +int nvidia_vgpu_open (struct pci_dev *pf_pdev,unsigned int gfid, +unsigned int dbdf,unsigned int vm_pid, +struct nvidia_vgpu_type_info *type_info); +void nvidia_vgpu_close (struct pci_dev *pf_pdev,unsigned int gfid); +int nvidia_vgpu_reset (struct pci_dev *pf_pdev,unsigned int gfid); + +#endif /* __DRM_NVIDIA_VGPU_H__ */
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>
Signature · 1 line
2.53.0
PATCH 12/13 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 driver that binds NVIDIA devices only through driver_override and rejects non-VFs. Delegate instance lifecycle operations to nova-core, present the firmware-selected device and subsystem IDs in configuration-space reads, and adjust the reported BAR1 aperture to the assigned profile. Use vfio-pci-core for the remaining VFIO operations.
--- drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/Kconfig | 16 ++ drivers/vfio/pci/nvidia-vgpu/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++ 5 files changed, 275 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 +16 -0
@@ -0,0 +1,16 @@ +# 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. + + 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 +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.53.0
Alex Williamson
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 90 lines · On Sat, 5 Sep 2026 11:11:15 +0300 Zhi Wang <[email protected]> wrote:
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
Add a VFIO PCI variant driver that binds NVIDIA devices only through
driver_overrideand rejects non-VFs. Delegate instance lifecycle operations to nova-core, present the firmware-selected device and subsystem IDs in configuration-space reads, and adjust the reported BAR1 aperture to the assigned profile. Use vfio-pci-core for the remaining VFIO operations.Signed-off-by Zhi Wang <[email protected]>--- drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/Kconfig | 16 ++ drivers/vfio/pci/nvidia-vgpu/Makefile | 2 + drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++ 5 files changed, 275 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.cdrivers/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" + endmenudrivers/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 +16
-0@@ -0,0 +1,16 @@ +# 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. + + 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.odrivers/vfio/pci/nvidia-vgpu/main.c new file +11
-0@@ -0,0 +1,253 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <linux/module.h> +#include <linux/overflow.h> +#include <linux/pci.h> +#include <linux/pid.h> +#include <linux/vfio_pci_core.h> +#include <drm/nvidia_vgpu.h> + +static int nvidia_vgpu_fb_bar_index (struct pci_dev *pdev) +{ +if (pci_resource_flags (pdev,0 ) &IORESOURCE_MEM_64 )
drivers/vfio/pci/nvidia-vgpu/main.c line 21
Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +10
-0+return 2 ; +return 1 ; +} + +struct nvidia_vgpu_pci_core_device { +struct vfio_pci_core_device core_device; +struct nvidia_vgpu_type_info type_info; +unsigned int gfid; +}; +
This is more commonly called an "sbdf". Also, consider some comments.
Quoted 5 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +5
-0+static inline unsigned int nvidia_vgpu_vf_dbdf (struct pci_dev *vf) +{ +return ((u32 )pci_domain_nr (vf->bus) <<16 ) |pci_dev_id (vf); +} +
drivers/vfio/pci/nvidia-vgpu/main.c line 36
Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +10
-0+static int nvidia_vgpu_open_device (struct vfio_device *core_vdev) +{ +struct nvidia_vgpu_pci_core_device *nvdev =container_of ( + core_vdev, struct nvidia_vgpu_pci_core_device, core_device.vdev); +struct pci_dev *vf =to_pci_dev (core_vdev->dev); +struct nvidia_vgpu_type_info type_info; +int ret; + +if (!vf->is_virtfn) +return -ENODEV ;
This is redundant to the probe check.
Quoted 47 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +47
-0+ + ret =vfio_pci_core_enable (&nvdev->core_device); +if (ret) +return ret; + + ret =nvidia_vgpu_open (pci_physfn (vf), nvdev->gfid, +nvidia_vgpu_vf_dbdf (vf),task_tgid_nr (current), + &type_info); +if (ret) { +vfio_pci_core_disable (&nvdev->core_device); +return ret; + } + + nvdev->type_info = type_info; +pci_dbg (vf,"vgpu open: dev_id=0x%x subsys_id=0x%x bar1_length=0x%llx\n" , + type_info.pci_dev_id, type_info.pci_subsys_id, + type_info.bar1_length); +vfio_pci_core_finish_enable (&nvdev->core_device); +return 0 ; +} + +static void nvidia_vgpu_close_device (struct vfio_device *core_vdev) +{ +struct nvidia_vgpu_pci_core_device *nvdev =container_of ( + core_vdev, struct nvidia_vgpu_pci_core_device, core_device.vdev); +struct pci_dev *vf =to_pci_dev (core_vdev->dev); + +nvidia_vgpu_close (pci_physfn (vf), nvdev->gfid); +vfio_pci_core_close_device (core_vdev); +} + +static ssize_t nvidia_vgpu_pci_read_config (struct vfio_device *core_vdev, +char __user *buf,size_t count, +loff_t *ppos) +{ +struct nvidia_vgpu_pci_core_device *nvdev =container_of ( + core_vdev, struct nvidia_vgpu_pci_core_device, core_device.vdev); +struct nvidia_vgpu_type_info *ti = &nvdev->type_info; +loff_t pos = *ppos &VFIO_PCI_OFFSET_MASK ; +size_t register_offset; +loff_t copy_offset; +size_t copy_count; +__le16 val16; +int ret; + + ret =vfio_pci_core_read (core_vdev, buf, count, ppos); +if (ret <0 )
drivers/vfio/pci/nvidia-vgpu/main.c line 93
Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +10
-0+return ret; + +if (vfio_pci_core_range_intersect_range (pos, count,PCI_DEVICE_ID , +sizeof (val16), ©_offset, + ©_count, ®ister_offset)) { + val16 =cpu_to_le16 (ti->pci_dev_id); +if (copy_to_user (buf + copy_offset, + (void *)&val16 + register_offset, copy_count)) +return -EFAULT ; + }
Just stuff the device ID into vconfig, it's already read from there.
drivers/vfio/pci/nvidia-vgpu/main.c line 102
Quoted 9 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +9
-0+ +if (vfio_pci_core_range_intersect_range (pos, count,PCI_SUBSYSTEM_ID , +sizeof (val16), ©_offset, + ©_count, ®ister_offset)) { + val16 =cpu_to_le16 (ti->pci_subsys_id); +if (copy_to_user (buf + copy_offset, + (void *)&val16 + register_offset, copy_count)) +return -EFAULT ; + }
There's possibly an argument to be made that subsystem ID could be read from vconfig by default too so it could be pre-filled after vfio_config_init(), ie. after vfio_pci_core_enable(). The only reason it might change would be if firmware was updated, but a firmware update through vfio that changes the subsystem ID would be pretty sketchy already.
Quoted 39 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +39
-0+ +return count; +} + +static ssize_t nvidia_vgpu_pci_read (struct vfio_device *core_vdev, +char __user *buf,size_t count, +loff_t *ppos) +{ +unsigned int index =VFIO_PCI_OFFSET_TO_INDEX (*ppos); + +if (index ==VFIO_PCI_CONFIG_REGION_INDEX ) +return nvidia_vgpu_pci_read_config (core_vdev, buf, count, ppos); + +return vfio_pci_core_read (core_vdev, buf, count, ppos); +} + +static int nvidia_vgpu_bar1_size (struct nvidia_vgpu_pci_core_device *nvdev, +u64 *size) +{ +if (check_shl_overflow (nvdev->type_info.bar1_length,20 , size)) +return -EOVERFLOW ; + +return 0 ; +} + +static int nvidia_vgpu_get_region_info (struct vfio_device *core_vdev, +struct vfio_region_info *info, +struct vfio_info_cap *caps) +{ +int ret; + + ret =vfio_pci_ioctl_get_region_info (core_vdev, info, caps); +if (ret) +return ret; + +if (info->index ==nvidia_vgpu_fb_bar_index ( +to_pci_dev (core_vdev->dev)) && info->size) { + struct nvidia_vgpu_pci_core_device *nvdev = container_of( + core_vdev, struct nvidia_vgpu_pci_core_device,
drivers/vfio/pci/nvidia-vgpu/main.c line 151
Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +10
-0+ core_device.vdev); +u64 vgpu_bar1; + + ret =nvidia_vgpu_bar1_size (nvdev, &vgpu_bar1); +if (ret) +return ret; + +if (vgpu_bar1 && vgpu_bar1 < info->size) + info->size = vgpu_bar1; + }
So we're changing the reported BAR1 size, but just trusting that userspace honors that size for read/write/mmap? Again, consider some comments.
Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +10
-0+ +return 0 ; +} + +static long nvidia_vgpu_pci_ioctl (struct vfio_device *core_vdev, +unsigned int cmd,unsigned long arg) +{ +if (cmd ==VFIO_DEVICE_RESET ) { + struct nvidia_vgpu_pci_core_device *nvdev = container_of( + core_vdev, struct nvidia_vgpu_pci_core_device,
drivers/vfio/pci/nvidia-vgpu/main.c line 171
Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +10
-0+ core_device.vdev); +struct pci_dev *vf =to_pci_dev (core_vdev->dev); +int ret; + + ret =nvidia_vgpu_reset (pci_physfn (vf), nvdev->gfid); +if (ret) +return ret; + } + +return vfio_pci_core_ioctl (core_vdev, cmd, arg);
What about reset invoked through FLR? Would this be better served through .reset_prepare and .reset_done?
Quoted 22 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +22
-0+} + +static const struct vfio_device_ops nvidia_vgpu_pci_ops = { + .name ="nvidia-vgpu-vfio-pci" , + .init = vfio_pci_core_init_dev, + .release = vfio_pci_core_release_dev, + .open_device = nvidia_vgpu_open_device, + .close_device = nvidia_vgpu_close_device, + .ioctl = nvidia_vgpu_pci_ioctl, + .get_region_info_caps = nvidia_vgpu_get_region_info, + .device_feature = vfio_pci_core_ioctl_feature, + .read = nvidia_vgpu_pci_read, + .write = vfio_pci_core_write, + .mmap = vfio_pci_core_mmap, + .request = vfio_pci_core_request, + .match = vfio_pci_core_match, + .match_token_uuid = vfio_pci_core_match_token_uuid, + .bind_iommufd = vfio_iommufd_physical_bind, + .unbind_iommufd = vfio_iommufd_physical_unbind, + .attach_ioas = vfio_iommufd_physical_attach_ioas, + .detach_ioas = vfio_iommufd_physical_detach_ioas, +};
drivers/vfio/pci/nvidia-vgpu/main.c line 203
Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +10
-0+ +static int nvidia_vgpu_pci_probe (struct pci_dev *pdev, +const struct pci_device_id *id) +{ +struct nvidia_vgpu_pci_core_device *nvdev; +int vf_id; +int ret; + +if (!pdev->is_virtfn) +return -ENODEV ;
This driver needs to bind to what it matches in the id table, we don't have a policy for userspace to pick a 2nd best variant driver. hisi_acc handles a similar situation where only the VFs are supported for the migration feature of the variant driver. The PF needs to be supported here and bind to a vfio-pci-core passthrough ops structure.
We should probably define a PCI_DRIVER_OVERRIDE_DEVICE_VFIO variant that allows a class code to be specified so we aren't using this for all 10de: devices. I'm hoping that class code is for a 3D accelerator or the like rather than VGA class (a VF can't technically support a legacy endpoint anyway), but we need to consider what existing devices that currently use vfio-pci would now be bound to this driver and what module option features they might use. Thanks,
Alex
Quoted 50 lines
drivers/vfio/pci/nvidia-vgpu/main.c new file +50
-0+ + vf_id =pci_iov_vf_id (pdev); +if (vf_id <0 ) +return vf_id; + + nvdev =vfio_alloc_device (nvidia_vgpu_pci_core_device, core_device.vdev, + &pdev->dev, &nvidia_vgpu_pci_ops); +if (IS_ERR (nvdev)) +return PTR_ERR (nvdev); + + nvdev->gfid = vf_id +1 ; +dev_set_drvdata (&pdev->dev, &nvdev->core_device); + ret =vfio_pci_core_register_device (&nvdev->core_device); +if (ret) + goto out_put_vdev; + +return 0 ; + +out_put_vdev: +vfio_put_device (&nvdev->core_device.vdev); +return ret; +} + +static void nvidia_vgpu_pci_remove (struct pci_dev *pdev) +{ +struct vfio_pci_core_device *core_device =dev_get_drvdata (&pdev->dev); + +vfio_pci_core_unregister_device (core_device); +vfio_put_device (&core_device->vdev); +} + +static const struct pci_device_id nvidia_vgpu_pci_table[] = { +/* Placeholder: match all NVIDIA VFs (vendor 0x10de) */ + {PCI_DRIVER_OVERRIDE_DEVICE_VFIO (PCI_VENDOR_ID_NVIDIA ,PCI_ANY_ID ) }, + {} +}; +MODULE_DEVICE_TABLE (pci, nvidia_vgpu_pci_table); + +static struct pci_driver nvidia_vgpu_pci_driver = { + .name ="nvidia-vgpu-vfio-pci" , + .id_table = nvidia_vgpu_pci_table, + .probe = nvidia_vgpu_pci_probe, + .remove = nvidia_vgpu_pci_remove, + .driver_managed_dma = true, +}; +module_pci_driver (nvidia_vgpu_pci_driver); + +MODULE_DESCRIPTION ("NVIDIA vGPU vfio-pci driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_IMPORT_NS ("NOVA_CORE_VGPU" );
Danilo Krummrich
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
In reply to Zhi WangHi Alex, Jason, Zhi,
Quoted 2 lines · Zhi Wang
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
[...]
Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++
This is going to be a longer response; sorry about this in advance.
Looking at the FFI boundary introduced in the previous patch, I'm concerned that it translates the driver model relationships we've expressed through Rust's ownership and lifetime model back into raw pointers and lifetime assumptions that callers must uphold. It also introduces manual lifecycle management across the boundary, rather than preserving nova-core's RAII-based ownership model.
I think implementing the NVIDIA vGPU driver in Rust would let us preserve those relationships across the interface, make lifecycle management less error-prone, and fit naturally alongside nova-core and nova-drm.
I did sketch up the necessary code for this in [1], which contains the VFIO/PCI Rust infrastructure [2], a Rust implementation of the NVIDIA vGPU driver [3] and the required PCI SR-IOV infrastructure [4].
This is PoC code; I focused on the general design, and I've tested the VFIO bits to a point that I can poke the character device from userspace. But it still needs a bit of cleanup and probably a few additional new type abstractions over primitive types, etc. As conferences are approaching and I have a bunch of stuff to prepare I could only finish it up after LPC, but I hope that Zhi is also interested in picking it up. :)
I'm aware that you may have some concerns about Rust code in VFIO and one of them might be maintainance. I already have a lot on my plate, but I'm happy to offer to take responsibility. It would also be great if Zhi were interested in helping maintain them.
In this context, I'd like to walk through the design and a few code examples below. We can also follow up at LPC, perhaps as part of the Nova workshop. (Zhi, would you be interested in preparing a brief session on this with me?)
In general, the VFIO/PCI Rust code is not much different from the FWCTL and DRM code that we have upstream already. In the end they are all the same design in terms of the Rust class device lifetime model.
Below is a PCI driver skeleton that implements a VFIO/PCI class device (stripped down version of the NVIDIA vGPU driver), with a bunch of comments.
#[pin_data]
struct NvidiaVgpuData<'bound> {
_reg: vfio::pci::Registration<'bound, NvidiaVgpuOps>,
}This is the driver's bus device private data. The driver core uses a RAII approach for this, it creates the driver's bus device private data from the initializer returned from probe() and calls the destructor of the driver's bus device private data on remove(), which is the equivalent of a remove() callback in C.
In this case it just contains the vfio::pci::Registration, which essentially is a RAII type for vfio_pci_core_register_device() and vfio_pci_core_unregister_device().
(I'm aware that that vfio_pci_core_register_device() currently requires the driver's bus device private data to be set to a struct vfio_pci_core_device pointer as a trick to support PCI bus callbacks, such as with vfio_pci_core_aer_err_detected(). I fixed this up in [5].)
#[pin_data]
pub struct NvidiaVgpuRegData<'a> {
pdev: &'a pci::Device<Bound>,
api: NovaCoreVfApiHandle<'a>,
}This is the private data attached to the vfio::pci::Registration, which is accessible from the callbacks in struct vfio_device_ops.
You may wonder why the private data is on the vfio::pci::Registration rather than the vfio::pci::Device.
The reason is that the callbacks in struct vfio_device_ops are lifetime wise associated with the vfio::pci::Registration and not the vfio::pci::Device, so the destructor of this data should be called when the destructor of vfio::pci::Registration runs, i.e. directly after vfio_pci_core_unregister_device().
Furthermore, it allows us to store device resources, such as a DMA coherent allocation, within this data in the first place, as the Rust compiler will ensure that a vfio::pci::Registration can't outlive driver unbind, since its lifetime is bound to the bus driver's bus device private data.
(This is also why NvidiaVgpuRegData<'a> can store e.g. &'a pci::Device<Bound>; the lifetime 'a is guaranteed to be shorter lived than the 'bound lifetime that describes the lifetime of the driver being bound to a device.)
The vfio::pci::Device on the other hand is reference counted and has an unbounded lifetime.
Note that in the end this is only a logical distinction for when the destructor is called. The actual memory this data goes into does not matter too much; it can be a new allocation, it can be the allocation of the struct vfio_pci_core_device (as it is in C), since the struct vfio_pci_core_device strictly outlives the vfio::pci::Registration, or it can also be the driver's bus device private data allocation itself.
kernel::pci_device_table!( PCI_TABLE, <NvidiaVgpuDriver as pci::Driver>::IdInfo, [ ( pci::DeviceId::from_class_and_vendor_vfio_override( Class::DISPLAY_VGA, ClassMask::ClassSubclass, Vendor::NVIDIA ), () ), ( pci::DeviceId::from_class_and_vendor_vfio_override( Class::DISPLAY_3D, ClassMask::ClassSubclass, Vendor::NVIDIA ), () ), ] );
The device ID table. It has some nice compile time guarantees as well, but it is otherwise not very interesting in this context.
Let's look at the pci::Driver trait, which provides the callbacks (such as probe()) and associated constants and types instead.
impl pci::Driver for NvidiaVgpuDriver {
type IdInfo = ();
type Data<'bound> = NvidiaVgpuData<'bound>;
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
const DRIVER_MANAGED_DMA: bool = true;
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {Note the 'bound lifetime in the signature of probe(); it represents the lifetime of the driver's bus device private data and hence the lifetime of the driver being bound to a device.
let vdev = vfio::pci::Device::<NvidiaVgpuOps>::new(pdev)?;
This represents a struct vfio_pci_core_device and is typed over an implementation of vfio::pci::Operations (i.e. a struct vfio_device_ops), but is otherwise not very interesting.
try_pin_init!(Self::Data {
// SAFETY: The registration is dropped when the PCI driver is unbound.
_reg <- unsafe { vfio::pci::Registration::new(
pdev,
&vdev,
try_pin_init!(NvidiaVgpuRegData {
pdev,
api: NovaCoreVfApi::handle(pdev)?,
}),
)},Here we create the vfio::pci::Registration (i.e. call vfio_pci_core_register_device()).
It takes three arguments, a &vfio::pci::Device, the private data and a &'bound pci::Device<Bound>.
The vfio::pci::Registration captures the lifetime ('bound) of the &'bound pci::Device<Bound>, such that it can't outlive driver unbind. In practice this is ensured as the compiler won't allow the vfio::pci::Registration to be stored anywhere else as in a place that is either the bus device private data itself or something else that is strictly shorter lived.
The call to
NovaCoreVfApi::handle(pdev)?
calls into nova-core, which will provide a handle to the nova-core API representation. This handle ties back to nova-core private data that by itself is shorter lived than nova-core's 'bound lifetime, but longer lived than vGPU's 'bound lifetime. IOW, the data is guaranteed to be valid for the full lifecycle of vfio::pci::Registration and hence can be stored within its private data.
I will come back to how this guarantee is upheld below. For now, let's have a look at how vfio::pci::Operations (i.e. struct vfio_device_ops) is represented.
})
}
}
#[pin_data]
struct NvidiaVgpuOpenData<'a> {
instance: VgpuInstance<'a>,
}This type (yes, Rust loves new types :) represents data that lives from open_device() until close_device().
Note that the implementation below does not have close_device() at all, as the destructor of the OpenData already represents close_device() as a RAII type.
This is also what makes the API with nova-core much better, since...
impl vfio::pci::Operations for NvidiaVgpuOps {
const NAME: &'static CStr = c"nvidia-vgpu-vfio-pci";
type RegistrationData<'a> = NvidiaVgpuRegData<'a>;
type OpenData<'a> = NvidiaVgpuOpenData<'a>;
fn open_device<'a>(
_dev: &'a vfio::pci::Device<Self>,
rd: &'a Self::RegistrationData<'a>,
) -> impl PinInit<Self::OpenData<'a>, Error> + 'a {
try_pin_init!(NvidiaVgpuOpenData {
instance: rd.api.open(),
})...here we can just call into nova-core via the API handle and obtain a VgpuInstance<'a> struct from nova-core. Where nova-core can just store all the objects that should be destructed on close_device() in the VgpuInstance struct.
This way we avoid an API contract where we have to translate a RAII based design into procedural cleanup and vice versa.
Also note how we can represent that OpenData is strictly shorter lived as RegistrationData and the driver's bus device private data, in a way that the Rust compiler can ensure this.
}
fn ioctl<'a>(
dev: &vfio::pci::Device<Self, Ioctl>,
_rd: &Self::RegistrationData<'a>,
open_data: Pin<&Self::OpenData<'a>>,
cmd: u32,
arg: usize,
) -> Result<isize> {
// Handle driver ioctl.
dev.core_ioctl(cmd, arg)
}
fn read<'a>(
dev: &vfio::pci::Device<Self, Read>,
_rd: &Self::RegistrationData<'a>,
open_data: Pin<&Self::OpenData<'a>>,
buf: &mut vfio::UserBuf,
ppos: &mut vfio::pci::Position<'_>,
) -> Result<isize> {
Ok(0)
}
fn get_region_info<'a>(
dev: &vfio::pci::Device<Self, GetRegionInfo>,
rd: &Self::RegistrationData<'a>,
open_data: Pin<&Self::OpenData<'a>>,
info: &mut bindings::vfio_region_info,
caps: &mut vfio::InfoCap<'_>,
) -> Result {
Ok(())
}
}The rest of the callbacks is not too interesting. The main thing to note is that the type state on the &vfio::pci::Device in e.g. ioctl() allows us to ensure that dev.core_ioctl() can only be called in ioctl() as it is only implemented for &vfio::pci::Device<_, Ioctl> and we only ever give out a &vfio::pci::Device<_, Ioctl> in ioctl().
In the VFIO/PCI code I only implemented the callbacks the NVIDIA vGPU driver needs; all other callbacks can just remain the default trampolines for now.
Now, I promised to come back to how the following call works.
NovaCoreVfApi::handle(vf_pdev)?
As mentioned it provides a handle to the nova-core API representation, which is shorter lived than nova-core's 'bound lifetime, but longer lived than vGPU's 'bound lifetime (and therefore always valid).
This is ensured by how I think we should implement the handling of the PF and VF relationship on the PCI bus. Let's have a look at nova-core's probe() for this:
impl pci::Driver for NovaCoreDriver {
type IdInfo = ();
type Data<'bound> = NovaCore<'bound>;
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
try_pin_init!(NovaCore {
_enable: {
let enable = pdev.enable_device()?;
pdev.set_master();
enable
},
gpu <- Gpu::new(pdev, pdev.iomap_region_sized::<BAR0_SIZE>(0, c"nova-core/bar0")?),
// SAFETY: `NovaCore` is dropped when the device is unbound.
_reg: unsafe {
auxiliary::Registration::new_with_lt(
pdev.as_ref(),
c"nova-drm",
AUXILIARY_ID_COUNTER.fetch_add(1, Relaxed),
crate::MODULE_NAME,
NovaCoreApi { gpu: gpu.get_ref(), pdev },
)?
},
// SAFETY: `NovaCore` is dropped when the device is unbound.
_vf_reg <- unsafe {
let total_vfs = pdev.sriov_get_totalvfs().map_or(0, |v| v.get());
pci::VfRegistration::new(
pdev,
total_vfs,
total_vfs > 0,
NovaCoreVfApi { _gpu: gpu.get_ref(), pdev },
)
},
})
}
}Similar to vfio::pci::Registration and auxiliary::Registration, we have a pci::VfRegistration, which can only be constructed once by a PF; for VFs it fails to construct.
This pci::VfRegistration returns an initializer and lives within the driver's bus device private data allocation. The constructor of pci::VfRegistration takes the private data type that should be shared with VFs.
IOW, we do not share the whole driver's bus device private data with the VFs, but just a defined container within the driver's bus device private data.
This is also what we do for all other kinds of registrations, such as irq::Registration, which has the advantage that it fundamentally prevents ordering issues. For instance, when constructing an irq::Registration the IRQ private data container is guaranteed to be fully initialized before the first IRQ is received, whereas the rest of the driver's bus device private data may not be initialized yet.
For the pci::VfRegistration this isn't a concern, as it would be valid to expose the entire driver's bus device private data, but it is still cleaner if a PF does not need to expose its whole bus device private data to the VFs, but just the intended API type.
The required lifetime guarantee comes from the fact the pci::VfRegistration lives in the driver's bus device private data, and serves as a guard that calls pci_disable_sriov() in its destructor.
This way we also do not need the patch in [6]. I still think it would be reasonable to have this, but the pci::VfRegistration approach is cleaner. In any case, it's not an either-or, we can have both.
Coming back to nova-core's probe() above, we can see how this perfectly aligns with how the API between nova-core and nova-drm works via the auxiliary bus.
Implementation wise the API on the nova-core side looks like this:
pub struct NovaCoreVfApi<'a> {
pub(crate) pdev: &'a pci::Device<device::Bound>,
pub(crate) _gpu: &'a Gpu<'a>,
}
/// Closure-based handle to the nova-core VF API.
pub struct NovaCoreVfApiHandle<'a> {
vf: &'a pci::Device<device::Bound>,
}
/// An active vGPU instance, closed on drop while the VF binding is still valid.
pub struct VgpuInstance<'a> {
api: &'a NovaCoreVfApiHandle<'a>,
}
impl NovaCoreVfApi<'_> {
/// Obtain a [`NovaCoreVfApiHandle`] from a VF registered by nova-core.
pub fn handle(vf: &pci::Device<device::Bound>) -> Result<NovaCoreVfApiHandle<'_>> {
NovaCoreVfApiHandle::of(vf)
}
}
impl<'a> NovaCoreVfApiHandle<'a> {
fn of(vf: &'a pci::Device<device::Bound>) -> Result<Self> {
vf.vf_registration_data_with::<ForLt!(NovaCoreVfApi<'_>), ()>(|_| ())?;
Ok(Self { vf })
}
/// Activate a vGPU instance, which is closed on drop.
pub fn open(&self) -> Result<VgpuInstance<'a>> {
VgpuInstance::new(self)
}
/// Access the [`NovaCoreVfApi`] through a closure.
pub fn with<R>(&self, f: impl for<'b> FnOnce(Pin<&NovaCoreVfApi<'b>>) -> R) -> R {
self.vf
.vf_registration_data_with::<ForLt!(NovaCoreVfApi<'_>), R>(f)
.expect("TypeId was validated in NovaCoreVfApiHandle::of()")
}
}
impl<'a> VgpuInstance<'a> {
fn new(api: NovaCoreVfApiHandle<'a>) -> Result<Self> {
// TODO: Create the vGPU instance object via `api.gpu`.
Ok(Self { api })
}
/// Reset this vGPU instance.
pub fn reset(&self) -> Result {
Ok(())
}
}(Don't worry too much about the NovaCoreVfApiHandle::of() and NovaCoreVfApiHandle::with() stuff. Those are helpers we also have in the nova-drm API to deal with invariant or non-covariant types respectively.)
If you've made it this far, thanks for reading through this long write-up. I hope you find it useful. Please let me know if you have any questions or thoughts.
Thanks,
Danilo
[1] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=poc/vgpu
[2] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=484316d855e3d61873122c295feb9a7457eeca21
[3] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=6292c1de7f0758dd31496a454b4034507f38bd40
[4] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=efac2cec97eab36edd01a2fe79aea67a04bd8842
[5] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=76b3bfd6386a01f338780e1a37b5bad3f5a48d31
[6] https://lore.kernel.org/lkml/[email protected]/
Alex Williamson
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Hi Danilo,
Quoted 21 lines · On Fri, 11 Sep 2026 22:39:16 +0200 "Danilo Krummrich" <[email protected]> wrote:
Hi Alex, Jason, Zhi,
Quoted 2 lines · Zhi Wang
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
[...]
Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++This is going to be a longer response; sorry about this in advance.
Looking at the FFI boundary introduced in the previous patch, I'm concerned that it translates the driver model relationships we've expressed through Rust's ownership and lifetime model back into raw pointers and lifetime assumptions that callers must uphold. It also introduces manual lifecycle management across the boundary, rather than preserving nova-core's RAII-based ownership model.
I think implementing the NVIDIA vGPU driver in Rust would let us preserve those relationships across the interface, make lifecycle management less error-prone, and fit naturally alongside nova-core and nova-drm.
[snip]
Quoted 4 lines
If you've made it this far, thanks for reading through this long write-up. I hope you find it useful. Please let me know if you have any questions or thoughts.
I can't really say I made it this far with comprehension, but thanks for the effort ;)
The one piece here that I can actually review is [5], where dev_get_drvdata() is replaced with a vfio-pci-core struct pointer embedded in the struct pci_dev, which is a non-starter as far as having a common PCI-core shared by various drivers.
Maybe Dave Airlie can share some experience here with a Rust driver growing up within a subsystem for a non-Rust-literate maintainer.
My concerns are of course who is going to review the Rust vfio-pci variant drivers from a vfio perspective, not just a drm driver viewpoint. Who is going to be responsive when the interfaces break and monitor vfio proactively to prevent such breakages, and how do we avoid derailing feature development in the core code base. Can a Rust vfio-pci variant driver be self-contained, or to what extent does it impose on the framework, such as the drvdata idiom.
FWIW, AI can only go so far to support reviews. Having the code insight to ask the right questions is essential. A human in the loop is a requirement.
Additionally, if we can't narrow the device matching to only the Nova-core supported VFs, then this variant driver must immediately provide feature parity of vfio-pci with pass-through to vfio-pci-core for matched devices. Libvirt selects a best matching variant driver by modalias with our override scheme.
I'd also like to hear from other core vfio contributors. Thanks,
Alex
Quoted 6 lines
[1] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=poc/vgpu
[2] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=484316d855e3d61873122c295feb9a7457eeca21
[3] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=6292c1de7f0758dd31496a454b4034507f38bd40
[4] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=efac2cec97eab36edd01a2fe79aea67a04bd8842
[5] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=76b3bfd6386a01f338780e1a37b5bad3f5a48d31
[6] https://lore.kernel.org/lkml/[email protected]/
Danilo Krummrich
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 32 lines · Alex Williamson
Hi Danilo,
Quoted 21 lines · On Fri, 11 Sep 2026 22:39:16 +0200 "Danilo Krummrich" <[email protected]> wrote:
Hi Alex, Jason, Zhi,
Quoted 2 lines · Zhi Wang
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
[...]
Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++This is going to be a longer response; sorry about this in advance.
Looking at the FFI boundary introduced in the previous patch, I'm concerned that it translates the driver model relationships we've expressed through Rust's ownership and lifetime model back into raw pointers and lifetime assumptions that callers must uphold. It also introduces manual lifecycle management across the boundary, rather than preserving nova-core's RAII-based ownership model.
I think implementing the NVIDIA vGPU driver in Rust would let us preserve those relationships across the interface, make lifecycle management less error-prone, and fit naturally alongside nova-core and nova-drm.
[snip]
Quoted 4 lines
If you've made it this far, thanks for reading through this long write-up. I hope you find it useful. Please let me know if you have any questions or thoughts.
Quoted 7 lines
I can't really say I made it this far with comprehension, but thanks for the effort ;)
The one piece here that I can actually review is [5], where
dev_get_drvdata()is replaced with a vfio-pci-core struct pointer embedded in the structpci_dev, which is a non-starter as far as having a common PCI-core shared by various drivers.
Well, that was just a quick hack to get it out of the way. :)
I think there are a couple of options.
(1) Make the PM helpers take a struct vfio_pci_core_device * in the first place and let the driver forward to the helpers in its own PM callbacks.
(2) Provide an (optional?) driver callback that translates a struct pci_dev to struct vfio_pci_core_device.
(3) Provide a macro for drivers to define PM ops, letting drivers provide the function that translates struct pci_dev to struct vfio_pci_core_device.
(4) Give struct vfio_pci_core_device its own PM domain (which is probably a bit overkill :).
I understand that the idea is to hide the PM handling in the vfio-pci framwork, but I think the existing implementation is a bit of a layering violation, since class device implementations shouldn't impose requirements on the bus device private data layout.
I also think that the approach to fully hide it in the framework is only really worth if it doesn't otherwise impose subtle requirements on the driver (such as the layout requirement of the bus device private data).
Thus, I'd personally just go with (1) as it is the most honest approach in terms of driver layering. But I think (2) is a good alternative that is not more invasive than asking drivers to set the bus device private data to struct vfio_pci_core_device *.
Quoted 3 lines
My concerns are of course who is going to review the Rust vfio-pci variant drivers from a vfio perspective, not just a drm driver viewpoint.
I did put some considerations about this; I think Zhi would be a great candidate for this. :) And as mentioned I can also take some of the responsibility, but I also want to be honest about the fact that I have a lot on my plate already.
Quoted 3 lines
Who is going to be responsive when the interfaces break and monitor vfio proactively to prevent such breakages, and how do we avoid derailing feature development in the core code base.
In practice we shouldn't see any breakages with the Rust code that wouldn't also break the C VFIO drivers. If this would be the case it would mean that the Rust code relies on guarantees that none of the C drivers rely on, which would likely mean that is was never a guarantee that was actually promised by the VFIO core code.
There may be cases where Rust code breaks, and C code won't, but those should be mechanical things, such as a type mismatch where Rust is more careful, e.g. if we'd change a CPP define to an enum, etc.
Quoted 2 lines
Can a Rust vfio-pci variant driver be self-contained, or to what extent does it impose on the framework, such as the drvdata idiom.
As mentioned above, I think this one is more of a layering violation in the vfio-pci-core; class devices shouldn't impose layout requirements on bus device private data.
The reason C drivers can get away with it more easily is e.g. that C relies on procedural cleanup and that all responsibility for managing lifetimes sits on the drivers themselves, so it is easier for them to adjust. But in general, it wouldn't work out if all class device registrations or other core primitives would have the same expectation.
For Rust specifically it is that the driver core controls the lifetime of the bus device private data, which is a fundamental requirement to e.g. represent registrations as RAII types. E.g. the vfio::pci::Registration has to be stored in the bus device private data, such that it is guaranteed to be correctly destroyed on driver unbind.
To get back to your question, a Rust vfio-pci variant driver should be self-contained. The interface sits in the abstraction that translates the C driver API to a Rust driver API. It sometimes can help quite significantly (e.g. in terms of how complex the Rust code needs to get in order to actually be safe) if the C code does a minor adjustment, but it shouldn't be necessary.
For instance, the only addition to the driver core we have is an additional callback in struct device_driver, and in the future an additional pointer in struct device_private; none of those couldn't be worked around in some way though.
On the other hand there are examples where the Rust introduction motivated design improvements on the C side, or bug fixes for issues that were caught while writing a safe abstraction. For instance, we recently had some fixes around dyn IDs in the PCI and USB core, which both were motivated by Rust code.
Quoted 6 lines
FWIW, AI can only go so far to support reviews. Having the code insight to ask the right questions is essential. A human in the loop is a requirement.
Additionally, if we can't narrow the device matching to only the Nova-core supported VFs,
Agreed, and I think that should be possible. Is there a particular case you think of where this wouldn't hold?
Alex Williamson
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 62 lines · On Mon, 14 Sep 2026 23:36:24 +0200 "Danilo Krummrich" <[email protected]> wrote:
Quoted 32 lines · Alex Williamson
Hi Danilo,
Quoted 21 lines · On Fri, 11 Sep 2026 22:39:16 +0200 "Danilo Krummrich" <[email protected]> wrote:
Hi Alex, Jason, Zhi,
Quoted 2 lines · Zhi Wang
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
[...]
Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++This is going to be a longer response; sorry about this in advance.
Looking at the FFI boundary introduced in the previous patch, I'm concerned that it translates the driver model relationships we've expressed through Rust's ownership and lifetime model back into raw pointers and lifetime assumptions that callers must uphold. It also introduces manual lifecycle management across the boundary, rather than preserving nova-core's RAII-based ownership model.
I think implementing the NVIDIA vGPU driver in Rust would let us preserve those relationships across the interface, make lifecycle management less error-prone, and fit naturally alongside nova-core and nova-drm.
[snip]
Quoted 4 lines
If you've made it this far, thanks for reading through this long write-up. I hope you find it useful. Please let me know if you have any questions or thoughts.
Quoted 7 lines
I can't really say I made it this far with comprehension, but thanks for the effort ;)
The one piece here that I can actually review is [5], where
dev_get_drvdata()is replaced with a vfio-pci-core struct pointer embedded in the structpci_dev, which is a non-starter as far as having a common PCI-core shared by various drivers.Well, that was just a quick hack to get it out of the way. :)
I think there are a couple of options.
(1) Make the PM helpers take a struct
vfio_pci_core_device* in the first place and let the driver forward to the helpers in its own PM callbacks.(2) Provide an (optional?) driver callback that translates a struct
pci_devto structvfio_pci_core_device.(3) Provide a macro for drivers to define PM ops, letting drivers provide the function that translates struct
pci_devto structvfio_pci_core_device.(4) Give struct
vfio_pci_core_deviceits own PM domain (which is probably a bit overkill :).I understand that the idea is to hide the PM handling in the vfio-pci framwork, but I think the existing implementation is a bit of a layering violation, since class device implementations shouldn't impose requirements on the bus device private data layout.
Quoted 8 lines
I also think that the approach to fully hide it in the framework is only really worth if it doesn't otherwise impose subtle requirements on the driver (such as the layout requirement of the bus device private data).
Thus, I'd personally just go with (1) as it is the most honest approach in terms of driver layering. But I think (2) is a good alternative that is not more invasive than asking drivers to set the bus device private data to struct
vfio_pci_core_device*.
I'd position this more as a library convention than a class layering violation. vfio-pci was originally one driver, vfio-pci-core was pulled out to enable device specific support, ex. migration, in a more manageable way. struct vfio_pci_core_device is not strictly a class, it's the object used by the library that variant drivers opt to use rather than re-implementing vfio-pci from the ground up.
The conventions of that library mean variant drivers get things like VGA routing and power management for free, in adherence with how these features are exported by the core, and can choose to opt-in to common error handling.
The use of drvdata is part of that convention and audited by the core such that failed compliance is rejected on registration. Clearly we could allow variant drivers to provide ops for their own callbacks and export core helpers they can use, but only a Rust driver requires this and we need to figure out how to do this without degrading the audit in the core.
Turning vfio-pci-core into a proper class to be able to have a real layering violation claim seems like a much larger project.
Quoted 7 lines
Quoted 3 lines
My concerns are of course who is going to review the Rust vfio-pci variant drivers from a vfio perspective, not just a drm driver viewpoint.
I did put some considerations about this; I think Zhi would be a great candidate for this. :) And as mentioned I can also take some of the responsibility, but I also want to be honest about the fact that I have a lot on my plate already.
And that's part of the problem, there are bandwidth issues all around and neither you nor Zhi are, as of yet, core vfio contributors. Rust may well be the better approach relative to the interface to Nova-core, but it's not clear it's the right approach for a subsystem that can't maintain or evaluate it and only has a sketch of what it looks like.
Quoted 9 lines
Quoted 3 lines
Who is going to be responsive when the interfaces break and monitor vfio proactively to prevent such breakages, and how do we avoid derailing feature development in the core code base.
In practice we shouldn't see any breakages with the Rust code that wouldn't also break the C VFIO drivers. If this would be the case it would mean that the Rust code relies on guarantees that none of the C drivers rely on, which would likely mean that is was never a guarantee that was actually promised by the VFIO core code.
s/practice/theory/
Quoted 3 lines
There may be cases where Rust code breaks, and C code won't, but those should be mechanical things, such as a type mismatch where Rust is more careful, e.g. if we'd change a CPP define to an enum, etc.
This seems like a very optimistic outlook. I don't have experience with Rust to claim otherwise, but I do have general software experience to be suspicious of anything sounding so clean.
Quoted 13 lines
Quoted 2 lines
Can a Rust vfio-pci variant driver be self-contained, or to what extent does it impose on the framework, such as the drvdata idiom.
As mentioned above, I think this one is more of a layering violation in the vfio-pci-core; class devices shouldn't impose layout requirements on bus device private data.
The reason C drivers can get away with it more easily is e.g. that C relies on procedural cleanup and that all responsibility for managing lifetimes sits on the drivers themselves, so it is easier for them to adjust. But in general, it wouldn't work out if all class device registrations or other core primitives would have the same expectation.
Quoted 5 lines
For Rust specifically it is that the driver core controls the lifetime of the bus device private data, which is a fundamental requirement to e.g. represent registrations as RAII types. E.g. the
vfio::pci::Registrationhas to be stored in the bus device private data, such that it is guaranteed to be correctly destroyed on driver unbind.
I see, so driver core has its own convention for how Rust drivers must use drvdata.
Quoted 5 lines
To get back to your question, a Rust vfio-pci variant driver should be self-contained. The interface sits in the abstraction that translates the C driver API to a Rust driver API. It sometimes can help quite significantly (e.g. in terms of how complex the Rust code needs to get in order to actually be safe) if the C code does a minor adjustment, but it shouldn't be necessary.
It's not clear to me to what extent these abstractions hinder our ability to evolve and refactor the C code. It may not "lock in" the core API for variant drivers, but it seems it raises the bar that any significant code refactor likely needs to refactor the abstraction layer, potentially the Rust variant driver itself, which imposes a burden on the vfio community that has so far not introduced Rust into the code base.
Quoted 9 lines
For instance, the only addition to the driver core we have is an additional callback in struct
device_driver, and in the future an additional pointer in structdevice_private; none of those couldn't be worked around in some way though.On the other hand there are examples where the Rust introduction motivated design improvements on the C side, or bug fixes for issues that were caught while writing a safe abstraction. For instance, we recently had some fixes around dyn IDs in the PCI and USB core, which both were motivated by Rust code.
I have no doubt that integration with a more structured language would lead to various improvements. However, it doesn't seem there are resources to support it in the short term.
Quoted 9 lines
Quoted 6 lines
FWIW, AI can only go so far to support reviews. Having the code insight to ask the right questions is essential. A human in the loop is a requirement.
Additionally, if we can't narrow the device matching to only the Nova-core supported VFs,
Agreed, and I think that should be possible. Is there a particular case you think of where this wouldn't hold?
The modalias scheme only matches on vendor/device ID, subsystem IDs, base/sub class, and interface. Nothing in the PCI spec requires that the VF device ID is different from the PF device ID. Variant drivers will often present a larger match surface to avoid the ongoing maintenance overhead of listing explicit device IDs. Such an approach here would put us in the position I noted in the previous reply where the Rust variant driver needs to fully support these devices via vfio-pci-core on day one. Binding GPU PFs to vfio-pci is a current, valid use case (VFs for some vendors as well). Thanks,
Alex
Danilo Krummrich
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 86 lines · Alex Williamson
Quoted 62 lines · On Mon, 14 Sep 2026 23:36:24 +0200 "Danilo Krummrich" <[email protected]> wrote:
Quoted 32 lines · Alex Williamson
Hi Danilo,
Quoted 21 lines · On Fri, 11 Sep 2026 22:39:16 +0200 "Danilo Krummrich" <[email protected]> wrote:
Hi Alex, Jason, Zhi,
Quoted 2 lines · Zhi Wang
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
[...]
Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++This is going to be a longer response; sorry about this in advance.
Looking at the FFI boundary introduced in the previous patch, I'm concerned that it translates the driver model relationships we've expressed through Rust's ownership and lifetime model back into raw pointers and lifetime assumptions that callers must uphold. It also introduces manual lifecycle management across the boundary, rather than preserving nova-core's RAII-based ownership model.
I think implementing the NVIDIA vGPU driver in Rust would let us preserve those relationships across the interface, make lifecycle management less error-prone, and fit naturally alongside nova-core and nova-drm.
[snip]
Quoted 4 lines
If you've made it this far, thanks for reading through this long write-up. I hope you find it useful. Please let me know if you have any questions or thoughts.
Quoted 7 lines
I can't really say I made it this far with comprehension, but thanks for the effort ;)
The one piece here that I can actually review is [5], where
dev_get_drvdata()is replaced with a vfio-pci-core struct pointer embedded in the structpci_dev, which is a non-starter as far as having a common PCI-core shared by various drivers.Well, that was just a quick hack to get it out of the way. :)
I think there are a couple of options.
(1) Make the PM helpers take a struct
vfio_pci_core_device* in the first place and let the driver forward to the helpers in its own PM callbacks.(2) Provide an (optional?) driver callback that translates a struct
pci_devto structvfio_pci_core_device.(3) Provide a macro for drivers to define PM ops, letting drivers provide the function that translates struct
pci_devto structvfio_pci_core_device.(4) Give struct
vfio_pci_core_deviceits own PM domain (which is probably a bit overkill :).I understand that the idea is to hide the PM handling in the vfio-pci framwork, but I think the existing implementation is a bit of a layering violation, since class device implementations shouldn't impose requirements on the bus device private data layout.
Quoted 8 lines
I also think that the approach to fully hide it in the framework is only really worth if it doesn't otherwise impose subtle requirements on the driver (such as the layout requirement of the bus device private data).
Thus, I'd personally just go with (1) as it is the most honest approach in terms of driver layering. But I think (2) is a good alternative that is not more invasive than asking drivers to set the bus device private data to struct
vfio_pci_core_device*.I'd position this more as a library convention than a class layering violation. vfio-pci was originally one driver, vfio-pci-core was pulled out to enable device specific support, ex. migration, in a more manageable way. struct
vfio_pci_core_deviceis not strictly a class, it's the object used by the library that variant drivers opt to use rather than re-implementing vfio-pci from the ground up.The conventions of that library mean variant drivers get things like VGA routing and power management for free, in adherence with how these features are exported by the core, and can choose to opt-in to common error handling.
Quoted 6 lines
The use of drvdata is part of that convention and audited by the core such that failed compliance is rejected on registration. Clearly we could allow variant drivers to provide ops for their own callbacks and export core helpers they can use, but only a Rust driver requires this and we need to figure out how to do this without degrading the audit in the core.
The driver_data pointer in struct device is defined to be a pointer where a driver can store *arbitrary* data for the duration the driver is bound to this device.
This is an API contract the driver core provides for the struct device structure when used in a bus device (such as struct pci_dev), i.e. it is an API contract between the driver core and drivers in general.
It is *not* the Rust driver core code breaking a convention here. The Rust driver core code just relies on its own subsystem's API contract.
The fact that the vfio-pci-core forces vfio-pci drivers to only ever store a struct vfio_pci_core_device pointer there re-defines the driver core's API contract and therefore is a layering violation.
Quoted 2 lines
Turning vfio-pci-core into a proper class to be able to have a real layering violation claim seems like a much larger project.
What you are describing rather sounds to me as if struct vfio_pci_core_device wants to be two things: a bus device layered on top of a PCI device and a class device around struct vfio_device. But in this case it should implement a real bus on top of the PCI bus.
Currently it really is a wrapper around struct vfio_device (and therefore a class device) which is bending the purpose of the driver's bus device private data pointer to make a connection with the real bus device underneath.
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
My concerns are of course who is going to review the Rust vfio-pci variant drivers from a vfio perspective, not just a drm driver viewpoint.
I did put some considerations about this; I think Zhi would be a great candidate for this. :) And as mentioned I can also take some of the responsibility, but I also want to be honest about the fact that I have a lot on my plate already.
And that's part of the problem, there are bandwidth issues all around and neither you nor Zhi are, as of yet, core vfio contributors.
That is true, but I suggest to also see it from the perspective that this effort is a good chance to get more people to engage with the VFIO subsystem in the first place and eventually become experts that also contribute to the C core.
For the Rust abstraction, there are two competencies needed: knowledge about writing a VFIO driver (which Zhi clearly covers) and knowledge about the driver model and its Rust implementation specifics as well as the Rust ecosystem in general (which is why I offered myself to take responsibility).
Remember the VFIO abstractions are translating the C VFIO driver APIs to Rust APIs for Rust drivers. They don't need to mess with VFIO internals.
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines
Who is going to be responsive when the interfaces break and monitor vfio proactively to prevent such breakages, and how do we avoid derailing feature development in the core code base.
In practice we shouldn't see any breakages with the Rust code that wouldn't also break the C VFIO drivers. If this would be the case it would mean that the Rust code relies on guarantees that none of the C drivers rely on, which would likely mean that is was never a guarantee that was actually promised by the VFIO core code.
s/practice/theory/
As mentioned above, the abstractions are translating the C VFIO driver APIs to Rust APIs for Rust drivers. I.e. they don't use other API than the C drivers use. Thus, code breakages should be limited to what I mentioned below.
Quoted 7 lines
Quoted 3 lines
There may be cases where Rust code breaks, and C code won't, but those should be mechanical things, such as a type mismatch where Rust is more careful, e.g. if we'd change a CPP define to an enum, etc.
This seems like a very optimistic outlook. I don't have experience with Rust to claim otherwise, but I do have general software experience to be suspicious of anything sounding so clean.
I maintain some subsystems that have Rust code, and I also maintain Rust code of subsystems I otherwise do not maintain. I haven't seen anything break so far other than for the reasons already mentioned.
Of course, that doesn't mean that mistakes can't happen. For instance, we could have the case that the Rust code makes assumptions that the subsystem never guaranteed in the first place. But that'd be something that could also happen for any other driver and it would be a bug in the Rust code that the maintainers of the Rust code have to take responsibility for.
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines
Can a Rust vfio-pci variant driver be self-contained, or to what extent does it impose on the framework, such as the drvdata idiom.
As mentioned above, I think this one is more of a layering violation in the vfio-pci-core; class devices shouldn't impose layout requirements on bus device private data.
The reason C drivers can get away with it more easily is e.g. that C relies on procedural cleanup and that all responsibility for managing lifetimes sits on the drivers themselves, so it is easier for them to adjust. But in general, it wouldn't work out if all class device registrations or other core primitives would have the same expectation.
Quoted 8 lines
Quoted 5 lines
For Rust specifically it is that the driver core controls the lifetime of the bus device private data, which is a fundamental requirement to e.g. represent registrations as RAII types. E.g. the
vfio::pci::Registrationhas to be stored in the bus device private data, such that it is guaranteed to be correctly destroyed on driver unbind.I see, so driver core has its own convention for how Rust drivers must use drvdata.
As mentioned above, the driver_data pointer of struct device is specifically reserved for drivers to store arbitrary data while they are bound to the device.
The only difference is that in C it is a convention and drivers call dev_set_drvdata() themselves, whereas in Rust we do it in the driver core code.
Note that clearing this pointer is also done in the driver core in C in device_unbind_cleanup().
Quoted 6 lines
Quoted 5 lines
To get back to your question, a Rust vfio-pci variant driver should be self-contained. The interface sits in the abstraction that translates the C driver API to a Rust driver API. It sometimes can help quite significantly (e.g. in terms of how complex the Rust code needs to get in order to actually be safe) if the C code does a minor adjustment, but it shouldn't be necessary.
Quoted 7 lines
It's not clear to me to what extent these abstractions hinder our ability to evolve and refactor the C code. It may not "lock in" the core API for variant drivers, but it seems it raises the bar that any significant code refactor likely needs to refactor the abstraction layer, potentially the Rust variant driver itself, which imposes a burden on the vfio community that has so far not introduced Rust into the code base.
In general, if the refactor does not affect C drivers, it shouldn't affect the Rust API either.
If the refactor affects C drivers, it will also affect Rust drivers and the change in the Rust abstraction could also be more complicated than the change required in the C drivers.
The reason is that we design the Rust APIs at minmum in a way that any arbitrary usage can not produce undefined behavior. Beyond that, we also always try to design them in a way that it also at least encourages correct semantical use.
So in theory, it could happen that we need to figure out a new way to abstract the C API in way that can't produce undefined behavior.
But if that happens it should be something minor, e.g. a new callback which requires a new type state, an argument that requires a new type carrying some invariants, etc.
The biggest part of the abstraction is the integration in the driver lifecycle, which is a repeating pattern. For instance, if you look at the fwctl Rust code it looks almsot the same.
From my experience maintaining both C and Rust code I can also tell that good design is pretty straight forward to abstract in Rust to produce a safe API; bad design isn't.
Where good design means APIs with defined ownership, clear lifetime relationships, and a consistent API surface. Whereas APIs that have unclear ownership and lifetime relationships and inconsistent API surfaces are a huge pain in the butt to abstract.
The reason is that Rust needs to get those things straight somehow in order to provide a safe API surface. I.e. an underlying bad API design (as defined above) needs the Rust implementation to make quite some stretches.
Quoted 5 lines
Quoted 5 lines
For instance, the only addition to the driver core we have is an additional callback in struct
device_driver, and in the future an additional pointer in structdevice_private; none of those couldn't be worked around in some way though.
Quoted 8 lines
Quoted 4 lines
On the other hand there are examples where the Rust introduction motivated design improvements on the C side, or bug fixes for issues that were caught while writing a safe abstraction. For instance, we recently had some fixes around dyn IDs in the PCI and USB core, which both were motivated by Rust code.
I have no doubt that integration with a more structured language would lead to various improvements. However, it doesn't seem there are resources to support it in the short term.
As mentoined above, there are people volunteering now. Without starting it, it can't scale further than that. :)
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
FWIW, AI can only go so far to support reviews. Having the code insight to ask the right questions is essential. A human in the loop is a requirement.
Additionally, if we can't narrow the device matching to only the Nova-core supported VFs,
Agreed, and I think that should be possible. Is there a particular case you think of where this wouldn't hold?
Quoted 9 lines
The modalias scheme only matches on vendor/device ID, subsystem IDs, base/sub class, and interface. Nothing in the PCI spec requires that the VF device ID is different from the PF device ID. Variant drivers will often present a larger match surface to avoid the ongoing maintenance overhead of listing explicit device IDs. Such an approach here would put us in the position I noted in the previous reply where the Rust variant driver needs to fully support these devices via vfio-pci-core on day one. Binding GPU PFs to vfio-pci is a current, valid use case (VFs for some vendors as well). Thanks,
My understanding is that in order to support PFs being bound to the variant driver the only thing necessary would be to fall back to the vfio-pci-core callbacks. If that's the case, my PoC code can already do that.
However, I don't really see the use-case; you can't load nvidia-vgpu without nova-core in the first place, so it would require to unbind nova-core through sysfs force unbind, no?
Re: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
On Tue, 15 Sep 2026 23:19:01 +0200
"Danilo Krummrich" <[email protected]> wrote:
Hi folks:
Since my name has been mentioned several times in this loop, It would be better I chime in besides re-spin my patches.
Danilo, thanks for putting the PoC together. I am interested in working it thorough and some parts of idea has already been in my rust SR-IOV rework patches [1]. I am already contributing to nova-core and working on the vGPU manager and VFIO driver, so I can help with nova-core integration and testing.
Alex, I take your concerns about review and ongoing maintenance seriously. I'm happy to help evaluate the PoC while those questions are being discussed and commit on the parts of what you think are maintainable and reasonable. For now, I've updated the existing C series to use the new SR-IOV support and incorporate your review feedback [2]. I'll keep following up on the remaining comments.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Quoted 334 lines · Alex Williamson
Quoted 96 lines
Quoted 76 lines · On Mon, 14 Sep 2026 23:36:24 +0200 "Danilo Krummrich" <[email protected]> wrote:
Quoted 38 lines · Alex Williamson
Hi Danilo,
Quoted 27 lines · On Fri, 11 Sep 2026 22:39:16 +0200 "Danilo Krummrich" <[email protected]> wrote:
Hi Alex, Jason, Zhi,
Quoted 3 lines · Zhi Wang
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
[...]
Quoted 2 lines
drivers/vfio/pci/nvidia-vgpu/main.c | 253++++++++++++++++++++++++++
This is going to be a longer response; sorry about this in advance.
Looking at the FFI boundary introduced in the previous patch, I'm concerned that it translates the driver model relationships we've expressed through Rust's ownership and lifetime model back into raw pointers and lifetime assumptions that callers must uphold. It also introduces manual lifecycle management across the boundary, rather than preserving nova-core's RAII-based ownership model.
I think implementing the NVIDIA vGPU driver in Rust would let us preserve those relationships across the interface, make lifecycle management less error-prone, and fit naturally alongside nova-core and nova-drm.
[snip]
Quoted 4 lines
If you've made it this far, thanks for reading through this long write-up. I hope you find it useful. Please let me know if you have any questions or thoughts.
Quoted 7 lines
I can't really say I made it this far with comprehension, but thanks for the effort ;)
The one piece here that I can actually review is [5], where
dev_get_drvdata()is replaced with a vfio-pci-core struct pointer embedded in the structpci_dev, which is a non-starter as far as having a common PCI-core shared by various drivers.Well, that was just a quick hack to get it out of the way. :)
I think there are a couple of options.
(1) Make the PM helpers take a struct
vfio_pci_core_device* in
the first place and let the driver forward to the helpers in its own PM callbacks.(2) Provide an (optional?) driver callback that translates a
structpci_devto structvfio_pci_core_device.(3) Provide a macro for drivers to define PM ops, letting
drivers provide the function that translates structpci_devto structvfio_pci_core_device.(4) Give struct
vfio_pci_core_deviceits own PM domain (which is
probably a bit overkill :).I understand that the idea is to hide the PM handling in the vfio-pci framwork, but I think the existing implementation is a bit of a layering violation, since class device implementations shouldn't impose requirements on the bus device private data layout.
I also think that the approach to fully hide it in the framework is only really worth if it doesn't otherwise impose subtle requirements on the driver (such as the layout requirement of the bus device private data).
Quoted 4 lines
Thus, I'd personally just go with (1) as it is the most honest approach in terms of driver layering. But I think (2) is a good alternative that is not more invasive than asking drivers to set the bus device private data to struct
vfio_pci_core_device*.I'd position this more as a library convention than a class layering violation. vfio-pci was originally one driver, vfio-pci-core was pulled out to enable device specific support, ex. migration, in a more manageable way. struct
vfio_pci_core_deviceis not strictly a class, it's the object used by the library that variant drivers opt to use rather than re-implementing vfio-pci from the ground up.The conventions of that library mean variant drivers get things like VGA routing and power management for free, in adherence with how these features are exported by the core, and can choose to opt-in to common error handling.
Quoted 6 lines
The use of drvdata is part of that convention and audited by the core such that failed compliance is rejected on registration. Clearly we could allow variant drivers to provide ops for their own callbacks and export core helpers they can use, but only a Rust driver requires this and we need to figure out how to do this without degrading the audit in the core.
The
driver_datapointer in struct device is defined to be a pointer where a driver can store *arbitrary* data for the duration the driver is bound to this device.This is an API contract the driver core provides for the struct device structure when used in a bus device (such as struct
pci_dev), i.e. it is an API contract between the driver core and drivers in general.It is *not* the Rust driver core code breaking a convention here. The Rust driver core code just relies on its own subsystem's API contract.
The fact that the vfio-pci-core forces vfio-pci drivers to only ever store a struct
vfio_pci_core_devicepointer there re-defines the driver core's API contract and therefore is a layering violation.Quoted 2 lines
Turning vfio-pci-core into a proper class to be able to have a real layering violation claim seems like a much larger project.
What you are describing rather sounds to me as if struct
vfio_pci_core_devicewants to be two things: a bus device layered on top of a PCI device and a class device around structvfio_device. But in this case it should implement a real bus on top of the PCI bus.Currently it really is a wrapper around struct
vfio_device(and therefore a class device) which is bending the purpose of the driver's bus device private data pointer to make a connection with the real bus device underneath.Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
My concerns are of course who is going to review the Rust vfio-pci variant drivers from a vfio perspective, not just a drm driver viewpoint.
Quoted 8 lines
Quoted 4 lines
I did put some considerations about this; I think Zhi would be a great candidate for this. :) And as mentioned I can also take some of the responsibility, but I also want to be honest about the fact that I have a lot on my plate already.
And that's part of the problem, there are bandwidth issues all around and neither you nor Zhi are, as of yet, core vfio contributors.
That is true, but I suggest to also see it from the perspective that this effort is a good chance to get more people to engage with the VFIO subsystem in the first place and eventually become experts that also contribute to the C core.
For the Rust abstraction, there are two competencies needed:
knowledge about writing a VFIO driver (which Zhi clearly covers) and knowledge about the driver model and its Rust implementation specifics as well as the Rust ecosystem in general (which is why I offered myself to take responsibility).Remember the VFIO abstractions are translating the C VFIO driver APIs to Rust APIs for Rust drivers. They don't need to mess with VFIO internals.
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines
Who is going to be responsive when the interfaces break and monitor vfio proactively to prevent such breakages, and how do we avoid derailing feature development in the core code base.
In practice we shouldn't see any breakages with the Rust code that wouldn't also break the C VFIO drivers. If this would be the case it would mean that the Rust code relies on guarantees that none of the C drivers rely on, which would likely mean that is was never a guarantee that was actually promised by the VFIO core code.
s/practice/theory/
As mentioned above, the abstractions are translating the C VFIO driver APIs to Rust APIs for Rust drivers. I.e. they don't use other API than the C drivers use. Thus, code breakages should be limited to what I mentioned below.
Quoted 8 lines
Quoted 4 lines
There may be cases where Rust code breaks, and C code won't, but those should be mechanical things, such as a type mismatch where Rust is more careful, e.g. if we'd change a CPP define to an enum, etc.
This seems like a very optimistic outlook. I don't have experience with Rust to claim otherwise, but I do have general software experience to be suspicious of anything sounding so clean.
I maintain some subsystems that have Rust code, and I also maintain Rust code of subsystems I otherwise do not maintain. I haven't seen anything break so far other than for the reasons already mentioned.
Of course, that doesn't mean that mistakes can't happen. For instance, we could have the case that the Rust code makes assumptions that the subsystem never guaranteed in the first place. But that'd be something that could also happen for any other driver and it would be a bug in the Rust code that the maintainers of the Rust code have to take responsibility for.
Quoted 22 lines
Quoted 15 lines
Quoted 3 lines
Can a Rust vfio-pci variant driver be self-contained, or to what extent does it impose on the framework, such as the drvdata idiom.
As mentioned above, I think this one is more of a layering violation in the vfio-pci-core; class devices shouldn't impose layout requirements on bus device private data.
The reason C drivers can get away with it more easily is e.g. that C relies on procedural cleanup and that all responsibility for managing lifetimes sits on the drivers themselves, so it is easier for them to adjust. But in general, it wouldn't work out if all class device registrations or other core primitives would have the same expectation.
Quoted 6 lines
For Rust specifically it is that the driver core controls the lifetime of the bus device private data, which is a fundamental requirement to e.g. represent registrations as RAII types. E.g. the
vfio::pci::Registrationhas to be stored in the bus device private data, such that it is guaranteed to be correctly destroyed on driver unbind.Quoted 2 lines
I see, so driver core has its own convention for how Rust drivers must use drvdata.
As mentioned above, the
driver_datapointer of struct device is specifically reserved for drivers to store arbitrary data while they are bound to the device.The only difference is that in C it is a convention and drivers call
dev_set_drvdata()themselves, whereas in Rust we do it in the driver core code.Note that clearing this pointer is also done in the driver core in C in
device_unbind_cleanup().Quoted 8 lines
Quoted 7 lines
To get back to your question, a Rust vfio-pci variant driver should be self-contained. The interface sits in the abstraction that translates the C driver API to a Rust driver API. It sometimes can help quite significantly (e.g. in terms of how complex the Rust code needs to get in order to actually be safe) if the C code does a minor adjustment, but it shouldn't be necessary.
Quoted 7 lines
It's not clear to me to what extent these abstractions hinder our ability to evolve and refactor the C code. It may not "lock in" the core API for variant drivers, but it seems it raises the bar that any significant code refactor likely needs to refactor the abstraction layer, potentially the Rust variant driver itself, which imposes a burden on the vfio community that has so far not introduced Rust into the code base.
In general, if the refactor does not affect C drivers, it shouldn't affect the Rust API either.
If the refactor affects C drivers, it will also affect Rust drivers and the change in the Rust abstraction could also be more complicated than the change required in the C drivers.
The reason is that we design the Rust APIs at minmum in a way that any arbitrary usage can not produce undefined behavior. Beyond that, we also always try to design them in a way that it also at least encourages correct semantical use.
So in theory, it could happen that we need to figure out a new way to abstract the C API in way that can't produce undefined behavior.
But if that happens it should be something minor, e.g. a new callback which requires a new type state, an argument that requires a new type carrying some invariants, etc.
The biggest part of the abstraction is the integration in the driver lifecycle, which is a repeating pattern. For instance, if you look at the fwctl Rust code it looks almsot the same.
From my experience maintaining both C and Rust code I can also tell that good design is pretty straight forward to abstract in Rust to produce a safe API; bad design isn't.
Where good design means APIs with defined ownership, clear lifetime relationships, and a consistent API surface. Whereas APIs that have unclear ownership and lifetime relationships and inconsistent API surfaces are a huge pain in the butt to abstract.
The reason is that Rust needs to get those things straight somehow in order to provide a safe API surface. I.e. an underlying bad API design (as defined above) needs the Rust implementation to make quite some stretches.
Quoted 11 lines
Quoted 10 lines
For instance, the only addition to the driver core we have is an additional callback in struct
device_driver, and in the future an additional pointer in structdevice_private; none of those couldn't be worked around in some way though.On the other hand there are examples where the Rust introduction motivated design improvements on the C side, or bug fixes for issues that were caught while writing a safe abstraction. For instance, we recently had some fixes around dyn IDs in the PCI and USB core, which both were motivated by Rust code.
Quoted 3 lines
I have no doubt that integration with a more structured language would lead to various improvements. However, it doesn't seem there are resources to support it in the short term.
As mentoined above, there are people volunteering now. Without starting it, it can't scale further than that. :)
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
FWIW, AI can only go so far to support reviews. Having the code insight to ask the right questions is essential. A human in the loop is a requirement.
Additionally, if we can't narrow the device matching to only the Nova-core supported VFs,
Agreed, and I think that should be possible. Is there a particular case you think of where this wouldn't hold?
Quoted 10 lines
The modalias scheme only matches on vendor/device ID, subsystem IDs, base/sub class, and interface. Nothing in the PCI spec requires that the VF device ID is different from the PF device ID. Variant drivers will often present a larger match surface to avoid the ongoing maintenance overhead of listing explicit device IDs. Such an approach here would put us in the position I noted in the previous reply where the Rust variant driver needs to fully support these devices via vfio-pci-core on day one. Binding GPU PFs to vfio-pci is a current, valid use case (VFs for some vendors as well). Thanks,
My understanding is that in order to support PFs being bound to the variant driver the only thing necessary would be to fall back to the vfio-pci-core callbacks. If that's the case, my PoC code can already do that.
However, I don't really see the use-case; you can't load nvidia-vgpu without nova-core in the first place, so it would require to unbind nova-core through sysfs force unbind, no?
Jason Gunthorpe
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
In reply to Danilo KrummrichQuoted 3 lines · Danilo Krummrich
The
driver_datapointer in struct device is defined to be a pointer where a driver can store *arbitrary* data for the duration the driver is bound to this device.
There are places in the kernel where the drvdata of the bound device ends up owned by the subsystem, not the end driver. Yes, an ideal driver + subsystem should never even need drvdatab beyond remove. Yet, things are not perfect..
The fundamental issue is some kernel API surfaces that the subystem needs to work with only provide a struct device in their callbacks and the subystem has no option but to use the drvdata for its own purpose to recover the subsystem specific data.
For example VFIO hooks into this nasty API:
ret = vga_client_register(pdev, vfio_pci_set_decode);
if (ret)
return ret;Which doesn't provide a void * token to pass the core code's struct.
Another is all the PCI callbacks which assume the op behind them uses drvdata to get its data.
It is not necessarily easy to fix. Rrouting all those PCI callbacks through trampolines in every single driver is really not an appealing design. There are alot of VFIO drivers.
Maybe it needs a dev->drvdata and dev->subsystem_data, maybe it needs some PCI thing where the pm ops can get a void *, IDK.
This is not some philosophical thing about busses or classes, it is just an accommodation for the way the kernel is now. Fix the above and you can get rid of it.
Quoted 6 lines
Quoted 3 lines
I have no doubt that integration with a more structured language would lead to various improvements. However, it doesn't seem there are resources to support it in the short term.
As mentoined above, there are people volunteering now. Without starting it, it can't scale further than that. :)
There are lots of other vfio patches that need attention too, and it seems we are short of that more than anything. Now you need to do a bunch of C refactoring patches as well just to get things ready to show a bunch of rust code. It is a lot of work.
I don't really understand in a nutshell why we should do this for nova the mails were so long... Can we not just ignore the lifetime imperfection for this?
Quoted 3 lines
However, I don't really see the use-case; you can't load nvidia-vgpu without nova-core in the first place, so it would require to unbind nova-core through sysfs force unbind, no?
nvidia gpu is a more unique scenario, if you are building a general bindings it has to support the flows like this.
I've wanted to rework the way the common ops are shimmed in for a while, you'd probably want to do that before rust bindings.
Jason
Danilo Krummrich
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 22 lines · Jason Gunthorpe
Quoted 3 lines · Danilo Krummrich
The
driver_datapointer in struct device is defined to be a pointer where a driver can store *arbitrary* data for the duration the driver is bound to this device.There are places in the kernel where the drvdata of the bound device ends up owned by the subsystem, not the end driver. Yes, an ideal driver + subsystem should never even need drvdatab beyond remove. Yet, things are not perfect..
The fundamental issue is some kernel API surfaces that the subystem needs to work with only provide a struct device in their callbacks and the subystem has no option but to use the drvdata for its own purpose to recover the subsystem specific data.
For example VFIO hooks into this nasty API:
ret = vga_client_register(pdev, vfio_pci_set_decode); if (ret) return ret;
Quoted 5 lines
Which doesn't provide a void * token to pass the core code's struct.
Another is all the PCI callbacks which assume the op behind them uses drvdata to get its data.
This is where the class (i.e. vfio-pci) should instead take a driver callback, as only the driver really knowns about the layering details.
Usually, class device implementations can't make assumptions of the underlying bus, because they have to work for any bus. I.e. there's no other way than providing helpers and letting drivers do the glue code between the bus and the class device.
Quoted 3 lines
It is not necessarily easy to fix. Rrouting all those PCI callbacks through trampolines in every single driver is really not an appealing design. There are alot of VFIO drivers.
The reason this seems undesirable from a vfio-pci perspective is that it is special in the sense that it is a class device that is specifically built to sit on top of a spcific bus device (i.e. struct pci_dev).
Since this is a rare (maybe even unique?) edge case, the driver core has indeed no infrastructure in place to represent this.
Quoted 2 lines
Maybe it needs a
dev->drvdataanddev->subsystem_data, maybe it needs some PCI thing where the pm ops can get a void *, IDK.
It still makes me think that there should be some closer integration of vfio-pci with the PCI core, as it is specifically built for this bus.
In fact, what you say above is the generalization of my "hack" [1], which, the more I think about this, seems actually less of a hack. :)
I would object a bit to the generalization with dev->subsystem_data as it screams for abuse, but the thing in [1] seems more and more reasonable to me.
(Another option would be to really split it up and have a virtual vfio-pci bus on top of PCI, which would also allow for custom match logic, but that also seems pretty overkill.)
Quoted 7 lines
Quoted 2 lines
As mentoined above, there are people volunteering now. Without starting it, it can't scale further than that. :)
There are lots of other vfio patches that need attention too, and it seems we are short of that more than anything. Now you need to do a bunch of C refactoring patches as well just to get things ready to show a bunch of rust code. It is a lot of work.
It's only the drvdata thing, what else is missing?
Quoted 3 lines
I don't really understand in a nutshell why we should do this for nova the mails were so long... Can we not just ignore the lifetime imperfection for this?
I mentioned some points in the first two paragraphs of [2]. Besides that, I don't see a reason why we should spend time and effort for working out the inferior solution, where the better alternative is even less effort, contributes to better quality and stability of the whole driver project and also offers a chance for the vfio subsystem to gain new contributors and gather experience with the language that has proven itself in many areas already.
I mean, there'd still be the option to make it an experiment and say let's add the abstractions and the nvidia-vgpu driver and see how it works out for a while before allowing more Rust drivers. And if it really turns out to be bad, it should also be easy to rip it out, replace nvidia-vgpu with a C driver and throw in a crappy FFI layer. :)
Quoted 6 lines
Quoted 3 lines
However, I don't really see the use-case; you can't load nvidia-vgpu without nova-core in the first place, so it would require to unbind nova-core through sysfs force unbind, no?
nvidia gpu is a more unique scenario, if you are building a general bindings it has to support the flows like this.
Sure, as mentioned, the code I sketched up should already be able to do this.
Quoted 2 lines
I've wanted to rework the way the common ops are shimmed in for a while, you'd probably want to do that before rust bindings.
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Actually, I even think it can be an advantage, as you could think of the Rust abstractions like a driver with built-in correctness checks, so it can help to validate the changes.
Of course, this requires the responsibles of the Rust code to help with that and I think we have this commitment.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/commit/?id=76b3bfd6386a01f338780e1a37b5bad3f5a48d31
[2] https://lore.kernel.org/nova-gpu/[email protected]/
Jason Gunthorpe
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 4 lines · Danilo Krummrich
Usually, class device implementations can't make assumptions of the underlying bus, because they have to work for any bus. I.e. there's no other way than providing helpers and letting drivers do the glue code between the bus and the class device.
You should think of VFIO as a series of helper libraries. One of those libraries is "here are all the PCI PM ops you need".
Drivers rarely need to customize these ops, they just need to wire it up to the support library to avoid a bunch of code duplication.
Stated another way - the very point of vfio-pci is to remove duplicated code from the drivers.
So if we wanted to push hard on removing drvdata, and don't want to touch the struct device I would probably say to #define up a way for the driver to build its unique trampolines. It wastes a bunch of .text but at least it doesn't duplicate code.
Quoted 3 lines
The reason this seems undesirable from a vfio-pci perspective is that it is special in the sense that it is a class device that is specifically built to sit on top of a spcific bus device (i.e. struct
pci_dev).
It is a library, all these ideas to do things with the driver core to implement a library make no architectural sense.
Quoted 2 lines
It still makes me think that there should be some closer integration of vfio-pci with the PCI core, as it is specifically built for this bus.
It has such a basic need I don't see this as a reason to pollute pci core with any vfio specific things. Like I would nak your [1], that's completely wrong layering.
Quoted 10 lines
Quoted 3 lines
I don't really understand in a nutshell why we should do this for nova the mails were so long... Can we not just ignore the lifetime imperfection for this?
I mentioned some points in the first two paragraphs of [2]. Besides that, I don't see a reason why we should spend time and effort for working out the inferior solution, where the better alternative is even less effort, contributes to better quality and stability of the whole driver project and also offers a chance for the vfio subsystem to gain new contributors and gather experience with the language that has proven itself in many areas already.
It seems to be quite a leap that it is less effort. IDK..
Quoted 3 lines
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Well, it is, but thats the point when judging effort..
Jason
Danilo Krummrich
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 20 lines · Jason Gunthorpe
Quoted 4 lines · Danilo Krummrich
Usually, class device implementations can't make assumptions of the underlying bus, because they have to work for any bus. I.e. there's no other way than providing helpers and letting drivers do the glue code between the bus and the class device.
You should think of VFIO as a series of helper libraries. One of those libraries is "here are all the PCI PM ops you need".
Drivers rarely need to customize these ops, they just need to wire it up to the support library to avoid a bunch of code duplication.
Stated another way - the very point of vfio-pci is to remove duplicated code from the drivers.
So if we wanted to push hard on removing drvdata, and don't want to touch the struct device I would probably say to #define up a way for the driver to build its unique trampolines. It wastes a bunch of .text but at least it doesn't duplicate code.
Quoted 6 lines
Quoted 3 lines
The reason this seems undesirable from a vfio-pci perspective is that it is special in the sense that it is a class device that is specifically built to sit on top of a spcific bus device (i.e. struct
pci_dev).It is a library, all these ideas to do things with the driver core to implement a library make no architectural sense.
Both is true, it is a library, and it is also a class device built on top of another class device (struct vfio_device) that accomodates to a specific underlying bus (PCI).
Which means that this library has the need to make a generic connection between the class (VFIO) and the bus (PCI). And this is something that the kernel has no generic solution for (and isn't represented by the driver core in any way).
Your dev->subsystem_data idea would accomodate this connection. However, I object to this, as it'd be for a very special case and I'd be worried it is abused by other subsystems in odd ways.
Besides that, I still think that the correct thing to do is to have the glue in the driver and just provide the helpers in the best possible form. In fact, this is what a library should do - provide the helpers, but do not directly interfere with with other layers.
Quoted 6 lines
Quoted 2 lines
It still makes me think that there should be some closer integration of vfio-pci with the PCI core, as it is specifically built for this bus.
It has such a basic need I don't see this as a reason to pollute pci core with any vfio specific things. Like I would nak your [1], that's completely wrong layering.
As I said in the beginning, it is just a "hack"; and in fact it is the exact same layering violation as abusing dev->driver_data or adding dev->subsystem_data.
The reasons I called it "more reasonable" and "less of a hack" in my previous reply are that it doesn't break an existing (driver core) API contract and it only affects the the exact two layers this is about in the first place.
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
I don't really understand in a nutshell why we should do this for nova the mails were so long... Can we not just ignore the lifetime imperfection for this?
I mentioned some points in the first two paragraphs of [2]. Besides that, I don't see a reason why we should spend time and effort for working out the inferior solution, where the better alternative is even less effort, contributes to better quality and stability of the whole driver project and also offers a chance for the vfio subsystem to gain new contributors and gather experience with the language that has proven itself in many areas already.
Quoted 7 lines
It seems to be quite a leap that it is less effort. IDK..
Quoted 3 lines
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Well, it is, but thats the point when judging effort..
So it seems that we agree that there isn't really a difference between adding a new C or Rust driver in this regard.
Jason Gunthorpe
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 8 lines · Danilo Krummrich
Quoted 5 lines
Quoted 3 lines
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Well, it is, but thats the point when judging effort..
So it seems that we agree that there isn't really a difference between adding a new C or Rust driver in this regard.
To be clear I was trying to say I think you are are underestimating how much work this is and how long it will take. Including all the preconditon C reworks has to be included when considering how much work is involved.
Why can't we just go forward with what Zhi already drafted? Do we really need another side quest?
I cannot forsee rust bindings for vfio until sometime in 2027.
Jason
Danilo Krummrich
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 7 lines · Jason Gunthorpe
Quoted 6 lines · Danilo Krummrich
Quoted 5 lines
Quoted 3 lines
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Well, it is, but thats the point when judging effort..
Quoted 7 lines
Quoted 2 lines
So it seems that we agree that there isn't really a difference between adding a new C or Rust driver in this regard.
To be clear I was trying to say I think you are are underestimating how much work this is and how long it will take. Including all the preconditon C reworks has to be included when considering how much work is involved.
I'm not sure I follow what you mean by "preconditon C reworks".
Do you refer to the drvdata thing? That seems rather trivial to address?
Or do you refer to other C core reworks people are working on? If so, they are only relevant if they affect the drivers. And if they affect the drivers, there's not really a difference between adding a new C driver and adding a Rust abstraction.
Quoted 2 lines
Why can't we just go forward with what Zhi already drafted? Do we really need another side quest?
Because I don't think it is a side quest. As mentioned, the FFI layer is already more complicated than the Rust abstraction we need, and I also don't see that this work is progressed further than the Rust abstraction I drafted. So, why not just go for the proper solution right away?
I still have to finish some talks, but I could probably finish that work until LPC and then we can walk through it?
Quoted 1 line
I cannot forsee rust bindings for vfio until sometime in 2027.
What is different in 2027 than is now?
Jason Gunthorpe
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 11 lines · Danilo Krummrich
Quoted 10 lines · Jason Gunthorpe
Quoted 8 lines · Danilo Krummrich
Quoted 5 lines
Quoted 3 lines
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Well, it is, but thats the point when judging effort..
So it seems that we agree that there isn't really a difference between adding a new C or Rust driver in this regard.
Quoted 6 lines
Quoted 4 lines
To be clear I was trying to say I think you are are underestimating how much work this is and how long it will take. Including all the preconditon C reworks has to be included when considering how much work is involved.
I'm not sure I follow what you mean by "preconditon C reworks".
Rust bindings often seem to need C code rework for Rust, drvdata here is an example.
Quoted 4 lines
Or do you refer to other C core reworks people are working on? If so, they are only relevant if they affect the drivers. And if they affect the drivers, there's not really a difference between adding a new C driver and adding a Rust abstraction.
A new C driver should not need reworks?
Quoted 3 lines
Quoted 1 line
I cannot forsee rust bindings for vfio until sometime in 2027.
What is different in 2027 than is now?
I mean I think that is how long it will take to merge something like that, given how many other vfio series there are, the lack of expertise, and some general expectations. There are already lots of series for vfio that are in front of something like this in the queue.
And then we end up with what will be one of the most complex drivers in a form nobody familiar with vfio can review.
It just seems like a much bigger thing to me than whatever the ffi problem is..
Jason
Danilo Krummrich
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 17 lines · Jason Gunthorpe
Quoted 16 lines · Danilo Krummrich
Quoted 14 lines · Jason Gunthorpe
Quoted 8 lines · Danilo Krummrich
Quoted 5 lines
Quoted 3 lines
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Well, it is, but thats the point when judging effort..
So it seems that we agree that there isn't really a difference between adding a new C or Rust driver in this regard.
To be clear I was trying to say I think you are are underestimating how much work this is and how long it will take. Including all the preconditon C reworks has to be included when considering how much work is involved.
Quoted 4 lines
Quoted 1 line
I'm not sure I follow what you mean by "preconditon C reworks".
Rust bindings often seem to need C code rework for Rust, drvdata here is an example.
I can assure you we can set this concern aside. The driver core code, auxiliary, platform, PCI, DMA, scatterlist, DRM, firmware loader, IRQ, I/O and fwctl, to name just a few, did not need any changes. And from the top of my head I can't think of any case where changes were needed.
For VFIO I already wrote the code, and no changes were required either, except for the drvdata things of course.
But, as discussed, this is an existing layering violation. The Rust driver code code simply relies on its own subsystem's API contract. Please let's not frame this as a Rust issue.
Plus, it is trivial to address, so it luckily is not a huge problem anyway. :)
Quoted 6 lines
Quoted 4 lines
Or do you refer to other C core reworks people are working on? If so, they are only relevant if they affect the drivers. And if they affect the drivers, there's not really a difference between adding a new C driver and adding a Rust abstraction.
A new C driver should not need reworks?
If a new C driver is not affected the Rust abstraction won't be affected either. They are just users of the same APIs the C drivers consume. So, that doesn't seem to be a concern then.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I cannot forsee rust bindings for vfio until sometime in 2027.
What is different in 2027 than is now?
I mean I think that is how long it will take to merge something like that, given how many other vfio series there are, the lack of expertise, and some general expectations. There are already lots of series for vfio that are in front of something like this in the queue.
The same would then be true for an nvidia-vgpu driver written in C, no? Again, the Rust abstractions are nothing else than a driver in the end. They only consume the driver facing APIs and translate them to a safe Rust API.
Quoted 2 lines
And then we end up with what will be one of the most complex drivers in a form nobody familiar with vfio can review.
I think this isn't the case; the people you refer to can still review semantics and vfio design specifics. It's not like everything is different.
For instance, there's still a get_region_info() callback on vfio::pci::Operations where people can review whether this semantically makes sense.
And for the language specifics we have a lot of Rust familiar people around who will review the code and help to improve it.
Why not see this as a chance to scale on both ends? More people on both ends will get familiar with VFIO and Rust at the same time.
Thanks,
Danilo
Alex Williamson
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 71 lines · On Thu, 17 Sep 2026 22:09:58 +0200 "Danilo Krummrich" <[email protected]> wrote:
Quoted 17 lines · Jason Gunthorpe
Quoted 16 lines · Danilo Krummrich
Quoted 14 lines · Jason Gunthorpe
Quoted 8 lines · Danilo Krummrich
Quoted 5 lines
Quoted 3 lines
TBH, I don't think it makes a difference; having Rust abstractions is pretty much the same as having another driver. I.e. it would be equivalent to saying "before we accept another pci-vfio driver we need to do some rework".
Well, it is, but thats the point when judging effort..
So it seems that we agree that there isn't really a difference between adding a new C or Rust driver in this regard.
To be clear I was trying to say I think you are are underestimating how much work this is and how long it will take. Including all the preconditon C reworks has to be included when considering how much work is involved.
Quoted 4 lines
Quoted 1 line
I'm not sure I follow what you mean by "preconditon C reworks".
Rust bindings often seem to need C code rework for Rust, drvdata here is an example.
I can assure you we can set this concern aside. The driver core code, auxiliary, platform, PCI, DMA, scatterlist, DRM, firmware loader, IRQ, I/O and fwctl, to name just a few, did not need any changes. And from the top of my head I can't think of any case where changes were needed.
For VFIO I already wrote the code, and no changes were required either, except for the drvdata things of course.
But, as discussed, this is an existing layering violation. The Rust driver code code simply relies on its own subsystem's API contract. Please let's not frame this as a Rust issue.
Plus, it is trivial to address, so it luckily is not a huge problem anyway. :)
Quoted 6 lines
Quoted 4 lines
Or do you refer to other C core reworks people are working on? If so, they are only relevant if they affect the drivers. And if they affect the drivers, there's not really a difference between adding a new C driver and adding a Rust abstraction.
A new C driver should not need reworks?
If a new C driver is not affected the Rust abstraction won't be affected either. They are just users of the same APIs the C drivers consume. So, that doesn't seem to be a concern then.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I cannot forsee rust bindings for vfio until sometime in 2027.
What is different in 2027 than is now?
I mean I think that is how long it will take to merge something like that, given how many other vfio series there are, the lack of expertise, and some general expectations. There are already lots of series for vfio that are in front of something like this in the queue.
The same would then be true for an nvidia-vgpu driver written in C, no? Again, the Rust abstractions are nothing else than a driver in the end. They only consume the driver facing APIs and translate them to a safe Rust API.
Quoted 2 lines
And then we end up with what will be one of the most complex drivers in a form nobody familiar with vfio can review.
I think this isn't the case; the people you refer to can still review semantics and vfio design specifics. It's not like everything is different.
For instance, there's still a
get_region_info()callback onvfio::pci::Operationswhere people can review whether this semantically makes sense.
Quoted 5 lines
And for the language specifics we have a lot of Rust familiar people around who will review the code and help to improve it.
Why not see this as a chance to scale on both ends? More people on both ends will get familiar with VFIO and Rust at the same time.
This thread has gone cold for a few days and nothing really seems to be dissuading from the direction of implementing the Nova interfacing vfio-pci variant vGPU driver in Rust. Zhi has been investigating the gaps and bugs in the PoC, and afaik, nothing stands out as a blocker.
I'll do my best to use LLM assisted reviews on my part, but the expectation should be that I won't be merging any Rust code without formal reviews on list. Over time I hope to be able to contribute from that perspective, but the Rust community is going to need to hold their end of the bargain as well. If meaningful reviews are not provided, the driver can be orphaned and removed.
The Rust community also needs to be proactive in supporting the vfio community such that abstractions and interfaces between C and Rust don't become a barrier for C-based development. Keeping the Rust code working when the C code changes is the Rust community's job, we shouldn't expect more than "best effort" from the existing C-focused community.
I also want to be clear, I'm not endorsing Rust as a pattern anywhere beyond this individual vfio-pci variant driver. Any other proposals would need to bring a comparably sized community to sponsor them.
Dave's approach to make vfio-pci-core a stateless helper with respect to drvdata, with a dash of Jason's macro idea to minimize the driver boilerplate for the common cases, seems like the right direction to remove that convention. I've handed off my own LLM generated version that does this and it should be refined and posted soon.
So, unless there's an aspect we haven't considered, it seems the Rust variant driver should be the direction here. Thanks,
Alex
Dave Airlie
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
In reply to Jason GunthorpeQuoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Danilo Krummrich
Usually, class device implementations can't make assumptions of the underlying bus, because they have to work for any bus. I.e. there's no other way than providing helpers and letting drivers do the glue code between the bus and the class device.
Quoted 5 lines
You should think of VFIO as a series of helper libraries. One of those libraries is "here are all the PCI PM ops you need".
Drivers rarely need to customize these ops, they just need to wire it up to the support library to avoid a bunch of code duplication.
It's currently a library being used as a midlayer. demidlayering it so drivers control drvdata removes that.
I sent the diffstat that covers all the current vfio pci drivers and that didn't seem excessive.
Quoted 8 lines
Stated another way - the very point of vfio-pci is to remove duplicated code from the drivers.
So if we wanted to push hard on removing drvdata, and don't want to touch the struct device I would probably say to #define up a way for the driver to build its unique trampolines. It wastes a bunch of .text but at least it doesn't duplicate code.
+static pci_ers_result_t hisi_acc_vfio_pci_aer_err_detected(
+ struct pci_dev *pdev, pci_channel_state_t state)
+{
+ struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev);
+
+ return vfio_pci_core_aer_err_detected(&hisi_acc_vdev->core_device,
state);
+}
+
+static int hisi_acc_vfio_pci_runtime_suspend(struct device *dev) +{
+ struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev);
+
+ return vfio_pci_core_runtime_suspend(&hisi_acc_vdev->core_device);
+}
+
+static int hisi_acc_vfio_pci_runtime_resume(struct device *dev) +{
+ struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev);
+
+ return vfio_pci_core_runtime_resume(&hisi_acc_vdev->core_device);
+}
+
+static const struct dev_pm_ops hisi_acc_vfio_pci_pm_ops = {
+ SET_RUNTIME_PM_OPS(hisi_acc_vfio_pci_runtime_suspend,
+ hisi_acc_vfio_pci_runtime_resume, NULL)
+};
is how much code it adds to current drivers, this doesn't seem excessive for 10 drivers,
like you could obfuscate it a bit with some macros, but I really don't see a lot of value in hiding
what is effectively just standard driver boilerplate.
Dave.
Gary Guo
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 38 lines · Dave Airlie
Quoted 8 lines · Jason Gunthorpe
Stated another way - the very point of vfio-pci is to remove duplicated code from the drivers.
So if we wanted to push hard on removing drvdata, and don't want to touch the struct device I would probably say to #define up a way for the driver to build its unique trampolines. It wastes a bunch of .text but at least it doesn't duplicate code.
(quoted diff) +6
-0+static pci_ers_result_t hisi_acc_vfio_pci_aer_err_detected( + struct pci_dev *pdev, pci_channel_state_t state) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev); + + return vfio_pci_core_aer_err_detected(&hisi_acc_vdev->core_device,state);
(quoted diff) +20
-0+} + +static int hisi_acc_vfio_pci_runtime_suspend(struct device *dev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev); + + return vfio_pci_core_runtime_suspend(&hisi_acc_vdev->core_device); +} + +static int hisi_acc_vfio_pci_runtime_resume(struct device *dev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev); + + return vfio_pci_core_runtime_resume(&hisi_acc_vdev->core_device); +} + +static const struct dev_pm_ops hisi_acc_vfio_pci_pm_ops = { + SET_RUNTIME_PM_OPS(hisi_acc_vfio_pci_runtime_suspend, + hisi_acc_vfio_pci_runtime_resume, NULL) +};
Quoted 5 lines
is how much code it adds to current drivers, this doesn't seem excessive for 10 drivers,
like you could obfuscate it a bit with some macros, but I really don't see a lot of value in hiding
what is effectively just standard driver boilerplate.
If it's just these callbacks, you could even have vfio-pci directly proxying these callbacks by having a struct device -> struct vfio_pci_core_device hashmap. (Not that I'm saying it's a good idea).
Best,
Gary
Jason Gunthorpe
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
In reply to Dave AirlieQuoted 28 lines · Dave Airlie
(quoted diff) +6
-0+static pci_ers_result_t hisi_acc_vfio_pci_aer_err_detected( + struct pci_dev *pdev, pci_channel_state_t state) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev); + + return vfio_pci_core_aer_err_detected(&hisi_acc_vdev->core_device,state);
(quoted diff) +20
-0+} + +static int hisi_acc_vfio_pci_runtime_suspend(struct device *dev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev); + + return vfio_pci_core_runtime_suspend(&hisi_acc_vdev->core_device); +} + +static int hisi_acc_vfio_pci_runtime_resume(struct device *dev) +{ + struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev); + + return vfio_pci_core_runtime_resume(&hisi_acc_vdev->core_device); +} + +static const struct dev_pm_ops hisi_acc_vfio_pci_pm_ops = { + SET_RUNTIME_PM_OPS(hisi_acc_vfio_pci_runtime_suspend, + hisi_acc_vfio_pci_runtime_resume, NULL) +};
Quoted 2 lines
is how much code it adds to current drivers, this doesn't seem excessive for 10 drivers,
Well, I think it is alot, and there it sucks if new ones are added.
Quoted 3 lines
like you could obfuscate it a bit with some macros, but I really don't see a lot of value in hiding
what is effectively just standard driver boilerplate.
This is exactly the kind of boilerplate people have been removing with macros. I would macro it..
Jason
Dave Airlie
maintainerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
In reply to Alex WilliamsonQuoted 75 lines · Alex Williamson
Quoted 62 lines · On Mon, 14 Sep 2026 23:36:24 +0200 "Danilo Krummrich" <[email protected]> wrote:
Quoted 32 lines · Alex Williamson
Hi Danilo,
Quoted 21 lines · On Fri, 11 Sep 2026 22:39:16 +0200 "Danilo Krummrich" <[email protected]> wrote:
Hi Alex, Jason, Zhi,
Quoted 2 lines · Zhi Wang
NVIDIA vGPU VFs require their open, reset, and close lifecycle to be coordinated with the PF-side nova-core driver.
[...]
Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/main.c | 253 ++++++++++++++++++++++++++This is going to be a longer response; sorry about this in advance.
Looking at the FFI boundary introduced in the previous patch, I'm concerned that it translates the driver model relationships we've expressed through Rust's ownership and lifetime model back into raw pointers and lifetime assumptions that callers must uphold. It also introduces manual lifecycle management across the boundary, rather than preserving nova-core's RAII-based ownership model.
I think implementing the NVIDIA vGPU driver in Rust would let us preserve those relationships across the interface, make lifecycle management less error-prone, and fit naturally alongside nova-core and nova-drm.
[snip]
Quoted 4 lines
If you've made it this far, thanks for reading through this long write-up. I hope you find it useful. Please let me know if you have any questions or thoughts.
Quoted 7 lines
I can't really say I made it this far with comprehension, but thanks for the effort ;)
The one piece here that I can actually review is [5], where
dev_get_drvdata()is replaced with a vfio-pci-core struct pointer embedded in the structpci_dev, which is a non-starter as far as having a common PCI-core shared by various drivers.Well, that was just a quick hack to get it out of the way. :)
I think there are a couple of options.
(1) Make the PM helpers take a struct
vfio_pci_core_device* in the first place and let the driver forward to the helpers in its own PM callbacks.(2) Provide an (optional?) driver callback that translates a struct
pci_devto structvfio_pci_core_device.(3) Provide a macro for drivers to define PM ops, letting drivers provide the function that translates struct
pci_devto structvfio_pci_core_device.(4) Give struct
vfio_pci_core_deviceits own PM domain (which is probably a bit overkill :).I understand that the idea is to hide the PM handling in the vfio-pci framwork, but I think the existing implementation is a bit of a layering violation, since class device implementations shouldn't impose requirements on the bus device private data layout.
Quoted 8 lines
I also think that the approach to fully hide it in the framework is only really worth if it doesn't otherwise impose subtle requirements on the driver (such as the layout requirement of the bus device private data).
Thus, I'd personally just go with (1) as it is the most honest approach in terms of driver layering. But I think (2) is a good alternative that is not more invasive than asking drivers to set the bus device private data to struct
vfio_pci_core_device*.
Quoted 6 lines
I'd position this more as a library convention than a class layering violation. vfio-pci was originally one driver, vfio-pci-core was pulled out to enable device specific support, ex. migration, in a more manageable way. struct
vfio_pci_core_deviceis not strictly a class, it's the object used by the library that variant drivers opt to use rather than re-implementing vfio-pci from the ground up.
Not to be critical of an evolved design, vfio-pci-core should probably be structured as a series of helpers that drivers can use, rather than a midlayer. Midlayers plagued us in drm, let drivers drive and provide the VGA/PM interfaces using standard vfio-pci-core methods rather than forcing vfio-pci-core to own the pci device data.
Just because C let's us take shortcuts with struct layouts and pointers, it doesn't mean it's a clean pattern we want to continue with indefinitely. You can look at the rust use of the subsystem as a chance to clean up some of the corners where layers aren't clean.
I just threw opencode at the refactor and for $12 of my massive budget it produced
the prompt was:
"in linux/drivers/vfio/pci the vfio pci core decides that drivers must install a vfio_pci_core_device struct to drvdata, this feels like a layering violation, I'd like the vfio pci core to be a set of helpers the drivers use instead of midlayering itself, can you plan that out and then execute"
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 54 ++++++++++++++++++++++++++++++++++++++---------------- drivers/vfio/pci/ism/main.c | 45 ++++++++++++++++++++++++++++++++++++--------- drivers/vfio/pci/mlx5/main.c | 39 ++++++++++++++++++++++++++++++++------- drivers/vfio/pci/nvgrace-gpu/main.c | 45 +++++++++++++++++++++++++++++++++++---------- drivers/vfio/pci/pds/pci_drv.c | 34 +++++++++++++++++++++++++++++++--- drivers/vfio/pci/pds/vfio_dev.c | 5 +---- drivers/vfio/pci/qat/main.c | 38 ++++++++++++++++++++++++++++++++------ drivers/vfio/pci/vfio_pci.c | 34 ++++++++++++++++++++++++++++++++-- drivers/vfio/pci/vfio_pci_core.c | 66 +++++++++++++++++++++++------------------------------------------- drivers/vfio/pci/virtio/main.c | 34 +++++++++++++++++++++++++++++++--- drivers/vfio/pci/xe/main.c | 34 +++++++++++++++++++++++++++++++--- 11 files changed, 322 insertions(+), 106 deletions(-)
It seems to be correct code, and makes things look more like drivers owning the outer structs. I did look for this pattern elsewhere in the kernel and it's not common at all, in fact my quick search couldn't spot any other instances which again suggests it's not a pattern we should be leaning into.
As for the rust stuff, I think for vfio your drivers are just not that much of a horror show or refactoring often enough that rust will be anything but a blip on your radar, having Zhi/Danilo and access to any sort of LLM will generally make most refactors trivial, lots of maintainers keep bringing up the same concerns about refactors and interfaces and breakage, but I'm not seeing the problems, and most of the refactors that are rust driven are make the C code clearer.
Dave.
Quoted 72 lines
Quoted 14 lines
Quoted 3 lines
Can a Rust vfio-pci variant driver be self-contained, or to what extent does it impose on the framework, such as the drvdata idiom.
As mentioned above, I think this one is more of a layering violation in the vfio-pci-core; class devices shouldn't impose layout requirements on bus device private data.
The reason C drivers can get away with it more easily is e.g. that C relies on procedural cleanup and that all responsibility for managing lifetimes sits on the drivers themselves, so it is easier for them to adjust. But in general, it wouldn't work out if all class device registrations or other core primitives would have the same expectation.
Quoted 5 lines
For Rust specifically it is that the driver core controls the lifetime of the bus device private data, which is a fundamental requirement to e.g. represent registrations as RAII types. E.g. the
vfio::pci::Registrationhas to be stored in the bus device private data, such that it is guaranteed to be correctly destroyed on driver unbind.I see, so driver core has its own convention for how Rust drivers must use drvdata.
Quoted 5 lines
To get back to your question, a Rust vfio-pci variant driver should be self-contained. The interface sits in the abstraction that translates the C driver API to a Rust driver API. It sometimes can help quite significantly (e.g. in terms of how complex the Rust code needs to get in order to actually be safe) if the C code does a minor adjustment, but it shouldn't be necessary.
It's not clear to me to what extent these abstractions hinder our ability to evolve and refactor the C code. It may not "lock in" the core API for variant drivers, but it seems it raises the bar that any significant code refactor likely needs to refactor the abstraction layer, potentially the Rust variant driver itself, which imposes a burden on the vfio community that has so far not introduced Rust into the code base.
Quoted 9 lines
For instance, the only addition to the driver core we have is an additional callback in struct
device_driver, and in the future an additional pointer in structdevice_private; none of those couldn't be worked around in some way though.On the other hand there are examples where the Rust introduction motivated design improvements on the C side, or bug fixes for issues that were caught while writing a safe abstraction. For instance, we recently had some fixes around dyn IDs in the PCI and USB core, which both were motivated by Rust code.
I have no doubt that integration with a more structured language would lead to various improvements. However, it doesn't seem there are resources to support it in the short term.
Quoted 9 lines
Quoted 6 lines
FWIW, AI can only go so far to support reviews. Having the code insight to ask the right questions is essential. A human in the loop is a requirement.
Additionally, if we can't narrow the device matching to only the Nova-core supported VFs,
Agreed, and I think that should be possible. Is there a particular case you think of where this wouldn't hold?
The modalias scheme only matches on vendor/device ID, subsystem IDs, base/sub class, and interface. Nothing in the PCI spec requires that the VF device ID is different from the PF device ID. Variant drivers will often present a larger match surface to avoid the ongoing maintenance overhead of listing explicit device IDs. Such an approach here would put us in the position I noted in the previous reply where the Rust variant driver needs to fully support these devices via vfio-pci-core on day one. Binding GPU PFs to vfio-pci is a current, valid use case (VFs for some vendors as well). Thanks,
Alex
Jason Gunthorpe
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
Quoted 3 lines · Dave Airlie
As for the rust stuff, I think for vfio your drivers are just not that much of a horror show or refactoring often enough that rust will be anything but a blip on your radar,
Uh? I've been sending a couple whole subsystem refactorings touching every driver a couple times a year for what, 5 years now?
There are still more that are needed, like trying to redo the drvdata apparently. As well as stuff on the ops side, and more and more.
Granted you are looking at it after all this work, but there are still problematic areas. drvdata, some of the ops, some of the locking, I think there will be alot of C work to fix things up enough rust bindings can happen sanely.
It is not so easy, your LLM looks like it put PM trampolines in every driver, which I would not like to see.. Not sure how it solved vga without touching drm..
Jason
Gary Guo
reviewerRe: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
In reply to Alex WilliamsonQuoted 57 lines · Alex Williamson
Quoted 27 lines · On Mon, 14 Sep 2026 23:36:24 +0200 "Danilo Krummrich" <[email protected]> wrote:
Quoted 4 lines · Alex Williamson
The one piece here that I can actually review is [5], where
dev_get_drvdata()is replaced with a vfio-pci-core struct pointer embedded in the structpci_dev, which is a non-starter as far as having a common PCI-core shared by various drivers.Well, that was just a quick hack to get it out of the way. :)
I think there are a couple of options.
(1) Make the PM helpers take a struct
vfio_pci_core_device* in the first place and let the driver forward to the helpers in its own PM callbacks.(2) Provide an (optional?) driver callback that translates a struct
pci_devto structvfio_pci_core_device.(3) Provide a macro for drivers to define PM ops, letting drivers provide the function that translates struct
pci_devto structvfio_pci_core_device.(4) Give struct
vfio_pci_core_deviceits own PM domain (which is probably a bit overkill :).I understand that the idea is to hide the PM handling in the vfio-pci framwork, but I think the existing implementation is a bit of a layering violation, since class device implementations shouldn't impose requirements on the bus device private data layout.
Quoted 8 lines
I also think that the approach to fully hide it in the framework is only really worth if it doesn't otherwise impose subtle requirements on the driver (such as the layout requirement of the bus device private data).
Thus, I'd personally just go with (1) as it is the most honest approach in terms of driver layering. But I think (2) is a good alternative that is not more invasive than asking drivers to set the bus device private data to struct
vfio_pci_core_device*.I'd position this more as a library convention than a class layering violation. vfio-pci was originally one driver, vfio-pci-core was pulled out to enable device specific support, ex. migration, in a more manageable way. struct
vfio_pci_core_deviceis not strictly a class, it's the object used by the library that variant drivers opt to use rather than re-implementing vfio-pci from the ground up.The conventions of that library mean variant drivers get things like VGA routing and power management for free, in adherence with how these features are exported by the core, and can choose to opt-in to common error handling.
The use of drvdata is part of that convention and audited by the core such that failed compliance is rejected on registration. Clearly we could allow variant drivers to provide ops for their own callbacks and export core helpers they can use, but only a Rust driver requires this and we need to figure out how to do this without degrading the audit in the core.
Quoted 6 lines
Turning vfio-pci-core into a proper class to be able to have a real layering violation claim seems like a much larger project.
Quoted 3 lines
Quoted 3 lines
My concerns are of course who is going to review the Rust vfio-pci variant drivers from a vfio perspective, not just a drm driver viewpoint.
FWIW, if we want vfio-pci to be a middle layer (looks like there're some disagreements about this), we could quite simply achieve this by define
mod vfio_pci {
trait Driver {
/* callbacks here */
}
struct Adapter<D: Driver>(D);
impl pci::Driver for Adapter {
...
}
}and then the way for people to be using this would to create the "Adapter" which does the middle layering and register *that* as pci driver instead. Then all PCI callbacks will first land in vfio-pci abstration's code before it filters through things in the driver. This way, vfio-pci-core imlements the pci driver then it controls its drvdata layout.
Best,
Gary
PATCH 13/13 gpu: nova-core: reserve the 48-VM WPR2 heap
In reply to Zhi WangGSP-RM needs the larger r000 vGPU WPR2 heap on devices that advertise more than 32 VFs. The default heap is too small for the 48-VF GB202 configuration and GSP-RM fails to start.
Select the firmware-defined 48-VM size from the detected VF count while retaining the default size for configurations with 2 through 32 VFs.
--- drivers/gpu/nova-core/fb.rs | 2 +- drivers/gpu/nova-core/gsp/fw.rs | 7 +++++-- drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs | 1 + 3 files changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/fb.rs +1 -1
@@ -306,7 +306,7 @@ fn wpr2_heap_params(chipset: Chipset, vgpu_state: VgpuState, fb_size: u64) -> Re ), VgpuState::Enabled { total_vfs } => ( u8::try_from (total_vfs.get ()).map_err (|_|EINVAL )?, - gsp::LibosParams ::vgpu_wpr_heap_size (), + gsp::LibosParams ::vgpu_wpr_heap_size (total_vfs.get ()), ), }) }
drivers/gpu/nova-core/gsp/fw.rs +5 -2
@@ -166,8 +166,11 @@ pub(crate) fn from_chipset(chipset: Chipset) -> &'static LibosParams { }/// Returns the WPR heap size to reserve when vGPU is enabled. -pub (crate )fn vgpu_wpr_heap_size () ->u64 { - u64::from (bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT ) +pub (crate )fn vgpu_wpr_heap_size (total_vfs:u16 ) ->u64 { + u64::from (match total_vfs { +2 ..=32 => bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT , + _ => r000_00::GSP_FW_HEAP_SIZE_VGPU_48VMS , + }) }/// Returns the amount of memory (in bytes) to allocate for the WPR heap for a framebuffer size
drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs +1 -0
@@ -85,6 +85,7 @@ impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {}pub const GSP_FW_HEAP_PARAM_SIZE_PER_GB :u32 =98304 ;pub const GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE :u32 =100663296 ;pub const GSP_FW_HEAP_SIZE_VGPU_DEFAULT :u32 =609222656 ; +pub const GSP_FW_HEAP_SIZE_VGPU_48VMS :u32 =1436549120 ;pub const GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MIN_MB :u32 =64 ;pub const GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB :u32 =256 ;pub const GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MIN_MB :u32 =88 ;
Signature · 1 line
2.53.0