Skip to content

RFC Add virtualization support for EGM

[email protected] kvm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest15 patches 26 repliesIn review
  2. v1 RFC14 patches 12 repliesSuperseded

Changes in v2 from the cover letter

* Replaced vmalloc calls with kmalloc for small structures in multiple files (Shameer Kolothum)
* Updated sysfs representation of the egm nodes in 14/15 (Jason Gunthorpe)
* Split EGM memory clearing in 1G chunks to avoid softlock logs in 10/15.
* Added EGM memory registration with memory_failure in 15/15.
* Updated aux device cleanup path to fix improper sequence in 8/15 (Shameer Kolothum)
* Range checks for remap_pfn_range in 9/15 (Jason Gunthorpe)
* Miscellaneous cleanup (Shameer Kolothum, Jason Gunthorpe)

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15vfio/nvgrace-gpu: Expand module_pci_driver to allow custom module initdrivers/vfio/pci/nvgrace-gpu/main.c+11 -10 replies
2/15vfio/nvgrace-gpu: Create auxiliary device for EGMMAINTAINERS drivers/vfio/pci/nvgrace-gpu/Makefile drivers/vfio/pci/nvgrace-gpu/egm_dev.c +3 more+181 -32 replies
3/15vfio/nvgrace-gpu: track GPUs associated with the EGM regionsdrivers/vfio/pci/nvgrace-gpu/egm_dev.c drivers/vfio/pci/nvgrace-gpu/egm_dev.h drivers/vfio/pci/nvgrace-gpu/main.c +1 more+72 -42 replies
4/15vfio/nvgrace-gpu: Introduce functions to fetch and save EGM infodrivers/vfio/pci/nvgrace-gpu/egm_dev.c drivers/vfio/pci/nvgrace-gpu/egm_dev.h drivers/vfio/pci/nvgrace-gpu/main.c +1 more+34 -42 replies
5/15vfio/nvgrace-egm: Introduce module to manage EGMMAINTAINERS drivers/vfio/pci/nvgrace-gpu/Kconfig drivers/vfio/pci/nvgrace-gpu/Makefile +2 more+44 -01 reply
6/15vfio/nvgrace-egm: Introduce egm class and register char device numbersdrivers/vfio/pci/nvgrace-gpu/egm.c+36 -01 reply
7/15vfio/nvgrace-egm: Register auxiliary driver opsdrivers/vfio/pci/nvgrace-gpu/egm.c+35 -31 reply
8/15vfio/nvgrace-egm: Expose EGM region as char devicedrivers/vfio/pci/nvgrace-gpu/egm.c+99 -02 replies
9/15vfio/nvgrace-egm: Add chardev ops for EGM managementdrivers/vfio/pci/nvgrace-gpu/egm.c include/linux/nvgrace-egm.h+41 -11 reply
10/15vfio/nvgrace-egm: Clear Memory before handing out to VMdrivers/vfio/pci/nvgrace-gpu/egm.c+43 -04 replies
11/15vfio/nvgrace-egm: Fetch EGM region retired pages listdrivers/vfio/pci/nvgrace-gpu/egm.c drivers/vfio/pci/nvgrace-gpu/egm_dev.c drivers/vfio/pci/nvgrace-gpu/egm_dev.h +2 more+112 -101 reply
12/15vfio/nvgrace-egm: Introduce ioctl to share retired pagesMAINTAINERS drivers/vfio/pci/nvgrace-gpu/egm.c include/uapi/linux/egm.h+96 -01 reply
13/15vfio/nvgrace-egm: expose the egm size through sysfsdrivers/vfio/pci/nvgrace-gpu/egm.c+27 -01 reply
14/15vfio/nvgrace-gpu: Add link from pci to EGMdrivers/vfio/pci/nvgrace-gpu/egm_dev.c+46 -11 reply
15/15vfio/nvgrace-egm: register EGM PFNMAP range with memory_failuredrivers/vfio/pci/nvgrace-gpu/egm.c+100 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH RFC v2 00/15] Add virtualization support for EGM

From: Ankit Agrawal <[email protected]>

Background
----------
Grace Hopper/Blackwell systems support the Extended GPU Memory (EGM) feature that enable the GPU to access the system memory allocations within and across nodes through high bandwidth path. This access path goes as: GPU <--> NVswitch <--> GPU <--> CPU. The GPU can utilize the system memory located on the same socket or from a different socket or even on a different node in a multi-node system [1]. This feature is being extended to virtualization.

Design Details
--------------
EGM when enabled in the virtualization stack, the host memory is partitioned into 2 parts: One partition for the Host OS usage called Hypervisor region, and a second Hypervisor-Invisible (HI) region for the VM. Only the hypervisor region is part of the host EFI map and is thus visible to the host OS on bootup. Since the entire VM sysmem is eligible for EGM allocations within the VM, the HI partition is interchangeably called as EGM region in the series. This HI/EGM region range base SPA and size is exposed through the ACPI DSDT properties.

Whilst the EGM region is accessible on the host, it is not added to the kernel. The HI region is assigned to a VM by mapping the QEMU VMA to the SPA using remap_pfn_range().

The following figure shows the memory map in the virtualization environment.

|---- Sysmem ----|                  |--- GPU mem ---|  VM Memory
|                |                  |               |
|IPA <-> SPA map |                  |IPA <-> SPA map|
|                |                  |               |
|--- HI / EGM ---|-- Host Mem --|   |--- GPU mem ---|  Host Memory

