[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251124171646.GU233636@ziepe.ca>
Date: Mon, 24 Nov 2025 13:16:46 -0400
From: Jason Gunthorpe <jgg@...pe.ca>
To: Shameer Kolothum <skolothumtho@...dia.com>
Cc: Ankit Agrawal <ankita@...dia.com>, Yishai Hadas <yishaih@...dia.com>,
"kevin.tian@...el.com" <kevin.tian@...el.com>,
"alex@...zbot.org" <alex@...zbot.org>,
Aniket Agashe <aniketa@...dia.com>,
Vikram Sethi <vsethi@...dia.com>, Matt Ochs <mochs@...dia.com>,
"Yunxiang.Li@....com" <Yunxiang.Li@....com>,
"yi.l.liu@...el.com" <yi.l.liu@...el.com>,
"zhangdongdong@...incomputing.com" <zhangdongdong@...incomputing.com>,
Avihai Horon <avihaih@...dia.com>,
"bhelgaas@...gle.com" <bhelgaas@...gle.com>,
"peterx@...hat.com" <peterx@...hat.com>,
"pstanner@...hat.com" <pstanner@...hat.com>,
Alistair Popple <apopple@...dia.com>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Neo Jia <cjia@...dia.com>, Kirti Wankhede <kwankhede@...dia.com>,
"Tarun Gupta (SW-GPU)" <targupta@...dia.com>,
Zhi Wang <zhiw@...dia.com>, Dan Williams <danw@...dia.com>,
Dheeraj Nigam <dnigam@...dia.com>,
Krishnakant Jaju <kjaju@...dia.com>
Subject: Re: [PATCH v5 1/7] vfio/nvgrace-gpu: Use faults to map device memory
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
Powered by blists - more mailing lists