Re: [PATCH V2] mm: Standardize printing for pgtable entries

From: Anshuman Khandual

Date: Wed Jul 08 2026 - 04:52:54 EST


On 08/07/26 1:31 PM, David Hildenbrand (Arm) wrote:
> On 7/8/26 05:28, Anshuman Khandual 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.
>>
>> 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.
>>
>> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
>> Cc: linux-mm@xxxxxxxxx
>> Cc: linux-kernel@xxxxxxxxxxxxxxx
>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> I still think you should add your
>
> Co-developed-by :)

OK - will add.

>
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
>> ---
>> This patch applies on v7.2-rc2
>>
>> Changes in V2:
>>
>> - Dropped space after ":" during print per Matthew
>> - Dropped CONFIG_CPU_BIG_ENDIAN per David
>>
>> Changes in V1:
>>
>> https://lore.kernel.org/all/20260707041703.658021-1-anshuman.khandual@xxxxxxx/
>>
>> mm/memory.c | 98 ++++++++++++++++++++++++++++++++++++++++-------------
>> 1 file changed, 75 insertions(+), 23 deletions(-)
>>
>
> In general, LGTM (I wrote of it, lol)
>
>> diff --git a/mm/memory.c b/mm/memory.c
>> index ff338c2abe92..a2b63af82792 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -519,9 +519,48 @@ static bool is_bad_page_map_ratelimited(void)
>> return false;
>> }
>>
>> +#define PTVAL_STR_MAX (32 + 1) /* Max 128-bit value in hex + NUL */
>
> We could reduce the stack space for !__SIZEOF_INT128__, but not sure if worth it.
>
> __print_bad_page_map_pgtable() will currently consume 132 bytes for strings,
> guess that's still tolerable.
>

That's a good point. Are you looking for something like the following
where stack space can be saved if __SIZEOF_INT128__ is not supported.

#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

Besides will move the macro just before __print_bad_page_map_pgtable()
where it gets used.