Skip to contentSkip to conversation

Introduce NVIDIA GPU Virtualization (vGPU) Support

RFC In review Zhi Wang 4 participants 23 messages Sep 3, 2025 – Sep 6, 2025

Subsystems (6)
lore
Share & tools
lore

Zhi Wang

author
#0 lore raw

v2 cover Introduce NVIDIA GPU Virtualization (vGPU) Support

1. Background
=============

NVIDIA vGPU[1] software enables powerful GPU performance for workloads ranging from graphics-rich virtual workstations to data science and AI, enabling IT to leverage the management and security benefits of virtualization as well as the performance of NVIDIA GPUs required for modern workloads. Installed on a physical GPU in a cloud or enterprise data center server, NVIDIA vGPU software creates virtual GPUs that can be shared across multiple virtual machines.

The vGPU architecture[2] can be illustrated as follow:

 +--------------------+    +--------------------+ +--------------------+ +--------------------+ 
 | Hypervisor         |    | Guest VM           | | Guest VM           | | Guest VM           | 
 |                    |    | +----------------+ | | +----------------+ | | +----------------+ | 
 | +----------------+ |    | |Applications... | | | |Applications... | | | |Applications... | | 
 | |  NVIDIA        | |    | +----------------+ | | +----------------+ | | +----------------+ | 
 | |  Virtual GPU   | |    | +----------------+ | | +----------------+ | | +----------------+ | 
 | |  Manager       | |    | |  Guest Driver  | | | |  Guest Driver  | | | |  Guest Driver  | | 
 | +------^---------+ |    | +----------------+ | | +----------------+ | | +----------------+ | 
 |        |           |    +---------^----------+ +----------^---------+ +----------^---------+ 
 |        |           |              |                       |                      |           
 |        |           +--------------+-----------------------+----------------------+---------+ 
 |        |                          |                       |                      |         | 
 |        |                          |                       |                      |         | 
 +--------+--------------------------+-----------------------+----------------------+---------+ 
+---------v--------------------------+-----------------------+----------------------+----------+
| NVIDIA                  +----------v---------+ +-----------v--------+ +-----------v--------+ |
| Physical GPU            |   Virtual GPU      | |   Virtual GPU      | |   Virtual GPU      | |
|                         +--------------------+ +--------------------+ +--------------------+ |
+----------------------------------------------------------------------------------------------+

Each NVIDIA vGPU is analogous to a conventional GPU, having a fixed amount of GPU framebuffer, and one or more virtual display outputs or "heads". The vGPU's framebuffer is allocated out of the physical GPU's framebuffer at the time the vGPU is created, and the vGPU retains exclusive use of that framebuffer until it is destroyed.

Each physical GPU can support several different types of virtual GPU (vGPU). vGPU types have a fixed amount of frame buffer, number of supported display heads, and maximum resolutions. They are grouped into different series according to the different classes of workload for which they are optimized. Each series is identified by the last letter of the vGPU type name.

NVIDIA vGPU supports Windows and Linux guest VM operating systems. The supported vGPU types depend on the guest VM OS.

2. Proposal For Upstream
========================

2.1 Architecture
----------------

Moving to the upstream, the proposed architecture can be illustrated as followings:

                            +--------------------+ +--------------------+ +--------------------+ 
                            | Linux VM           | | Windows VM         | | Guest VM           | 
                            | +----------------+ | | +----------------+ | | +----------------+ | 
                            | |Applications... | | | |Applications... | | | |Applications... | | 
                            | +----------------+ | | +----------------+ | | +----------------+ | ... 
                            | +----------------+ | | +----------------+ | | +----------------+ | 
                            | |  Guest Driver  | | | |  Guest Driver  | | | |  Guest Driver  | | 
                            | +----------------+ | | +----------------+ | | +----------------+ | 
                            +---------^----------+ +----------^---------+ +----------^---------+ 
                                      |                       |                      |           
                           +--------------------------------------------------------------------+
                           |+--------------------+ +--------------------+ +--------------------+|
                           ||       QEMU         | |       QEMU         | |       QEMU         ||
                           ||                    | |                    | |                    ||
                           |+--------------------+ +--------------------+ +--------------------+|
                           +--------------------------------------------------------------------+
                                      |                       |                      |
+-----------------------------------------------------------------------------------------------+
|                           +----------------------------------------------------------------+  |
|                           |                                VFIO                            |  |
|                           |                                                                |  |
| +-----------------------+ | +-------------------------------------------------------------+|  |
| |                       | | |                                                             ||  |
| |     nova_core        <--->|                                                             ||  |
| +    (core driver)      + | |                      NVIDIA vGPU VFIO Driver                ||  |
| |                       | | |                                                             ||  |
| |                       | | +-------------------------------------------------------------+|  |
| +--------^--------------+ +----------------------------------------------------------------+  |
|          |                          |                       |                      |          |
+-----------------------------------------------------------------------------------------------+
           |                          |                       |                      |           
+----------|--------------------------|-----------------------|----------------------|----------+
|          v               +----------v---------+ +-----------v--------+ +-----------v--------+ |
|  NVIDIA                  |       PCI VF       | |       PCI VF       | |       PCI VF       | |
|  Physical GPU            |                    | |                    | |                    | |
|                          |   (Virtual GPU)    | |   (Virtual GPU)    | |    (Virtual GPU)   | |
|                          +--------------------+ +--------------------+ +--------------------+ |
+-----------------------------------------------------------------------------------------------+

Each virtual GPU (vGPU) instance is implemented atop a PCIe Virtual Function (VF). The NVIDIA vGPU VFIO driver, in coordination with the VFIO framework, operates directly on these VFs to enable key functionalities including vGPU type selection, dynamic instantiation and destruction of vGPU instances, support for live migration, and warm update.

Consistent with other VFIO variant drivers, the NVIDIA vGPU VFIO driver adheres to the standard VFIO userspace interface, facilitating device lifecycle management and integration with advanced VFIO capabilities.

At the low level, the NVIDIA vGPU VFIO driver interfaces with the core driver, which provides the necessary abstractions and mechanisms to access and manipulate the underlying GPU hardware resources.

2.2 Core Driver (nova_core)
---------------------------

The primary deployment model for cloud service providers (CSPs) and enterprise environments is to have a standalone, minimal driver stack with the vGPU support and other essential components. Thus, a minimal core driver is required to support the NVIDIA vGPU VFIO driver.

The core GPU driver provides the foundational infrastructure necessary to support the following operations:

- Firmware management: Load the GSP (GPU System Processor) firmware, initiate GSP boot procedures, and establish the communication channel between the host and the GSP.

- Hardware resource management: Control and partition shared GPU resources-such as framebuffer memory and hardware channels-used by the VFIO driver for instantiating and operating vGPUs.

- Exception handling: Relay hardware and firmware-level exception events, including GSP notifications, to the VFIO driver. E.g. FIFO nonstall.

- Host event coordination: Handle system-wide events such as suspend and resume, PF driver unbind, etc. ensuring proper synchronization with GPU subsystems.

- Hardware configuration enumeration: Discover and expose static and dynamic hardware capabilities required for vGPU orchestration. E.g. engine bitmap, total FB memory size.

2.3 NVIDIA vGPU VFIO Driver
---------------------------

The NVIDIA vGPU VFIO driver exposes standard VFIO interfaces for userspace access to vGPUs, while also providing control paths for vGPU creation and destruction with the help of core driver.

The driver provides an additional sysfs interface for the admin to query the creatable vGPU types on a VF. Once the vGPU type is selected, the userspace VMM, e.g. QEMU can manipulate the VF via the standard VFIO device interfaces. Only homogeneous vGPU has been supported.

As different NVIDIA GPUs support different available vGPU types, a loadable vGPU metadata file is introduced to host those blobs, which are the support vGPU types on supported NVIDIA GPUs. It is loaded together with the VFIO driver. The VFIO driver chooses the usable vGPU types from it based on the installed NVIDIA GPU in the system.

The driver also exposes an per-vGPU logging interface to collect the GSP logs for bug report.

2.4 Changes from RFC [3]
-----------------------------

- vGPU is supported since GSP microcode 570.
- Multiple vGPU support with homogeneous scheme.
- CE workload submission for FB memory scrubbing.
- Interface to create/destroy/select vGPUs.
- Loadable vGPU type support via vGPU metadata file.
- Expose per-vGPU GSP log.
- Proper VFIO driver attach/detach flow.
- PF driver event forwarding to support PF driver unbind by admin.

3 Try the patches
-----------------------

- Host kernel: http://github.com/zhiwang-nvidia/linux/tree/zhi/vgpu-rfc-v2
- vGPU metadata file: https://github.com/zhiwang-nvidia/vgpu-tools/blob/metadata/metadata/18.1/vgpu-570.144.bin
The metadata file needs to be placed at: /lib/firmware/nvidia
- Guest driver package: NVIDIA-Linux-x86_64-570.124.04.run [4]

Install guest driver:

  # export GRID_BUILD=1
  # ./NVIDIA-Linux-x86_64-570.124.04.run

- Tested platforms: RTX A6000 Ada.
- Tested host OS: RHEL 8.4.
- Tested guest OS: Ubutnu 24.04 LTS, Windows 11.
- Supported experience: Rich desktop experience with simple 3D workload, e.g. glmark2, heaven.

- Demo video: running heaven on two -24Q vGPUs on NVIDIA RTX A6000 Ada [5]

[1] https://www.nvidia.com/en-us/data-center/virtual-solutions/
[2] https://docs.nvidia.com/vgpu/17.0/grid-vgpu-user-guide/index.html#architecture-grid-vgpu
[3] https://lore.kernel.org/kvm/[email protected]/T/
[4] https://us.download.nvidia.com/XFree86/Linux-x86_64/570.124.04/NVIDIA-Linux-x86_64-570.124.04.run
[5] https://youtu.be/DhW--wVlLfU

Zhi Wang (14):
vfio/nvidia-vgpu: introduce vGPU lifecycle management prelude vfio/nvidia-vgpu: allocate GSP RM client for NVIDIA vGPU manager vfio/nvidia-vgpu: introduce vGPU type uploading vfio/nvidia-vgpu: allocate vGPU channels when creating vGPUs vfio/nvidia-vgpu: allocate vGPU FB memory when creating vGPUs vfio/nvidia-vgpu: allocate mgmt heap when creating vGPUs vfio/nvidia-vgpu: map mgmt heap when creating a vGPU vfio/nvidia-vgpu: allocate GSP RM client when creating vGPUs vfio/nvidia-vgpu: bootload the new vGPU vfio/nvidia-vgpu: introduce vGPU host RPC channel vfio/nvidia-vgpu: introduce NVIDIA vGPU VFIO variant driver vfio/nvidia-vgpu: scrub the guest FB memory of a vGPU vfio/nvidia-vgpu: introduce vGPU logging vfio/nvidia-vgpu: add a kernel doc to introduce NVIDIA vGPU

 .../ABI/stable/sysfs-driver-nvidia-vgpu       |  11 +
 Documentation/gpu/drivers.rst                 |   1 +
 Documentation/gpu/nvidia-vgpu.rst             | 264 +++++++
 drivers/vfio/pci/Kconfig                      |   2 +
 drivers/vfio/pci/Makefile                     |   2 +
 drivers/vfio/pci/nvidia-vgpu/Kconfig          |  15 +
 drivers/vfio/pci/nvidia-vgpu/Makefile         |   6 +
 drivers/vfio/pci/nvidia-vgpu/debug.h          |  35 +
 drivers/vfio/pci/nvidia-vgpu/debugfs.c        |  65 ++
 .../pci/nvidia-vgpu/include/nvrm/bootload.h   |  58 ++
 .../vfio/pci/nvidia-vgpu/include/nvrm/ecc.h   |  45 ++
 .../vfio/pci/nvidia-vgpu/include/nvrm/gsp.h   |  18 +
 .../nvidia-vgpu/include/nvrm/nv_vgpu_types.h  |  34 +
 .../pci/nvidia-vgpu/include/nvrm/nvtypes.h    |  26 +
 .../vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h  | 182 +++++
 .../vfio/pci/nvidia-vgpu/include/nvrm/vmmu.h  |  39 +
 drivers/vfio/pci/nvidia-vgpu/metadata.c       | 319 ++++++++
 drivers/vfio/pci/nvidia-vgpu/metadata.h       |  89 +++
 .../vfio/pci/nvidia-vgpu/metadata_vgpu_type.c | 153 ++++
 drivers/vfio/pci/nvidia-vgpu/pf.h             | 145 ++++
 drivers/vfio/pci/nvidia-vgpu/rpc.c            | 254 ++++++
 drivers/vfio/pci/nvidia-vgpu/vfio.h           |  65 ++
 drivers/vfio/pci/nvidia-vgpu/vfio_access.c    | 313 ++++++++
 drivers/vfio/pci/nvidia-vgpu/vfio_debugfs.c   | 117 +++
 drivers/vfio/pci/nvidia-vgpu/vfio_main.c      | 730 ++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vfio_sysfs.c     | 209 +++++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c           | 690 +++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c       | 450 +++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h       | 231 ++++++
 29 files changed, 4568 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-driver-nvidia-vgpu
 create mode 100644 Documentation/gpu/nvidia-vgpu.rst
 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/debug.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/debugfs.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/bootload.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/ecc.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/nv_vgpu_types.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/nvtypes.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/vmmu.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/metadata.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/metadata.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/metadata_vgpu_type.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/pf.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/rpc.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_access.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_debugfs.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_main.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_sysfs.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vgpu.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h
Signature · 1 line
2.34.1
author
#1 lore raw

RFC v2 1/14 vfio/nvidia-vgpu: introduce vGPU lifecycle management prelude

To introduce the routines when creating a vGPU one by one in the following patches, first, introduce the prelude of the vGPU lifecycle management as the skeleton.

Introduce the vGPU lifecycle managemement data structures and routines.

---
 drivers/vfio/pci/Kconfig                |   2 +
 drivers/vfio/pci/Makefile               |   2 +
 drivers/vfio/pci/nvidia-vgpu/Kconfig    |  15 ++
 drivers/vfio/pci/nvidia-vgpu/Makefile   |   3 +
 drivers/vfio/pci/nvidia-vgpu/debug.h    |  17 +++
 drivers/vfio/pci/nvidia-vgpu/pf.h       |  65 ++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c     | 101 +++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c | 193 ++++++++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h |  79 ++++++++++
 9 files changed, 477 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/debug.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/pf.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vgpu.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h
drivers/vfio/pci/Kconfig +2 -0
index 2b0172f54665..4bb2ddb120cc 100644
@@ -65,6 +65,8 @@ source "drivers/vfio/pci/virtio/Kconfig"
 
 source "drivers/vfio/pci/nvgrace-gpu/Kconfig"
 
+source "drivers/vfio/pci/nvidia-vgpu/Kconfig"
+
 source "drivers/vfio/pci/qat/Kconfig"
 
 endmenu
drivers/vfio/pci/Makefile +2 -0
index cf00c0a7e55c..0e56f2e7ea36 100644
@@ -18,4 +18,6 @@ obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio/
 
 obj-$(CONFIG_NVGRACE_GPU_VFIO_PCI) += nvgrace-gpu/
 
+obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia-vgpu/
+
 obj-$(CONFIG_QAT_VFIO_PCI) += qat/
drivers/vfio/pci/nvidia-vgpu/Kconfig new file +15 -0
new file mode 100644
index 000000000000..3a0dab70e31d
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config NVIDIA_VGPU_VFIO_PCI
+	tristate "VFIO support for the NVIDIA vGPU"
+	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 +3 -0
new file mode 100644
index 000000000000..14ff08175231
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia_vgpu_vfio_pci.o
+nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o
drivers/vfio/pci/nvidia-vgpu/debug.h new file +17 -0
new file mode 100644
index 000000000000..19a2ecd8863e
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright © 2025 NVIDIA Corporation
+ */
+
+#ifndef __NVIDIA_VGPU_DEBUG_H__
+#define __NVIDIA_VGPU_DEBUG_H__
+
+#define vgpu_mgr_debug(v, f, a...) \
+	pci_dbg((v)->handle.pf_pdev, "nvidia-vgpu-mgr: "f, ##a)
+
+#define vgpu_debug(v, f, a...) ({ \
+	typeof(v) __v = (v); \
+	pci_dbg(__v->pdev, "nvidia-vgpu %d: "f, __v->info.id, ##a); \
+})
+
+#endif
drivers/vfio/pci/nvidia-vgpu/pf.h new file +65 -0

65 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu.c new file +101 -0

101 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c new file +193 -0

193 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#2 lore raw

RFC v2 2/14 vfio/nvidia-vgpu: allocate GSP RM client for NVIDIA vGPU manager

In reply to Zhi Wang

A GSP RM client is required when talking to the GSP firmware via GSP RM controls.

In order to create vGPUs, NVIDIA vGPU manager requires a GSP RM client to acquire necessary information from GSP, upload vGPU types to GSP...

Allocate a dedicated GSP RM client for NVIDIA vGPU manager.

---
 drivers/vfio/pci/nvidia-vgpu/pf.h       | 11 +++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c |  8 ++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h |  3 +++
 3 files changed, 22 insertions(+)
drivers/vfio/pci/nvidia-vgpu/pf.h +11 -0
index e8a11dd29427..044bc3aef5a6 100644
@@ -62,4 +62,15 @@ static inline int nvidia_vgpu_mgr_init_handle(struct pci_dev *pdev,
 	__m->handle.ops->get_total_fbmem_size(__m->handle.pf_drvdata); \
 })
 
+#define nvidia_vgpu_mgr_alloc_gsp_client(m, c) ({ \
+	typeof(m) __m = (m); \
+	__m->handle.ops->alloc_gsp_client(__m->handle.pf_drvdata, c); \
+})
+
+#define nvidia_vgpu_mgr_free_gsp_client(m, c) \
+	((m)->handle.ops->free_gsp_client(c))
+
+#define nvidia_vgpu_mgr_get_gsp_client_handle(m, c) \
+	((m)->handle.ops->get_gsp_client_handle(c))
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +8 -0
index 3ef81b89c748..1455ca51eca1 100644
@@ -16,6 +16,7 @@ static void vgpu_mgr_release(struct kref *kref)
 	if (WARN_ON(atomic_read(&vgpu_mgr->num_vgpus)))
 		return;
 
+	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu_mgr->gsp_client);
 	kvfree(vgpu_mgr);
 }
 
