Thread (37 messages) 37 messages, 6 authors, 9d ago

Re: [PATCH v3 5/9] mm: convert PTE table entry to pte

flat view

From: Muhammad Usama Anjum <hidden>
Date: 2026-10-02 14:58:48
Also in: bpf, damon, intel-gfx, linux-arch, linux-fsdevel, linux-mm, linux-perf-users, lkml, xen-devel

On 01/10/2026 12:17 pm, David Hildenbrand (Arm) wrote:
quoted hunk ↗ jump to hunk
On 9/22/26 19:12, Muhammad Usama Anjum wrote:
quoted
The non-MMU stub receives hw_pte_t but returns a software PTE value. It
has no attached PTE that requires ptep_get(), so convert only the stored
entry through __pte_from_hw().

Signed-off-by: Muhammad Usama Anjum <redacted>
---
Changes since v1:
- Explain why the NOMMU stub does not use ptep_get().
- Use software PTE value terminology.
---
 include/linux/hugetlb.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 0d2101facaa50..637fc863d3687 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -1278,7 +1278,8 @@ static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 #ifdef CONFIG_MMU
 	return ptep_get(ptep);
 #else
-	return *ptep;
+	/* No attached PTE that requires ptep_get(). */
+	return __pte_from_hw(*ptep);
 #endif
 }
 
Okay, that looks quite odd. No NOMMU code should ever be calling this helper. I
can understand that some NOMMU code might, for some odd reason, end up including
hguetlb.h where we have !CONFIG_HUGETLB_PAGE.

But let's see who actually calls huge_ptep_clear_flush():

arch/arm64/mm/hugetlbpage.c: only with CONFIG_HUGETLB_PAGE
mm/hugetlb.c: only with CONFIG_HUGETLB_PAGE
mm/rmap.c: only after checking folio_test_hugetlb().

I suspect we can simply do:
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 80a5a03e9cee..8642c863c1b7 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -1268,15 +1268,8 @@ static inline void hugetlb_count_sub(long l, struct
mm_struct *mm)
 pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
 unsigned long huge_pte_dirty(pte_t pte);

-static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
-                                         unsigned long addr, pte_t *ptep)
-{
-#ifdef CONFIG_MMU
-       return ptep_get(ptep);
-#else
-       return *ptep;
-#endif
-}
+pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr,
+               pte_t *ptep);

 static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
                                   pte_t *ptep, pte_t pte, unsigned long sz)
Thank you for digging into the code to sort this out. I'll confirm
and update this patch in the next version.

-- 
Thanks,
Usama
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help