[PATCH 5/9] mm: convert PTE table entries in ptep_get()
From: Muhammad Usama Anjum
Date: Thu Aug 06 2026 - 04:43:15 EST
ptep_get() now accepts a pointer to hw_pte_t storage but must continue to
return a logical pte_t value. Add __pte_from_hw for both generic hw_pte_t
definitions. Read the hw_pte_t table element atomically before converting
it to pte_t.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
---
Changes since RFC v1:
- Define __pte_from_hw for the opted-in generic wrapper.
- Apply READ_ONCE() to hw_pte_t before converting it to pte_t.
---
include/linux/pgtable.h | 2 +-
include/linux/pgtable_types.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index dad80d264aac2..1768421755a9c 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -493,7 +493,7 @@ static inline int pudp_set_access_flags(struct vm_area_struct *vma,
#ifndef ptep_get
static inline pte_t ptep_get(hw_pte_t *ptep)
{
- return READ_ONCE(*ptep);
+ return __pte_from_hw(READ_ONCE(*ptep));
}
#endif
diff --git a/include/linux/pgtable_types.h b/include/linux/pgtable_types.h
index 70c3edd00a01b..a625516fd67b1 100644
--- a/include/linux/pgtable_types.h
+++ b/include/linux/pgtable_types.h
@@ -8,8 +8,10 @@
#ifdef CONFIG_ARCH_HAS_HW_PTE_T
typedef struct { pte_t __pte; } hw_pte_t;
+#define __pte_from_hw(pte) ((pte).__pte)
#else
#define hw_pte_t pte_t
+#define __pte_from_hw(pte) (pte)
#endif
#endif /* !__ASSEMBLY__ */
--
2.47.3