@@ -140,6 +141,11 @@ static int pf_attach_handle_fn(void *handle, struct nvidia_vgpu_vfio_handle_data
 	if (ret)
 		goto fail_setup_pf_driver_caps;
 
+	ret = nvidia_vgpu_mgr_alloc_gsp_client(vgpu_mgr,
+					       &vgpu_mgr->gsp_client);
+	if (ret)
+		goto fail_alloc_gsp_client;
+
 	ret = init_vgpu_mgr(vgpu_mgr);
 	if (ret)
 		goto fail_init_vgpu_mgr;
@@ -157,6 +163,8 @@ static int pf_attach_handle_fn(void *handle, struct nvidia_vgpu_vfio_handle_data
 fail_init_fn:
 	detach_vgpu_mgr(handle_data);
 fail_init_vgpu_mgr:
+	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu_mgr->gsp_client);
+fail_alloc_gsp_client:
 fail_setup_pf_driver_caps:
 	kvfree(vgpu_mgr);
 	return ret;
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +3 -0
index 9fe25b2d8ec1..98dcbb682b92 100644
@@ -51,6 +51,7 @@ struct nvidia_vgpu {
  * @vgpu_list_lock: lock to protect vGPU list
  * @vgpu_list_head: list head of vGPU list
  * @num_vgpus: number of vGPUs in the vGPU list
+ * @gsp_client: the GSP client
  */
 struct nvidia_vgpu_mgr {
 	struct kref refcount;
@@ -64,6 +65,8 @@ struct nvidia_vgpu_mgr {
 	struct mutex vgpu_list_lock;
 	struct list_head vgpu_list_head;
 	atomic_t num_vgpus;
+
+	struct nvidia_vgpu_gsp_client gsp_client;
 };
 
 #define nvidia_vgpu_mgr_for_each_vgpu(vgpu, vgpu_mgr) \
Signature · 1 line
2.34.1
author
#3 lore raw

RFC v2 3/14 vfio/nvidia-vgpu: introduce vGPU type uploading

In reply to Zhi Wang

Each type of vGPU is designed to meet specific requirements, from supporting multiple users with demanding graphics applications to powering AI workloads in virtualized environments.

To create a vGPU associated with a vGPU type, the vGPU type specs are required to be uploaded to GSP firmware.

Intorduce vGPU metadata uploading framework to check and upload vGPU types from the vGPU metadata file when vGPU is enabled.

---
 drivers/vfio/pci/nvidia-vgpu/Makefile         |   4 +-
 drivers/vfio/pci/nvidia-vgpu/debug.h          |   3 +
 .../vfio/pci/nvidia-vgpu/include/nvrm/gsp.h   |  18 +
 .../pci/nvidia-vgpu/include/nvrm/nvtypes.h    |  26 ++
 drivers/vfio/pci/nvidia-vgpu/metadata.c       | 319 ++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/metadata.h       |  89 +++++
 .../vfio/pci/nvidia-vgpu/metadata_vgpu_type.c | 153 +++++++++
 drivers/vfio/pci/nvidia-vgpu/pf.h             |  12 +
 drivers/vfio/pci/nvidia-vgpu/vgpu.c           |   5 +-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c       |   7 +
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h       |  27 ++
 11 files changed, 660 insertions(+), 3 deletions(-)
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/nvtypes.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/metadata.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/metadata.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/metadata_vgpu_type.c
drivers/vfio/pci/nvidia-vgpu/Makefile +3 -1
index 14ff08175231..94ba4ed4e131 100644
@@ -1,3 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
+subdir-ccflags-y += -I$(src)/include
+
 obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia_vgpu_vfio_pci.o
-nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o
+nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o metadata.o metadata_vgpu_type.o
drivers/vfio/pci/nvidia-vgpu/debug.h +3 -0
index 19a2ecd8863e..7cf92c9060ae 100644
@@ -9,6 +9,9 @@
 #define vgpu_mgr_debug(v, f, a...) \
 	pci_dbg((v)->handle.pf_pdev, "nvidia-vgpu-mgr: "f, ##a)
 
+#define vgpu_mgr_error(v, f, a...) \
+	pci_err((v)->handle.pf_pdev, "nvidia-vgpu-mgr: "f, ##a)
+
 #define vgpu_debug(v, f, a...) ({ \
 	typeof(v) __v = (v); \
 	pci_dbg(__v->pdev, "nvidia-vgpu %d: "f, __v->info.id, ##a); \
drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h new file +18 -0
new file mode 100644
index 000000000000..c3fb7b299533
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __NVRM_GSP_H__
+#define __NVRM_GSP_H__
+
+#include <nvrm/nvtypes.h>
+
+/* Excerpt of RM headers from https://github.com/NVIDIA/open-gpu-kernel-modules/tree/570 */
+
+#define NV2080_CTRL_CMD_GSP_GET_FEATURES (0x20803601)
+
+typedef struct NV2080_CTRL_GSP_GET_FEATURES_PARAMS {
+	NvU32  gspFeatures;
+	NvBool bValid;
+	NvBool bDefaultGspRmGpu;
+	NvU8   firmwareVersion[GSP_MAX_BUILD_VERSION_LENGTH];
+} NV2080_CTRL_GSP_GET_FEATURES_PARAMS;
+
+#endif
drivers/vfio/pci/nvidia-vgpu/include/nvrm/nvtypes.h new file +26 -0
new file mode 100644
index 000000000000..5445ba15500f
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __NVRM_NVTYPES_H__
+#define __NVRM_NVTYPES_H__
+
+#define NV_ALIGN_BYTES(a) __attribute__ ((__aligned__(a)))
+#define NV_DECLARE_ALIGNED(f, a) f __attribute__ ((__aligned__(a)))
+
+typedef u32 NvV32;
+
+typedef u8 NvU8;
+typedef u16 NvU16;
+typedef u32 NvU32;
+typedef u64 NvU64;
+
+typedef void* NvP64;
+
+typedef NvU8 NvBool;
+typedef NvU32 NvHandle;
+typedef NvU64 NvLength;
+
+typedef NvU64 RmPhysAddr;
+
+typedef NvU32 NV_STATUS;
+
+typedef union {} rpc_generic_union;
+#endif
drivers/vfio/pci/nvidia-vgpu/metadata.c new file +319 -0

319 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/metadata.h new file +89 -0

89 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/metadata_vgpu_type.c new file +153 -0

153 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/pf.h +12 -0
index 044bc3aef5a6..19f0aca56d12 100644
@@ -73,4 +73,16 @@ static inline int nvidia_vgpu_mgr_init_handle(struct pci_dev *pdev,
 #define nvidia_vgpu_mgr_get_gsp_client_handle(m, c) \
 	((m)->handle.ops->get_gsp_client_handle(c))
 
+#define nvidia_vgpu_mgr_rm_ctrl_get(m, g, c, s) \
+	((m)->handle.ops->rm_ctrl_get(g, c, s))
+
+#define nvidia_vgpu_mgr_rm_ctrl_wr(m, g, c) \
+	((m)->handle.ops->rm_ctrl_wr(g, c))
+
+#define nvidia_vgpu_mgr_rm_ctrl_rd(m, g, c, s) \
+	((m)->handle.ops->rm_ctrl_rd(g, c, s))
+
+#define nvidia_vgpu_mgr_rm_ctrl_done(m, g, c) \
+	((m)->handle.ops->rm_ctrl_done(g, c))
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vgpu.c +3 -2
index 79e6a9f16f74..cbb51b939f0b 100644
@@ -75,7 +75,7 @@ int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu)
 	struct nvidia_vgpu_info *info = &vgpu->info;
 	int ret;
 
-	if (WARN_ON(!info->gfid || !info->dbdf))
+	if (WARN_ON(!info->gfid || !info->dbdf || !info->vgpu_type))
 		return -EINVAL;
 
 	if (WARN_ON(!vgpu->vgpu_mgr || !vgpu->pdev))
@@ -86,7 +86,8 @@ int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu)
 
 	vgpu->info = *info;
 
-	vgpu_debug(vgpu, "create vgpu on vgpu_mgr %px\n", vgpu->vgpu_mgr);
+	vgpu_debug(vgpu, "create vgpu %s on vgpu_mgr %px\n",
+		   info->vgpu_type->vgpu_type_name, vgpu->vgpu_mgr);
 
 	ret = register_vgpu(vgpu);
 	if (ret)
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +7 -0
index 1455ca51eca1..a7f8a00f96bf 100644
@@ -16,6 +16,7 @@ static void vgpu_mgr_release(struct kref *kref)
 	if (WARN_ON(atomic_read(&vgpu_mgr->num_vgpus)))
 		return;
 
+	nvidia_vgpu_mgr_clean_metadata(vgpu_mgr);
 	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu_mgr->gsp_client);
 	kvfree(vgpu_mgr);
 }
@@ -150,6 +151,10 @@ static int pf_attach_handle_fn(void *handle, struct nvidia_vgpu_vfio_handle_data
 	if (ret)
 		goto fail_init_vgpu_mgr;
 
+	ret = nvidia_vgpu_mgr_setup_metadata(vgpu_mgr);
+	if (ret)
+		goto fail_setup_metadata;
+
 	attach_vgpu_mgr(vgpu_mgr, handle_data);
 
 	ret = attach_data->init_vfio_fn(vgpu_mgr, attach_data->init_vfio_fn_data);
@@ -162,6 +167,8 @@ static int pf_attach_handle_fn(void *handle, struct nvidia_vgpu_vfio_handle_data
 
 fail_init_fn:
 	detach_vgpu_mgr(handle_data);
+	nvidia_vgpu_mgr_clean_metadata(vgpu_mgr);
+fail_setup_metadata:
 fail_init_vgpu_mgr:
 	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu_mgr->gsp_client);
 fail_alloc_gsp_client:
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +27 -0
index 98dcbb682b92..0519b595378f 100644
@@ -7,6 +7,21 @@
 
 #include "pf.h"
 
+#define NVIDIA_VGPU_TYPE_NAME_MAX 32
+
+struct nvidia_vgpu_type {
+	u32 vgpu_type;
+	char vgpu_type_name[NVIDIA_VGPU_TYPE_NAME_MAX];
+	u64 vdev_id;
+	u64 pdev_id;
+	u64 fb_length;
+	u64 gsp_heap_size;
+	u64 bar1_length;
+	u32 max_instance;
+	u32 ecc_supported;
+	u64 fb_reservation;
+};
+
 /**
  * struct nvidia_vgpu_info - vGPU information
  *
@@ -18,6 +33,7 @@ struct nvidia_vgpu_info {
 	int id;
 	u32 gfid;
 	u32 dbdf;
+	struct nvidia_vgpu_type *vgpu_type;
 };
 
 /**
@@ -48,10 +64,14 @@ struct nvidia_vgpu {
  * @handle: the driver handle
  * @total_avail_chids: total available channel IDs
  * @total_fbmem_size: total FB memory size
+ * @vgpu_major: vGPU major version
+ * @vgpu_minor: vGPU minor version
  * @vgpu_list_lock: lock to protect vGPU list
  * @vgpu_list_head: list head of vGPU list
  * @num_vgpus: number of vGPUs in the vGPU list
  * @gsp_client: the GSP client
+ * @vgpu_types: installed vGPU types
+ * @num_vgpu_types: number of installed vGPU types
  */
 struct nvidia_vgpu_mgr {
 	struct kref refcount;
@@ -61,12 +81,17 @@ struct nvidia_vgpu_mgr {
 	u32 total_avail_chids;
 	u64 total_fbmem_size;
 
+	u64 vgpu_major;
+	u64 vgpu_minor;
+
 	/* lock for vGPU list */
 	struct mutex vgpu_list_lock;
 	struct list_head vgpu_list_head;
 	atomic_t num_vgpus;
 
 	struct nvidia_vgpu_gsp_client gsp_client;
+	struct nvidia_vgpu_type *vgpu_types;
+	unsigned int num_vgpu_types;
 };
 
 #define nvidia_vgpu_mgr_for_each_vgpu(vgpu, vgpu_mgr) \
@@ -78,5 +103,7 @@ void nvidia_vgpu_mgr_release(struct nvidia_vgpu_mgr *vgpu_mgr);
 
 int nvidia_vgpu_mgr_destroy_vgpu(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu);
+int nvidia_vgpu_mgr_setup_metadata(struct nvidia_vgpu_mgr *vgpu_mgr);
+void nvidia_vgpu_mgr_clean_metadata(struct nvidia_vgpu_mgr *vgpu_mgr);
 
 #endif
Signature · 1 line
2.34.1
#4 lore raw

Re: [RFC v2 03/14] vfio/nvidia-vgpu: introduce vGPU type uploading

Quoted 24 lines · Zhi Wang
drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h new file +18 -0
new file mode 100644
index 000000000000..c3fb7b299533
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __NVRM_GSP_H__
+#define __NVRM_GSP_H__
+
+#include <nvrm/nvtypes.h>
+
+/* Excerpt of RM headers from https://github.com/NVIDIA/open-gpu-kernel-modules/tree/570 */
+
+#define NV2080_CTRL_CMD_GSP_GET_FEATURES (0x20803601)
+
+typedef struct NV2080_CTRL_GSP_GET_FEATURES_PARAMS {
+	NvU32  gspFeatures;
+	NvBool bValid;
+	NvBool bDefaultGspRmGpu;
+	NvU8   firmwareVersion[GSP_MAX_BUILD_VERSION_LENGTH];
+} NV2080_CTRL_GSP_GET_FEATURES_PARAMS;
+
+#endif

<snip>

drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h

Quoted 3 lines
drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h new file +3 -0
+static struct version supported_version_list[] = {
+	{ 18, 1, "570.144" },
+};

nova-core won't provide any firmware specific APIs, it is meant to serve as a hardware and firmware abstraction layer for higher level drivers, such as vGPU or nova-drm.

As a general rule the interface between nova-core and higher level drivers must not leak any hardware or firmware specific details, but work on a higher level abstraction layer.

Now, I recognize that at some point it might be necessary to do some kind of versioning in this API anyways. For instance, when the semantics of the firmware API changes too significantly.

However, this would be a separte API where nova-core, at the initial handshake, then asks clients to use e.g. v2 of the nova-core API, still hiding any firmware and hardware details from the client.

Some more general notes, since I also had a look at the nova-core <-> vGPU interface patches in your tree (even though I'm aware that they're not part of the RFC of course):

The interface for the general lifecycle management for any clients attaching to nova-core (VGPU, nova-drm) should be common and not specific to vGPU. (The same goes for interfaces that will be used by vGPU and nova-drm.)

The interface nova-core provides for that should be designed in Rust, so we can take advantage of all the features the type system provides us with connecting to Rust clients (nova-drm).

For vGPU, we can then monomorphize those types into the corresponding C structures and provide the corresponding functions very easily.

Doing it the other way around would be a very bad idea, since the Rust type system is much more powerful and hence it'd be very hard to avoid introducing limitations on the Rust side of things.

Hence, I recommend to start with some patches defining the API in nova-core for the general lifecycle (in Rust), so we can take it from there.

Another note: I don't see any use of the auxiliary bus in vGPU, any clients should attach via the auxiliary bus API, it provides proper matching where there's more than on compatible GPU in the system. nova-core already registers an auxiliary device for each bound PCI device.

Please don't re-implement what the auxiliary bus already does for us.

- Danilo

#5 lore raw

Re: [RFC v2 03/14] vfio/nvidia-vgpu: introduce vGPU type uploading

(Cc: Alex, John, Joel, Alistair, nouveau)

Quoted 78 lines · Danilo Krummrich
Quoted 24 lines · Zhi Wang
drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h new file +18 -0
new file mode 100644
index 000000000000..c3fb7b299533
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __NVRM_GSP_H__
+#define __NVRM_GSP_H__
+
+#include <nvrm/nvtypes.h>
+
+/* Excerpt of RM headers from https://github.com/NVIDIA/open-gpu-kernel-modules/tree/570 */
+
+#define NV2080_CTRL_CMD_GSP_GET_FEATURES (0x20803601)
+
+typedef struct NV2080_CTRL_GSP_GET_FEATURES_PARAMS {
+	NvU32  gspFeatures;
+	NvBool bValid;
+	NvBool bDefaultGspRmGpu;
+	NvU8   firmwareVersion[GSP_MAX_BUILD_VERSION_LENGTH];
+} NV2080_CTRL_GSP_GET_FEATURES_PARAMS;
+
+#endif

<snip>

drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h

Quoted 3 lines
drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h new file +3 -0
+static struct version supported_version_list[] = {
+	{ 18, 1, "570.144" },
+};

nova-core won't provide any firmware specific APIs, it is meant to serve as a hardware and firmware abstraction layer for higher level drivers, such as vGPU or nova-drm.

As a general rule the interface between nova-core and higher level drivers must not leak any hardware or firmware specific details, but work on a higher level abstraction layer.

Now, I recognize that at some point it might be necessary to do some kind of versioning in this API anyways. For instance, when the semantics of the firmware API changes too significantly.

However, this would be a separte API where nova-core, at the initial handshake, then asks clients to use e.g. v2 of the nova-core API, still hiding any firmware and hardware details from the client.

Some more general notes, since I also had a look at the nova-core <-> vGPU interface patches in your tree (even though I'm aware that they're not part of the RFC of course):

The interface for the general lifecycle management for any clients attaching to nova-core (VGPU, nova-drm) should be common and not specific to vGPU. (The same goes for interfaces that will be used by vGPU and nova-drm.)

The interface nova-core provides for that should be designed in Rust, so we can take advantage of all the features the type system provides us with connecting to Rust clients (nova-drm).

For vGPU, we can then monomorphize those types into the corresponding C structures and provide the corresponding functions very easily.

Doing it the other way around would be a very bad idea, since the Rust type system is much more powerful and hence it'd be very hard to avoid introducing limitations on the Rust side of things.

Hence, I recommend to start with some patches defining the API in nova-core for the general lifecycle (in Rust), so we can take it from there.

Another note: I don't see any use of the auxiliary bus in vGPU, any clients should attach via the auxiliary bus API, it provides proper matching where there's more than on compatible GPU in the system. nova-core already registers an auxiliary device for each bound PCI device.

Please don't re-implement what the auxiliary bus already does for us.

- Danilo

#6 lore raw

Re: [RFC v2 03/14] vfio/nvidia-vgpu: introduce vGPU type uploading

Quoted 4 lines · Danilo Krummrich
Quoted 4 lines

Another note: I don't see any use of the auxiliary bus in vGPU, any clients should attach via the auxiliary bus API, it provides proper matching where there's more than on compatible GPU in the system. nova-core already registers an auxiliary device for each bound PCI device.

The driver here attaches to the SRIOV VF pci_device, it should obtain the nova-core handle of the PF device through pci_iov_get_pf_drvdata().

This is the expected design of VFIO drivers because the driver core does not support a single driver binding to two devices (aux and VF) today.

Jason

#7 lore raw

Re: [RFC v2 03/14] vfio/nvidia-vgpu: introduce vGPU type uploading

Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Danilo Krummrich
Quoted 4 lines

Another note: I don't see any use of the auxiliary bus in vGPU, any clients should attach via the auxiliary bus API, it provides proper matching where there's more than on compatible GPU in the system. nova-core already registers an auxiliary device for each bound PCI device.

Quoted 6 lines

The driver here attaches to the SRIOV VF pci_device, it should obtain the nova-core handle of the PF device through pci_iov_get_pf_drvdata().

This is the expected design of VFIO drivers because the driver core does not support a single driver binding to two devices (aux and VF) today.

Yeah, that's for the VF PCI devices, but I thought vGPU will also have some kind of "control instance" for each physical device through which it can control the creation of VFs?

#8 lore raw

Re: [RFC v2 03/14] vfio/nvidia-vgpu: introduce vGPU type uploading

Quoted 11 lines · Danilo Krummrich
Quoted 10 lines · Jason Gunthorpe
Quoted 4 lines · Danilo Krummrich
Quoted 4 lines

Another note: I don't see any use of the auxiliary bus in vGPU, any clients should attach via the auxiliary bus API, it provides proper matching where there's more than on compatible GPU in the system. nova-core already registers an auxiliary device for each bound PCI device.

The driver here attaches to the SRIOV VF pci_device, it should obtain the nova-core handle of the PF device through pci_iov_get_pf_drvdata().

Quoted 7 lines
Quoted 3 lines

This is the expected design of VFIO drivers because the driver core does not support a single driver binding to two devices (aux and VF) today.

Yeah, that's for the VF PCI devices, but I thought vGPU will also have some kind of "control instance" for each physical device through which it can control the creation of VFs?

I recall there is something on the PF that is independent of the VFs, but it is hard to stick that in an aux device, it will make the the lifetime model very difficult since aux devices can become unbound at any time while the vf is using it. It is alot easier to be part of the PF driver somehow..

Then userspace activities like provisioning VFs I hope we will see that done through fwctl as the networking drivers are doing. I see this series is using request_firmware() to get VF profiles and some sysfs, which seems inconsisent with any other VF provisioning scheme in the kernel.

Jason

author
#9 lore raw

Re: [RFC v2 03/14] vfio/nvidia-vgpu: introduce vGPU type uploading

In reply to Danilo Krummrich
Quoted 31 lines · On Thu, 04 Sep 2025 11:41:03 +0200 "Danilo Krummrich" <[email protected]> wrote:

(Cc: Alex, John, Joel, Alistair, nouveau)

Quoted 28 lines · Danilo Krummrich
Quoted 24 lines · Zhi Wang
drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h new file +18 -0
new file mode 100644
index 000000000000..c3fb7b299533
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __NVRM_GSP_H__
+#define __NVRM_GSP_H__
+
+#include <nvrm/nvtypes.h>
+
+/* Excerpt of RM headers from https://github.com/NVIDIA/open-gpu-kernel-modules/tree/570 */
+
+#define NV2080_CTRL_CMD_GSP_GET_FEATURES (0x20803601)
+
+typedef struct NV2080_CTRL_GSP_GET_FEATURES_PARAMS {
+	NvU32  gspFeatures;
+	NvBool bValid;
+	NvBool bDefaultGspRmGpu;
+	NvU8   firmwareVersion[GSP_MAX_BUILD_VERSION_LENGTH];
+} NV2080_CTRL_GSP_GET_FEATURES_PARAMS;
+
+#endif

<snip>

The RFC v2 is based on the same architecture of RFC V1 but switching the core driver from NVKM to nova-core. Yet the new architecture and auxiliary bus is WIP. So it doesn't represent the final picture, e.g. the rust code I wrote in the nova-core. The main idea is to demonstrate the progress of the vGPU development.

Quoted 8 lines
Quoted 8 lines

drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h

Quoted 3 lines
drivers/vfio/pci/nvidia-vgpu/include/nvrm/gsp.h new file +3 -0
+static struct version supported_version_list[] = {
+	{ 18, 1, "570.144" },
+};

nova-core won't provide any firmware specific APIs, it is meant to serve as a hardware and firmware abstraction layer for higher level drivers, such as vGPU or nova-drm.

Quoted 4 lines
Quoted 4 lines

As a general rule the interface between nova-core and higher level drivers must not leak any hardware or firmware specific details, but work on a higher level abstraction layer.

It is more a matter of where we are going to place vGPU specific functionality in the whole picture. In this case, if we are thinking about the requirement of vGPU type loading, which requires the GSP version number and checking. Are we leaning towards putting some vGPU specific functionality also in nova-core?

Regarding not leaking any of the hardware details, is that doable? Looking at {nv04 * _fence}.c {chan*}.c in the current NVIF interfaces, I think we will expose the HW concept somehow.

Quoted 40 lines
Quoted 38 lines

Now, I recognize that at some point it might be necessary to do some kind of versioning in this API anyways. For instance, when the semantics of the firmware API changes too significantly.

However, this would be a separte API where nova-core, at the initial handshake, then asks clients to use e.g. v2 of the nova-core API, still hiding any firmware and hardware details from the client.

Some more general notes, since I also had a look at the nova-core <-> vGPU interface patches in your tree (even though I'm aware that they're not part of the RFC of course):

The interface for the general lifecycle management for any clients attaching to nova-core (VGPU, nova-drm) should be common and not specific to vGPU. (The same goes for interfaces that will be used by vGPU and nova-drm.)

The interface nova-core provides for that should be designed in Rust, so we can take advantage of all the features the type system provides us with connecting to Rust clients (nova-drm).

For vGPU, we can then monomorphize those types into the corresponding C structures and provide the corresponding functions very easily.

Doing it the other way around would be a very bad idea, since the Rust type system is much more powerful and hence it'd be very hard to avoid introducing limitations on the Rust side of things.

Hence, I recommend to start with some patches defining the API in nova-core for the general lifecycle (in Rust), so we can take it from there.

Another note: I don't see any use of the auxiliary bus in vGPU, any clients should attach via the auxiliary bus API, it provides proper matching where there's more than on compatible GPU in the system. nova-core already registers an auxiliary device for each bound PCI device.

Please don't re-implement what the auxiliary bus already does for us.

- Danilo

#10 lore raw

Re: [RFC v2 03/14] vfio/nvidia-vgpu: introduce vGPU type uploading

Quoted 15 lines · Zhi Wang
Quoted 11 lines · On Thu, 04 Sep 2025 11:41:03 +0200 "Danilo Krummrich" <[email protected]> wrote:

(Cc: Alex, John, Joel, Alistair, nouveau)

Quoted 8 lines · Danilo Krummrich

nova-core won't provide any firmware specific APIs, it is meant to serve as a hardware and firmware abstraction layer for higher level drivers, such as vGPU or nova-drm.

As a general rule the interface between nova-core and higher level drivers must not leak any hardware or firmware specific details, but work on a higher level abstraction layer.

Quoted 5 lines

It is more a matter of where we are going to place vGPU specific functionality in the whole picture. In this case, if we are thinking about the requirement of vGPU type loading, which requires the GSP version number and checking. Are we leaning towards putting some vGPU specific functionality also in nova-core?

As much as needed to abstract firmware (and hardware) API details.

Quoted 3 lines

Regarding not leaking any of the hardware details, is that doable? Looking at {nv04 * _fence}.c {chan*}.c in the current NVIF interfaces, I think we will expose the HW concept somehow.

I don't really mean that vGPU must be entirely unaware of the hardware, it's still a driver of course. But for the API between nova-core and client drivers we want to abstract how the firmware and hardware is programmed, i.e. not leak any (version specific) RM structures or provide APIs that consume raw register values to write, etc.

author
#11 lore raw

RFC v2 4/14 vfio/nvidia-vgpu: allocate vGPU channels when creating vGPUs

In reply to Zhi Wang

Creating a vGPU requires allocating a portion of the channels from the reserved channel pool.

Allocate the channels from the reserved channel pool when creating a vGPU.

Cc Aniket Agashe <[email protected]>
---
 drivers/vfio/pci/nvidia-vgpu/pf.h       | 10 ++++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c     | 76 +++++++++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c | 33 ++++++++++-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h | 21 +++++++
 4 files changed, 138 insertions(+), 2 deletions(-)
drivers/vfio/pci/nvidia-vgpu/pf.h +10 -0
index 19f0aca56d12..b8008d8ee434 100644
@@ -85,4 +85,14 @@ static inline int nvidia_vgpu_mgr_init_handle(struct pci_dev *pdev,
 #define nvidia_vgpu_mgr_rm_ctrl_done(m, g, c) \
 	((m)->handle.ops->rm_ctrl_done(g, c))
 
+#define nvidia_vgpu_mgr_alloc_chids(m, o, s) ({ \
+	typeof(m) __m = (m); \
+	__m->handle.ops->alloc_chids(__m->handle.pf_drvdata, o, s); \
+})
+
+#define nvidia_vgpu_mgr_free_chids(m, o, s) ({ \
+	typeof(m) __m = (m); \
+	__m->handle.ops->free_chids(__m->handle.pf_drvdata, o, s); \
+})
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vgpu.c +76 -0

104 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +31 -2
index a7f8a00f96bf..8565bb881fda 100644
@@ -6,6 +6,14 @@
 #include "debug.h"
 #include "vgpu_mgr.h"
 
+static void clean_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
+{
+	if (vgpu_mgr->use_chid_alloc_bitmap) {
+		bitmap_free(vgpu_mgr->chid_alloc_bitmap);
+		vgpu_mgr->chid_alloc_bitmap = NULL;
+	}
+}
+
 static void vgpu_mgr_release(struct kref *kref)
 {
 	struct nvidia_vgpu_mgr *vgpu_mgr =
@@ -17,6 +25,7 @@ static void vgpu_mgr_release(struct kref *kref)
 		return;
 
 	nvidia_vgpu_mgr_clean_metadata(vgpu_mgr);
+	clean_vgpu_mgr(vgpu_mgr);
 	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu_mgr->gsp_client);
 	kvfree(vgpu_mgr);
 }
@@ -95,6 +104,20 @@ static void attach_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr,
 	handle_data->vfio.pf_detach_handle_fn = pf_detach_handle_fn;
 }
 
