#include <linux/delay.h>
#include <linux/jiffies.h>
+#ifdef CONFIG_MEMORY_FAILURE
+#include <linux/memory-failure.h>
+#endif
+
/*
* The device memory usable to the workloads running in the VM is cached
* and showcased as a 64b device BAR (comprising of BAR4 and BAR5 region)
void *memaddr;
void __iomem *ioaddr;
}; /* Base virtual address of the region */
+#ifdef CONFIG_MEMORY_FAILURE
+ struct pfn_address_space pfn_address_space;
+#endif
};
struct nvgrace_gpu_pci_core_device {
bool has_mig_hw_bug;
};
+#ifdef CONFIG_MEMORY_FAILURE
+
+static int
+nvgrace_gpu_vfio_pci_register_pfn_range(struct mem_region *region,
+ struct vm_area_struct *vma)
+{
+ unsigned long nr_pages;
+ int ret = 0;
+
+ nr_pages = region->memlength >> PAGE_SHIFT;
+
+ region->pfn_address_space.node.start = vma->vm_pgoff;
+ region->pfn_address_space.node.last = vma->vm_pgoff + nr_pages - 1;
+ region->pfn_address_space.mapping = vma->vm_file->f_mapping;
+
+ ret = register_pfn_address_space(®ion->pfn_address_space);
+
+ return ret;
+}
+
+#endif
+
static void nvgrace_gpu_init_fake_bar_emu_regs(struct vfio_device *core_vdev)
{
struct nvgrace_gpu_pci_core_device *nvdev =
mutex_destroy(&nvdev->remap_lock);
+#ifdef CONFIG_MEMORY_FAILURE
+ if (nvdev->resmem.memlength)
+ unregister_pfn_address_space(&nvdev->resmem.pfn_address_space);
+
+ unregister_pfn_address_space(&nvdev->usemem.pfn_address_space);
+#endif
+
vfio_pci_core_close_device(core_vdev);
}
vma->vm_pgoff = start_pfn;
- return 0;
+#ifdef CONFIG_MEMORY_FAILURE
+ if (nvdev->resmem.memlength && index == VFIO_PCI_BAR2_REGION_INDEX)
+ ret = nvgrace_gpu_vfio_pci_register_pfn_range(&nvdev->resmem, vma);
+ else if (index == VFIO_PCI_BAR4_REGION_INDEX)
+ ret = nvgrace_gpu_vfio_pci_register_pfn_range(&nvdev->usemem, vma);
+#endif
+
+ return ret;
}
static long