Re: [PATCH v5 3/9] vfio/pci: Add a helper to look up PFNs for DMABUFs
From: Jason Gunthorpe
Date: Tue Aug 04 2026 - 20:42:21 EST
On Mon, Aug 03, 2026 at 07:22:06PM +0100, Matt Evans wrote:
> The second problem is this isn't just a limitation to not do an mmap()
> with offset approaching 1TB, because you could run into trouble just
> mapping, say, a 2TB BAR and then splitting it by unmapping a hole in the
> middle: the second VMA now has a huge offset.
>
> It seems a proper fix is easy though:
>
> unsigned long vma_off = (vma->vm_pgoff - priv->vma_pgoff_adjust) <<
> PAGE_SHIFT; /* No masking! */
>
> Then in vfio_pci_core_mmap_prep_dmabuf(),
>
> priv->vma_pgoff_adjust = vma->vm_pgoff;
>
> I.e., if vma_pgoff_adjust just includes the region index up high, it
> cancels out the (same) index in the vm_pgoff. Thus regular mmap should
> work (up to the 1TB offset), and DMABUF VMAs can have arbitrarily large
> offsets.
This is what I was expecting when I pointed at this stuff in the first
place :)
Jason