Add a new format for printing page table entries. Cc: Petr Mladek <pmladek@xxxxxxxx> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx> Cc: Jonathan Corbet <corbet@xxxxxxx> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: linux-doc@xxxxxxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx Cc: linux-mm@xxxxxxxxx Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx> --- Documentation/core-api/printk-formats.rst | 14 ++++++++++++++ lib/vsprintf.c | 20 ++++++++++++++++++++ mm/memory.c | 5 ++--- scripts/checkpatch.pl | 2 +- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst index 4b7f3646ec6ce..75a110b059ee1 100644 --- a/Documentation/core-api/printk-formats.rst +++ b/Documentation/core-api/printk-formats.rst @@ -689,6 +689,20 @@ Rust Only intended to be used from Rust code to format ``core::fmt::Arguments``. Do *not* use it from C. +Page Table Entry +---------------- + +:: + %ppte + +Print standard page table entry pte_t. + +Passed by reference. + +Examples for a 64 bit page table entry, given &(u64)0xc0ffee:: + + %ppte 0x00c0ffee + Thanks ====== diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3d85800757aa5..005490202ffb5 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2433,6 +2433,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 + * - 'pte' For a 64 bit page table entry, this prints its contents in + * a hexa decimal 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 @@ -2542,6 +2545,23 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, default: return error_string(buf, end, "(einval)", spec); } + case 'p': + if (fmt[1] == 't' && fmt[2] == 'e') { + pte_t *pte = (pte_t *)ptr; + + spec.field_width = 10; + spec.precision = 8; + spec.base = 16; + spec.flags = SPECIAL | SMALL | ZEROPAD; + if (sizeof(pte_t) == sizeof(u64)) { + u64 val = pte_val(*pte); + + return number(buf, end, val, spec); + } + WARN_ONCE(1, "Non standard pte_t\n"); + return error_string(buf, end, "(einval)", spec); + } + fallthrough; default: return default_pointer(buf, end, ptr, spec); } diff --git a/mm/memory.c b/mm/memory.c index 8eba595056fe3..c9a057b371eae 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -522,9 +522,8 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr, mapping = vma->vm_file ? vma->vm_file->f_mapping : NULL; index = linear_page_index(vma, addr); - pr_alert("BUG: Bad page map in process %s pte:%08llx pmd:%08llx\n", - current->comm, - (long long)pte_val(pte), (long long)pmd_val(*pmd)); + pr_alert("BUG: Bad page map in process %s pte:%ppte pmd:%ppte\n", + current->comm, &pte, pmd); if (page) dump_page(page, "bad pte"); pr_alert("addr:%px vm_flags:%08lx anon_vma:%px mapping:%px index:%lx\n", diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 664f7b7a622c2..fb8abc5dbfb8e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6906,7 +6906,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*)(\te))/g) { $specifier = $1; $extension = $2; $qualifier = $3; -- 2.30.2