The patch series introduce a new nvgrace-egm auxiliary driver module to manage and map the HI/EGM region in the Grace Blackwell systems. This binds to the auxiliary device created by the parent nvgrace-gpu (in-tree module for device assignment) / nvidia-vgpu-vfio (out-of-tree open source module for SRIOV vGPU) to manage the EGM region for the VM. Note that there is a unique EGM region per socket and the auxiliary device gets created for every region. The parent module fetches the EGM region information from the ACPI tables and populate to the data structures shared with the auxiliary nvgrace-egm module.

nvgrace-egm module handles the following:
1. Fetch the EGM memory properties (base HPA, length, proximity domain) from the parent device shared EGM region structure.
2. Create a char device that can be used as memory-backend-file by Qemu for the VM and implement file operations. The char device is /dev/egmX, where X is the PXM node ID of the EGM being mapped fetched in 1.
3. Zero the EGM memory on first device open().
4. Map the QEMU VMA to the EGM region using remap_pfn_range.
5. Cleaning up state and destroying the chardev on device unbind.
6. Handle presence of retired poisoned pages on the EGM region.

Since nvgrace-egm is an auxiliary module to the nvgrace-gpu, it is kept in the same directory.

Implementation
--------------
Patch 1-4 makes changes to the nvgrace-gpu module to fetch the EGM information, create auxiliary device and save the EGM region information in the shared structures.
Path 5-10 introduce the new nvgrace-egm module to manage the EGM region. The module implements a char device to expose the EGM to usermode apps such as QEMU. The module does the mapping of the QEMU VMA to the EGM SPA using remap_pfn range.
Patch 11-12 fetches the list of pages on EGM with known poisoned errors. Patch 13-14 expose the EGM topology and size through sysfs.
Patch 15 register EGM memory to memory_handle and track runtime poison errors

Enablement
----------
The EGM mode is enabled through a flag in the SBIOS. The size of the Hypervisor region is modifiable through a second parameter in the SBIOS. All the remaining system memory on the host will be invisible to the Hypervisor.

Verification
------------
Applied over v6.19-rc4 and tested using qemu repository [3]. Tested on the Grace Blackwell platform by booting up VM, loading NVIDIA module [2] and running nvidia-smi in the VM to check for the presence of EGM capability.

There is a dependency on iommu support for generic dmabuf exports being worked on by Jason Gunthorpe ([email protected]). Need to use the patch [4] until then.

Changelog
---------
v2:
* Replaced vmalloc calls with kmalloc for small structures in multiple files (Shameer Kolothum)
* Updated sysfs representation of the egm nodes in 14/15 (Jason Gunthorpe)
* Split EGM memory clearing in 1G chunks to avoid softlock logs in 10/15.
* Added EGM memory registration with memory_failure in 15/15.
* Updated aux device cleanup path to fix improper sequence in 8/15 (Shameer Kolothum)
* Range checks for remap_pfn_range in 9/15 (Jason Gunthorpe)
* Miscellaneous cleanup (Shameer Kolothum, Jason Gunthorpe)

Recognitions
------------
Many thanks to Jason Gunthorpe, Vikram Sethi, Aniket Agashe for design suggestions and Matt Ochs, Neo Jia, Kirti Wankhede among others for the review feedbacks.

Links
-----

Github Branch
-------------

Ankit Agrawal (15):
vfio/nvgrace-gpu: Expand module_pci_driver to allow custom module init vfio/nvgrace-gpu: Create auxiliary device for EGM vfio/nvgrace-gpu: track GPUs associated with the EGM regions vfio/nvgrace-gpu: Introduce functions to fetch and save EGM info vfio/nvgrace-egm: Introduce module to manage EGM vfio/nvgrace-egm: Introduce egm class and register char device numbers vfio/nvgrace-egm: Register auxiliary driver ops vfio/nvgrace-egm: Expose EGM region as char device vfio/nvgrace-egm: Add chardev ops for EGM management vfio/nvgrace-egm: Clear Memory before handing out to VM vfio/nvgrace-egm: Fetch EGM region retired pages list vfio/nvgrace-egm: Introduce ioctl to share retired pages vfio/nvgrace-egm: expose the egm size through sysfs vfio/nvgrace-gpu: Add link from pci to EGM vfio/nvgrace-egm: register EGM PFNMAP range with memory_failure

 MAINTAINERS                            |  12 +-
 drivers/vfio/pci/nvgrace-gpu/Kconfig   |  12 +
 drivers/vfio/pci/nvgrace-gpu/Makefile  |   5 +-
 drivers/vfio/pci/nvgrace-gpu/egm.c     | 540 +++++++++++++++++++++++++
 drivers/vfio/pci/nvgrace-gpu/egm_dev.c | 179 ++++++++
 drivers/vfio/pci/nvgrace-gpu/egm_dev.h |  24 ++
 drivers/vfio/pci/nvgrace-gpu/main.c    | 124 +++++-
 include/linux/nvgrace-egm.h            |  34 ++
 include/uapi/linux/egm.h               |  28 ++
 9 files changed, 954 insertions(+), 4 deletions(-)
 create mode 100644 drivers/vfio/pci/nvgrace-gpu/egm.c
 create mode 100644 drivers/vfio/pci/nvgrace-gpu/egm_dev.c
 create mode 100644 drivers/vfio/pci/nvgrace-gpu/egm_dev.h
 create mode 100644 include/linux/nvgrace-egm.h
 create mode 100644 include/uapi/linux/egm.h
Signature · 1 line
2.34.1