+static int setup_chid_alloc_bitmap(struct nvidia_vgpu_mgr *vgpu_mgr)
+{
+	if (WARN_ON(!vgpu_mgr->use_chid_alloc_bitmap))
+		return 0;
+
+	vgpu_mgr->chid_alloc_bitmap = bitmap_alloc(vgpu_mgr->total_avail_chids, GFP_KERNEL);
+	if (!vgpu_mgr->chid_alloc_bitmap)
+		return -ENOMEM;
+	bitmap_zero(vgpu_mgr->chid_alloc_bitmap, vgpu_mgr->total_avail_chids);
+
+	vgpu_mgr_debug(vgpu_mgr, "using chid allocation bitmap.\n");
+	return 0;
+}
+
 static int init_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 {
 	vgpu_mgr->total_avail_chids = nvidia_vgpu_mgr_get_avail_chids(vgpu_mgr);
@@ -103,12 +126,17 @@ static int init_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 	vgpu_mgr_debug(vgpu_mgr, "total avail chids %u\n", vgpu_mgr->total_avail_chids);
 	vgpu_mgr_debug(vgpu_mgr, "total fbmem size 0x%llx\n", vgpu_mgr->total_fbmem_size);
 
-	return 0;
+	return vgpu_mgr->use_chid_alloc_bitmap ? setup_chid_alloc_bitmap(vgpu_mgr) : 0;
 }
 
 static int setup_pf_driver_caps(struct nvidia_vgpu_mgr *vgpu_mgr, unsigned long *caps)
 {
-	/* more to come */
+#define HAS_CAP(cap) \
+	test_bit(NVIDIA_VGPU_PF_DRIVER_CAP_HAS_##cap, caps)
+
+	vgpu_mgr->use_chid_alloc_bitmap = !HAS_CAP(CHID_ALLOC);
+
+#undef HAS_CAP
 	return 0;
 }
 
@@ -169,6 +197,7 @@ static int pf_attach_handle_fn(void *handle, struct nvidia_vgpu_vfio_handle_data
 	detach_vgpu_mgr(handle_data);
 	nvidia_vgpu_mgr_clean_metadata(vgpu_mgr);
 fail_setup_metadata:
+	clean_vgpu_mgr(vgpu_mgr);
 fail_init_vgpu_mgr:
 	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu_mgr->gsp_client);
 fail_alloc_gsp_client:
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +21 -0
index 0519b595378f..5a7a6103a677 100644
@@ -36,6 +36,19 @@ struct nvidia_vgpu_info {
 	struct nvidia_vgpu_type *vgpu_type;
 };
 
+/**
+ * struct nvidia_vgpu_chid - per-vGPU channel IDs
+ *
+ * @chid_offset: beginning offset of channel IDs
+ * @num_chid: number of allocated channel IDs
+ * @num_plugin_channels: number of channels for vGPU manager
+ */
+struct nvidia_vgpu_chid {
+	u32 chid_offset;
+	u32 num_chid;
+	u32 num_plugin_channels;
+};
+
 /**
  * struct nvidia_vgpu - per-vGPU state
  *
@@ -45,6 +58,7 @@ struct nvidia_vgpu_info {
  * @vgpu_list: list node to the vGPU list
  * @info: vGPU info
  * @vgpu_mgr: pointer to vGPU manager
+ * @chid: vGPU channel IDs
  */
 struct nvidia_vgpu {
 	/* Per-vGPU lock */
@@ -55,6 +69,8 @@ struct nvidia_vgpu {
 
 	struct nvidia_vgpu_info info;
 	struct nvidia_vgpu_mgr *vgpu_mgr;
+
+	struct nvidia_vgpu_chid chid;
 };
 
 /**
@@ -72,6 +88,8 @@ struct nvidia_vgpu {
  * @gsp_client: the GSP client
  * @vgpu_types: installed vGPU types
  * @num_vgpu_types: number of installed vGPU types
+ * @use_alloc_bitmap: use chid allocator for the PF driver doesn't support chid allocation
+ * @chid_alloc_bitmap: chid allocator bitmap
  */
 struct nvidia_vgpu_mgr {
 	struct kref refcount;
@@ -92,6 +110,9 @@ struct nvidia_vgpu_mgr {
 	struct nvidia_vgpu_gsp_client gsp_client;
 	struct nvidia_vgpu_type *vgpu_types;
 	unsigned int num_vgpu_types;
+
+	bool use_chid_alloc_bitmap;
+	void *chid_alloc_bitmap;
 };
 
 #define nvidia_vgpu_mgr_for_each_vgpu(vgpu, vgpu_mgr) \
Signature · 1 line
2.34.1
author
#12 lore raw

RFC v2 5/14 vfio/nvidia-vgpu: allocate vGPU FB memory when creating vGPUs

In reply to Zhi Wang

Creating a vGPU requires allocating a portion of the FB memory from the NVKM. The size of the FB memory that a vGPU requires is from the vGPU type.

Acquire the size of the required FB memory from the vGPU type. Allocate the FB memory from NVKM when creating a vGPU.

---
 drivers/vfio/pci/nvidia-vgpu/debug.h          |  5 ++
 .../vfio/pci/nvidia-vgpu/include/nvrm/ecc.h   | 45 ++++++++++++
 .../vfio/pci/nvidia-vgpu/include/nvrm/vmmu.h  | 39 +++++++++++
 drivers/vfio/pci/nvidia-vgpu/pf.h             |  8 +++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c           | 70 +++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c       | 56 ++++++++++++++-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h       |  8 +++
 7 files changed, 229 insertions(+), 2 deletions(-)
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/ecc.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/vmmu.h
drivers/vfio/pci/nvidia-vgpu/debug.h +5 -0
index 7cf92c9060ae..db9288752384 100644
@@ -17,4 +17,9 @@
 	pci_dbg(__v->pdev, "nvidia-vgpu %d: "f, __v->info.id, ##a); \
 })
 
+#define vgpu_error(v, f, a...) ({ \
+	typeof(v) __v = (v); \
+	pci_err(__v->pdev, "nvidia-vgpu %d: "f, __v->info.id, ##a); \
+})
+
 #endif
drivers/vfio/pci/nvidia-vgpu/include/nvrm/ecc.h new file +45 -0

45 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/include/nvrm/vmmu.h new file +39 -0
new file mode 100644
index 000000000000..fb1f100deac4
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: MIT */
+
+/* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. */
+
+#ifndef __NVRM_VMMU_H__
+#define __NVRM_VMMU_H__
+
+#include <nvrm/nvtypes.h>
+
+/* Excerpt of RM headers from https://github.com/NVIDIA/open-gpu-kernel-modules/tree/570.124.04 */
+
+/*
+ * NV2080_CTRL_CMD_GPU_GET_VMMU_SEGMENT_SIZE
+ *
+ * This command returns the VMMU page size
+ *
+ *   vmmuSegmentSize
+ *     Output parameter.
+ *     Returns the VMMU segment size (in bytes)
+ *
+ * Possible status values returned are:
+ *   NV_OK
+ *   NV_ERR_NOT_SUPPORTED
+ */
+#define NV2080_CTRL_CMD_GPU_GET_VMMU_SEGMENT_SIZE  (0x2080017eU) /* finn: Evaluated from "(FINN_NV20_SUBDEVICE_0_GPU_INTERFACE_ID << 8) | NV2080_CTRL_GPU_GET_VMMU_SEGMENT_SIZE_PARAMS_MESSAGE_ID" */
+
+#define NV2080_CTRL_GPU_GET_VMMU_SEGMENT_SIZE_PARAMS_MESSAGE_ID (0x7EU)
+
+typedef struct NV2080_CTRL_GPU_GET_VMMU_SEGMENT_SIZE_PARAMS {
+	NV_DECLARE_ALIGNED(NvU64 vmmuSegmentSize, 8);
+} NV2080_CTRL_GPU_GET_VMMU_SEGMENT_SIZE_PARAMS;
+
+#define NV2080_CTRL_GPU_VMMU_SEGMENT_SIZE_32MB     0x02000000U
+#define NV2080_CTRL_GPU_VMMU_SEGMENT_SIZE_64MB     0x04000000U
+#define NV2080_CTRL_GPU_VMMU_SEGMENT_SIZE_128MB    0x08000000U
+#define NV2080_CTRL_GPU_VMMU_SEGMENT_SIZE_256MB    0x10000000U
+#define NV2080_CTRL_GPU_VMMU_SEGMENT_SIZE_512MB    0x20000000U
+
+#endif
drivers/vfio/pci/nvidia-vgpu/pf.h +8 -0
index b8008d8ee434..ce2728ce969b 100644
@@ -95,4 +95,12 @@ static inline int nvidia_vgpu_mgr_init_handle(struct pci_dev *pdev,
 	__m->handle.ops->free_chids(__m->handle.pf_drvdata, o, s); \
 })
 
+#define nvidia_vgpu_mgr_alloc_fbmem(m, info) ({\
+	typeof(m) __m = (m); \
+	__m->handle.ops->alloc_fbmem(__m->handle.pf_drvdata, info); \
+})
+
+#define nvidia_vgpu_mgr_free_fbmem(m, h) \
+	((m)->handle.ops->free_fbmem(h))
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vgpu.c +70 -0

95 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +54 -2

