From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE1E3C73C66 for ; Thu, 19 Jun 2025 09:53:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AF756B00B7; Thu, 19 Jun 2025 05:53:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85EA36B00B8; Thu, 19 Jun 2025 05:53:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6636B6B00B9; Thu, 19 Jun 2025 05:53:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4F8326B00B7 for ; Thu, 19 Jun 2025 05:53:47 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ED087BC513 for ; Thu, 19 Jun 2025 09:53:46 +0000 (UTC) X-FDA: 83571688452.19.A38ED95 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf15.hostedemail.com (Postfix) with ESMTP id 2EAD6A000C for ; Thu, 19 Jun 2025 09:53:45 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750326825; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MkQCrzncCVavkYZ/XLL5XuP091cju7755pTcSTcPt68=; b=Rw7IudkTduowjZm/PentgZKLtN4poykYF5kqbsXvvcjbu0atv0jxRIx1Ggdu42YkGvA547 UMlY5GP56xV/UE6Tfid1/gbGmkPuz9tVwdFH6WXo4HM3ewKi+GQwRnrcOVUqvUFoD77I6l XHVZQKWEoIc9yfC+vrsVbEpztJFufHY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750326825; a=rsa-sha256; cv=none; b=kWJJ6aXrSBO1xsNXEtGyFahdkevWMZ0OWtgpDJs0awyplToVd3m2YmRtDCSMTB9nrNDEcT xgH9c3XyX4EwxVe41UwrOu5WULXOixHAO6BRFmV2/SYya8bLtRtBbO9CpP2jdopSOZCqbQ hoFkxa2OQnPJncS4Fr6TMsg47sKmPv0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=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 26899113E; Thu, 19 Jun 2025 02:53:24 -0700 (PDT) Received: from [10.163.35.214] (unknown [10.163.35.214]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A26673F66E; Thu, 19 Jun 2025 02:53:40 -0700 (PDT) Message-ID: Date: Thu, 19 Jun 2025 15:23:37 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 1/2] lib/vsprintf: Add support for pte_t To: Pedro Falcato Cc: linux-mm@kvack.org, 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 References: <20250618041235.1716143-1-anshuman.khandual@arm.com> <20250618041235.1716143-2-anshuman.khandual@arm.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2EAD6A000C X-Stat-Signature: wqyyqw4mse75tpc94u3u768q4sbixgfc X-Rspam-User: X-HE-Tag: 1750326824-294076 X-HE-Meta: U2FsdGVkX1+zUKN9uJ6HGfBoW4cQAc5q/dgzUkwXCB9O4qxPlQwPnVUm/hjHcTvehc+ddUfNQkG5zY8vvXk9gvnz1dy6dYmB1CzK+NN4fWa7bMOJDGc9p+JOtv4BQgQHm+vMjkxkFcXo37DpTSjL6p61OujFou9vFUDDqPQK9SOK/wyyGQgcjTwegb2HZAnpmncYuKg5uV8dhCKLZZFHnJXzPls+0N5i4viT4U8s/Uy64ABr1dfhfoW+MX6NtQl3pLim29g9jLDT1xmWs57fVFMjNJijqEHTchyD3ROgISdGg8wdswzNcSOBfkoRyK6NYFJ5Vg9AfqQklz6s+yL5NHQpZzAOro7WY/ZekEhp+qDxWkBkCN5pzEo/1P5+uQQvLkPHRpV1Y3J6CXlA8EbFrbvTiXLkd+jHHgr01ejr9oten/Fv9DeyxErTUfm3aXgeKLdlKv1MUdc9PIMpMpe7X5SAEVts0exP4z8yJAiDsHErhbSEH6atxP2+Bs6aQiI90Uh8KzTSsWQrkjZcNHuRtwZwO5yVNuBU9PEqg1zAmzbddEzLexdUsGBRAJM8gkK5npj29qO2eDFIa9CU2twVZICTgjDuwZ6uPeCSLxrkBsGvqxNUZWRTjJQGo4jx6psL59hZ8Yv0VmuUqTWQRjNxvDbYVhfVjZTrmOhuzp9GjGtM+dF0d1F5q6C7BahNhIuh1xOc6o5XlHRZEJ+wSTY4qV+TN+5gDvYZ+3AJv9HFLKM/RNkOfyuN7u6xUEX6wsjAoXXIT22EPlgJm06sASceR8pPY98hm3vk3vNO4nMrn8OHaiRI+3aTr5Sw4iYqTzwZMZuvnTKHwjEymiwvfmj/KtffqvJyuQionppwiio1VQxIv5zDosXV2pPkpD8jbIgjR7VfWkvULppe2ZPMbtXaoP+6fZr2SinxdAC5YwjFEtzHtFwykRzIDtsFkkoulLjHm5kLi/yup6c4zeQ3Lrs cwh9Zx6Z eizZk/rwn23UcArOFOdHVx716tDpEsL1q/Time6UDSiX5Dqfcpsi2FC215IzKp4RmzMo8v5+UXq3+SYyReGZeBTa/PdZGmc0NfxN8OOLE9yXeLaBb3OYUtRvjrw0XSMC5GmUEdrSwF57kAT5YzTY/nIyFUIEimz00MMXtOxJMzSmPuMlQ1ml4QGeLADA+nqRULz2XiUJxqNOaqlFkzDd5hnJCRoAAhpvZsrxgUKxbP63ZueIHDm4nXoeuoJ47JYvoLuElevJ8/9e/SbKNnNa9JhcO6ZYqahkF5cshBaHDkEJo9DowVWPaM/oZWRqOnTHaIY/GYqU59DvhM4+n7lA8cDyrZkqN7jgWWNIxfEBQz8vlJ3mFXiSPrSqQuS69iT6FI0qw9U9NgzpwdFGGnQmrcbtBobwR6xpPmoEu4dqSw/pmF2fITMbCMXjfvwuXiPmLq5yYr0Y/L3j/ZOvTeOPZk39CpArevtA9tYJ2hqeVjQob7f+00+wZn1KYQsZIsEztE6ZiRm9M+ppow1b5SpAkc/ZYfxSDa2DJ6k598sx/sxzLi+Vc36DZ7qooBlAJPKQx0DDhgFArc4oZsCZqJoAoQAKqeg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 18/06/25 11:49 PM, Pedro Falcato wrote: > On Wed, Jun 18, 2025 at 09:42:34AM +0530, Anshuman Khandual wrote: >> 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. >> >> +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 > > Ok, so what's the point of this if you're just printing the number? I might have got this wrong probably. The ideas is to represent a 64 bit address containing a 64 bit value i.e 0xc0ffee - which needs to be printed via the new print format. > > Could at least do something like: > > %ppte 0xc0ff000|WRITE|DIRTY|PRESENT > > no? Otherwise it's a not super useful wrapper around printing pte_val(*pte). Although it would be great to have PTE flags called out as well, the proposed patch here just wanted to transparently extract 64 bit printable value from pte_t represented page table entries. But coming back to your suggestion above. %ppte 0xc0ff000|WRITE|DIRTY|PRESENT Should all the generic page table entry flags and contained pfn be extracted from the pte_t and printed via new format %ppte ? > >> + >> 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); >> + } > > As mentioned elsewhere in the thread, this obviously doesn't work for everything > 32-bit, and 64-bit PAE, and all of the weird page table formats we have around. I will accommodate 32 bit formats. But what about 64-bit PAE ? Would not pte_val() also return a printable 64 bit number for such cases. Could you please elaborate on the weird page table formats you mentioned and why would not pte_val() work for those as well.