Re: [RFC V2 08/14] arm64/mm: Route all pgtable writes via pxxval_set()
From: Ryan Roberts
Date: Wed May 27 2026 - 10:19:19 EST
On 13/05/2026 05:45, Anshuman Khandual wrote:
> Currently pxxval_set() is defined as WRITE_ONCE() but this will change for
> D128 pgtable builds, for which WRITE_ONCE() is not sufficient for single
> copy atomicity.
>
> In future this infrastructure can be used for D128 to maintain single copy
> atomicity semantics with inline asm blocks.
>
> Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
> Cc: Will Deacon <will@xxxxxxxxxx>
> Cc: Ryan Roberts <ryan.roberts@xxxxxxx>
> Cc: Mark Rutland <mark.rutland@xxxxxxx>
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
> ---
> Changes in RFC V2:
>
> - Renamed all ptdesc_ instances as pxxval_ instead
>
> arch/arm64/include/asm/pgtable.h | 11 ++++++-----
> arch/arm64/mm/mmu.c | 4 ++--
> 2 files changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 72da582e8d12..c71bb829e9f1 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -85,6 +85,7 @@ static inline void arch_leave_lazy_mmu_mode(void)
> }
>
> #define pxxval_get(x) READ_ONCE(x)
> +#define pxxval_set(x, val) WRITE_ONCE(x, val)
Same comment as for pxxval_get(): I think it would be clearer if this was an
inline function that took a pointer.
Thanks,
Ryan
>
> #define pmdp_get pmdp_get
> static inline pmd_t pmdp_get(pmd_t *pmdp)
> @@ -385,7 +386,7 @@ static inline pte_t pte_clear_uffd_wp(pte_t pte)
>
> static inline void __set_pte_nosync(pte_t *ptep, pte_t pte)
> {
> - WRITE_ONCE(*ptep, pte);
> + pxxval_set(*ptep, pte);
> }
>
> static inline void __set_pte_complete(pte_t pte)
> @@ -856,7 +857,7 @@ static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
> }
> #endif /* __PAGETABLE_PMD_FOLDED */
>
> - WRITE_ONCE(*pmdp, pmd);
> + pxxval_set(*pmdp, pmd);
>
> if (pmd_valid(pmd))
> queue_pte_barriers();
> @@ -921,7 +922,7 @@ static inline void set_pud(pud_t *pudp, pud_t pud)
> return;
> }
>
> - WRITE_ONCE(*pudp, pud);
> + pxxval_set(*pudp, pud);
>
> if (pud_valid(pud))
> queue_pte_barriers();
> @@ -1003,7 +1004,7 @@ static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)
> return;
> }
>
> - WRITE_ONCE(*p4dp, p4d);
> + pxxval_set(*p4dp, p4d);
> queue_pte_barriers();
> }
>
> @@ -1131,7 +1132,7 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
> return;
> }
>
> - WRITE_ONCE(*pgdp, pgd);
> + pxxval_set(*pgdp, pgd);
> queue_pte_barriers();
> }
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 7fbb2ef86cfa..6eb92d8f46be 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -76,7 +76,7 @@ void noinstr set_swapper_pgd(pgd_t *pgdp, pgd_t pgd)
> * writable in the kernel mapping.
> */
> if (rodata_is_rw) {
> - WRITE_ONCE(*pgdp, pgd);
> + pxxval_set(*pgdp, pgd);
> dsb(ishst);
> isb();
> return;
> @@ -84,7 +84,7 @@ void noinstr set_swapper_pgd(pgd_t *pgdp, pgd_t pgd)
>
> spin_lock(&swapper_pgdir_lock);
> fixmap_pgdp = pgd_set_fixmap(__pa_symbol(pgdp));
> - WRITE_ONCE(*fixmap_pgdp, pgd);
> + pxxval_set(*fixmap_pgdp, pgd);
> /*
> * We need dsb(ishst) here to ensure the page-table-walker sees
> * our new entry before set_p?d() returns. The fixmap's