Re: [PATCH 4/5] mm/page_vma_mapped: use huge_ptep_get() for hugetlb

From: Lance Yang

Date: Mon Jun 29 2026 - 03:17:44 EST



On Mon, Jun 29, 2026 at 08:39:22AM +0200, David Hildenbrand (Arm) wrote:
>On 6/28/26 07:44, Lance Yang wrote:
>>
>> On Sat, Jun 27, 2026 at 12:43:31PM +0530, Dev Jain wrote:
>>>
>>>
>>> On 26/06/26 10:16 pm, Lance Yang wrote:
>> [...]
>>>>
>>>> Just thinking out loud: given that huge_ptep_get() already assumes that
>>>> addr matches the huge pte, at least on arm64, would it make sense to
>>>> have a small hugetlb wrapper around it that takes hstate and aligns
>>>> the address before calling the arch helper?
>>>>
>>>> Might make the rule clearer, and a bit harder to get wrong again :)
>>>
>>> Are you suggesting something like:
>>
>> Yes, that's what I had in mind :) thanks!
>>
>>> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
>>> index fdb7bdf7645c..xxxxxxxxxxxx 100644
>>> --- a/include/linux/hugetlb.h
>>> +++ b/include/linux/hugetlb.h
>>> @@ -825,6 +825,15 @@ static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h,
>>>
>>> #include <asm/hugetlb.h>
>>
>> Maybe worth spelling out the rule as well:
>>
>> For arch helpers that use addr, huge_ptep_get() assumes addr is the
>> address for the hugetlb entry ptep points to. arm64 already makes that
>> assumption.
>>
>> Callers where addr may not be hugepage-aligned should use
>> hugetlb_ptep_get() instead.
>
>Do we have any examples where code would do that? I would think that all code
>must properly align addr ahead of times.

I was thinking of the memory-failure case from earlier:

https://lore.kernel.org/linux-mm/20260626141031.14309-1-lance.yang@xxxxxxxxx/

There, page_mapped_in_vma() can be called with the poisoned tail page,
so pvmw.address comes from page_pgoff(folio, page) and need not be
hugepage-aligned.

Cheers, Lance