Skip to content

Commit e12c478

Browse files
ankita-nvgregkh
authored andcommitted
vfio/nvgrace-gpu: Read dvsec register to determine need for uncached resmem
[ Upstream commit bd53764 ] NVIDIA's recently introduced Grace Blackwell (GB) Superchip is a continuation with the Grace Hopper (GH) superchip that provides a cache coherent access to CPU and GPU to each other's memory with an internal proprietary chip-to-chip cache coherent interconnect. There is a HW defect on GH systems to support the Multi-Instance GPU (MIG) feature [1] that necessiated the presence of a 1G region with uncached mapping carved out from the device memory. The 1G region is shown as a fake BAR (comprising region 2 and 3) to workaround the issue. This is fixed on the GB systems. The presence of the fix for the HW defect is communicated by the device firmware through the DVSEC PCI config register with ID 3. The module reads this to take a different codepath on GB vs GH. Scan through the DVSEC registers to identify the correct one and use it to determine the presence of the fix. Save the value in the device's nvgrace_gpu_pci_core_device structure. Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu/ [1] CC: Jason Gunthorpe <[email protected]> CC: Kevin Tian <[email protected]> Signed-off-by: Ankit Agrawal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent e8e0eb5 commit e12c478

File tree

1 file changed

+28
-0
lines changed
  • drivers/vfio/pci/nvgrace-gpu

1 file changed

+28
-0
lines changed

drivers/vfio/pci/nvgrace-gpu/main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
/* A hardwired and constant ABI value between the GPU FW and VFIO driver. */
2424
#define MEMBLK_SIZE SZ_512M
2525

26+
#define DVSEC_BITMAP_OFFSET 0xA
27+
#define MIG_SUPPORTED_WITH_CACHED_RESMEM BIT(0)
28+
29+
#define GPU_CAP_DVSEC_REGISTER 3
30+
2631
/*
2732
* The state of the two device memory region - resmem and usemem - is
2833
* saved as struct mem_region.
@@ -46,6 +51,7 @@ struct nvgrace_gpu_pci_core_device {
4651
struct mem_region resmem;
4752
/* Lock to control device memory kernel mapping */
4853
struct mutex remap_lock;
54+
bool has_mig_hw_bug;
4955
};
5056

5157
static void nvgrace_gpu_init_fake_bar_emu_regs(struct vfio_device *core_vdev)
@@ -812,6 +818,26 @@ nvgrace_gpu_init_nvdev_struct(struct pci_dev *pdev,
812818
return ret;
813819
}
814820

821+
static bool nvgrace_gpu_has_mig_hw_bug(struct pci_dev *pdev)
822+
{
823+
int pcie_dvsec;
824+
u16 dvsec_ctrl16;
825+
826+
pcie_dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_NVIDIA,
827+
GPU_CAP_DVSEC_REGISTER);
828+
829+
if (pcie_dvsec) {
830+
pci_read_config_word(pdev,
831+
pcie_dvsec + DVSEC_BITMAP_OFFSET,
832+
&dvsec_ctrl16);
833+
834+
if (dvsec_ctrl16 & MIG_SUPPORTED_WITH_CACHED_RESMEM)
835+
return false;
836+
}
837+
838+
return true;
839+
}
840+
815841
static int nvgrace_gpu_probe(struct pci_dev *pdev,
816842
const struct pci_device_id *id)
817843
{
@@ -832,6 +858,8 @@ static int nvgrace_gpu_probe(struct pci_dev *pdev,
832858
dev_set_drvdata(&pdev->dev, &nvdev->core_device);
833859

834860
if (ops == &nvgrace_gpu_pci_ops) {
861+
nvdev->has_mig_hw_bug = nvgrace_gpu_has_mig_hw_bug(pdev);
862+
835863
/*
836864
* Device memory properties are identified in the host ACPI
837865
* table. Set the nvgrace_gpu_pci_core_device structure.

0 commit comments

Comments
 (0)