Re: [PATCH v2 2/6] arm64: use hw_pte_val for HW PTE atomics

From: Ryan Roberts

Date: Thu Sep 24 2026 - 08:44:15 EST


On 22/09/2026 18:31, Muhammad Usama Anjum wrote:
> The low-level atomic PTE update paths take the address of
> pte_val(*ptep). That assumes HW PTE storage can be passed directly to
> the SW PTE value accessor and no longer type-checks when hw_pte_t is
> distinct.
>
> Use hw_pte_val() for the lvalues passed to compare-exchange and exchange
> operations. The atomic operations and their ordering are unchanged.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>

Reviewed-by: Ryan Roberts <ryan.roberts@xxxxxxx>

> ---
> Chagnes in v2:
> - Remove comment change
> - Move hw_pte_val() to generic series
> ---
> arch/arm64/include/asm/pgtable.h | 10 +++++-----
> arch/arm64/mm/fault.c | 2 +-
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 652ce413be389..4768ec59de555 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -1303,7 +1303,7 @@ static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
> do {
> old_pte = pte;
> pte = pte_mkold(pte);
> - pte_val(pte) = cmpxchg_relaxed(&pte_val(*ptep),
> + pte_val(pte) = cmpxchg_relaxed(&hw_pte_val(*ptep),
> pte_val(old_pte), pte_val(pte));
> } while (pte_val(pte) != pte_val(old_pte));
>
> @@ -1346,7 +1346,7 @@ static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,
> hw_pte_t *ptep,
> unsigned long pgsize)
> {
> - pte_t pte = __pte(xchg_relaxed(&pte_val(*ptep), 0));
> + pte_t pte = __pte(xchg_relaxed(&hw_pte_val(*ptep), 0));
>
> switch (pgsize) {
> case PAGE_SIZE:
> @@ -1422,7 +1422,7 @@ static inline void ___ptep_set_wrprotect(struct mm_struct *mm,
> do {
> old_pte = pte;
> pte = pte_wrprotect(pte);
> - pte_val(pte) = cmpxchg_relaxed(&pte_val(*ptep),
> + pte_val(pte) = cmpxchg_relaxed(&hw_pte_val(*ptep),
> pte_val(old_pte), pte_val(pte));
> } while (pte_val(pte) != pte_val(old_pte));
> }
> @@ -1460,7 +1460,7 @@ static inline void __clear_young_dirty_pte(struct vm_area_struct *vma,
> if (flags & CYDP_CLEAR_DIRTY)
> pte = pte_mkclean(pte);
>
> - pte_val(pte) = cmpxchg_relaxed(&pte_val(*ptep),
> + pte_val(pte) = cmpxchg_relaxed(&hw_pte_val(*ptep),
> pte_val(old_pte), pte_val(pte));
> } while (pte_val(pte) != pte_val(old_pte));
> }
> @@ -1830,7 +1830,7 @@ static inline bool ptep_try_set(hw_pte_t *ptep, pte_t new_pte)
> {
> pteval_t old = 0;
>
> - if (!try_cmpxchg(&pte_val(*ptep), &old, pte_val(new_pte)))
> + if (!try_cmpxchg(&hw_pte_val(*ptep), &old, pte_val(new_pte)))
> return false;
>
> /*
> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> index b77f4be88e3ea..3322f4e7174dc 100644
> --- a/arch/arm64/mm/fault.c
> +++ b/arch/arm64/mm/fault.c
> @@ -235,7 +235,7 @@ int __ptep_set_access_flags_anysz(struct vm_area_struct *vma,
> pteval ^= PTE_RDONLY;
> pteval |= pte_val(entry);
> pteval ^= PTE_RDONLY;
> - pteval = cmpxchg_relaxed(&pte_val(*ptep), old_pteval, pteval);
> + pteval = cmpxchg_relaxed(&hw_pte_val(*ptep), old_pteval, pteval);
> } while (pteval != old_pteval);
>
> /*
>