[RFC V1 10/16] arm64/mm: Route all pgtable writes via ptdesc_set()
Usama Arif
usama.arif at linux.dev
Thu Feb 26 04:37:45 PST 2026
On Tue, 24 Feb 2026 10:41:47 +0530 Anshuman Khandual <anshuman.khandual at arm.com> wrote:
> Currently ptdesc_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 at arm.com>
> Cc: Will Deacon <will at kernel.org>
> Cc: Ryan Roberts <ryan.roberts at arm.com>
> Cc: Mark Rutland <mark.rutland at arm.com>
> Cc: linux-arm-kernel at lists.infradead.org
> Cc: linux-kernel at vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual at arm.com>
> ---
> arch/arm64/include/asm/pgtable.h | 11 ++++++-----
> arch/arm64/mm/mmu.c | 4 ++--
> mm/debug_vm_pgtable.c | 4 ++--
> 3 files changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 804ef49aea88..42124d2f323d 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 ptdesc_get(x) READ_ONCE(x)
> +#define ptdesc_set(x, val) WRITE_ONCE(x, val)
>
> #define pmdp_get pmdp_get
> static inline pmd_t pmdp_get(pmd_t *pmdp)
> @@ -389,7 +390,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);
> + ptdesc_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);
> + ptdesc_set(*pmdp, pmd);
>
> if (pmd_valid(pmd))
> queue_pte_barriers();
> @@ -917,7 +918,7 @@ static inline void set_pud(pud_t *pudp, pud_t pud)
> return;
> }
>
> - WRITE_ONCE(*pudp, pud);
> + ptdesc_set(*pudp, pud);
>
> if (pud_valid(pud))
> queue_pte_barriers();
> @@ -999,7 +1000,7 @@ static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)
> return;
> }
>
> - WRITE_ONCE(*p4dp, p4d);
> + ptdesc_set(*p4dp, p4d);
> queue_pte_barriers();
> }
>
> @@ -1120,7 +1121,7 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
> return;
> }
>
> - WRITE_ONCE(*pgdp, pgd);
> + ptdesc_set(*pgdp, pgd);
> queue_pte_barriers();
> }
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index bcf32d1a92de..ffd307c546f5 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -83,7 +83,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);
> + ptdesc_set(*pgdp, pgd);
> dsb(ishst);
> isb();
> return;
> @@ -91,7 +91,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);
> + ptdesc_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
> diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c
> index 83cf07269f13..faf6a19a89a1 100644
> --- a/mm/debug_vm_pgtable.c
> +++ b/mm/debug_vm_pgtable.c
> @@ -445,7 +445,7 @@ static void __init pmd_huge_tests(struct pgtable_debug_args *args)
> * X86 defined pmd_set_huge() verifies that the given
> * PMD is not a populated non-leaf entry.
> */
> - WRITE_ONCE(*args->pmdp, __pmd(0));
> + ptdesc_set(*args->pmdp, __pmd(0));
The ptdesc_set() and ptdesc_get() macros are defined in
arch/arm64/include/asm/pgtable.h and are arm64-specific. This change is
in mm/debug_vm_pgtable.c which is generic code compiled for all
architectures. Other architectures do not define ptdesc_set(), so this
will would cause a build failure on other architectures..
> WARN_ON(!pmd_set_huge(args->pmdp, __pfn_to_phys(args->fixed_pmd_pfn), args->page_prot));
> WARN_ON(!pmd_clear_huge(args->pmdp));
> pmd = pmdp_get(args->pmdp);
> @@ -465,7 +465,7 @@ static void __init pud_huge_tests(struct pgtable_debug_args *args)
> * X86 defined pud_set_huge() verifies that the given
> * PUD is not a populated non-leaf entry.
> */
> - WRITE_ONCE(*args->pudp, __pud(0));
> + ptdesc_set(*args->pudp, __pud(0));
> WARN_ON(!pud_set_huge(args->pudp, __pfn_to_phys(args->fixed_pud_pfn), args->page_prot));
> WARN_ON(!pud_clear_huge(args->pudp));
> pud = pudp_get(args->pudp);
> --
> 2.43.0
>
>
More information about the linux-arm-kernel
mailing list