77 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +8 -0
index 5a7a6103a677..356779404cc2 100644
@@ -59,6 +59,7 @@ struct nvidia_vgpu_chid {
  * @info: vGPU info
  * @vgpu_mgr: pointer to vGPU manager
  * @chid: vGPU channel IDs
+ * @fbmem_heap: allocated FB memory for the vGPU
  */
 struct nvidia_vgpu {
 	/* Per-vGPU lock */
@@ -71,6 +72,7 @@ struct nvidia_vgpu {
 	struct nvidia_vgpu_mgr *vgpu_mgr;
 
 	struct nvidia_vgpu_chid chid;
+	struct nvidia_vgpu_mem *fbmem_heap;
 };
 
 /**
@@ -80,6 +82,8 @@ struct nvidia_vgpu {
  * @handle: the driver handle
  * @total_avail_chids: total available channel IDs
  * @total_fbmem_size: total FB memory size
+ * @vmmu_segment_size: VMMU segment size
+ * @ecc_enabled: ECC is enabled in the GPU
  * @vgpu_major: vGPU major version
  * @vgpu_minor: vGPU minor version
  * @vgpu_list_lock: lock to protect vGPU list
@@ -99,6 +103,10 @@ struct nvidia_vgpu_mgr {
 	u32 total_avail_chids;
 	u64 total_fbmem_size;
 
+	/* GSP RM configurations */
+	u64 vmmu_segment_size;
+	bool ecc_enabled;
+
 	u64 vgpu_major;
 	u64 vgpu_minor;
 
Signature · 1 line
2.34.1
author
#13 lore raw

RFC v2 6/14 vfio/nvidia-vgpu: allocate mgmt heap when creating vGPUs

In reply to Zhi Wang

The mgmt heap is a block of shared FBMEM between the GSP firmware and the vGPU host. It is used for supporting vGPU RPCs, vGPU logging.

Creating a vGPU requires allocating a mgmt heap from the FBMEM. The size of the mgmt heap that a vGPU requires is from the vGPU type.

Acquire the size of mgmt heap from the vGPU type. Allocate the mgmt heap from nvkm when creating a vGPU.

---
 drivers/vfio/pci/nvidia-vgpu/vgpu.c     | 42 +++++++++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h |  7 +++++
 2 files changed, 49 insertions(+)
drivers/vfio/pci/nvidia-vgpu/vgpu.c +42 -0
index 7025c7e2b9ac..53c2da0645b3 100644
@@ -172,6 +172,41 @@ static int setup_fbmem_heap(struct nvidia_vgpu *vgpu)
 	return 0;
 }
 
+static void clean_mgmt_heap(struct nvidia_vgpu *vgpu)
+{
+	struct nvidia_vgpu_mgr *vgpu_mgr = vgpu->vgpu_mgr;
+	struct nvidia_vgpu_mgmt *mgmt = &vgpu->mgmt;
+
+	vgpu_debug(vgpu, "free mgmt heap, offset 0x%llx size 0x%llx\n", mgmt->heap_mem->addr,
+		   mgmt->heap_mem->size);
+
+	nvidia_vgpu_mgr_free_fbmem(vgpu_mgr, mgmt->heap_mem);
+	mgmt->heap_mem = NULL;
+}
+
+static int setup_mgmt_heap(struct nvidia_vgpu *vgpu)
+{
+	struct nvidia_vgpu_mgr *vgpu_mgr = vgpu->vgpu_mgr;
+	struct nvidia_vgpu_mgmt *mgmt = &vgpu->mgmt;
+	struct nvidia_vgpu_info *info = &vgpu->info;
+	struct nvidia_vgpu_type *vgpu_type = info->vgpu_type;
+	struct nvidia_vgpu_alloc_fbmem_info alloc_info = {0};
+	struct nvidia_vgpu_mem *mem;
+
+	alloc_info.size = vgpu_type->gsp_heap_size;
+
+	vgpu_debug(vgpu, "alloc mgmt heap, size 0x%llx\n", alloc_info.size);
+
+	mem = nvidia_vgpu_mgr_alloc_fbmem(vgpu_mgr, &alloc_info);
+	if (IS_ERR(mem))
+		return PTR_ERR(mem);
+
+	vgpu_debug(vgpu, "mgmt heap offset 0x%llx size 0x%llx\n", mem->addr, mem->size);
+
+	mgmt->heap_mem = mem;
+	return 0;
+}
+
 /**
  * nvidia_vgpu_mgr_destroy_vgpu - destroy a vGPU instance
  * @vgpu: the vGPU instance going to be destroyed.
@@ -183,6 +218,7 @@ int nvidia_vgpu_mgr_destroy_vgpu(struct nvidia_vgpu *vgpu)
 	if (!atomic_cmpxchg(&vgpu->status, 1, 0))
 		return -ENODEV;
 
+	clean_mgmt_heap(vgpu);
 	clean_fbmem_heap(vgpu);
 	clean_chids(vgpu);
 	unregister_vgpu(vgpu);
@@ -232,12 +268,18 @@ int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu)
 	if (ret)
 		goto err_setup_fbmem_heap;
 
+	ret = setup_mgmt_heap(vgpu);
+	if (ret)
+		goto err_setup_mgmt_heap;
+
 	atomic_set(&vgpu->status, 1);
 
 	vgpu_debug(vgpu, "created\n");
 
 	return 0;
 
+err_setup_mgmt_heap:
+	clean_fbmem_heap(vgpu);
 err_setup_fbmem_heap:
 	clean_chids(vgpu);
 err_setup_chids:
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +7 -0
index 356779404cc2..facecd060856 100644
@@ -49,6 +49,11 @@ struct nvidia_vgpu_chid {
 	u32 num_plugin_channels;
 };
 
+struct nvidia_vgpu_mgmt {
+	struct nvidia_vgpu_mem *heap_mem;
+	/* more to come */
+};
+
 /**
  * struct nvidia_vgpu - per-vGPU state
  *
@@ -60,6 +65,7 @@ struct nvidia_vgpu_chid {
  * @vgpu_mgr: pointer to vGPU manager
  * @chid: vGPU channel IDs
  * @fbmem_heap: allocated FB memory for the vGPU
+ * @mgmt: vGPU mgmt heap
  */
 struct nvidia_vgpu {
 	/* Per-vGPU lock */
@@ -73,6 +79,7 @@ struct nvidia_vgpu {
 
 	struct nvidia_vgpu_chid chid;
 	struct nvidia_vgpu_mem *fbmem_heap;
+	struct nvidia_vgpu_mgmt mgmt;
 };
 
 /**
Signature · 1 line
2.34.1
author
#14 lore raw

RFC v2 7/14 vfio/nvidia-vgpu: map mgmt heap when creating a vGPU

In reply to Zhi Wang

The mgmt heap is a block of shared FB memory between the GSP firmware and the vGPU host. It is used for supporting vGPU RPCs, vGPU logging.

To access the data structures of vGPU RPCs and vGPU logging, the mgmt heap FB memory needs to mapped into BAR1 and the region in the BAR1 is required to be mapped into CPU vaddr.

Map the mgmt heap FB memory into BAR1 and map the related BAR1 region into CPU vaddr. Initialize the pointers to the mgmt heap FB memory.

---
 drivers/vfio/pci/nvidia-vgpu/pf.h       |  6 ++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c     | 23 ++++++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c | 26 +++++++++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h | 17 +++++++++++++++-
 4 files changed, 71 insertions(+), 1 deletion(-)
drivers/vfio/pci/nvidia-vgpu/pf.h +6 -0
index ce2728ce969b..167296ba7e3d 100644
@@ -103,4 +103,10 @@ static inline int nvidia_vgpu_mgr_init_handle(struct pci_dev *pdev,
 #define nvidia_vgpu_mgr_free_fbmem(m, h) \
 	((m)->handle.ops->free_fbmem(h))
 
+#define nvidia_vgpu_mgr_bar1_map_mem(m, mem, info) \
+	((m)->handle.ops->bar1_map_mem(mem, info))
+
+#define nvidia_vgpu_mgr_bar1_unmap_mem(m, mem) \
+	((m)->handle.ops->bar1_unmap_mem(mem))
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vgpu.c +23 -0
index 53c2da0645b3..4c106a9803f6 100644
@@ -177,10 +177,14 @@ static void clean_mgmt_heap(struct nvidia_vgpu *vgpu)
 	struct nvidia_vgpu_mgr *vgpu_mgr = vgpu->vgpu_mgr;
 	struct nvidia_vgpu_mgmt *mgmt = &vgpu->mgmt;
 
+	nvidia_vgpu_mgr_bar1_unmap_mem(vgpu_mgr, mgmt->heap_mem);
+
 	vgpu_debug(vgpu, "free mgmt heap, offset 0x%llx size 0x%llx\n", mgmt->heap_mem->addr,
 		   mgmt->heap_mem->size);
 
 	nvidia_vgpu_mgr_free_fbmem(vgpu_mgr, mgmt->heap_mem);
+	mgmt->init_task_log_vaddr = mgmt->vgpu_task_log_vaddr = NULL;
+	mgmt->ctrl_vaddr = mgmt->kernel_log_vaddr = NULL;
 	mgmt->heap_mem = NULL;
 }
 
@@ -191,7 +195,9 @@ static int setup_mgmt_heap(struct nvidia_vgpu *vgpu)
 	struct nvidia_vgpu_info *info = &vgpu->info;
 	struct nvidia_vgpu_type *vgpu_type = info->vgpu_type;
 	struct nvidia_vgpu_alloc_fbmem_info alloc_info = {0};
+	struct nvidia_vgpu_map_mem_info map_info = {0};
 	struct nvidia_vgpu_mem *mem;
+	int ret;
 
 	alloc_info.size = vgpu_type->gsp_heap_size;
 
@@ -203,6 +209,23 @@ static int setup_mgmt_heap(struct nvidia_vgpu *vgpu)
 
 	vgpu_debug(vgpu, "mgmt heap offset 0x%llx size 0x%llx\n", mem->addr, mem->size);
 
+	map_info.map_size = vgpu_mgr->comm_buff_size;
+
+	ret = nvidia_vgpu_mgr_bar1_map_mem(vgpu_mgr, mem, &map_info);
+	if (ret) {
+		nvidia_vgpu_mgr_free_fbmem(vgpu_mgr, mem);
+		return ret;
+	}
+
+	vgpu_debug(vgpu, "mgmt heap mapped\n");
+
+	mgmt->ctrl_vaddr = mem->bar1_vaddr;
+	mgmt->init_task_log_vaddr = mgmt->ctrl_vaddr +
+				    vgpu_mgr->init_task_log_offset;
+	mgmt->vgpu_task_log_vaddr = mgmt->init_task_log_vaddr +
+				    vgpu_mgr->init_task_log_size;
+	mgmt->kernel_log_vaddr = mgmt->vgpu_task_log_vaddr +
+				 vgpu_mgr->vgpu_task_log_size;
 	mgmt->heap_mem = mem;
 	return 0;
 }
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +26 -0
index e8b670308b21..cf5dd9a8e258 100644
@@ -154,6 +154,30 @@ static int setup_chid_alloc_bitmap(struct nvidia_vgpu_mgr *vgpu_mgr)
 	return 0;
 }
 
+static void init_gsp_rm_constraints(struct nvidia_vgpu_mgr *vgpu_mgr)
+{
+	vgpu_mgr->comm_buff_size = (3 * SZ_4K) + SZ_2M + SZ_4K + SZ_128K + SZ_256K + SZ_64K;
+	vgpu_mgr->init_task_log_offset = (3 * SZ_4K) + SZ_2M + SZ_4K;
+	vgpu_mgr->init_task_log_size = SZ_128K;
+	vgpu_mgr->vgpu_task_log_size = SZ_256K;
+	vgpu_mgr->kernel_log_size = SZ_64K;
+
+	vgpu_mgr_debug(vgpu_mgr, "[GSP RM constraint] comm_buff_size 0x%llx\n",
+		       vgpu_mgr->comm_buff_size);
+
+	vgpu_mgr_debug(vgpu_mgr, "[GSP RM constraint] init_task_log_offset 0x%llx\n",
+		       vgpu_mgr->init_task_log_offset);
+
+	vgpu_mgr_debug(vgpu_mgr, "[GSP RM constraint] init_task_log size 0x%llx\n",
+		       vgpu_mgr->init_task_log_size);
+
+	vgpu_mgr_debug(vgpu_mgr, "[GSP RM constraint] vgpu_task_log size 0x%llx\n",
+		       vgpu_mgr->vgpu_task_log_size);
+
+	vgpu_mgr_debug(vgpu_mgr, "[GSP RM constraint] kernel_log size 0x%llx\n",
+		       vgpu_mgr->kernel_log_size);
+}
+
 static int init_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 {
 	int ret;
@@ -178,6 +202,8 @@ static int init_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 	vgpu_mgr_debug(vgpu_mgr, "[core driver] total fbmem size 0x%llx\n",
 		       vgpu_mgr->total_fbmem_size);
 
+	init_gsp_rm_constraints(vgpu_mgr);
+
 	return vgpu_mgr->use_chid_alloc_bitmap ? setup_chid_alloc_bitmap(vgpu_mgr) : 0;
 }
 
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +16 -1
index facecd060856..9a3af35e5eee 100644
@@ -51,7 +51,10 @@ struct nvidia_vgpu_chid {
 
 struct nvidia_vgpu_mgmt {
 	struct nvidia_vgpu_mem *heap_mem;
-	/* more to come */
+	void __iomem *ctrl_vaddr;
+	void __iomem *init_task_log_vaddr;
+	void __iomem *vgpu_task_log_vaddr;
+	void __iomem *kernel_log_vaddr;
 };
 
 /**
@@ -91,6 +94,11 @@ struct nvidia_vgpu {
  * @total_fbmem_size: total FB memory size
  * @vmmu_segment_size: VMMU segment size
  * @ecc_enabled: ECC is enabled in the GPU
+ * @comm_buff_size: communication buffer size of mgmt heap
+ * @init_task_log_offset: offset of init task log in mgmt heap
+ * @init_task_log_size: size of init task size in mgmt heap
+ * @vgpu_task_log_size: size of vgpu task log size in mgmt heap
+ * @kernel_log_size: size of kernel log size in mgmt heap
  * @vgpu_major: vGPU major version
  * @vgpu_minor: vGPU minor version
  * @vgpu_list_lock: lock to protect vGPU list
@@ -114,6 +122,13 @@ struct nvidia_vgpu_mgr {
 	u64 vmmu_segment_size;
 	bool ecc_enabled;
 
+	/* GSP RM constraints */
+	u64 comm_buff_size;
+	u64 init_task_log_offset;
+	u64 init_task_log_size;
+	u64 vgpu_task_log_size;
+	u64 kernel_log_size;
+
 	u64 vgpu_major;
 	u64 vgpu_minor;
 
Signature · 1 line
2.34.1
author
#15 lore raw

RFC v2 8/14 vfio/nvidia-vgpu: allocate GSP RM client when creating vGPUs

In reply to Zhi Wang

A GSP RM client is required when talking to the GSP firmware via GSP RM controls.

So far, all the vGPU GSP RPCs are sent via the GSP RM client allocated for vGPU manager and some vGPU GSP RPCs needs a per-vGPU GSP RM client.

Allocate a dedicated GSP RM client for each vGPU.

---
 drivers/vfio/pci/nvidia-vgpu/vgpu.c     | 11 +++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h |  2 ++
 2 files changed, 13 insertions(+)
drivers/vfio/pci/nvidia-vgpu/vgpu.c +11 -0
index 4c106a9803f6..cf28367ac6a0 100644
@@ -238,9 +238,12 @@ static int setup_mgmt_heap(struct nvidia_vgpu *vgpu)
  */
 int nvidia_vgpu_mgr_destroy_vgpu(struct nvidia_vgpu *vgpu)
 {
+	struct nvidia_vgpu_mgr *vgpu_mgr = vgpu->vgpu_mgr;
+
 	if (!atomic_cmpxchg(&vgpu->status, 1, 0))
 		return -ENODEV;
 
+	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu->gsp_client);
 	clean_mgmt_heap(vgpu);
 	clean_fbmem_heap(vgpu);
 	clean_chids(vgpu);
