Re: [PATCH V3] mm: Standardize printing for pgtable entries
From: Andrew Morton
Date: Thu Jul 09 2026 - 20:08:24 EST
On Thu, 9 Jul 2026 10:13:34 +0530 Anshuman Khandual <anshuman.khandual@xxxxxxx> wrote:
> From: "David Hildenbrand (Arm)" <david@xxxxxxxxxx>
>
> Bad page map reporting currently stores page table entry values in an
> unsigned long long and prints them with fixed 64-bit-oriented format
> strings. This is inconsistent across call sites and does not work well for
> architectures where page table entry values are not naturally represented
> as 64-bit values, such as 32-bit or 128-bit entries.
Well grumble. It's a lot of fuss for something which nobody is hurting
from. Or are they? What's the actual utility here?
> Introduce a common helper to convert raw page table entry values into a
> fixed-width hexadecimal string based on the actual entry size. Use it for
> bad page map reporting and for dumping the page table walk in
> __print_bad_page_map_pgtable().
>
> Pass page table entry values to the reporting path as raw bytes together
> with their size, instead of forcing them through an unsigned long long.
> It keeps the printed output consistent and avoids truncation or misleading
> formatting for non-64-bit page table entries.
>
> --- a/mm/memory.c
> +++ b/mm/memory.c
>
> ...
>
> +#if defined(__SIZEOF_INT128__)
> +#define PTVAL_STR_MAX (32 + 1) /* Max 128-bit value in hex + NUL */
> +#else
> +#define PTVAL_STR_MAX (16 + 1) /* Max 64-bit value in hex + NUL */
> +#endif
> +
> static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long addr)
> {
> - unsigned long long pgdv, p4dv, pudv, pmdv;
> + char pgd_str[PTVAL_STR_MAX];
> + char p4d_str[PTVAL_STR_MAX];
> + char pud_str[PTVAL_STR_MAX];
> + char pmd_str[PTVAL_STR_MAX];
That's another 128b of stack, in a potentially deep code path.
Hopefully gcc can reuse the same stack space for some of these but it's
not been good at this in the past.
> p4d_t p4d, *p4dp;
> pud_t pud, *pudp;
> pmd_t pmd, *pmdp;
> @@ -532,34 +575,34 @@ static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long add
> * see locking requirements for print_bad_page_map().
> */
> pgdp = pgd_offset(mm, addr);
> - pgdv = pgd_val(*pgdp);
> + ptval_to_str(pgd_str, pgd_val(*pgdp));
>
> if (!pgd_present(*pgdp) || pgd_leaf(*pgdp)) {
> - pr_alert("pgd:%08llx\n", pgdv);
> + pr_alert("pgd:%s\n", pgd_str);
can this do
pr_alert("pgd:%s\n", ptval_to_str(pgd_str, pgd_val(*pgdp)));
and eliminate a few locals?