[RFC V1 12/16] arm64/mm: Abstract printing of pxd_val()

Anshuman Khandual
2026-02-24T05:13:39Z

Ahead of adding support for D128 pgtables, refactor places that print
PTE values to use the new __PRIpte format specifier and __PRIpte_args()
macro to prepare the argument(s). When using D128 pgtables in future,
we can simply redefine __PRIpte and __PTIpte_args().

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
arch/arm64/include/asm/pgtable-types.h | 3 +++
arch/arm64/include/asm/pgtable.h | 22 +++++++++++-----------
arch/arm64/mm/fault.c | 10 +++++-----
3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable-types.h b/arch/arm64/include/asm/pgtable-types.h
index 265e8301d7ba..dc3791dc9f14 100644
--- a/arch/arm64/include/asm/pgtable-types.h
+++ b/arch/arm64/include/asm/pgtable-types.h
@@ -11,6 +11,9 @@

#include <asm/types.h>

+#define __PRIpte "016llx"
+#define __PRIpte_args(val) ((u64)val)
+
/*
* Page Table Descriptor
*
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index cf69ce68f951..c4142b734112 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -152,7 +152,7 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
#define ZERO_PAGE(vaddr) phys_to_page(__pa_symbol(empty_zero_page))

#define pte_ERROR(e) \
- pr_err("%s:%d: bad pte %016llx.\n", __FILE__, __LINE__, pte_val(e))
+ pr_err("%s:%d: bad pte %" __PRIpte ".\n", __FILE__, __LINE__, __PRIpte_args(pte_val(e)))

#ifdef CONFIG_ARM64_PA_BITS_52
static inline phys_addr_t __pte_to_phys(pte_t pte)
@@ -465,14 +465,14 @@ static inline void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep,
* through an invalid entry).
*/
VM_WARN_ONCE(!pte_young(pte),
- "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
+ "%s: racy access flag clearing: 0x%" __PRIpte " -> 0x%" __PRIpte,
+ __func__, __PRIpte_args(pte_val(old_pte)), __PRIpte_args(pte_val(pte)));
VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
- "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
+ "%s: racy dirty state clearing: 0x%" __PRIpte " -> 0x%" __PRIpte,
+ __func__, __PRIpte_args(pte_val(old_pte)), __PRIpte_args(pte_val(pte)));
VM_WARN_ONCE(!pgattr_change_is_safe(pte_val(old_pte), pte_val(pte)),
- "%s: unsafe attribute change: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
+ "%s: unsafe attribute change: 0x%" __PRIpte " -> 0x%" __PRIpte,
+ __func__, __PRIpte_args(pte_val(old_pte)), __PRIpte_args(pte_val(pte)));
}

static inline void __sync_cache_and_tags(pte_t pte, unsigned int nr_pages)
@@ -905,7 +905,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
#if CONFIG_PGTABLE_LEVELS > 2

#define pmd_ERROR(e) \
- pr_err("%s:%d: bad pmd %016llx.\n", __FILE__, __LINE__, pmd_val(e))
+ pr_err("%s:%d: bad pmd %" __PRIpte ".\n", __FILE__, __LINE__, __PRIpte_args(pmd_val(e)))

#define pud_none(pud) (!pud_val(pud))
#define pud_bad(pud) ((pud_val(pud) & PUD_TYPE_MASK) != \
@@ -996,7 +996,7 @@ static inline bool mm_pud_folded(const struct mm_struct *mm)
#define mm_pud_folded mm_pud_folded

#define pud_ERROR(e) \
- pr_err("%s:%d: bad pud %016llx.\n", __FILE__, __LINE__, pud_val(e))
+ pr_err("%s:%d: bad pud %" __PRIpte ".\n", __FILE__, __LINE__, __PRIpte_args(pud_val(e)))

#define p4d_none(p4d) (pgtable_l4_enabled() && !p4d_val(p4d))
#define p4d_bad(p4d) (pgtable_l4_enabled() && \
@@ -1117,7 +1117,7 @@ static inline bool mm_p4d_folded(const struct mm_struct *mm)
#define mm_p4d_folded mm_p4d_folded

#define p4d_ERROR(e) \
- pr_err("%s:%d: bad p4d %016llx.\n", __FILE__, __LINE__, p4d_val(e))
+ pr_err("%s:%d: bad p4d %" __PRIpte ".\n", __FILE__, __LINE__, __PRIpte_args(p4d_val(e)))

#define pgd_none(pgd) (pgtable_l5_enabled() && !pgd_val(pgd))
#define pgd_bad(pgd) (pgtable_l5_enabled() && \
@@ -1238,7 +1238,7 @@ p4d_t *p4d_offset_lockless_folded(pgd_t *pgdp, pgd_t pgd, unsigned long addr)
#endif /* CONFIG_PGTABLE_LEVELS > 4 */

#define pgd_ERROR(e) \
- pr_err("%s:%d: bad pgd %016llx.\n", __FILE__, __LINE__, pgd_val(e))
+ pr_err("%s:%d: bad pgd %" __PRIpte ".\n", __FILE__, __LINE__, __PRIpte_args(pgd_val(e)))

#define pgd_set_fixmap(addr) ((pgd_t *)set_fixmap_offset(FIX_PGD, addr))
#define pgd_clear_fixmap() clear_fixmap(FIX_PGD)
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 21964a387bf8..9e44c84734f1 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -153,7 +153,7 @@ static void show_pte(unsigned long addr)
vabits_actual, mm_to_pgd_phys(mm));
pgdp = pgd_offset(mm, addr);
pgd = pgdp_get(pgdp);
- pr_alert("[%016lx] pgd=%016llx", addr, pgd_val(pgd));
+ pr_alert("[%016lx] pgd=%" __PRIpte, addr, __PRIpte_args(pgd_val(pgd)));

do {
p4d_t *p4dp, p4d;
@@ -166,19 +166,19 @@ static void show_pte(unsigned long addr)

p4dp = p4d_offset(pgdp, addr);
p4d = p4dp_get(p4dp);
- pr_cont(", p4d=%016llx", p4d_val(p4d));
+ pr_cont(", p4d=%" __PRIpte, __PRIpte_args(p4d_val(p4d)));
if (p4d_none(p4d) || p4d_bad(p4d))
break;

pudp = pud_offset(p4dp, addr);
pud = pudp_get(pudp);
- pr_cont(", pud=%016llx", pud_val(pud));
+ pr_cont(", pud=%" __PRIpte, __PRIpte_args(pud_val(pud)));
if (pud_none(pud) || pud_bad(pud))
break;

pmdp = pmd_offset(pudp, addr);
pmd = pmdp_get(pmdp);
- pr_cont(", pmd=%016llx", pmd_val(pmd));
+ pr_cont(", pmd=%" __PRIpte, __PRIpte_args(pmd_val(pmd)));
if (pmd_none(pmd) || pmd_bad(pmd))
break;

@@ -187,7 +187,7 @@ static void show_pte(unsigned long addr)
break;

pte = __ptep_get(ptep);
- pr_cont(", pte=%016llx", pte_val(pte));
+ pr_cont(", pte=%" __PRIpte, __PRIpte_args(pte_val(pte)));
pte_unmap(ptep);
} while(0);

--
2.43.0