Re: [PATCH] vfio: Request THP-aligned mmap for device fds
From: Jason Gunthorpe
Date: Thu Jun 18 2026 - 11:30:45 EST
On Thu, Jun 18, 2026 at 03:55:58PM +0100, Lorenzo Stoakes wrote:
> > A pfn driver often has a single already known physical range that it
> > will use for the VMA and that range should drive the alignment
> > decision of the VMA.
> >
> > vfio in particular has common use cases where you want to mmap from
> > weird offsets, but we still want to achieve a VMA starting point that
> > has pa % PUD_SIZE == va % PUD_SIZE. It is impossible to do this if the
> > thing building info does not know pa.
> >
> > I do think it makes sense that no file provider should be computing
> > the VA area itself, I think I made that case when Peter was last
> > working on this. Now that we have Lorenzo's mmap changes maybe we
> > should be talking about supporting VFIO by having a callback to obtain
> > the starting pfn for the VMA. Usable only by drivers like VFIO that
> > are working with the pfn functions.
>
> Can't we figure this out from what the driver tells us when it invokes an
> mmap_prepare action?
VFIO installs the pages via fault handler so there is not a naturally
existing way to pass in the pfn?
> Can't we figure it out from the PFN the driver tells mmap_prepare about?
Maybe it can pass the pfn anyhow and not have the mmap logic map
anything?
> > Maybe other users would prefer a 'max order' callback and then the mm
> > would assume the VMA will be popoulated with pgoff aligned folios up
> > to that highest order?
>
> Not in favour of that, fear it'll be seen as a new go-faster stripe. Ask
> somebody how many free pints they want and they may veer rather towards the
> upper bound :)
I think you need something, otherwise we will be aligning VMAs that
never have anything larger than a 2M THP to 1GB boundaries, doesn't
seem good.
Jason