@@ -262,6 +265,7 @@ EXPORT_SYMBOL_GPL(nvidia_vgpu_mgr_destroy_vgpu);
  */
 int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu)
 {
+	struct nvidia_vgpu_mgr *vgpu_mgr = vgpu->vgpu_mgr;
 	struct nvidia_vgpu_info *info = &vgpu->info;
 	int ret;
 
@@ -295,12 +299,19 @@ int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu)
 	if (ret)
 		goto err_setup_mgmt_heap;
 
+	ret = nvidia_vgpu_mgr_alloc_gsp_client(vgpu_mgr,
+					       &vgpu->gsp_client);
+	if (ret)
+		goto err_alloc_gsp_client;
+
 	atomic_set(&vgpu->status, 1);
 
 	vgpu_debug(vgpu, "created\n");
 
 	return 0;
 
+err_alloc_gsp_client:
+	clean_mgmt_heap(vgpu);
 err_setup_mgmt_heap:
 	clean_fbmem_heap(vgpu);
 err_setup_fbmem_heap:
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +2 -0
index 9a3af35e5eee..84bafea295a0 100644
@@ -66,6 +66,7 @@ struct nvidia_vgpu_mgmt {
  * @vgpu_list: list node to the vGPU list
  * @info: vGPU info
  * @vgpu_mgr: pointer to vGPU manager
+ * @gsp_client: per-vGPU GSP client
  * @chid: vGPU channel IDs
  * @fbmem_heap: allocated FB memory for the vGPU
  * @mgmt: vGPU mgmt heap
@@ -79,6 +80,7 @@ struct nvidia_vgpu {
 
 	struct nvidia_vgpu_info info;
 	struct nvidia_vgpu_mgr *vgpu_mgr;
+	struct nvidia_vgpu_gsp_client gsp_client;
 
 	struct nvidia_vgpu_chid chid;
 	struct nvidia_vgpu_mem *fbmem_heap;
Signature · 1 line
2.34.1
author
#16 lore raw

RFC v2 9/14 vfio/nvidia-vgpu: bootload the new vGPU

In reply to Zhi Wang

All the resources that required by a new vGPU has been set up. It is time to activate it.

Send the NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_BOOTLOAD_GSP_VGPU_PLUGIN_TASK GSP RPC to activate the new vGPU.

---
 .../pci/nvidia-vgpu/include/nvrm/bootload.h   | 58 +++++++++++
 drivers/vfio/pci/nvidia-vgpu/pf.h             | 10 ++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c           | 97 +++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c       | 36 ++++++-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h       |  2 +
 5 files changed, 202 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/bootload.h
drivers/vfio/pci/nvidia-vgpu/include/nvrm/bootload.h new file +58 -0
new file mode 100644
index 000000000000..ec0cb03f27e8
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: MIT */
+
+/* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. */
+
+#ifndef __NVRM_BOOTLOAD_H__
+#define __NVRM_BOOTLOAD_H__
+
+#include <nvrm/nvtypes.h>
+
+/* Excerpt of RM headers from https://github.com/NVIDIA/open-gpu-kernel-modules/tree/570.124.04 */
+
+#define NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_BOOTLOAD_GSP_VGPU_PLUGIN_TASK (0x20804001)
+
+#define NV2080_CTRL_MAX_VMMU_SEGMENTS                                   384
+
+/* Must match NV2080_ENGINE_TYPE_LAST from cl2080.h */
+#define NV2080_GPU_MAX_ENGINES                                          0x54
+
+typedef struct NV2080_CTRL_VGPU_MGR_INTERNAL_BOOTLOAD_GSP_VGPU_PLUGIN_TASK_PARAMS {
+	NvU32  dbdf;
+	NvU32  gfid;
+	NvU32  vgpuType;
+	NvU32  vmPid;
+	NvU32  swizzId;
+	NvU32  numChannels;
+	NvU32  numPluginChannels;
+	NvU32  chidOffset[NV2080_GPU_MAX_ENGINES];
+	NvBool bDisableDefaultSmcExecPartRestore;
+	NvU32  numGuestFbSegments;
+	NV_DECLARE_ALIGNED(NvU64 guestFbPhysAddrList[NV2080_CTRL_MAX_VMMU_SEGMENTS], 8);
+	NV_DECLARE_ALIGNED(NvU64 guestFbLengthList[NV2080_CTRL_MAX_VMMU_SEGMENTS], 8);
+	NV_DECLARE_ALIGNED(NvU64 pluginHeapMemoryPhysAddr, 8);
+	NV_DECLARE_ALIGNED(NvU64 pluginHeapMemoryLength, 8);
+	NV_DECLARE_ALIGNED(NvU64 ctrlBuffOffset, 8);
+	NV_DECLARE_ALIGNED(NvU64 initTaskLogBuffOffset, 8);
+	NV_DECLARE_ALIGNED(NvU64 initTaskLogBuffSize, 8);
+	NV_DECLARE_ALIGNED(NvU64 vgpuTaskLogBuffOffset, 8);
+	NV_DECLARE_ALIGNED(NvU64 vgpuTaskLogBuffSize, 8);
+	NV_DECLARE_ALIGNED(NvU64 kernelLogBuffOffset, 8);
+	NV_DECLARE_ALIGNED(NvU64 kernelLogBuffSize, 8);
+	NV_DECLARE_ALIGNED(NvU64 migRmHeapMemoryPhysAddr, 8);
+	NV_DECLARE_ALIGNED(NvU64 migRmHeapMemoryLength, 8);
+	NvBool bDeviceProfilingEnabled;
+} NV2080_CTRL_VGPU_MGR_INTERNAL_BOOTLOAD_GSP_VGPU_PLUGIN_TASK_PARAMS;
+
+#define NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_SHUTDOWN_GSP_VGPU_PLUGIN_TASK (0x20804002)
+
+typedef struct NV2080_CTRL_VGPU_MGR_INTERNAL_SHUTDOWN_GSP_VGPU_PLUGIN_TASK_PARAMS {
+	NvU32 gfid;
+} NV2080_CTRL_VGPU_MGR_INTERNAL_SHUTDOWN_GSP_VGPU_PLUGIN_TASK_PARAMS;
+
+#define NV2080_CTRL_CMD_VGPU_MGR_INTERNAL_VGPU_PLUGIN_CLEANUP (0x20804008)
+
+typedef struct NV2080_CTRL_VGPU_MGR_INTERNAL_VGPU_PLUGIN_CLEANUP_PARAMS {
+	NvU32 gfid;
+} NV2080_CTRL_VGPU_MGR_INTERNAL_VGPU_PLUGIN_CLEANUP_PARAMS;
+
+#endif
drivers/vfio/pci/nvidia-vgpu/pf.h +10 -0
index 167296ba7e3d..d081d8e718e1 100644
@@ -109,4 +109,14 @@ static inline int nvidia_vgpu_mgr_init_handle(struct pci_dev *pdev,
 #define nvidia_vgpu_mgr_bar1_unmap_mem(m, mem) \
 	((m)->handle.ops->bar1_unmap_mem(mem))
 
+#define nvidia_vgpu_mgr_get_engine_bitmap_size(m) ({ \
+	typeof(m) __m = (m); \
+	__m->handle.ops->get_engine_bitmap_size(__m->handle.pf_drvdata); \
+})
+
+#define nvidia_vgpu_mgr_get_engine_bitmap(m, bitmap) ({ \
+	typeof(m) __m = (m); \
+	__m->handle.ops->get_engine_bitmap(__m->handle.pf_drvdata, bitmap); \
+})
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vgpu.c +97 -0

127 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +35 -1
index cf5dd9a8e258..6338dd9c86b6 100644
@@ -15,6 +15,9 @@ static void clean_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 		bitmap_free(vgpu_mgr->chid_alloc_bitmap);
 		vgpu_mgr->chid_alloc_bitmap = NULL;
 	}
+
+	kvfree(vgpu_mgr->engine_bitmap);
+	vgpu_mgr->engine_bitmap = NULL;
 }
 
 static void vgpu_mgr_release(struct kref *kref)
@@ -140,6 +143,25 @@ static int get_ecc_status(struct nvidia_vgpu_mgr *vgpu_mgr)
 	return 0;
 }
 
+static int setup_engine_bitmap(struct nvidia_vgpu_mgr *vgpu_mgr)
+{
+	u64 size;
+
+	size = nvidia_vgpu_mgr_get_engine_bitmap_size(vgpu_mgr);
+
+	if (WARN_ON(!size))
+		return -EINVAL;
+
+	vgpu_mgr->engine_bitmap = kvmalloc(ALIGN(size, 8), GFP_KERNEL);
+	if (!vgpu_mgr->engine_bitmap)
+		return -ENOMEM;
+
+	vgpu_mgr_debug(vgpu_mgr, "[core driver] engine bitmap size: 0x%llx\n", size);
+
+	nvidia_vgpu_mgr_get_engine_bitmap(vgpu_mgr, vgpu_mgr->engine_bitmap);
+	return 0;
+}
+
 static int setup_chid_alloc_bitmap(struct nvidia_vgpu_mgr *vgpu_mgr)
 {
 	if (WARN_ON(!vgpu_mgr->use_chid_alloc_bitmap))
@@ -194,6 +216,10 @@ static int init_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 		       vgpu_mgr->vmmu_segment_size);
 	vgpu_mgr_debug(vgpu_mgr, "[GSP RM] ECC enabled: %d\n", vgpu_mgr->ecc_enabled);
 
+	ret = setup_engine_bitmap(vgpu_mgr);
+	if (ret)
+		return ret;
+
 	vgpu_mgr->total_avail_chids = nvidia_vgpu_mgr_get_avail_chids(vgpu_mgr);
 	vgpu_mgr->total_fbmem_size = nvidia_vgpu_mgr_get_total_fbmem_size(vgpu_mgr);
 
@@ -204,7 +230,15 @@ static int init_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 
 	init_gsp_rm_constraints(vgpu_mgr);
 
-	return vgpu_mgr->use_chid_alloc_bitmap ? setup_chid_alloc_bitmap(vgpu_mgr) : 0;
+	if (vgpu_mgr->use_chid_alloc_bitmap) {
+		ret = setup_chid_alloc_bitmap(vgpu_mgr);
+		if (ret) {
+			kvfree(vgpu_mgr->engine_bitmap);
+			vgpu_mgr->engine_bitmap = NULL;
+			return ret;
+		}
+	}
+	return 0;
 }
 
 static int setup_pf_driver_caps(struct nvidia_vgpu_mgr *vgpu_mgr, unsigned long *caps)
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +2 -0
index 84bafea295a0..323acf52068e 100644
@@ -34,6 +34,7 @@ struct nvidia_vgpu_info {
 	u32 gfid;
 	u32 dbdf;
 	struct nvidia_vgpu_type *vgpu_type;
+	u32 vm_pid;
 };
 
 /**
@@ -119,6 +120,7 @@ struct nvidia_vgpu_mgr {
 	/* core driver configurations */
 	u32 total_avail_chids;
 	u64 total_fbmem_size;
+	void *engine_bitmap;
 
 	/* GSP RM configurations */
 	u64 vmmu_segment_size;
Signature · 1 line
2.34.1
author
#17 lore raw

RFC v2 10/14 vfio/nvidia-vgpu: introduce vGPU host RPC channel

In reply to Zhi Wang

A newly created vGPU requires some runtime configuration to be uploaded before moving on.

Introduce the vGPU host RPCs manipulation APIs to send vGPU RPCs. Send vGPU RPCs to upload the runtime configuration of a vGPU.

Cc Timur Tabi <[email protected]>
Cc Aniket Agashe <[email protected]>
---
 drivers/vfio/pci/nvidia-vgpu/Makefile         |   2 +-
 .../nvidia-vgpu/include/nvrm/nv_vgpu_types.h  |  34 +++
 .../vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h  | 182 +++++++++++++
 drivers/vfio/pci/nvidia-vgpu/rpc.c            | 254 ++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c           |   8 +
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c       |  31 +++
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h       |  22 ++
 7 files changed, 532 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/nv_vgpu_types.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/rpc.c
drivers/vfio/pci/nvidia-vgpu/Makefile +1 -1
index 94ba4ed4e131..91e57c65ca27 100644
@@ -2,4 +2,4 @@
 subdir-ccflags-y += -I$(src)/include
 
 obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia_vgpu_vfio_pci.o
-nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o metadata.o metadata_vgpu_type.o
+nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o metadata.o metadata_vgpu_type.o rpc.o
drivers/vfio/pci/nvidia-vgpu/include/nvrm/nv_vgpu_types.h new file +34 -0
new file mode 100644
index 000000000000..fc067caf5dea
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: MIT */
+
+/* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. */
+
+#ifndef __NVRM_VGPU_TYPES_H__
+#define __NVRM_VGPU_TYPES_H__
+
+/* Excerpt of RM headers from https://github.com/NVIDIA/open-gpu-kernel-modules/tree/570.124.04 */
+
+#include <nvrm/nvtypes.h>
+
+#define VM_UUID_SIZE            16
+#define INVALID_VGPU_DEV_INST   0xFFFFFFFFU
+#define MAX_VGPU_DEVICES_PER_VM 16U
+
+/* This enum represents the current state of guest dependent fields */
+typedef enum GUEST_VM_INFO_STATE {
+	GUEST_VM_INFO_STATE_UNINITIALIZED = 0,
+	GUEST_VM_INFO_STATE_INITIALIZED = 1,
+} GUEST_VM_INFO_STATE;
+
+/* This enum represents types of VM identifiers */
+typedef enum VM_ID_TYPE {
+	VM_ID_DOMAIN_ID = 0,
+	VM_ID_UUID = 1,
+} VM_ID_TYPE;
+
+/* This structure represents VM identifier */
+typedef union VM_ID {
+	NvU8 vmUuid[VM_UUID_SIZE];
+	NV_DECLARE_ALIGNED(NvU64 vmId, 8);
+} VM_ID;
+
+#endif
drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h new file +182 -0

182 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/rpc.c new file +254 -0

254 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu.c +8 -0
index 5778365c051f..9e8ea77bbcc5 100644
@@ -332,6 +332,7 @@ int nvidia_vgpu_mgr_destroy_vgpu(struct nvidia_vgpu *vgpu)
 	if (!atomic_cmpxchg(&vgpu->status, 1, 0))
 		return -ENODEV;
 
+	nvidia_vgpu_clean_rpc(vgpu);
 	WARN_ON(shutdown_vgpu_plugin_task(vgpu));
 	WARN_ON(cleanup_vgpu_plugin_task(vgpu));
 	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu->gsp_client);
