Re: [PATCH] vfio: Request THP-aligned mmap for device fds
From: Jason Gunthorpe
Date: Wed Jun 17 2026 - 15:29:44 EST
On Wed, Jun 17, 2026 at 07:34:06PM +0100, Matthew Wilcox wrote:
> I don't see this as being something that drivers should be involved with
> at all. The MM should be able to get this right without any hints from
> the file-provider. Yes, that means I also want to get rid of the setting
> of get_unmapped_area in ext4/xfs/other filesystems.
>
> Looking at generic_get_unmapped_area_topdown(), I think we can do this by
> making an additional call to vm_unmapped_area() before the existing two,
> setting info.align_mask and info.align_offset appropriately.
>
> Now, what's "appropriately"? I think it's based on length (>= PMD_SIZE,
> then >= PUD_SIZE), but we should also take CONTPTE architectures into
> account.
The info.align_mask and info.align_offset do need information from the
driver based on what it intends to map into the VMA that is being
created.
Filesystems probably have quite different requirements than drivers
using remap_pfn() or vmf_insert_pfn() that have locked down pfn's.
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.
The starting pfn and VMA size is enough for the mm to setup info
suitably.
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?
> And maybe there's a CONTPMD architecture we should also consider?
ARM HW supports "CONTPMD" but I suppose it is not implemented..
Jason