From nobody Thu Oct 9 15:00:04 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C98361EDA26; Wed, 18 Jun 2025 04:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750219973; cv=none; b=CqN0JeO/ig8fQ/45TZ0PA8SoL52urCRry/ry5YrURTZUtdiFJKRhtC+rzZlVwyrtVVJy11NMUFW8tcNjrx0AhjjuHNm9oGEt8DeA6HmCtx0aDX9y4GwrzQd0vyBogsFWmqVl63AUwIWn5aq8cM3ZsuiuwjgRva6dNseuwd1gbPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750219973; c=relaxed/simple; bh=TOoC0U10ODrhjgPZKf7BXsEAXTZceLQX+8xKDYYs+9k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aTJy0XAQVwHrm5UfgEcoH21wTEzjsvHb4ouyT6SvKzvzyR7der2lkIO5I2rWh3BE075/05tZjifGXQQhbHPtt7jEIDGN1SV9z+wAQ9j9ZupvcFTmQSrusmJwWPHvG836/wMxeGq0WRQw+CflAcD8o1SkxWegw686hmzPt/Ukw/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 614E114BF; Tue, 17 Jun 2025 21:12:29 -0700 (PDT) Received: from a076716.blr.arm.com (a076716.blr.arm.com [10.164.21.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9A4793F66E; Tue, 17 Jun 2025 21:12:46 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org Cc: Anshuman Khandual , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , Petr Mladek , Steven Rostedt , Jonathan Corbet , Andrew Morton , David Hildenbrand , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [RFC 1/2] lib/vsprintf: Add support for pte_t Date: Wed, 18 Jun 2025 09:42:34 +0530 Message-Id: <20250618041235.1716143-2-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250618041235.1716143-1-anshuman.khandual@arm.com> References: <20250618041235.1716143-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new format for printing page table entries. Cc: Petr Mladek Cc: Steven Rostedt Cc: Jonathan Corbet Cc: Andrew Morton Cc: David Hildenbrand Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Anshuman Khandual --- 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. =20 +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 =3D=3D=3D=3D=3D=3D =20 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_enab= le); * 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] =3D=3D 't' && fmt[2] =3D=3D 'e') { + pte_t *pte =3D (pte_t *)ptr; + + spec.field_width =3D 10; + spec.precision =3D 8; + spec.base =3D 16; + spec.flags =3D SPECIAL | SMALL | ZEROPAD; + if (sizeof(pte_t) =3D=3D sizeof(u64)) { + u64 val =3D 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, u= nsigned long addr, mapping =3D vma->vm_file ? vma->vm_file->f_mapping : NULL; index =3D linear_page_index(vma, addr); =20 - 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 =3D get_quoted_string($lines[$count - 1], raw_line($count, 0)); $fmt =3D~ s/%%//g; =20 - while ($fmt =3D~ /(\%[\*\d\.]*p(\w)(\w*))/g) { + while ($fmt =3D~ /(\%[\*\d\.]*p(\w)(\w*)(\te))/g) { $specifier =3D $1; $extension =3D $2; $qualifier =3D $3; --=20 2.30.2