vfio/nvgrace-gpu: Add Blackwell-Next GPU readiness check via CXL DVSEC
Subsystems (5)
Ankit Agrawal
maintainerPATCH v3 1/1 vfio/nvgrace-gpu: Add Blackwell-Next GPU readiness check via CXL DVSEC
Add a CXL DVSEC-based readiness check for Blackwell-Next GPUs alongside the existing legacy BAR0 polling path. On probe and after reset, the driver reads the CXL Device DVSEC capability to determine whether the GPU memory is valid. This is checked by polling on the Memory_Active bit based on the Memory_Active_Timeout. Also check if MEM_INFO_VALID is set within 1 second per CXL spec 4.0 Tables 8-13. If not, return error.
A static inline wrapper dispatches to the appropriate readiness check based on whether the CXL DVSEC capability is present.
Add PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT to pci_regs.h for the timeout field encoding.
--- drivers/vfio/pci/nvgrace-gpu/main.c | 96 ++++++++++++++++++++++++++--- include/uapi/linux/pci_regs.h | 1 + 2 files changed, 89 insertions(+), 8 deletions(-)
drivers/vfio/pci/nvgrace-gpu/main.c +88 -8
@@ -64,6 +64,8 @@ struct nvgrace_gpu_pci_core_device {bool has_mig_hw_bug;/* GPU has just been reset */ bool reset_done; +/* CXL Device DVSEC offset; 0 if not present (legacy GB path) */ +int cxl_dvsec; };static void nvgrace_gpu_init_fake_bar_emu_regs (struct vfio_device *core_vdev)
@@ -242,7 +244,7 @@ static void nvgrace_gpu_close_device(struct vfio_device *core_vdev)vfio_pci_core_close_device (core_vdev); } -static int nvgrace_gpu_wait_device_ready (void __iomem *io) +static int nvgrace_gpu_wait_device_ready_legacy (void __iomem *io) {unsigned long timeout = jiffies +msecs_to_jiffies (POLL_TIMEOUT_MS );
@@ -256,6 +258,76 @@ static int nvgrace_gpu_wait_device_ready(void __iomem *io)return -ETIME ; } +/* +* Decode the 3-bit Memory_Active_Timeout field from CXL DVSEC Range 1 Low +* (bits 15:13) into milliseconds. Encoding per CXL spec r4.0 sec 8.1.3.8.2: +* 000b = 1s, 001b = 4s, 010b = 16s, 011b = 64s, 100b = 256s, +* 101b-111b = reserved (clamped to 256s). +*/ +static inline unsigned long cxl_mem_active_timeout_ms (u8 timeout) +{ +return 1000UL << (2 *min_t (u8, timeout,4 )); +} + +/* +* Check if CXL DVSEC reports memory as valid and active. +*/ +static inline bool cxl_dvsec_mem_is_active (u32 status) +{ +return (status &PCI_DVSEC_CXL_MEM_INFO_VALID ) && + (status &PCI_DVSEC_CXL_MEM_ACTIVE ); +} + +static int nvgrace_gpu_wait_device_ready_cxl (struct nvgrace_gpu_pci_core_device *nvdev) +{ +struct pci_dev *pdev = nvdev->core_device.pdev; +int cxl_dvsec = nvdev->cxl_dvsec; +unsigned long mem_info_valid_deadline; +unsigned long timeout; +u32 dvsec_memory_status; +u8 mem_active_timeout; + +pci_read_config_dword (pdev, cxl_dvsec +PCI_DVSEC_CXL_RANGE_SIZE_LOW (0 ), + &dvsec_memory_status); + +if (cxl_dvsec_mem_is_active (dvsec_memory_status)) +return 0 ; + + mem_active_timeout =FIELD_GET (PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT , + dvsec_memory_status); + + timeout = jiffies + +msecs_to_jiffies (cxl_mem_active_timeout_ms (mem_active_timeout)); + + mem_info_valid_deadline = jiffies +msecs_to_jiffies (POLL_QUANTUM_MS ); + +do { +pci_read_config_dword (pdev, + cxl_dvsec +PCI_DVSEC_CXL_RANGE_SIZE_LOW (0 ), + &dvsec_memory_status); + +if (cxl_dvsec_mem_is_active (dvsec_memory_status)) +return 0 ; + +/* Bail early if MEM_INFO_VALID is not set within 1 second */ +if (!(dvsec_memory_status &PCI_DVSEC_CXL_MEM_INFO_VALID ) && +time_after (jiffies, mem_info_valid_deadline)) +return -ETIME ; + +msleep (POLL_QUANTUM_MS ); + }while (!time_after (jiffies, timeout)); + +return -ETIME ; +} + +static inline int nvgrace_gpu_wait_device_ready (struct nvgrace_gpu_pci_core_device *nvdev, +void __iomem *io) +{ +return nvdev->cxl_dvsec ? +nvgrace_gpu_wait_device_ready_cxl (nvdev) : +nvgrace_gpu_wait_device_ready_legacy (io); +} +/* * If the GPU memory is accessed by the CPU while the GPU is not ready * after reset, it can cause harmless corrected RAS events to be logged.
@@ -275,7 +347,7 @@ nvgrace_gpu_check_device_ready(struct nvgrace_gpu_pci_core_device *nvdev)if (!__vfio_pci_memory_enabled (vdev))return -EIO ; - ret =nvgrace_gpu_wait_device_ready (vdev->barmap[0 ]); + ret =nvgrace_gpu_wait_device_ready (nvdev, vdev->barmap[0 ]);if (ret)return ret;
@@ -1146,11 +1218,16 @@ static bool nvgrace_gpu_has_mig_hw_bug(struct pci_dev *pdev)* Ensure that the BAR0 region is enabled before accessing the * registers. */ -static int nvgrace_gpu_probe_check_device_ready (struct pci_dev *pdev) +static int nvgrace_gpu_probe_check_device_ready (struct nvgrace_gpu_pci_core_device *nvdev) { +struct pci_dev *pdev = nvdev->core_device.pdev;void __iomem *io;int ret; +/* CXL path only reads PCI config space; no need to map BAR0. */ +if (nvdev->cxl_dvsec) +return nvgrace_gpu_wait_device_ready_cxl (nvdev); + ret =pci_enable_device (pdev);if (ret)return ret;
@@ -1165,7 +1242,7 @@ static int nvgrace_gpu_probe_check_device_ready(struct pci_dev *pdev) goto iomap_exit; } - ret =nvgrace_gpu_wait_device_ready (io); + ret =nvgrace_gpu_wait_device_ready_legacy (io);pci_iounmap (pdev, io); iomap_exit:
@@ -1183,10 +1260,6 @@ static int nvgrace_gpu_probe(struct pci_dev *pdev,u64 memphys, memlength;int ret; - ret =nvgrace_gpu_probe_check_device_ready (pdev); -if (ret) -return ret; - ret =nvgrace_gpu_fetch_memory_property (pdev, &memphys, &memlength);if (!ret) ops = &nvgrace_gpu_pci_ops;
@@ -1198,6 +1271,13 @@ static int nvgrace_gpu_probe(struct pci_dev *pdev,dev_set_drvdata (&pdev->dev, &nvdev->core_device); + nvdev->cxl_dvsec =pci_find_dvsec_capability (pdev,PCI_VENDOR_ID_CXL , +PCI_DVSEC_CXL_DEVICE ); + + ret =nvgrace_gpu_probe_check_device_ready (nvdev); +if (ret) + goto out_put_vdev; +if (ops == &nvgrace_gpu_pci_ops) { nvdev->has_mig_hw_bug =nvgrace_gpu_has_mig_hw_bug (pdev);
include/uapi/linux/pci_regs.h +1 -0
@@ -1357,6 +1357,7 @@#define PCI_DVSEC_CXL_RANGE_SIZE_LOW (i) (0x1C + (i * 0x10))#define PCI_DVSEC_CXL_MEM_INFO_VALID _BITUL(0)#define PCI_DVSEC_CXL_MEM_ACTIVE _BITUL(1) +#define PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT __GENMASK(15, 13)#define PCI_DVSEC_CXL_MEM_SIZE_LOW __GENMASK(31, 28)#define PCI_DVSEC_CXL_RANGE_BASE_HIGH (i) (0x20 + (i * 0x10))#define PCI_DVSEC_CXL_RANGE_BASE_LOW (i) (0x24 + (i * 0x10))
Signature · 1 line
2.34.1
Tian, Kevin
reviewerQuoted 23 lines
From: Ankit Agrawal <[email protected]>
Sent: Thursday, April 16, 2026 9:45 AM(quoted diff) +2
-0+ +static int nvgrace_gpu_wait_device_ready_cxl(struct
nvgrace_gpu_pci_core_device*nvdev)drivers/vfio/pci/nvgrace-gpu/main.c +9
-0+{ +struct pci_dev *pdev = nvdev->core_device.pdev; +int cxl_dvsec = nvdev->cxl_dvsec; +unsigned long mem_info_valid_deadline; +unsigned long timeout; +u32 dvsec_memory_status; +u8 mem_active_timeout; + + pci_read_config_dword(pdev, cxl_dvsec +
PCI_DVSEC_CXL_RANGE_SIZE_LOW(0),drivers/vfio/pci/nvgrace-gpu/main.c +6
-0+ &dvsec_memory_status); + +if (cxl_dvsec_mem_is_active (dvsec_memory_status)) +return 0 ; + + mem_active_timeout =FIELD_GET(PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT,
drivers/vfio/pci/nvgrace-gpu/main.c static int nvgrace_gpu_wait_device_ready(void __iomem *io) · line 297
Quoted 1 line
drivers/vfio/pci/nvgrace-gpu/main.c +1
-0+ dvsec_memory_status);
Sashiko pointed out that " the Memory_Active_Timeout field is only valid when the Memory_Info_Valid bit is set ". If it's true then blindly reading it here is incorrect.
https://sashiko.dev/#/patchset/20260416014504.63067-1-ankita%40nvidia.com
drivers/vfio/pci/nvgrace-gpu/main.c static bool · line 1223
Quoted 8 lines
drivers/vfio/pci/nvgrace-gpu/main.c +1
-1@@ -1146,11 +1218,16 @@ static boolnvgrace_gpu_has_mig_hw_bug(struct pci_dev *pdev) * Ensure that the BAR0 region is enabled before accessing the * registers. */ -static int nvgrace_gpu_probe_check_device_ready(struct pci_dev *pdev) +static int nvgrace_gpu_probe_check_device_ready (struct nvgrace_gpu_pci_core_device *nvdev)
the comment above should be updated too.
Quoted 7 lines · Ankit Agrawal
Add a CXL DVSEC-based readiness check for Blackwell-Next GPUs alongside the existing legacy BAR0 polling path. On probe and after reset, the driver reads the CXL Device DVSEC capability to determine whether the GPU memory is valid. This is checked by polling on the
Memory_Activebit based on theMemory_Active_Timeout. Also check ifMEM_INFO_VALIDis set within 1 second per CXL spec 4.0 Tables 8-13. If not, return error.
Quoted 7 lines
A static inline wrapper dispatches to the appropriate readiness check based on whether the CXL DVSEC capability is present.
Add
PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUTtopci_regs.hfor the timeout field encoding.Signed-off-by Ankit Agrawal <[email protected]>
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Ankit,
kernel test robot noticed the following build errors:
[auto build test ERROR on awilliam-vfio/next]
[also build test ERROR on awilliam-vfio/for-linus pci/next pci/for-linus linus/master v7.0 next-20260420] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ankit-Agrawal/vfio-nvgrace-gpu-Add-Blackwell-Next-GPU-readiness-check-via-CXL-DVSEC/20260419-053131 base: https://github.com/awilliam/linux-vfio.git next patch link: https://lore.kernel.org/r/20260416014504.63067-1-ankita%40nvidia.com patch subject: [PATCH v3 1/1] vfio/nvgrace-gpu: Add Blackwell-Next GPU readiness check via CXL DVSEC config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20260421/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260421/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/vfio/pci/nvgrace-gpu/main.c:296:23: error: call to undeclared function 'FIELD_GET'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
296 | mem_active_timeout = FIELD_GET(PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT,
| ^
1 error generated.
vim +/FIELD_GET +296 drivers/vfio/pci/nvgrace-gpu/main.c
280
281 static int nvgrace_gpu_wait_device_ready_cxl(struct nvgrace_gpu_pci_core_device *nvdev)
282 {
283 struct pci_dev *pdev = nvdev->core_device.pdev;
284 int cxl_dvsec = nvdev->cxl_dvsec;
285 unsigned long mem_info_valid_deadline;
286 unsigned long timeout;
287 u32 dvsec_memory_status;
288 u8 mem_active_timeout;
289
290 pci_read_config_dword(pdev, cxl_dvsec + PCI_DVSEC_CXL_RANGE_SIZE_LOW(0),
291 &dvsec_memory_status);
292
293 if (cxl_dvsec_mem_is_active(dvsec_memory_status))
294 return 0;
295
> 296 mem_active_timeout = FIELD_GET(PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT,
297 dvsec_memory_status);
298
299 timeout = jiffies +
300 msecs_to_jiffies(cxl_mem_active_timeout_ms(mem_active_timeout));
301
302 mem_info_valid_deadline = jiffies + msecs_to_jiffies(POLL_QUANTUM_MS);
303
304 do {
305 pci_read_config_dword(pdev,
306 cxl_dvsec + PCI_DVSEC_CXL_RANGE_SIZE_LOW(0),
307 &dvsec_memory_status);
308
309 if (cxl_dvsec_mem_is_active(dvsec_memory_status))
310 return 0;
311
312 /* Bail early if MEM_INFO_VALID is not set within 1 second */
313 if (!(dvsec_memory_status & PCI_DVSEC_CXL_MEM_INFO_VALID) &&
314 time_after(jiffies, mem_info_valid_deadline))
315 return -ETIME;
316
317 msleep(POLL_QUANTUM_MS);
318 } while (!time_after(jiffies, timeout));
319
320 return -ETIME;
321 }
322
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Ankit,
kernel test robot noticed the following build errors:
[auto build test ERROR on awilliam-vfio/next]
[also build test ERROR on awilliam-vfio/for-linus pci/next pci/for-linus linus/master v7.0 next-20260420] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ankit-Agrawal/vfio-nvgrace-gpu-Add-Blackwell-Next-GPU-readiness-check-via-CXL-DVSEC/20260419-053131 base: https://github.com/awilliam/linux-vfio.git next patch link: https://lore.kernel.org/r/20260416014504.63067-1-ankita%40nvidia.com patch subject: [PATCH v3 1/1] vfio/nvgrace-gpu: Add Blackwell-Next GPU readiness check via CXL DVSEC config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20260421/[email protected]/config) compiler: alpha-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260421/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/vfio/pci/nvgrace-gpu/main.c: In function 'nvgrace_gpu_wait_device_ready_cxl':
>> drivers/vfio/pci/nvgrace-gpu/main.c:296:30: error: implicit declaration of function 'FIELD_GET' [-Wimplicit-function-declaration]
296 | mem_active_timeout = FIELD_GET(PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT,
| ^~~~~~~~~
vim +/FIELD_GET +296 drivers/vfio/pci/nvgrace-gpu/main.c
280
281 static int nvgrace_gpu_wait_device_ready_cxl(struct nvgrace_gpu_pci_core_device *nvdev)
282 {
283 struct pci_dev *pdev = nvdev->core_device.pdev;
284 int cxl_dvsec = nvdev->cxl_dvsec;
285 unsigned long mem_info_valid_deadline;
286 unsigned long timeout;
287 u32 dvsec_memory_status;
288 u8 mem_active_timeout;
289
290 pci_read_config_dword(pdev, cxl_dvsec + PCI_DVSEC_CXL_RANGE_SIZE_LOW(0),
291 &dvsec_memory_status);
292
293 if (cxl_dvsec_mem_is_active(dvsec_memory_status))
294 return 0;
295
> 296 mem_active_timeout = FIELD_GET(PCI_DVSEC_CXL_MEM_ACTIVE_TIMEOUT,
297 dvsec_memory_status);
298
299 timeout = jiffies +
300 msecs_to_jiffies(cxl_mem_active_timeout_ms(mem_active_timeout));
301
302 mem_info_valid_deadline = jiffies + msecs_to_jiffies(POLL_QUANTUM_MS);
303
304 do {
305 pci_read_config_dword(pdev,
306 cxl_dvsec + PCI_DVSEC_CXL_RANGE_SIZE_LOW(0),
307 &dvsec_memory_status);
308
309 if (cxl_dvsec_mem_is_active(dvsec_memory_status))
310 return 0;
311
312 /* Bail early if MEM_INFO_VALID is not set within 1 second */
313 if (!(dvsec_memory_status & PCI_DVSEC_CXL_MEM_INFO_VALID) &&
314 time_after(jiffies, mem_info_valid_deadline))
315 return -ETIME;
316
317 msleep(POLL_QUANTUM_MS);
318 } while (!time_after(jiffies, timeout));
319
320 return -ETIME;
321 }
322
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki