Re: [PATCH v5 1/7] vfio/nvgrace-gpu: Use faults to map device memory
From: Jason Gunthorpe
Date: Mon Nov 24 2025 - 12:17:21 EST
On Mon, Nov 24, 2025 at 05:09:30PM +0000, Shameer Kolothum wrote:
> > +static vm_fault_t nvgrace_gpu_vfio_pci_fault(struct vm_fault *vmf)
> > +{
> > + struct vm_area_struct *vma = vmf->vma;
> > + struct nvgrace_gpu_pci_core_device *nvdev = vma->vm_private_data;
> > + int index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT -
> > PAGE_SHIFT);
> > + vm_fault_t ret = VM_FAULT_SIGBUS;
> > + struct mem_region *memregion;
> > + unsigned long pgoff, pfn;
> > +
> > + memregion = nvgrace_gpu_memregion(index, nvdev);
> > + if (!memregion)
> > + return ret;
> > +
> > + pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
> > + pfn = PHYS_PFN(memregion->memphys) + pgoff;
>
> The core fault code seems to calculate the BAR offset in vma_to_pfn()
> which is missing here.
>
> pgoff = vma->vm_pgoff &
> ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
Yes, that should be included for this reason:
> Is the assumption here is user space will always map at BAR offset 0?
It should not be assumed.
Jason