@@ -399,12 +400,19 @@ int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu)
 	if (ret)
 		goto err_bootload_vgpu_plugin_task;
 
+	ret = nvidia_vgpu_setup_rpc(vgpu);
+	if (ret)
+		goto err_setup_rpc;
+
 	atomic_set(&vgpu->status, 1);
 
 	vgpu_debug(vgpu, "created\n");
 
 	return 0;
 
+err_setup_rpc:
+	shutdown_vgpu_plugin_task(vgpu);
+	cleanup_vgpu_plugin_task(vgpu);
 err_bootload_vgpu_plugin_task:
 	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu->gsp_client);
 err_alloc_gsp_client:
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +31 -0
index 6338dd9c86b6..6f53bd7ca940 100644
@@ -9,6 +9,29 @@
 #include <nvrm/vmmu.h>
 #include <nvrm/ecc.h>
 
+static void unmap_pf_mmio(struct nvidia_vgpu_mgr *vgpu_mgr)
+{
+	iounmap(vgpu_mgr->bar0_vaddr);
+}
+
+static int map_pf_mmio(struct nvidia_vgpu_mgr *vgpu_mgr)
+{
+	struct pci_dev *pdev = vgpu_mgr->pdev;
+	resource_size_t start, size;
+	void *vaddr;
+
+	start = pci_resource_start(pdev, 0);
+	size = pci_resource_len(pdev, 0);
+
+	vaddr = ioremap(start, size);
+	if (!vaddr)
+		return -ENOMEM;
+
+	vgpu_mgr->bar0_vaddr = vaddr;
+
+	return 0;
+}
+
 static void clean_vgpu_mgr(struct nvidia_vgpu_mgr *vgpu_mgr)
 {
 	if (vgpu_mgr->use_chid_alloc_bitmap) {
@@ -30,6 +53,7 @@ static void vgpu_mgr_release(struct kref *kref)
 	if (WARN_ON(atomic_read(&vgpu_mgr->num_vgpus)))
 		return;
 
+	unmap_pf_mmio(vgpu_mgr);
 	nvidia_vgpu_mgr_clean_metadata(vgpu_mgr);
 	clean_vgpu_mgr(vgpu_mgr);
 	nvidia_vgpu_mgr_free_gsp_client(vgpu_mgr, &vgpu_mgr->gsp_client);
@@ -73,6 +97,7 @@ static struct nvidia_vgpu_mgr *alloc_vgpu_mgr(struct nvidia_vgpu_mgr_handle *han
 		return ERR_PTR(-ENOMEM);
 
 	vgpu_mgr->handle = *handle;
+	vgpu_mgr->pdev = handle->pf_pdev;
 
 	kref_init(&vgpu_mgr->refcount);
 	mutex_init(&vgpu_mgr->vgpu_list_lock);
@@ -295,6 +320,10 @@ static int pf_attach_handle_fn(void *handle, struct nvidia_vgpu_vfio_handle_data
 	if (ret)
 		goto fail_setup_metadata;
 
+	ret = map_pf_mmio(vgpu_mgr);
+	if (ret)
+		goto fail_map_pf_mmio;
+
 	attach_vgpu_mgr(vgpu_mgr, handle_data);
 
 	ret = attach_data->init_vfio_fn(vgpu_mgr, attach_data->init_vfio_fn_data);
@@ -307,6 +336,8 @@ static int pf_attach_handle_fn(void *handle, struct nvidia_vgpu_vfio_handle_data
 
 fail_init_fn:
 	detach_vgpu_mgr(handle_data);
+	unmap_pf_mmio(vgpu_mgr);
+fail_map_pf_mmio:
 	nvidia_vgpu_mgr_clean_metadata(vgpu_mgr);
 fail_setup_metadata:
 	clean_vgpu_mgr(vgpu_mgr);
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +22 -0
index 323acf52068e..fe475f8b2882 100644
@@ -58,6 +58,17 @@ struct nvidia_vgpu_mgmt {
 	void __iomem *kernel_log_vaddr;
 };
 
+struct nvidia_vgpu_rpc {
+	/* RPC channel lock */
+	struct mutex lock;
+	u32 msg_seq_num;
+	void __iomem *ctrl_buf;
+	void __iomem *resp_buf;
+	void __iomem *msg_buf;
+	void __iomem *migration_buf;
+	void __iomem *error_buf;
+};
+
 /**
  * struct nvidia_vgpu - per-vGPU state
  *
@@ -71,6 +82,7 @@ struct nvidia_vgpu_mgmt {
  * @chid: vGPU channel IDs
  * @fbmem_heap: allocated FB memory for the vGPU
  * @mgmt: vGPU mgmt heap
+ * @rpc: vGPU host RPC
  */
 struct nvidia_vgpu {
 	/* Per-vGPU lock */
@@ -86,6 +98,7 @@ struct nvidia_vgpu {
 	struct nvidia_vgpu_chid chid;
 	struct nvidia_vgpu_mem *fbmem_heap;
 	struct nvidia_vgpu_mgmt mgmt;
+	struct nvidia_vgpu_rpc rpc;
 };
 
 /**
@@ -112,6 +125,8 @@ struct nvidia_vgpu {
  * @num_vgpu_types: number of installed vGPU types
  * @use_alloc_bitmap: use chid allocator for the PF driver doesn't support chid allocation
  * @chid_alloc_bitmap: chid allocator bitmap
+ * @pdev: the PCI device pointer
+ * @bar0_vaddr: the virtual address of BAR0
  */
 struct nvidia_vgpu_mgr {
 	struct kref refcount;
@@ -147,6 +162,9 @@ struct nvidia_vgpu_mgr {
 
 	bool use_chid_alloc_bitmap;
 	void *chid_alloc_bitmap;
+
+	struct pci_dev *pdev;
+	void __iomem *bar0_vaddr;
 };
 
 #define nvidia_vgpu_mgr_for_each_vgpu(vgpu, vgpu_mgr) \
@@ -160,5 +178,9 @@ int nvidia_vgpu_mgr_destroy_vgpu(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_mgr_setup_metadata(struct nvidia_vgpu_mgr *vgpu_mgr);
 void nvidia_vgpu_mgr_clean_metadata(struct nvidia_vgpu_mgr *vgpu_mgr);
+int nvidia_vgpu_rpc_call(struct nvidia_vgpu *vgpu, u32 msg_type,
+			 void *data, u64 size);
+void nvidia_vgpu_clean_rpc(struct nvidia_vgpu *vgpu);
+int nvidia_vgpu_setup_rpc(struct nvidia_vgpu *vgpu);
 
 #endif
Signature · 1 line
2.34.1
#18 lore raw

Re: [RFC v2 10/14] vfio/nvidia-vgpu: introduce vGPU host RPC channel

Quoted 14 lines · Zhi Wang
drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h new file +14 -0
+typedef struct {
+	NvU8   vgpu_uuid[VM_UUID_SIZE];
+	NvU32  dbdf;
+	NvU32  driver_vm_vf_dbdf;
+	NvU32  vgpu_device_instance_id;
+	NvU32  vgpu_type;
+	NvU32  vm_pid;
+	NvU32  swizz_id;
+	NvU32  num_channels;
+	NvU32  num_plugin_channels;
+	NvU32  vmm_cap;
+	NvU32  migration_feature;
+	NvU32  hypervisor_type;
+	NvU32  host_cpu_arch;

drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h line 124

Quoted 10 lines
drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h new file +9 -0
+	NvU64  host_page_size;
 
+	NvBool rev1[3];
+	NvBool enable_uvm;
+	NvBool linux_interrupt_optimization;
+	NvBool vmm_migration_supported;
+	NvBool rev2;
+	NvBool enable_console_vnc;
+	NvBool use_non_stall_linux_events;
+	NvBool rev3[3];

This is 12 bytes

drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h line 125

Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h new file +1 -0
+	NvU16  placement_id;

This is 2 bytes, for a total of 14 so far ...

drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h line 126

Quoted 1 line
drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h new file +1 -0
+	NvU32  rev4;

This is misaligned.

Quoted 5 lines
drivers/vfio/pci/nvidia-vgpu/include/nvrm/vgpu.h new file +5 -0
+	NvU32  channel_usage_threshold_percentage;
+	NvBool rev5;
+	NvU32  rev6;
+	NvBool rev7;
+} NV_VGPU_CPU_RPC_DATA_COPY_CONFIG_PARAMS;
author
#19 lore raw

RFC v2 11/14 vfio/nvidia-vgpu: introduce NVIDIA vGPU VFIO variant driver

In reply to Zhi Wang

A VFIO variant driver module is designed to extend the capabilities of the existing VFIO (Virtual Function I/O), offering device management interfaces to the userspace and advanced feature support.

For the userspace to use the NVIDIA vGPU, a new vGPU VFIO variant driver is introduced to provide vGPU management, like selecting/creating vGPU instance, support advance features like live migration.

Introduce the NVIDIA vGPU VFIO variant driver to support vGPU lifecycle management UABI and the future advancd features.

Cc Aniket Agashe <[email protected]>
Cc Ankit Agrawal <[email protected]>
---
 .../ABI/stable/sysfs-driver-nvidia-vgpu       |  11 +
 drivers/vfio/pci/nvidia-vgpu/Makefile         |   3 +-
 drivers/vfio/pci/nvidia-vgpu/debug.h          |  10 +
 drivers/vfio/pci/nvidia-vgpu/vfio.h           |  49 ++
 drivers/vfio/pci/nvidia-vgpu/vfio_access.c    | 313 ++++++++
 drivers/vfio/pci/nvidia-vgpu/vfio_main.c      | 688 ++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vfio_sysfs.c     | 209 ++++++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c           |  53 +-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c       |  68 +-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h       |  29 +
 10 files changed, 1427 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/ABI/stable/sysfs-driver-nvidia-vgpu
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio.h
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_access.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_main.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_sysfs.c
Documentation/ABI/stable/sysfs-driver-nvidia-vgpu new file +11 -0
new file mode 100644
index 000000000000..1fc3ac8e234d
@@ -0,0 +1,11 @@
+What:           /sys/devices/pciXXXX:XX/0000:XX:XX.X/nvidia/creatable_vgpu_types
+Date:		June 2, 2025
+KernelVersion:	6.17
+Contact:	[email protected]
+Description:	Query the creatble vGPU types on a virtual function.
+
+What:           /sys/devices/pciXXXX:XX/0000:XX:XX.X/nvidia/current_vgpu_type
+Date:		June 2, 2025
+KernelVersion:	6.17
+Contact:	[email protected]
+Description:	Set the vGPU type for the virtual function.
drivers/vfio/pci/nvidia-vgpu/Makefile +2 -1
index 91e57c65ca27..2aba9b4868aa 100644
@@ -2,4 +2,5 @@
 subdir-ccflags-y += -I$(src)/include
 
 obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia_vgpu_vfio_pci.o
-nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o metadata.o metadata_vgpu_type.o rpc.o
+nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o metadata.o metadata_vgpu_type.o rpc.o \
+			  vfio_main.o vfio_access.o vfio_sysfs.o
drivers/vfio/pci/nvidia-vgpu/debug.h +10 -0
index db9288752384..05cb2ea13543 100644
@@ -22,4 +22,14 @@
 	pci_err(__v->pdev, "nvidia-vgpu %d: "f, __v->info.id, ##a); \
 })
 
+#define nvdev_debug(n, f, a...) ({ \
+	typeof(n) __n = (n); \
+	pci_dbg(__n->core_dev.pdev, "nvidia-vgpu-vfio: "f, ##a); \
+})
+
+#define nvdev_error(n, f, a...) ({ \
+	typeof(n) __n = (n); \
+	pci_err(__n->core_dev.pdev, "nvidia-vgpu-vfio: "f, ##a); \
+})
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vfio.h new file +49 -0

49 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vfio_access.c new file +313 -0

313 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vfio_main.c new file +688 -0

688 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vfio_sysfs.c new file +209 -0

209 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu.c +50 -3

74 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +66 -2

93 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +29 -0
index fe475f8b2882..dc782f825f2b 100644
@@ -101,6 +101,17 @@ struct nvidia_vgpu {
 	struct nvidia_vgpu_rpc rpc;
 };
 
+struct nvidia_vgpu_event_listener {
+	int (*func)(struct nvidia_vgpu_event_listener *self, unsigned int event, void *data);
+	struct list_head list;
+};
+
+struct nvidia_vgpu_event_chain {
+	/* lock for PF event listener list */
+	struct mutex lock;
+	struct list_head head;
+};
+
 /**
  * struct nvidia_vgpu_mgr - the vGPU manager
  *
@@ -125,6 +136,10 @@ struct nvidia_vgpu {
  * @num_vgpu_types: number of installed vGPU types
  * @use_alloc_bitmap: use chid allocator for the PF driver doesn't support chid allocation
  * @chid_alloc_bitmap: chid allocator bitmap
+ * @curr_vgpu_lock: lock to protect curr_vgpu_type
+ * @curr_vgpu_type: type of current created vgpu in homogeneous mode
+ * @num_instances: number of created vGPU with curr_vgpu_type in homogeneous mode
+ * @pf_driver_event_chain: PF driver event chain
  * @pdev: the PCI device pointer
  * @bar0_vaddr: the virtual address of BAR0
  */
@@ -163,6 +178,13 @@ struct nvidia_vgpu_mgr {
 	bool use_chid_alloc_bitmap;
 	void *chid_alloc_bitmap;
 
+	/* lock for current vGPU type */
+	struct mutex curr_vgpu_type_lock;
+	struct nvidia_vgpu_type *curr_vgpu_type;
+	unsigned int num_instances;
+
+	struct nvidia_vgpu_event_chain pf_driver_event_chain;
+
 	struct pci_dev *pdev;
 	void __iomem *bar0_vaddr;
 };
@@ -173,14 +195,21 @@ struct nvidia_vgpu_mgr {
 int nvidia_vgpu_mgr_setup(struct pci_dev *dev, int (*init_vfio_fn)(void *priv, void *data),
 			  void *init_vfio_fn_data);
 void nvidia_vgpu_mgr_release(struct nvidia_vgpu_mgr *vgpu_mgr);
+void nvidia_vgpu_event_init_chain(struct nvidia_vgpu_event_chain *chain);
+void nvidia_vgpu_event_register_listener(struct nvidia_vgpu_event_chain *chain,
+					 struct nvidia_vgpu_event_listener *l);
+void nvidia_vgpu_event_unregister_listener(struct nvidia_vgpu_event_chain *chain,
+					   struct nvidia_vgpu_event_listener *l);
 
 int nvidia_vgpu_mgr_destroy_vgpu(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_mgr_create_vgpu(struct nvidia_vgpu *vgpu);
+int nvidia_vgpu_mgr_reset_vgpu(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_mgr_setup_metadata(struct nvidia_vgpu_mgr *vgpu_mgr);
 void nvidia_vgpu_mgr_clean_metadata(struct nvidia_vgpu_mgr *vgpu_mgr);
 int nvidia_vgpu_rpc_call(struct nvidia_vgpu *vgpu, u32 msg_type,
 			 void *data, u64 size);
 void nvidia_vgpu_clean_rpc(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_setup_rpc(struct nvidia_vgpu *vgpu);
+int nvidia_vgpu_mgr_set_bme(struct nvidia_vgpu *vgpu, bool enable);
 
 #endif
Signature · 1 line
2.34.1
author
#20 lore raw

RFC v2 12/14 vfio/nvidia-vgpu: scrub the guest FB memory of a vGPU

In reply to Zhi Wang

Before reassigning a vGPU to a new guest, its associated FB memory must be scrubbed to prevent potential information leakage across users.

Residual data left in the FB memory could be visible to the subsequent guest, posing a significant security risk without the scrubbing.

Scrub the FB memory by issusing copy engine workloads when the user opening and closing the VFIO device.

Cc Aniket Agashe <[email protected]>
---
 drivers/vfio/pci/nvidia-vgpu/pf.h       |  23 +++
 drivers/vfio/pci/nvidia-vgpu/vgpu.c     | 218 +++++++++++++++++++++++-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c |   6 +
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h |  24 ++-
 4 files changed, 264 insertions(+), 7 deletions(-)
drivers/vfio/pci/nvidia-vgpu/pf.h +23 -0
index d081d8e718e1..d9daaace7d31 100644
@@ -119,4 +119,27 @@ static inline int nvidia_vgpu_mgr_init_handle(struct pci_dev *pdev,
 	__m->handle.ops->get_engine_bitmap(__m->handle.pf_drvdata, bitmap); \
 })
 
+#define nvidia_vgpu_mgr_channel_map_mem(m, chan, mem, info) \
+	((m)->handle.ops->channel_map_mem(chan, mem, info))
+
+#define nvidia_vgpu_mgr_channel_unmap_mem(m, mem) \
+	((m)->handle.ops->channel_unmap_mem(mem))
+
+#define nvidia_vgpu_mgr_alloc_ce_channel(m, chid) ({ \
+	typeof(m) __m = (m); \
+	__m->handle.ops->alloc_ce_channel(__m->handle.pf_drvdata, chid); \
+})
+
+#define nvidia_vgpu_mgr_free_ce_channel(m, chan) \
+	((m)->handle.ops->free_ce_channel(chan))
+
+#define nvidia_vgpu_mgr_begin_pushbuf(m, chan, num_dwords) \
+	((m)->handle.ops->begin_pushbuf(chan, num_dwords))
+
+#define nvidia_vgpu_mgr_emit_pushbuf(m, chan, dwords) \
+	((m)->handle.ops->emit_pushbuf(chan, dwords))
+
+#define nvidia_vgpu_mgr_submit_pushbuf(m, chan) \
+	((m)->handle.ops->submit_pushbuf(chan))
+
 #endif
drivers/vfio/pci/nvidia-vgpu/vgpu.c +216 -2

254 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.c +6 -0
index e502a37468e3..79b8d4b917f7 100644
@@ -105,6 +105,7 @@ static struct nvidia_vgpu_mgr *alloc_vgpu_mgr(struct nvidia_vgpu_mgr_handle *han
 	atomic_set(&vgpu_mgr->num_vgpus, 0);
 	mutex_init(&vgpu_mgr->curr_vgpu_type_lock);
 	nvidia_vgpu_event_init_chain(&vgpu_mgr->pf_driver_event_chain);
+	nvidia_vgpu_event_init_chain(&vgpu_mgr->pf_channel_event_chain);
 
 	return vgpu_mgr;
 }
@@ -132,6 +133,7 @@ static int call_chain(struct nvidia_vgpu_event_chain *chain, unsigned int event,
 static const char *pf_events_string[NVIDIA_VGPU_PF_EVENT_MAX] = {
 	[NVIDIA_VGPU_PF_DRIVER_EVENT_SRIOV_CONFIGURE] = "SRIOV configure",
 	[NVIDIA_VGPU_PF_DRIVER_EVENT_DRIVER_UNBIND] = "driver unbind",
+	[NVIDIA_VGPU_PF_CHANNEL_EVENT_FIFO_NONSTALL] = "FIFO nonstall",
 };
 
 static int pf_event_notify_fn(void *priv, unsigned int event, void *data)
@@ -148,6 +150,9 @@ static int pf_event_notify_fn(void *priv, unsigned int event, void *data)
 	case NVIDIA_VGPU_PF_DRIVER_EVENT_START...NVIDIA_VGPU_PF_DRIVER_EVENT_END:
 		ret = call_chain(&vgpu_mgr->pf_driver_event_chain, event, data);
 		break;
+	case NVIDIA_VGPU_PF_CHANNEL_EVENT_START...NVIDIA_VGPU_PF_CHANNEL_EVENT_END:
+		ret = call_chain(&vgpu_mgr->pf_channel_event_chain, event, data);
+		break;
 	}
 
 	return ret;
@@ -300,6 +305,7 @@ static int setup_pf_driver_caps(struct nvidia_vgpu_mgr *vgpu_mgr, unsigned long
 	test_bit(NVIDIA_VGPU_PF_DRIVER_CAP_HAS_##cap, caps)
 
 	vgpu_mgr->use_chid_alloc_bitmap = !HAS_CAP(CHID_ALLOC);
+	vgpu_mgr->use_ce_scrub_fbmem = HAS_CAP(CE_CHAN_ALLOC) | HAS_CAP(PUSHBUF_SUBMIT);
 
 #undef HAS_CAP
 	return 0;
drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +19 -5
index dc782f825f2b..b5bcde555a5d 100644
@@ -69,6 +69,18 @@ struct nvidia_vgpu_rpc {
 	void __iomem *error_buf;
 };
 
+struct nvidia_vgpu_event_listener {
+	int (*func)(struct nvidia_vgpu_event_listener *self, unsigned int event, void *data);
+	struct list_head list;
+};
+
+struct nvidia_vgpu_ce_channel {
+	struct nvidia_vgpu_chan *chan;
+	struct nvidia_vgpu_mem *sema_mem;
+	struct nvidia_vgpu_event_listener listener;
+	struct wait_queue_head wq;
+};
+
 /**
  * struct nvidia_vgpu - per-vGPU state
  *
@@ -83,6 +95,7 @@ struct nvidia_vgpu_rpc {
  * @fbmem_heap: allocated FB memory for the vGPU
  * @mgmt: vGPU mgmt heap
  * @rpc: vGPU host RPC
+ * @ce_channel: copy engine channel
  */
 struct nvidia_vgpu {
 	/* Per-vGPU lock */
@@ -99,11 +112,7 @@ struct nvidia_vgpu {
 	struct nvidia_vgpu_mem *fbmem_heap;
 	struct nvidia_vgpu_mgmt mgmt;
 	struct nvidia_vgpu_rpc rpc;
-};
-
-struct nvidia_vgpu_event_listener {
-	int (*func)(struct nvidia_vgpu_event_listener *self, unsigned int event, void *data);
-	struct list_head list;
+	struct nvidia_vgpu_ce_channel ce_channel;
 };
 
 struct nvidia_vgpu_event_chain {
@@ -140,8 +149,10 @@ struct nvidia_vgpu_event_chain {
  * @curr_vgpu_type: type of current created vgpu in homogeneous mode
  * @num_instances: number of created vGPU with curr_vgpu_type in homogeneous mode
  * @pf_driver_event_chain: PF driver event chain
+ * @pf_channel_event_chain: PF channel event chain
  * @pdev: the PCI device pointer
  * @bar0_vaddr: the virtual address of BAR0
+ * @use_ce_scrub_fbmem: scrub the FB memory if the PF driver supports.
  */
 struct nvidia_vgpu_mgr {
 	struct kref refcount;
@@ -184,9 +195,12 @@ struct nvidia_vgpu_mgr {
 	unsigned int num_instances;
 
 	struct nvidia_vgpu_event_chain pf_driver_event_chain;
+	struct nvidia_vgpu_event_chain pf_channel_event_chain;
 
 	struct pci_dev *pdev;
 	void __iomem *bar0_vaddr;
+
+	bool use_ce_scrub_fbmem;
 };
 
 #define nvidia_vgpu_mgr_for_each_vgpu(vgpu, vgpu_mgr) \
Signature · 1 line
2.34.1
author
#21 lore raw

RFC v2 13/14 vfio/nvidia-vgpu: introduce vGPU logging

In reply to Zhi Wang

The GSP firmware provides several per-vGPU logging buffers to help on debugging bugs.

Export those buffers to userspace. Thus, the user can attach them when reporting bugs.

---
 drivers/vfio/pci/nvidia-vgpu/Makefile       |   4 +-
 drivers/vfio/pci/nvidia-vgpu/debugfs.c      |  65 +++++++++++
 drivers/vfio/pci/nvidia-vgpu/vfio.h         |  16 +++
 drivers/vfio/pci/nvidia-vgpu/vfio_debugfs.c | 117 ++++++++++++++++++++
 drivers/vfio/pci/nvidia-vgpu/vfio_main.c    |  44 +++++++-
 drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h     |   2 +
 6 files changed, 245 insertions(+), 3 deletions(-)
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/debugfs.c
 create mode 100644 drivers/vfio/pci/nvidia-vgpu/vfio_debugfs.c
drivers/vfio/pci/nvidia-vgpu/Makefile +2 -2
index 2aba9b4868aa..615712b40128 100644
@@ -2,5 +2,5 @@
 subdir-ccflags-y += -I$(src)/include
 
 obj-$(CONFIG_NVIDIA_VGPU_VFIO_PCI) += nvidia_vgpu_vfio_pci.o
-nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o metadata.o metadata_vgpu_type.o rpc.o \
-			  vfio_main.o vfio_access.o vfio_sysfs.o
+nvidia_vgpu_vfio_pci-y := vgpu_mgr.o vgpu.o metadata.o metadata_vgpu_type.o rpc.o debugfs.o\
+			  vfio_main.o vfio_access.o vfio_sysfs.o vfio_debugfs.o
drivers/vfio/pci/nvidia-vgpu/debugfs.c new file +65 -0

65 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vfio.h +16 -0
index 4c9bf9c80f5c..8edc8cd6c6dc 100644
@@ -6,6 +6,7 @@
 #ifndef _NVIDIA_VGPU_VFIO_H__
 #define _NVIDIA_VGPU_VFIO_H__
 
+#include <linux/debugfs.h>
 #include <linux/vfio_pci_core.h>
 
 #include "vgpu_mgr.h"
@@ -15,6 +16,12 @@
 #define CAP_LIST_NEXT_PTR_MSIX 0x7c
 #define MSIX_CAP_SIZE   0xc
 
+struct nvidia_vgpu_vfio_log {
+	struct debugfs_blob_wrapper blob;
+	void *mem;
+	struct dentry *dentry;
+};
+
 struct nvidia_vgpu_vfio {
 	struct vfio_pci_core_device core_dev;
 	u8 vconfig[PCI_CONFIG_SPACE_LENGTH];
@@ -32,6 +39,12 @@ struct nvidia_vgpu_vfio {
 	struct completion vdev_closing_completion;
 
 	struct nvidia_vgpu_event_listener pf_driver_event_listener;
+	struct nvidia_vgpu_event_listener pf_event_listener;
+
+	/* Logs */
+	struct nvidia_vgpu_vfio_log log_init_task;
+	struct nvidia_vgpu_vfio_log log_vgpu_task;
+	struct nvidia_vgpu_vfio_log log_kernel;
 };
 
 static inline struct nvidia_vgpu_vfio *core_dev_to_nvdev(struct vfio_pci_core_device *core_dev)
@@ -45,5 +58,8 @@ ssize_t nvidia_vgpu_vfio_access(struct nvidia_vgpu_vfio *nvdev, char __user *buf
 
 int nvidia_vgpu_vfio_setup_sysfs(struct nvidia_vgpu_vfio *nvdev);
 void nvidia_vgpu_vfio_clean_sysfs(struct nvidia_vgpu_vfio *nvdev);
+int nvidia_vgpu_vfio_setup_debugfs(struct nvidia_vgpu_vfio *nvdev);
+void nvidia_vgpu_vfio_clean_debugfs(struct nvidia_vgpu_vfio *nvdev);
+void nvidia_vgpu_vfio_update_logs(struct nvidia_vgpu_vfio *nvdev);
 
 #endif /* _NVIDIA_VGPU_VFIO_H__ */
drivers/vfio/pci/nvidia-vgpu/vfio_debugfs.c new file +117 -0

117 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vfio_main.c +43 -1

76 lines not on this page · raw message

drivers/vfio/pci/nvidia-vgpu/vgpu_mgr.h +2 -0
index b5bcde555a5d..04fef4f69793 100644
@@ -225,5 +225,7 @@ int nvidia_vgpu_rpc_call(struct nvidia_vgpu *vgpu, u32 msg_type,
 void nvidia_vgpu_clean_rpc(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_setup_rpc(struct nvidia_vgpu *vgpu);
 int nvidia_vgpu_mgr_set_bme(struct nvidia_vgpu *vgpu, bool enable);
+struct dentry *nvidia_vgpu_get_debugfs_root(void);
+void nvidia_vgpu_put_debugfs_root(void);
 
 #endif
Signature · 1 line
2.34.1
author
#22 lore raw

RFC v2 14/14 vfio/nvidia-vgpu: add a kernel doc to introduce NVIDIA vGPU

In reply to Zhi Wang

In order to introduce NVIDIA vGPU and the requirements to a core driver, a kernel doc is introduced to explain the architecture and the requirements.

Add a kernel doc to introduce NVIDIA vGPU.

---
 Documentation/gpu/drivers.rst     |   1 +
 Documentation/gpu/nvidia-vgpu.rst | 264 ++++++++++++++++++++++++++++++
 2 files changed, 265 insertions(+)
 create mode 100644 Documentation/gpu/nvidia-vgpu.rst
Documentation/gpu/drivers.rst +1 -0
index 78b80be17f21..abdca636d3ef 100644
@@ -11,6 +11,7 @@ GPU Driver Documentation
    mcde
    meson
    nouveau
+   nvidia-vgpu
    pl111
    tegra
    tve200
Documentation/gpu/nvidia-vgpu.rst new file +264 -0

264 lines not on this page · raw message

Signature · 1 line
2.34.1