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

From: Lance Yang

Date: Sun Jun 28 2026 - 01:44:19 EST



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.

>+static inline pte_t hugetlb_ptep_get(struct vm_area_struct *vma,
>+ unsigned long addr, pte_t *ptep)
>+{
>+ struct hstate *h = hstate_vma(vma);
>+
>+ return huge_ptep_get(vma->vm_mm, addr & huge_page_mask(h), ptep);
>+}
>+
> #ifndef is_hugepage_only_range
> static inline int is_hugepage_only_range(struct mm_struct *mm,
> unsigned long addr, unsigned long len)
>diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
>index 18e1d341f463..xxxxxxxxxxxx 100644
>--- a/mm/page_vma_mapped.c
>+++ b/mm/page_vma_mapped.c
>@@ -110,8 +110,7 @@ static bool check_pte(struct page_vma_mapped_walk *pvmw, unsigned long pte_nr)
> pte_t ptent;
>
> if (is_vm_hugetlb_page(pvmw->vma))
>- ptent = huge_ptep_get(pvmw->vma->vm_mm, pvmw->address,
>- pvmw->pte);
>+ ptent = hugetlb_ptep_get(pvmw->vma, pvmw->address, pvmw->pte);
> else
> ptent = ptep_get(pvmw->pte);

[...]

Cheers, Lance