vfio: selftest: Add NVIDIA GPU Falcon DMA test driver
Subsystems (4)
v14 cover vfio: selftest: Add NVIDIA GPU Falcon DMA test driver
Patch 1:
Add a chunking loop to vfio_pci_driver_memcpy() so that it handles arbitrarily sized memcpy requests by breaking them into max_memcpy_size-sized chunks. This allows tests to request any memcpy size. Update the test to use a size of 4x max_memcpy_size to exercise the chunking logic.
Patch 2:
Add vfio_pci_cmd_set()/vfio_pci_cmd_clear() macros for PCI_COMMAND operations.
Patch 3:
Allow drivers that cannot trigger MSI interrupts to leave the send_msi callback NULL. Tests check ops->send_msi directly and gracefully skip MSI-related operations when it is absent.
Patch 4:
Introduce the nv_falcon plugin driver, which extracts and adapts relevant functionality from NVIDIA's gpu-admin-tools project [1] and integrates it into the VFIO selftest framework. As a result, any system equipped with a PCIe slot and a supported NVIDIA GPU can now run VFIO DMA selftests using commonly available hardware.
Falcons are general-purpose microcontrollers present on NVIDIA GPUs that can perform DMA operations between system memory and device memory.
[1] https://github.com/NVIDIA/gpu-admin-tools
Changes for v14:
- Re-tested with vfio_pci_driver_test on K2200, M60, P100, P4000, V100, T4, RTX 3090, RTX 4000 Ada and H100.
- Alex prepared this respin addressing David's review of v13.
- Patch 1 & 3: No change.
- Patch 2: R-b collected.
- Patch 4: address David's review -
- Include <linux/types.h>
- Factor out get_elapsed_ms()
- Rename NV_*_BOOT_COMPLETE_MASK to _SUCCESS
- Drop the redundant falcon_enable() and move the no_outside_reset check to the top of falcon_enable() so falcon_reset() is unconditional
- Fold dev_err() and size_to_dma_encoding() into nv_falcon_dma()
- Drop gpu->memcpy_count and the redundant GPU_ARCH_UNKNOWN assert
- Alignment fixes
Note on version numbering: v1 through v9 were internal review iterations that were mistakenly carried over to the upstream submission. Apologies for the confusion, the internal changelog has been dropped.
Rubin Du (4):
vfio: selftests: Add memcpy chunking to vfio_pci_driver_memcpy()
vfio: selftests: Add generic PCI command register helpers
vfio: selftests: Allow drivers without send_msi() support
vfio: selftests: Add NVIDIA Falcon driver for DMA testing
.../selftests/vfio/lib/drivers/nv_falcon/hw.h | 352 ++++++++ .../vfio/lib/drivers/nv_falcon/nv_falcon.c | 783 ++++++++++++++++++ .../lib/include/libvfio/vfio_pci_device.h | 14 + tools/testing/selftests/vfio/lib/libvfio.mk | 2 + .../selftests/vfio/lib/vfio_pci_driver.c | 21 +- .../selftests/vfio/vfio_pci_driver_test.c | 57 +- 6 files changed, 1206 insertions(+), 23 deletions(-) create mode 100644 tools/testing/selftests/vfio/lib/drivers/nv_falcon/hw.h create mode 100644 tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c
base-commit: d0c3bcd5b8976159d835a897254048e078f447e6 --
2.43.0
PATCH v14 1/4 vfio: selftests: Add memcpy chunking to vfio_pci_driver_memcpy()
Add a chunking loop to vfio_pci_driver_memcpy() so that it breaks up large memcpy requests into max_memcpy_size-sized chunks. This allows callers to request any size without worrying about per-driver limits. The memcpy_start()/memcpy_wait() semantics are unchanged.
Update the test to use 4x max_memcpy_size so it exercises the new chunking path (4 iterations) while keeping execution fast for drivers with small DMA transfer sizes.
--- .../selftests/vfio/lib/vfio_pci_driver.c | 18 ++++++++++++++++-- .../selftests/vfio/vfio_pci_driver_test.c | 18 ++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-)
tools/testing/selftests/vfio/lib/vfio_pci_driver.c +16 -2
@@ -106,7 +106,21 @@ int vfio_pci_driver_memcpy_wait(struct vfio_pci_device *device)int vfio_pci_driver_memcpy (struct vfio_pci_device *device,iova_t src,iova_t dst,u64 size) { -vfio_pci_driver_memcpy_start (device, src, dst, size,1 ); +struct vfio_pci_driver *driver = &device->driver; +u64 offset =0 ; + +while (offset < size) { +u64 chunk =min (size - offset, driver->max_memcpy_size); +int ret; + +vfio_pci_driver_memcpy_start (device, src + offset, + dst + offset, chunk,1 ); + ret =vfio_pci_driver_memcpy_wait (device); +if (ret) +return ret; + + offset += chunk; + } -return vfio_pci_driver_memcpy_wait (device); +return 0 ; }
tools/testing/selftests/vfio/vfio_pci_driver_test.c +10 -8
@@ -89,12 +89,12 @@ FIXTURE_SETUP(vfio_pci_driver_test) self->msi_fd = self->device->msi_eventfds[driver->msi];/* -* Use the maximum size supported by the device for memcpy operations, -* slimmed down to fit into the memcpy region (divided by 2 so src and -* dst regions do not overlap). +* Use 4x the driver's max_memcpy_size to exercise the chunking +* logic in vfio_pci_driver_memcpy(). Cap to half the memcpy +* region so src and dst do not overlap. */ - self->size = self->device->driver.max_memcpy_size; - self->size =min (self->size, self->memcpy_region.size /2 ); + self->size =min_t (u64, driver->max_memcpy_size *4 , + self->memcpy_region.size /2 ); self->src = self->memcpy_region.vaddr; self->dst = self->src + self->size;
@@ -211,6 +211,7 @@ TEST_F_TIMEOUT(vfio_pci_driver_test, memcpy_storm, 60) {struct vfio_pci_driver *driver = &self->device->driver;u64 total_size; +u64 size;u64 count;fcntl_set_nonblock (self->msi_fd);
@@ -221,13 +222,14 @@ TEST_F_TIMEOUT(vfio_pci_driver_test, memcpy_storm, 60)* will take too long. */ total_size =250UL *SZ_1G ; - count =min (total_size / self->size, driver->max_memcpy_count); + size =min (driver->max_memcpy_size, self->memcpy_region.size /2 ); + count =min (total_size / size, driver->max_memcpy_count); -printf ("Kicking off %lu memcpys of size 0x%lx\n" , count, self->size); +printf ("Kicking off %lu memcpys of size 0x%lx\n" , count, size);vfio_pci_driver_memcpy_start (self->device, self->src_iova, self->dst_iova, - self->size, count); + size, count);ASSERT_EQ (0 ,vfio_pci_driver_memcpy_wait (self->device));ASSERT_NO_MSI (self->msi_fd);
base-commit: d0c3bcd5b8976159d835a897254048e078f447e6
Signature · 1 line
2.43.0
PATCH v14 2/4 vfio: selftests: Add generic PCI command register helpers
In reply to Rubin DuAdd vfio_pci_cmd_set()/vfio_pci_cmd_clear() read-modify-write macros for PCI_COMMAND in vfio_pci_device.h.
--- .../vfio/lib/include/libvfio/vfio_pci_device.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +14 -0
@@ -65,6 +65,20 @@ void vfio_pci_config_access(struct vfio_pci_device *device, bool write,#define vfio_pci_config_writew (_d, _o, _v) vfio_pci_config_write(_d, _o, _v, u16)#define vfio_pci_config_writel (_d, _o, _v) vfio_pci_config_write(_d, _o, _v, u32) +static inline void vfio_pci_cmd_set (struct vfio_pci_device *device,u16 bits) +{ +u16 cmd =vfio_pci_config_readw (device,PCI_COMMAND ); + +vfio_pci_config_writew (device,PCI_COMMAND , cmd | bits); +} + +static inline void vfio_pci_cmd_clear (struct vfio_pci_device *device,u16 bits) +{ +u16 cmd =vfio_pci_config_readw (device,PCI_COMMAND ); + +vfio_pci_config_writew (device,PCI_COMMAND , cmd & ~bits); +} +void vfio_pci_irq_enable (struct vfio_pci_device *device,u32 index,u32 vector,int count);void vfio_pci_irq_disable (struct vfio_pci_device *device,u32 index);
Signature · 1 line
2.43.0
PATCH v14 3/4 vfio: selftests: Allow drivers without send_msi() support
In reply to Rubin DuAllow drivers that cannot trigger MSI interrupts to leave the send_msi callback NULL. Add an fcntl_set_msi_nonblock() wrapper that only sets nonblocking mode when send_msi is available, and update ASSERT_NO_MSI() to skip when the driver lacks MSI support. The send_msi test SKIPs and mix_and_match skips the MSI portion per iteration.
--- .../selftests/vfio/vfio_pci_driver_test.c | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-)
tools/testing/selftests/vfio/vfio_pci_driver_test.c +26 -13
@@ -11,11 +11,18 @@static const char *device_bdf; -#define ASSERT_NO_MSI (_eventfd) do { \ - u64 __value; \ - \ - ASSERT_EQ(-1, read(_eventfd, &__value, 8)); \ - ASSERT_EQ(EAGAIN, errno); \ +#define fcntl_set_msi_nonblock (_self) do { \ + if (_self->device->driver.ops->send_msi) \ + fcntl_set_nonblock(_self->msi_fd); \ +} while (0) + +#define ASSERT_NO_MSI (_self) do { \ + u64 __value; \ + \ + if (!_self->device->driver.ops->send_msi) \ + break; \ + ASSERT_EQ(-1, read(_self->msi_fd, &__value, 8)); \ + ASSERT_EQ(EAGAIN, errno); \ } while (0) static void region_setup(struct iommu *iommu,
@@ -129,7 +136,7 @@ TEST_F(vfio_pci_driver_test, init_remove) TEST_F(vfio_pci_driver_test, memcpy_success) { -fcntl_set_nonblock (self->msi_fd); +fcntl_set_msi_nonblock (self);memset (self->src,'x' , self->size);memset (self->dst,'y' , self->size);
@@ -140,12 +147,12 @@ TEST_F(vfio_pci_driver_test, memcpy_success) self->size));ASSERT_EQ (0 ,memcmp (self->src, self->dst, self->size)); -ASSERT_NO_MSI (self->msi_fd); +ASSERT_NO_MSI (self); } TEST_F(vfio_pci_driver_test, memcpy_from_unmapped_iova) { -fcntl_set_nonblock (self->msi_fd); +fcntl_set_msi_nonblock (self);/* * Ignore the return value since not all devices will detect and report
@@ -154,12 +161,12 @@ TEST_F(vfio_pci_driver_test, memcpy_from_unmapped_iova)vfio_pci_driver_memcpy (self->device, self->unmapped_iova, self->dst_iova, self->size); -ASSERT_NO_MSI (self->msi_fd); +ASSERT_NO_MSI (self); } TEST_F(vfio_pci_driver_test, memcpy_to_unmapped_iova) { -fcntl_set_nonblock (self->msi_fd); +fcntl_set_msi_nonblock (self);/* * Ignore the return value since not all devices will detect and report
@@ -168,13 +175,16 @@ TEST_F(vfio_pci_driver_test, memcpy_to_unmapped_iova)vfio_pci_driver_memcpy (self->device, self->src_iova, self->unmapped_iova, self->size); -ASSERT_NO_MSI (self->msi_fd); +ASSERT_NO_MSI (self); } TEST_F(vfio_pci_driver_test, send_msi) {u64 value; +if (!self->device->driver.ops->send_msi) +SKIP (return,"Driver does not support send_msi()\n" ); +vfio_pci_driver_send_msi (self->device);ASSERT_EQ (8 ,read (self->msi_fd, &value,8 ));ASSERT_EQ (1 , value);
@@ -201,6 +211,9 @@ TEST_F(vfio_pci_driver_test, mix_and_match) self->dst_iova, self->size); +if (!self->device->driver.ops->send_msi) +continue ; +vfio_pci_driver_send_msi (self->device);ASSERT_EQ (8 ,read (self->msi_fd, &value,8 ));ASSERT_EQ (1 , value);
@@ -214,7 +227,7 @@ TEST_F_TIMEOUT(vfio_pci_driver_test, memcpy_storm, 60)u64 size;u64 count; -fcntl_set_nonblock (self->msi_fd); +fcntl_set_msi_nonblock (self);/* * Perform up to 250GiB worth of DMA reads and writes across several
@@ -232,7 +245,7 @@ TEST_F_TIMEOUT(vfio_pci_driver_test, memcpy_storm, 60) size, count);ASSERT_EQ (0 ,vfio_pci_driver_memcpy_wait (self->device)); -ASSERT_NO_MSI (self->msi_fd); +ASSERT_NO_MSI (self); }static bool device_has_selftests_driver (const char *bdf)
Signature · 1 line
2.43.0
PATCH v14 4/4 vfio: selftests: Add NVIDIA Falcon driver for DMA testing
In reply to Rubin DuAdd a new VFIO PCI driver for NVIDIA GPUs that enables DMA testing via the Falcon (Fast Logic Controller) microcontrollers. This driver extracts and adapts the DMA test functionality from NVIDIA's gpu-admin-tools project and integrates it into the existing VFIO selftest framework.
Falcons are general-purpose microcontrollers present on NVIDIA GPUs that can perform DMA operations between system memory and device memory. By leveraging Falcon DMA, this driver allows NVIDIA GPUs to be tested alongside Intel IOAT and DSA devices using the same selftest infrastructure.
The driver is named 'nv_falcon' to reflect that it specifically controls the Falcon microcontrollers for DMA operations, rather than exposing general GPU functionality.
Reference implementation:
https://github.com/NVIDIA/gpu-admin-tools
--- .../selftests/vfio/lib/drivers/nv_falcon/hw.h | 352 ++++++++ .../vfio/lib/drivers/nv_falcon/nv_falcon.c | 783 ++++++++++++++++++ tools/testing/selftests/vfio/lib/libvfio.mk | 2 + .../selftests/vfio/lib/vfio_pci_driver.c | 3 + 4 files changed, 1140 insertions(+) create mode 100644 tools/testing/selftests/vfio/lib/drivers/nv_falcon/hw.h create mode 100644 tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c
tools/testing/selftests/vfio/lib/drivers/nv_falcon/hw.h new file +352 -0
@@ -0,0 +1,352 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +*/ +#ifndef _NV_FALCON_HW_H_ +#define _NV_FALCON_HW_H_ + +#include <linux/types.h> + +/* PMC (Power Management Controller) Registers */ +#define NV_PMC_BOOT_0 0x00000000 +#define NV_PMC_ENABLE 0x00000200 +#define NV_PMC_ENABLE_PWR 0x00002000 +#define NV_PMC_ENABLE_HUB 0x20000000 + +/* Falcon Base Pages for Different Engines */ +#define NV_PPWR_FALCON_BASE 0x10a000 +#define NV_PGSP_FALCON_BASE 0x110000 + +/* Falcon Common Register Offsets (relative to base_page) */ +#define NV_FALCON_DMACTL_OFFSET 0x010c +#define NV_FALCON_ENGINE_RESET_OFFSET 0x03c0 + +/* DMEM Control Register Flags */ +#define NV_PPWR_FALCON_DMEMC_AINCR_TRUE 0x01000000 +#define NV_PPWR_FALCON_DMEMC_AINCW_TRUE 0x02000000 + +/* Falcon DMEM port offsets (for port 0) */ +#define NV_FALCON_DMEMC_OFFSET 0x1c0 +#define NV_FALCON_DMEMD_OFFSET 0x1c4 + +/* DMA Register Offsets (relative to base_page) */ +#define NV_FALCON_DMA_ADDR_LOW_OFFSET 0x110 +#define NV_FALCON_DMA_MEM_OFFSET 0x114 +#define NV_FALCON_DMA_CMD_OFFSET 0x118 +#define NV_FALCON_DMA_BLOCK_OFFSET 0x11c +#define NV_FALCON_DMA_ADDR_HIGH_OFFSET 0x128 + +/* DMA Global Address Top Bits Register */ +#define NV_GPU_DMA_ADDR_TOP_BITS_REG 0x100f04 + +/* DMA Command Register Bit Definitions */ +#define NV_FALCON_DMA_CMD_WRITE_BIT 0x20 +#define NV_FALCON_DMA_CMD_SIZE_SHIFT 8 +#define NV_FALCON_DMA_CMD_DONE_BIT 0x2 + +/* +* Falcon DMA is synchronous, so a transfer size and count larger than +* its per-operation maximum adds no value. +*/ + +/* DMA block size and alignment */ +#define NV_FALCON_DMA_MIN_TRANSFER_SIZE 4 +#define NV_FALCON_DMA_MAX_TRANSFER_SIZE 256 +#define NV_FALCON_DMA_BLOCK_SIZE 256 +#define NV_FALCON_DMA_MAX_TRANSFER_COUNT 1 + +/* DMACTL register bits */ +#define NV_FALCON_DMACTL_DMEM_SCRUBBING 0x1 +#define NV_FALCON_DMACTL_READY_MASK 0x6 + +/* Falcon Core Selection Register */ +#define NV_FALCON_CORE_SELECT_OFFSET 0x1668 +#define NV_FALCON_CORE_SELECT_MASK 0x30 + +/* Falcon mailbox register (for Ada+ reset check) */ +#define NV_FALCON_MAILBOX_TEST_OFFSET 0x40c +#define NV_FALCON_MAILBOX_RESET_MAGIC 0xbadf5620 + +/* Falcon Message Queue Register Offsets (relative to base_page) */ +#define NV_FALCON_QUEUE_HEAD_BASE_OFFSET 0x2c00 +#define NV_FALCON_QUEUE_TAIL_BASE_OFFSET 0x2c04 +#define NV_FALCON_QUEUE_STRIDE 0x8 +#define NV_FALCON_MSG_QUEUE_HEAD_BASE_OFFSET 0x2c80 +#define NV_FALCON_MSG_QUEUE_TAIL_BASE_OFFSET 0x2c84 + +/* FSP Falcon Base Pages */ +#define NV_FSP_FALCON_BASE 0x8f0100 +/* base_page = cpuctl & ~0xfff */ +#define NV_FSP_FALCON_BASE_PAGE 0x8f0000 +#define NV_FSP_EMEM_BASE 0x8f2000 + +/* FSP EMEM Port Offsets (relative to FSP EMEM base) */ +#define NV_FSP_EMEMC_OFFSET 0xac0 +#define NV_FSP_EMEMD_OFFSET 0xac4 +#define NV_FSP_EMEM_PORT_STRIDE 0x8 + +/* EMEM Control Register Flags (same as DMEM) */ +#define NV_FALCON_EMEMC_AINCR 0x01000000 +#define NV_FALCON_EMEMC_AINCW 0x02000000 + +/* FSP RPC channel configuration */ +#define NV_FSP_RPC_CHANNEL_SIZE 1024 +#define NV_FSP_RPC_MAX_PACKET_SIZE 1024 +#define NV_FSP_RPC_CHANNEL_HOPPER 2 +#define NV_FSP_RPC_EMEM_BASE \ + (NV_FSP_RPC_CHANNEL_HOPPER * NV_FSP_RPC_CHANNEL_SIZE) + +/* FSP EMEM port 2 registers (pre-computed for Hopper channel 2) */ +#define NV_FSP_EMEM_PORT2_CTRL (NV_FSP_EMEM_BASE + NV_FSP_EMEMC_OFFSET + \ + NV_FSP_RPC_CHANNEL_HOPPER * NV_FSP_EMEM_PORT_STRIDE) +#define NV_FSP_EMEM_PORT2_DATA (NV_FSP_EMEM_BASE + NV_FSP_EMEMD_OFFSET + \ + NV_FSP_RPC_CHANNEL_HOPPER * NV_FSP_EMEM_PORT_STRIDE) + +/* FSP queue register offsets (pre-computed for Hopper channel 2) */ +#define NV_FSP_QUEUE_HEAD \ + (NV_FSP_FALCON_BASE_PAGE + NV_FALCON_QUEUE_HEAD_BASE_OFFSET + \ + NV_FSP_RPC_CHANNEL_HOPPER * NV_FALCON_QUEUE_STRIDE) +#define NV_FSP_QUEUE_TAIL \ + (NV_FSP_FALCON_BASE_PAGE + NV_FALCON_QUEUE_TAIL_BASE_OFFSET + \ + NV_FSP_RPC_CHANNEL_HOPPER * NV_FALCON_QUEUE_STRIDE) +#define NV_FSP_MSG_QUEUE_HEAD \ + (NV_FSP_FALCON_BASE_PAGE + NV_FALCON_MSG_QUEUE_HEAD_BASE_OFFSET + \ + NV_FSP_RPC_CHANNEL_HOPPER * NV_FALCON_QUEUE_STRIDE) +#define NV_FSP_MSG_QUEUE_TAIL \ + (NV_FSP_FALCON_BASE_PAGE + NV_FALCON_MSG_QUEUE_TAIL_BASE_OFFSET + \ + NV_FSP_RPC_CHANNEL_HOPPER * NV_FALCON_QUEUE_STRIDE) + +/* MCTP Header */ +#define NV_MCTP_HDR_SEID_SHIFT 16 +#define NV_MCTP_HDR_SEID_MASK 0xff +#define NV_MCTP_HDR_SEQ_SHIFT 28 +#define NV_MCTP_HDR_SEQ_MASK 0x3 +#define NV_MCTP_HDR_EOM_BIT 0x40000000 +#define NV_MCTP_HDR_SOM_BIT 0x80000000 + +/* MCTP Message Header */ +#define NV_MCTP_MSG_TYPE_SHIFT 0 +#define NV_MCTP_MSG_TYPE_MASK 0x7f +#define NV_MCTP_MSG_TYPE_VENDOR_DEFINED 0x7e +#define NV_MCTP_MSG_VENDOR_ID_SHIFT 8 +#define NV_MCTP_MSG_VENDOR_ID_MASK 0xffff +#define NV_MCTP_MSG_VENDOR_ID_NVIDIA 0x10de +#define NV_MCTP_MSG_NVDM_TYPE_SHIFT 24 +#define NV_MCTP_MSG_NVDM_TYPE_MASK 0xff + +/* NVDM response type */ +#define NV_NVDM_TYPE_RESPONSE 0x15 + +/* Minimum response size: mctp_hdr + msg_hdr + status_hdr + type + status */ +#define NV_FSP_RPC_MIN_RESPONSE_WORDS 5 + +/* FBIF (Frame Buffer Interface) Registers */ +/* Legacy PMU FBIF offsets (Kepler, Maxwell Gen1) */ +#define NV_PMU_LEGACY_FBIF_CTL_OFFSET 0x624 +#define NV_PMU_LEGACY_FBIF_TRANSCFG_OFFSET 0x600 + +/* PMU FBIF offsets */ +#define NV_PMU_FBIF_CTL_OFFSET 0xe24 +#define NV_PMU_FBIF_TRANSCFG_OFFSET 0xe00 + +/* GSP FBIF offsets */ +#define NV_GSP_FBIF_CTL_OFFSET 0x624 +#define NV_GSP_FBIF_TRANSCFG_OFFSET 0x600 + +/* OFA Falcon Base Page and FBIF offsets (used for Hopper+ DMA) */ +#define NV_OFA_FALCON_BASE 0x844000 +#define NV_OFA_FBIF_CTL_OFFSET 0x424 +#define NV_OFA_FBIF_TRANSCFG_OFFSET 0x400 + +/* OFA DMA support check register (Hopper+) */ +#define NV_OFA_DMA_SUPPORT_CHECK_REG 0x8443c0 + +/* FSP NVDM command types */ +#define NV_NVDM_TYPE_FBDMA 0x22 +#define NV_FBDMA_SUBCMD_ENABLE 0x1 + +/* FBIF CTL2 offset (relative to fbif_ctl) */ +#define NV_FBIF_CTL2_OFFSET 0x60 + +/* FBIF TRANSCFG register bits */ +#define NV_FBIF_TRANSCFG_TARGET_MASK 0x3 +#define NV_FBIF_TRANSCFG_SYSMEM_DEFAULT 0x5 + +/* FBIF CTL register bits */ +#define NV_FBIF_CTL_ALLOW_PHYS_MODE 0x10 +#define NV_FBIF_CTL_ALLOW_FULL_PHYS_MODE 0x80 + +/* Memory clear register offsets */ +#define NV_MEM_CLEAR_OFFSET 0x100b20 +#define NV_BOOT_COMPLETE_OFFSET 0x118234 +#define NV_BOOT_COMPLETE_SUCCESS 0x3ff + +/* FSP boot complete register (Hopper+) */ +#define NV_FSP_BOOT_COMPLETE_OFFSET 0x200bc +#define NV_FSP_BOOT_COMPLETE_SUCCESS 0xff + +enum gpu_arch { +GPU_ARCH_UNKNOWN =-1 , +GPU_ARCH_KEPLER =0 , +GPU_ARCH_MAXWELL_GEN1 , +GPU_ARCH_MAXWELL_GEN2 , +GPU_ARCH_PASCAL , +GPU_ARCH_PASCAL_10X , +GPU_ARCH_VOLTA , +GPU_ARCH_TURING , +GPU_ARCH_AMPERE , +GPU_ARCH_ADA , +GPU_ARCH_HOPPER , +}; + +enum falcon_type { +FALCON_TYPE_PMU_LEGACY =0 , +FALCON_TYPE_PMU , +FALCON_TYPE_GSP , +FALCON_TYPE_OFA , +}; + +struct falcon { +u32 base_page; +u32 dmactl; +u32 engine_reset; +u32 fbif_ctl; +u32 fbif_ctl2; +u32 fbif_transcfg; +u32 dmem_control_reg; +u32 dmem_data_reg; +bool no_outside_reset; +}; + +struct gpu_properties { +u32 pmc_enable_mask; +bool memory_clear_supported; +enum falcon_type falcon_type; +}; + +static const u32 verified_gpu_map[] = { +0x0e40a0a2 ,/* K520 */ +0x0e6000a1 ,/* GTX660 */ +0x0e63a0a1 ,/* K4000 */ +0x0f22d0a1 ,/* K80 */ +0x108000a1 ,/* GT635 */ +0x117010a2 ,/* GTX750 */ +0x117020a2 ,/* GTX745 */ +0x124320a1 ,/* M60 */ +0x130000a1 ,/* P100 */ +0x134000a1 ,/* P4 */ +0x132000a1 ,/* P40 */ +0x140000a1 ,/* V100 */ +0x164000a1 ,/* T4 */ +0xb77000a1 ,/* A16 */ +0x170000a1 ,/* A100 */ +0xb72000a1 ,/* A10 */ +0x180000a1 ,/* H100 */ +0x194000a1 ,/* L4 */ +0x192000a1 ,/* L40S */ +}; + +#define VERIFIED_GPU_MAP_SIZE ARRAY_SIZE(verified_gpu_map) + +static const struct gpu_properties gpu_properties_map[] = { + [GPU_ARCH_KEPLER ] = { + .pmc_enable_mask =NV_PMC_ENABLE_PWR |NV_PMC_ENABLE_HUB , + .memory_clear_supported = false, + .falcon_type =FALCON_TYPE_PMU_LEGACY , + }, + [GPU_ARCH_MAXWELL_GEN1 ] = { + .pmc_enable_mask =NV_PMC_ENABLE_PWR |NV_PMC_ENABLE_HUB , + .memory_clear_supported = false, + .falcon_type =FALCON_TYPE_PMU_LEGACY , + }, + [GPU_ARCH_MAXWELL_GEN2 ] = { + .pmc_enable_mask =NV_PMC_ENABLE_PWR , + .memory_clear_supported = false, + .falcon_type =FALCON_TYPE_PMU , + }, + [GPU_ARCH_PASCAL ] = { + .pmc_enable_mask =NV_PMC_ENABLE_PWR , + .memory_clear_supported = false, + .falcon_type =FALCON_TYPE_PMU , + }, + [GPU_ARCH_PASCAL_10X ] = { + .pmc_enable_mask =0 , + .memory_clear_supported = false, + .falcon_type =FALCON_TYPE_PMU , + }, + [GPU_ARCH_VOLTA ] = { + .pmc_enable_mask =0 , + .memory_clear_supported = false, + .falcon_type =FALCON_TYPE_GSP , + }, + [GPU_ARCH_TURING ] = { + .pmc_enable_mask =0 , + .memory_clear_supported = true, + .falcon_type =FALCON_TYPE_GSP , + }, + [GPU_ARCH_AMPERE ] = { + .pmc_enable_mask =0 , + .memory_clear_supported = true, + .falcon_type =FALCON_TYPE_GSP , + }, + [GPU_ARCH_ADA ] = { + .pmc_enable_mask =0 , + .memory_clear_supported = true, + .falcon_type =FALCON_TYPE_PMU , + }, + [GPU_ARCH_HOPPER ] = { + .pmc_enable_mask =0 , + .memory_clear_supported = true, + .falcon_type =FALCON_TYPE_OFA , + }, +}; + +static const struct falcon falcon_map[] = { + [FALCON_TYPE_PMU_LEGACY ] = { + .base_page =NV_PPWR_FALCON_BASE , + .dmactl =NV_PPWR_FALCON_BASE +NV_FALCON_DMACTL_OFFSET , + .engine_reset =NV_PPWR_FALCON_BASE +NV_FALCON_ENGINE_RESET_OFFSET , + .fbif_ctl =NV_PPWR_FALCON_BASE +NV_PMU_LEGACY_FBIF_CTL_OFFSET , + .fbif_ctl2 =NV_PPWR_FALCON_BASE + +NV_PMU_LEGACY_FBIF_CTL_OFFSET +NV_FBIF_CTL2_OFFSET , + .fbif_transcfg =NV_PPWR_FALCON_BASE +NV_PMU_LEGACY_FBIF_TRANSCFG_OFFSET , + .dmem_control_reg =NV_PPWR_FALCON_BASE +NV_FALCON_DMEMC_OFFSET , + .dmem_data_reg =NV_PPWR_FALCON_BASE +NV_FALCON_DMEMD_OFFSET , + .no_outside_reset = false, + }, + [FALCON_TYPE_PMU ] = { + .base_page =NV_PPWR_FALCON_BASE , + .dmactl =NV_PPWR_FALCON_BASE +NV_FALCON_DMACTL_OFFSET , + .engine_reset =NV_PPWR_FALCON_BASE +NV_FALCON_ENGINE_RESET_OFFSET , + .fbif_ctl =NV_PPWR_FALCON_BASE +NV_PMU_FBIF_CTL_OFFSET , + .fbif_ctl2 =NV_PPWR_FALCON_BASE +NV_PMU_FBIF_CTL_OFFSET +NV_FBIF_CTL2_OFFSET , + .fbif_transcfg =NV_PPWR_FALCON_BASE +NV_PMU_FBIF_TRANSCFG_OFFSET , + .dmem_control_reg =NV_PPWR_FALCON_BASE +NV_FALCON_DMEMC_OFFSET , + .dmem_data_reg =NV_PPWR_FALCON_BASE +NV_FALCON_DMEMD_OFFSET , + .no_outside_reset = false, + }, + [FALCON_TYPE_GSP ] = { + .base_page =NV_PGSP_FALCON_BASE , + .dmactl =NV_PGSP_FALCON_BASE +NV_FALCON_DMACTL_OFFSET , + .engine_reset =NV_PGSP_FALCON_BASE +NV_FALCON_ENGINE_RESET_OFFSET , + .fbif_ctl =NV_PGSP_FALCON_BASE +NV_GSP_FBIF_CTL_OFFSET , + .fbif_ctl2 =NV_PGSP_FALCON_BASE +NV_GSP_FBIF_CTL_OFFSET +NV_FBIF_CTL2_OFFSET , + .fbif_transcfg =NV_PGSP_FALCON_BASE +NV_GSP_FBIF_TRANSCFG_OFFSET , + .dmem_control_reg =NV_PGSP_FALCON_BASE +NV_FALCON_DMEMC_OFFSET , + .dmem_data_reg =NV_PGSP_FALCON_BASE +NV_FALCON_DMEMD_OFFSET , + .no_outside_reset = false, + }, + [FALCON_TYPE_OFA ] = { + .base_page =NV_OFA_FALCON_BASE , + .dmactl =NV_OFA_FALCON_BASE +NV_FALCON_DMACTL_OFFSET , + .engine_reset =NV_OFA_FALCON_BASE +NV_FALCON_ENGINE_RESET_OFFSET , + .fbif_ctl =NV_OFA_FALCON_BASE +NV_OFA_FBIF_CTL_OFFSET , + .fbif_ctl2 =NV_OFA_FALCON_BASE +NV_OFA_FBIF_CTL_OFFSET +NV_FBIF_CTL2_OFFSET , + .fbif_transcfg =NV_OFA_FALCON_BASE +NV_OFA_FBIF_TRANSCFG_OFFSET , + .dmem_control_reg =NV_OFA_FALCON_BASE +NV_FALCON_DMEMC_OFFSET , + .dmem_data_reg =NV_OFA_FALCON_BASE +NV_FALCON_DMEMD_OFFSET , + .no_outside_reset = true, + }, +}; + +#endif /* _NV_FALCON_HW_H_ */
tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c new file +783 -0
783 lines not on this page · raw message
tools/testing/selftests/vfio/lib/libvfio.mk +2 -0
@@ -14,6 +14,8 @@ LIBVFIO_C += drivers/ioat/ioat.c LIBVFIO_C += drivers/dsa/dsa.c endif +LIBVFIO_C += drivers/nv_falcon/nv_falcon.c + LIBVFIO_OUTPUT := $(OUTPUT)/libvfio LIBVFIO_O := $(patsubst %.c, $(LIBVFIO_OUTPUT)/%.o, $(LIBVFIO_C))
tools/testing/selftests/vfio/lib/vfio_pci_driver.c +3 -0
@@ -7,11 +7,14 @@ extern struct vfio_pci_driver_ops dsa_ops;extern struct vfio_pci_driver_ops ioat_ops;#endif +extern struct vfio_pci_driver_ops nv_falcon_ops; +static struct vfio_pci_driver_ops *driver_ops[] = { #ifdef __x86_64__ &dsa_ops, &ioat_ops, #endif + &nv_falcon_ops, };void vfio_pci_driver_probe (struct vfio_pci_device *device)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v14 4/4] vfio: selftests: Add NVIDIA Falcon driver for DMA testing
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Double fetch of the NV_PMC_BOOT_0 register leads to unvalidated array index and out-of-bounds…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Double fetch of the NV_PMC_BOOT_0 register leads to unvalidated array index and out-of-bounds access.
- [Medium] Missing 4-byte alignment validation for source and destination addresses causes an assertion crash. --
commit 50161cb43066f380e2c0477f9ea68885628a0a3b
Author: Rubin Du <[email protected]>
vfio: selftests: Add NVIDIA Falcon driver for DMA testing
This patch adds a new VFIO PCI driver for NVIDIA GPUs to enable DMA testing via Falcon microcontrollers within the existing VFIO selftest framework.
Quoted 5 lines
tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c new file +0
-0
[ ... ]
Quoted 6 lines
tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c new file +6
-0+static void nv_falcon_init (struct vfio_pci_device *device) +{ +struct gpu_device *gpu =to_gpu_device (device); +const struct gpu_properties *props; +u32 pmc_boot_0; +int ret;
tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c line 683
Quoted 10 lines
tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c new file +10
-0+ +VFIO_ASSERT_GE (device->driver.region.size,sizeof (*gpu)); + +/* Read PMC_BOOT_0 register from BAR0 to identify GPU */ + pmc_boot_0 =readl (device->bars[0 ].vaddr +NV_PMC_BOOT_0 ); + +/* Look up GPU architecture */ + gpu->arch =nv_gpu_arch_lookup (pmc_boot_0); + + props = &gpu_properties_map[gpu->arch];
[Severity: Medium]
Since the NV_PMC_BOOT_0 register is re-read from MMIO here rather than reusing the validated value from nv_falcon_probe(), could a hardware state change cause nv_gpu_arch_lookup() to return GPU_ARCH_UNKNOWN (-1)?
If so, this would use -1 as an out-of-bounds index into gpu_properties_map. Would it be safer to store the validated architecture in the device struct during probe, or validate the return value of nv_gpu_arch_lookup() here?
[ ... ]
tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c line 721
Quoted 12 lines
tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c new file +12
-0+static void nv_falcon_memcpy_start (struct vfio_pci_device *device, +iova_t src,iova_t dst,u64 size,u64 count) +{ +struct gpu_device *gpu =to_gpu_device (device); + +VFIO_ASSERT_EQ (count,1 ); +VFIO_ASSERT_EQ (size & (NV_FALCON_DMA_MIN_TRANSFER_SIZE -1 ),0 , +"size 0x%lx must be %u-byte aligned\n" , + (unsigned long )size,NV_FALCON_DMA_MIN_TRANSFER_SIZE ); + + gpu->memcpy_src = src; + gpu->memcpy_dst = dst;
[Severity: Medium]
Does this function also need to validate that the src and dst addresses are 4-byte aligned?
If an unaligned address is passed (e.g., offset by 1 byte), dma_block_remain() in nv_falcon_memcpy_wait() will yield a chunk size of 1. This invalid size is then passed to nv_falcon_dma(), which triggers the VFIO_ASSERT_GE(size, NV_FALCON_DMA_MIN_TRANSFER_SIZE) assertion in size_to_dma_encoding() and crashes the test framework.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v14 4/4] vfio: selftests: Add NVIDIA Falcon driver for DMA testing
In reply to Rubin DuQuoted 16 lines · Rubin Du
Add a new VFIO PCI driver for NVIDIA GPUs that enables DMA testing via the Falcon (Fast Logic Controller) microcontrollers. This driver extracts and adapts the DMA test functionality from NVIDIA's gpu-admin-tools project and integrates it into the existing VFIO selftest framework.
Falcons are general-purpose microcontrollers present on NVIDIA GPUs that can perform DMA operations between system memory and device memory. By leveraging Falcon DMA, this driver allows NVIDIA GPUs to be tested alongside Intel IOAT and DSA devices using the same selftest infrastructure.
The driver is named '
nv_falcon' to reflect that it specifically controls the Falcon microcontrollers for DMA operations, rather than exposing general GPU functionality.
Quoted 5 lines
Reference implementation:
https://github.com/NVIDIA/gpu-admin-toolsSigned-off-by Alex Williamson <[email protected]>Signed-off-by Rubin Du <[email protected]>
Quoted 71 lines · On Tue, 9 Jun 2026 16:28:51 -0700 Rubin Du <[email protected]> wrote:
Patch 1:
Add a chunking loop to
vfio_pci_driver_memcpy()so that it handles arbitrarily sized memcpy requests by breaking them into max_memcpy_size-sized chunks. This allows tests to request any memcpy size. Update the test to use a size of 4xmax_memcpy_sizeto exercise the chunking logic.Patch 2:
Add vfio_pci_cmd_set()/vfio_pci_cmd_clear() macros for
PCI_COMMANDoperations.Patch 3:
Allow drivers that cannot trigger MSI interrupts to leave the
send_msicallback NULL. Tests checkops->send_msidirectly and gracefully skip MSI-related operations when it is absent.Patch 4:
Introduce the
nv_falconplugin driver, which extracts and adapts relevant functionality from NVIDIA's gpu-admin-tools project [1] and integrates it into the VFIO selftest framework. As a result, any system equipped with a PCIe slot and a supported NVIDIA GPU can now run VFIO DMA selftests using commonly available hardware.Falcons are general-purpose microcontrollers present on NVIDIA GPUs that can perform DMA operations between system memory and device memory.
[1] https://github.com/NVIDIA/gpu-admin-tools
Changes for v14:
- Re-tested withvfio_pci_driver_teston K2200, M60, P100, P4000, V100, T4, RTX 3090, RTX 4000 Ada and H100.
- Alex prepared this respin addressing David's review of v13.
- Patch 1 & 3: No change.
- Patch 2: R-b collected.
- Patch 4: address David's review -
- Include <linux/types.h>
- Factor outget_elapsed_ms()
- Rename NV_*_BOOT_COMPLETE_MASK to_SUCCESS
- Drop the redundantfalcon_enable()and move theno_outside_resetcheck to the top offalcon_enable()sofalcon_reset()is unconditional
- Folddev_err()andsize_to_dma_encoding()intonv_falcon_dma()
- Dropgpu->memcpy_countand the redundantGPU_ARCH_UNKNOWNassert
- Alignment fixesNote on version numbering: v1 through v9 were internal review iterations that were mistakenly carried over to the upstream submission. Apologies for the confusion, the internal changelog has been dropped.
Rubin Du (4):
vfio: selftests: Add memcpy chunking tovfio_pci_driver_memcpy()
vfio: selftests: Add generic PCI command register helpers
vfio: selftests: Allow drivers withoutsend_msi()support
vfio: selftests: Add NVIDIA Falcon driver for DMA testing.../selftests/vfio/lib/drivers/nv_falcon/hw.h | 352 ++++++++ .../vfio/lib/drivers/nv_falcon/nv_falcon.c | 783 ++++++++++++++++++ .../lib/include/libvfio/vfio_pci_device.h | 14 + tools/testing/selftests/vfio/lib/libvfio.mk | 2 + .../selftests/vfio/lib/vfio_pci_driver.c | 21 +- .../selftests/vfio/vfio_pci_driver_test.c | 57 +- 6 files changed, 1206 insertions(+), 23 deletions(-) create mode 100644 tools/testing/selftests/vfio/lib/drivers/nv_falcon/hw.h create mode 100644 tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c
Quoted 3 lines
base-commit:
d0c3bcd5b8976159d835a897254048e078f447e6--
2.43.0
Applied to vfio next branch for v7.3. Thanks,
Alex