[PATCH v8 04/15] mm: convert PTE table entries in ptep_get()

From: Alexander Gordeev

Date: Wed Oct 07 2026 - 07:58:52 EST


From: Muhammad Usama Anjum <usama.anjum@xxxxxxx>

ptep_get() now accepts a pointer to hw_pte_t storage but must continue to
return a software PTE 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>
---
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 dad80d264aac..1768421755a9 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 07da05d375c2..d6c5a7548550 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 __hw_pte_t { 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.53.0