Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Anshuman Khandual <anshuman.khandual@arm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, andriy.shevchenko@linux.intel.com,
	usama.arif@linux.dev, hughd@google.com, willy@infradead.org,
	ryan.roberts@arm.com,
	"David Hildenbrand (Arm)" <david@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V3] mm: Standardize printing for pgtable entries
Date: Fri, 10 Jul 2026 08:40:25 +0530	[thread overview]
Message-ID: <25857f58-9ef1-49e0-99f7-366d91028c02@arm.com> (raw)
In-Reply-To: <20260709170816.4e876a16eef9a93f41bb1940@linux-foundation.org>



On 10/07/26 5:38 AM, Andrew Morton wrote:
> On Thu,  9 Jul 2026 10:13:34 +0530 Anshuman Khandual <anshuman.khandual@arm.com> wrote:
> 
>> From: "David Hildenbrand (Arm)" <david@kernel.org>
>>
>> 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?

Current page table entries print does not work here for
128 bits format (arm64 D128) because neither 'unsigned
long long' can hold 128 bits nor printing extracts u64
from the 128 bit entries while printing with "%llx".

Proposed a separate printk format %pp[te|md|ud|p4d|gd]

https://lore.kernel.org/all/20260610043545.3725735-1-anshuman.khandual@arm.com/  
 
But there after it was decided to rather have a local
solution in mm/memory.c instead of adding a new print
format.

The proposed change here streamlines existing u32/u64
page table entries format prints but also enables for
u128 which will be added later.

> >> 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?

But that would not eliminate any local variable.

The helper ptval_to_str() does not return but instead
fills up the provided buffer which later gets printed.


  reply	other threads:[~2026-07-10  3:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09  4:43 [PATCH V3] mm: Standardize printing for pgtable entries Anshuman Khandual
2026-07-09  7:40 ` Andy Shevchenko
2026-07-09  9:12   ` David Hildenbrand (Arm)
2026-07-09 10:09     ` Andy Shevchenko
2026-07-09 10:19       ` David Hildenbrand (Arm)
2026-07-09  9:15   ` Petr Mladek
2026-07-09 10:11     ` Andy Shevchenko
2026-07-09 10:13       ` Andy Shevchenko
2026-07-09 10:24         ` David Hildenbrand (Arm)
2026-07-09 10:43           ` Andy Shevchenko
2026-07-09 11:12             ` Anshuman Khandual
2026-07-09 11:54               ` Andy Shevchenko
2026-07-10  0:08 ` Andrew Morton
2026-07-10  3:10   ` Anshuman Khandual [this message]
2026-07-10  3:32     ` Andrew Morton
2026-07-10  8:16   ` David Hildenbrand (Arm)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25857f58-9ef1-49e0-99f7-366d91028c02@arm.com \
    --to=anshuman.khandual@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=david@kernel.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=usama.arif@linux.dev \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox