On Tue, Sep 22, 2026 at 06:12:32PM +0100, Muhammad Usama Anjum wrote:
> 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 <[email protected]>
> ---
> Changes since v1:
> - Use software PTE value terminology.
>
> 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 19098e302b75a..41337da0d65aa 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));
> }
Just curious - when would other pgtable levels (PMD, PUD, P4D and PGD) be
converted
in this format as well ?
> #endif
>
> diff --git a/include/linux/pgtable_types.h b/include/linux/pgtable_types.h
> index 07da05d375c2c..d6c5a7548550b 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.47.3
>