From: Anshuman Khandual <anshuman.khandual@arm.com>
To: linux-mm@kvack.org
Cc: Anshuman Khandual <anshuman.khandual@arm.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
Andy Whitcroft <apw@canonical.com>
Subject: [RFC V2 1/3] lib/vsprintf: Add support for pgtable entries
Date: Wed, 10 Jun 2026 05:35:43 +0100 [thread overview]
Message-ID: <20260610043545.3725735-2-anshuman.khandual@arm.com> (raw)
In-Reply-To: <20260610043545.3725735-1-anshuman.khandual@arm.com>
Add some print formats for pgtable entries at any pgtable level. These new
formats are %pp[g|4|u|m|t][d|e] i.e %ppgd, %pp4d, %ppud, %ppmd, and %ppte.
These currently support both 32 bit and 64 bit pgtable entries that can be
extended up to 128 bit when required.
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Documentation/core-api/printk-formats.rst | 19 ++++++++
lib/vsprintf.c | 58 +++++++++++++++++++++++
scripts/checkpatch.pl | 2 +-
3 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index c0b1b6089307..e69f91a9dd9d 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -696,6 +696,25 @@ Rust
Only intended to be used from Rust code to format ``core::fmt::Arguments``.
Do *not* use it from C.
+Page Table Entry
+----------------
+
+::
+
+ %p[pgd|p4dp|pud|pmd|pte]
+
+Print page table entry at any level.
+
+Passed by reference.
+
+Examples for a 64 bit page table entry, given &(u64)0xc0ffee::
+
+ %ppte 0x0000000000c0ffee
+ %ppmd 0x0000000000c0ffee
+ %ppud 0x0000000000c0ffee
+ %pp4d 0x0000000000c0ffee
+ %ppgd 0x0000000000c0ffee
+
Thanks
======
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 9f359b31c8d1..d4ad3048a4db 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -856,6 +856,59 @@ static char *default_pointer(char *buf, char *end, const void *ptr,
return ptr_to_id(buf, end, ptr, spec);
}
+static char *pxd_pointer(char *buf, char *end, const void *ptr,
+ struct printf_spec spec, const char *fmt)
+{
+ if (check_pointer(&buf, end, ptr, spec))
+ return buf;
+
+ if (fmt[1] == 't' && fmt[2] == 'e') {
+ pte_t *pte = (pte_t *)ptr;
+
+ static_assert(sizeof(pte_t) == 4 ||
+ sizeof(pte_t) == 8,
+ "pte_t size must be 4 or 8 bytes");
+ return special_hex_number(buf, end, pte_val(ptep_get(pte)), sizeof(pte_t));
+ }
+
+ if (fmt[1] == 'm' && fmt[2] == 'd') {
+ pmd_t *pmd = (pmd_t *)ptr;
+
+ static_assert(sizeof(pmd_t) == 4 ||
+ sizeof(pmd_t) == 8,
+ "pmd_t size must be 4 or 8 bytes");
+ return special_hex_number(buf, end, pmd_val(pmdp_get(pmd)), sizeof(pmd_t));
+ }
+
+ if (fmt[1] == 'u' && fmt[2] == 'd') {
+ pud_t *pud = (pud_t *)ptr;
+
+ static_assert(sizeof(pud_t) == 4 ||
+ sizeof(pud_t) == 8,
+ "pud_t size must be 4 or 8 bytes");
+ return special_hex_number(buf, end, pud_val(pudp_get(pud)), sizeof(pud_t));
+ }
+
+ if (fmt[1] == '4' && fmt[2] == 'd') {
+ p4d_t *p4d = (p4d_t *)ptr;
+
+ static_assert(sizeof(p4d_t) == 4 ||
+ sizeof(p4d_t) == 8,
+ "p4d_t size must be 4 or 8 bytes");
+ return special_hex_number(buf, end, p4d_val(p4dp_get(p4d)), sizeof(p4d_t));
+ }
+
+ if (fmt[1] == 'g' && fmt[2] == 'd') {
+ pgd_t *pgd = (pgd_t *)ptr;
+
+ static_assert(sizeof(pgd_t) == 4 ||
+ sizeof(pgd_t) == 8,
+ "pgd_t size must be 4 or 8 bytes");
+ return special_hex_number(buf, end, pgd_val(pgdp_get(pgd)), sizeof(pgd_t));
+ }
+ return default_pointer(buf, end, ptr, spec);
+}
+
int kptr_restrict __read_mostly;
static noinline_for_stack
@@ -2506,6 +2559,9 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
* Without an option prints the full name of the node
* f full name
* P node name, including a possible unit address
+ * - 'p[g|4|u|m|t|][d|e]' For a page table entry, this prints its
+ * contents in a hexadecimal format
+ *
* - 'x' For printing the address unmodified. Equivalent to "%lx".
* Please read the documentation (path below) before using!
* - '[ku]s' For a BPF/tracing related format specifier, e.g. used out of
@@ -2615,6 +2671,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
default:
return error_string(buf, end, "(einval)", spec);
}
+ case 'p':
+ return pxd_pointer(buf, end, ptr, spec, fmt);
default:
return default_pointer(buf, end, ptr, spec);
}
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0492d6afc9a1..f68955858e29 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6975,7 +6975,7 @@ sub process {
my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
$fmt =~ s/%%//g;
- while ($fmt =~ /(\%[\*\d\.]*p(\w)(\w*))/g) {
+ while ($fmt =~ /(\%[\*\d\.]*p(\w)(\w*)(pte|pmd|pud|p4d|pgd))/g) {
$specifier = $1;
$extension = $2;
$qualifier = $3;
--
2.30.2
next prev parent reply other threads:[~2026-06-10 4:36 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 4:35 [RFC V2 0/3] lib/vsprintf: Add support for pgtable entries Anshuman Khandual
2026-06-10 4:35 ` Anshuman Khandual [this message]
2026-06-10 11:13 ` [RFC V2 1/3] " Usama Arif
2026-06-11 5:15 ` Anshuman Khandual
2026-06-11 7:17 ` Andy Shevchenko
2026-06-11 9:50 ` Anshuman Khandual
2026-06-11 18:59 ` Andy Shevchenko
2026-06-10 4:35 ` [RFC V2 2/3] kunit: printf: Add test " Anshuman Khandual
2026-06-10 4:35 ` [RFC V2 3/3] mm: Replace pgtable entry prints with new format Anshuman Khandual
2026-06-11 11:32 ` David Hildenbrand (Arm)
2026-06-12 11:08 ` David Hildenbrand (Arm)
2026-06-12 21:26 ` Hugh Dickins
2026-06-15 16:01 ` David Hildenbrand (Arm)
2026-06-16 6:19 ` Hugh Dickins
2026-06-30 13:36 ` David Hildenbrand (Arm)
2026-07-01 9:00 ` Andy Shevchenko
2026-07-02 4:29 ` Anshuman Khandual
2026-07-02 7:32 ` David Hildenbrand (Arm)
2026-07-02 9:04 ` Anshuman Khandual
2026-07-02 9:20 ` Andy Shevchenko
2026-07-02 9:36 ` David Hildenbrand (Arm)
2026-06-11 19:15 ` [RFC V2 0/3] lib/vsprintf: Add support for pgtable entries Matthew Wilcox
2026-06-11 19:33 ` Andy Shevchenko
2026-06-11 19:37 ` Matthew Wilcox
2026-06-12 11:14 ` 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=20260610043545.3725735-2-anshuman.khandual@arm.com \
--to=anshuman.khandual@arm.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=apw@canonical.com \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=david@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@rasmusvillemoes.dk \
--cc=ljs@kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.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