spapr: Support NVIDIA V100 GPU with NVLink2
PATCH v6 1/1 spapr: Support NVIDIA V100 GPU with NVLink2
NVIDIA V100 GPUs have on-board RAM which is mapped into the host memory space and accessible as normal RAM via an NVLink bus. The VFIO-PCI driver implements special regions for such GPUs and emulates an NVLink bridge. NVLink2-enabled POWER9 CPUs also provide address translation services which includes an ATS shootdown (ATSD) register exported via the NVLink bridge device.
This adds a quirk to VFIO to map the GPU memory and create an MR; the new MR is stored in a PCI device as a QOM link. The sPAPR PCI uses this to get the MR and map it to the system address space. Another quirk does the same for ATSD.
This adds additional steps to sPAPR PHB setup:
1. Search for specific GPUs and NPUs, collect findings in sPAPRPHBState::nvgpus, manage system address space mappings;
2. Add device-specific properties such as "ibm,npu", "ibm,gpu", "memory-block", "link-speed" to advertise the NVLink2 function to the guest;
3. Add "mmio-atsd" to vPHB to advertise the ATSD capability;
4. Add new memory blocks (with extra "linux,memory-usable" to prevent the guest OS from accessing the new memory until it is onlined) and npuphb# nodes representing an NPU unit for every vPHB as the GPU driver uses it for link discovery.
This allocates space for GPU RAM and ATSD like we do for MMIOs by adding 2 new parameters to the phb_placement() hook. Older machine types set these to zero.
This puts new memory nodes in a separate NUMA node to as the GPU RAM needs to be configured equally distant from any other node in the system. Unlike the host setup which assigns numa ids from 255 downwards, this adds new NUMA nodes after the user configures nodes or from 1 if none were configured.
This adds requirement similar to EEH - one IOMMU group per vPHB. The reason for this is that ATSD registers belong to a physical NPU so they cannot invalidate translations on GPUs attached to another NPU. It is guaranteed by the host platform as it does not mix NVLink bridges or GPUs from different NPU in the same IOMMU group. If more than one IOMMU group is detected on a vPHB, this disables ATSD support for that vPHB and prints a warning.
---
This is based on David's ppc-for-4.0 and acked "vfio_info_cap public" from
https://patchwork.ozlabs.org/patch/1052645/
Changes:
v6:
* changed error handling in spapr-nvlink code
* fixed mmap error checking from NULL to MAP_FAILED
* changed NUMA node ids and changed the commit log about it
v5:
* converted MRs to VFIOQuirk - this fixed leaks
v4:
* fixed ATSD placement
* fixed spapr_phb_unrealize() to do nvgpu cleanup
* replaced warn_report() with Error*
v3:
* moved GPU RAM above PCI MMIO limit
* renamed QOM property to nvlink2-tgt
* moved nvlink2 code to its own file
---
The example command line for redbud system:
pbuild/qemu-aiku1804le-ppc64/ppc64-softmmu/qemu-system-ppc64 \
-nodefaults \
-chardev stdio,id=STDIO0,signal=off,mux=on \
-device spapr-vty,id=svty0,reg=0x71000110,chardev=STDIO0 \
-mon id=MON0,chardev=STDIO0,mode=readline -nographic -vga none \
-enable-kvm -m 384G \
-chardev socket,id=SOCKET0,server,nowait,host=localhost,port=40000 \
-mon chardev=SOCKET0,mode=control \
-smp 80,sockets=1,threads=4 \
-netdev "tap,id=TAP0,helper=/home/aik/qemu-bridge-helper --br=br0" \
-device "virtio-net-pci,id=vnet0,mac=52:54:00:12:34:56,netdev=TAP0" \
img/vdisk0.img \
-device "vfio-pci,id=vfio0004_04_00_0,host=0004:04:00.0" \
-device "vfio-pci,id=vfio0006_00_00_0,host=0006:00:00.0" \
-device "vfio-pci,id=vfio0006_00_00_1,host=0006:00:00.1" \
-device "vfio-pci,id=vfio0006_00_00_2,host=0006:00:00.2" \
-device "vfio-pci,id=vfio0004_05_00_0,host=0004:05:00.0" \
-device "vfio-pci,id=vfio0006_00_01_0,host=0006:00:01.0" \
-device "vfio-pci,id=vfio0006_00_01_1,host=0006:00:01.1" \
-device "vfio-pci,id=vfio0006_00_01_2,host=0006:00:01.2" \
-device spapr-pci-host-bridge,id=phb1,index=1 \
-device "vfio-pci,id=vfio0035_03_00_0,host=0035:03:00.0" \
-device "vfio-pci,id=vfio0007_00_00_0,host=0007:00:00.0" \
-device "vfio-pci,id=vfio0007_00_00_1,host=0007:00:00.1" \
-device "vfio-pci,id=vfio0007_00_00_2,host=0007:00:00.2" \
-device "vfio-pci,id=vfio0035_04_00_0,host=0035:04:00.0" \
-device "vfio-pci,id=vfio0007_00_01_0,host=0007:00:01.0" \
-device "vfio-pci,id=vfio0007_00_01_1,host=0007:00:01.1" \
-device "vfio-pci,id=vfio0007_00_01_2,host=0007:00:01.2" -snapshot \
-machine pseries \
-L /home/aik/t/qemu-ppc64-bios/ -d guest_errors
Note that QEMU attaches PCI devices to the last added vPHB so first 8 devices - 4:04:00.0 till 6:00:01.2 - go to the default vPHB, and 35:03:00.0..7:00:01.2 to the vPHB with id=phb1.
--- hw/ppc/Makefile.objs | 2 +- hw/vfio/pci.h | 2 + include/hw/pci-host/spapr.h | 45 ++++ include/hw/ppc/spapr.h | 5 +- hw/ppc/spapr.c | 48 +++- hw/ppc/spapr_pci.c | 19 ++ hw/ppc/spapr_pci_nvlink2.c | 450 ++++++++++++++++++++++++++++++++++++ hw/vfio/pci-quirks.c | 131 +++++++++++ hw/vfio/pci.c | 14 ++ hw/vfio/trace-events | 4 + 10 files changed, 711 insertions(+), 9 deletions(-) create mode 100644 hw/ppc/spapr_pci_nvlink2.c
hw/ppc/Makefile.objs +1 -1
@@ -9,7 +9,7 @@ obj-$(CONFIG_SPAPR_RNG) += spapr_rng.o # IBM PowerNV obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o pnv_bmc.o ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy) -obj-y += spapr_pci_vfio.o +obj-y += spapr_pci_vfio.o spapr_pci_nvlink2.o endif obj-$(CONFIG_PSERIES) += spapr_rtas_ddw.o # PowerPC 4xx boards
hw/vfio/pci.h +2 -0
@@ -194,6 +194,8 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp);int vfio_pci_igd_opregion_init (VFIOPCIDevice *vdev,struct vfio_region_info *info,Error **errp); +int vfio_pci_nvidia_v100_ram_init (VFIOPCIDevice *vdev,Error **errp); +int vfio_pci_nvlink2_init (VFIOPCIDevice *vdev,Error **errp);void vfio_display_reset (VFIOPCIDevice *vdev);int vfio_display_probe (VFIOPCIDevice *vdev,Error **errp);
include/hw/pci-host/spapr.h +45 -0
69 lines not on this page · raw message
include/hw/ppc/spapr.h +4 -1
@@ -122,7 +122,8 @@ struct SpaprMachineClass {void (*phb_placement)(SpaprMachineState *spapr,uint32_t index,uint64_t *buid,hwaddr *pio,hwaddr *mmio32,hwaddr *mmio64, -unsigned n_dma,uint32_t *liobns,Error **errp); +unsigned n_dma,uint32_t *liobns,hwaddr *nv2gpa, +hwaddr *nv2atsd,Error **errp);SpaprResizeHpt resize_hpt_default;SpaprCapabilities default_caps;SpaprIrq *irq;
@@ -198,6 +199,8 @@ struct SpaprMachineState {bool cmd_line_caps[SPAPR_CAP_NUM ];SpaprCapabilities def, eff, mig; + +unsigned gpu_numa_id; };#define H_SUCCESS 0
hw/ppc/spapr.c +41 -7
104 lines not on this page · raw message
hw/ppc/spapr_pci.c +19 -0
@@ -1355,6 +1355,8 @@ static void spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int offset,if (sphb->pcie_ecs &&pci_is_express (dev)) {_FDT (fdt_setprop_cell (fdt, offset,"ibm,pci-config-space-type" ,0x1 )); } + +spapr_phb_nvgpu_populate_pcidev_dt (dev, fdt, offset, sphb); }/* create OF node for pci device and required OF DT properties */
@@ -1589,6 +1591,8 @@ static void spapr_phb_unrealize(DeviceState *dev, Error **errp)int i;const unsigned windows_supported =spapr_phb_windows_supported (sphb); +spapr_phb_nvgpu_free (sphb); +if (sphb->msi) {g_hash_table_unref (sphb->msi); sphb->msi =NULL ;
@@ -1877,8 +1881,14 @@ void spapr_phb_dma_reset(SpaprPhbState *sphb)static void spapr_phb_reset (DeviceState *qdev) {SpaprPhbState *sphb =SPAPR_PCI_HOST_BRIDGE (qdev); +Error *errp =NULL ;spapr_phb_dma_reset (sphb); +spapr_phb_nvgpu_free (sphb); +spapr_phb_nvgpu_setup (sphb, &errp); +if (errp) { +error_report_err (errp); + }/* Reset the IOMMU state */ object_child_foreach (OBJECT (qdev), spapr_phb_children_reset,NULL );
@@ -1911,6 +1921,8 @@ static Property spapr_phb_properties[] = { pre_2_8_migration, false),DEFINE_PROP_BOOL ("pcie-extended-configuration-space" , SpaprPhbState, pcie_ecs, true), +DEFINE_PROP_UINT64 ("gpa" , SpaprPhbState, nv2_gpa_win_addr,0 ), +DEFINE_PROP_UINT64 ("atsd" , SpaprPhbState, nv2_atsd_win_addr,0 ), DEFINE_PROP_END_OF_LIST(), };
@@ -2191,6 +2203,7 @@ int spapr_populate_pci_dt(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt,PCIBus *bus =PCI_HOST_BRIDGE (phb)->bus;SpaprFdt s_fdt;SpaprDrc *drc; +Error *errp =NULL ;/* Start populating the FDT */ nodename =g_strdup_printf ("pci@%" PRIx64, phb->buid);
@@ -2283,6 +2296,12 @@ int spapr_populate_pci_dt(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt,return ret; } +spapr_phb_nvgpu_populate_dt (phb, fdt, bus_off, &errp); +if (errp) { +error_report_err (errp); + } +spapr_phb_nvgpu_ram_populate_dt (phb, fdt); +return 0 ; }
hw/ppc/spapr_pci_nvlink2.c new file +450 -0
450 lines not on this page · raw message
hw/vfio/pci-quirks.c +131 -0
134 lines not on this page · raw message
hw/vfio/pci.c +14 -0
@@ -3069,6 +3069,20 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) goto out_teardown; } +if (vdev->vendor_id ==PCI_VENDOR_ID_NVIDIA ) { + ret =vfio_pci_nvidia_v100_ram_init (vdev, errp); +if (ret && ret != -ENODEV ) { +error_report ("Failed to setup NVIDIA V100 GPU RAM" ); + } + } + +if (vdev->vendor_id ==PCI_VENDOR_ID_IBM ) { + ret =vfio_pci_nvlink2_init (vdev, errp); +if (ret && ret != -ENODEV ) { +error_report ("Failed to setup NVlink2 bridge" ); + } + } +vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev);
hw/vfio/trace-events +4 -0
@@ -87,6 +87,10 @@ vfio_pci_igd_opregion_enabled(const char *name) "%s" vfio_pci_igd_host_bridge_enabled(const char *name) "%s" vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s" +vfio_pci_nvidia_gpu_setup_quirk(const char *name, uint64_t tgt, uint64_t size) "%s tgt=0x%"PRIx64" size=0x%"PRIx64 +vfio_pci_nvlink2_setup_quirk_ssatgt(const char *name, uint64_t tgt, uint64_t size) "%s tgt=0x%"PRIx64" size=0x%"PRIx64 +vfio_pci_nvlink2_setup_quirk_lnkspd(const char *name, uint32_t link_speed) "%s link_speed=0x%x" + # hw/vfio/common.c vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
Signature · 1 line
2.17.1