RE: [PATCH 2/4] mm: add vmf_insert_pfn_order() and vmf_pfn_order_ok() helpers
From: Farber, Eliav
Date: Tue Nov 24 2026 - 07:45:29 EST
On 11/15/26 17:54, David Hildenbrand (Arm) wrote:
> Please rewrite your answer in a way that doesn't make me hate kernel
> development.
Sorry, I should have written it myself.
> But looking again, this all looks like sanity checks where the user is just
> doing something stupid?
>
> Why is that required at all? I'd get rid of this entirely.
You were right, the helper is gone.
The checks are not a bug. They are incomplete. insert_pmd() and
insert_pud() test the start of the window but not its end. I extended
that to both ends, and made it fall back instead of SIGBUS. A VMA that
does not span a whole PMD is ordinary. The pfn is not checked at all, so
I added that to vmf_insert_pfn_pmd() and vmf_insert_pfn_pud().
No caller can reach either case today, because each one checks the
geometry first. The callers of vmf_insert_pfn_order() will not.
> And maybe rejecting IS_ALIGNED(pfn, 1UL << order) with WARN_ONCE() as this
> sounds like the user is doing something stupid?
No WARN. An unaligned pfn comes from an ordinary mmap(), not from a bug.
For /dev/mem, vm_pgoff is the base pfn. An mmap() at offset 0x1000 gives
pfn 1, which no PMD entry can map. Falling back to PTE order is correct,
and a WARN would fire on that mmap().
Dropping the check is not safe either. x86 pfn_pmd() masks the pfn with
PHYSICAL_PMD_PAGE_MASK. An unaligned pfn is rounded down, and the mapping
points at the wrong memory.
This is in v3, which I will post soon.
Thanks,
Eliav