From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>,
linux-mm@kvack.org, usama.arif@linux.dev, hughd@google.com,
willy@infradead.org, ryan.roberts@arm.com,
"David Hildenbrand (Arm)" <david@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH V3] mm: Standardize printing for pgtable entries
Date: Thu, 9 Jul 2026 13:11:41 +0300 [thread overview]
Message-ID: <ak9z3ZRdRqGoOu-T@ashevche-desk.local> (raw)
In-Reply-To: <ak9mrw37kTORZXmc@pathway.suse.cz>
On Thu, Jul 09, 2026 at 11:15:27AM +0200, Petr Mladek wrote:
> On Thu 2026-07-09 10:40:43, Andy Shevchenko wrote:
> > On Thu, Jul 09, 2026 at 10:13:34AM +0530, Anshuman Khandual wrote:
...
> > > +static void ptval_bytes_to_hex_str(char *buf, size_t buf_size, const void *entry, size_t entry_size)
> > > +{
> > > + if (WARN_ON_ONCE(buf_size < entry_size * 2 + 1)) {
> > > + snprintf(buf, buf_size, "overflow");
> > > + return;
> > > + }
> > > +
> > > + switch (entry_size) {
> > > + case sizeof(u32):
> > > + snprintf(buf, buf_size, "%08x", *(const u32 *)entry);
> > > + break;
> > > + case sizeof(u64):
> > > + snprintf(buf, buf_size, "%016llx", *(const u64 *)entry);
> > > + break;
> > > +#if defined(__SIZEOF_INT128__)
> > > + case sizeof(u128):
> > > + snprintf(buf, buf_size, "%016llx%016llx",
> > > + (unsigned long long)(*(const u128 *)entry >> 64),
> > > + (unsigned long long)*(const u128 *)entry);
> > > + break;
> > > +#endif
> > > + default:
> > > + snprintf(buf, buf_size, "unsupported");
> > > + break;
> > > + }
> > > +}
> > > +
> > > +#define ptval_to_str(buf, val) \
> > > + do { \
> > > + auto __val = (val); \
> > > + \
> > > + ptval_bytes_to_hex_str((buf), sizeof(buf), &__val, sizeof(__val)); \
> > > + } while (0)
> > > +
> > > +#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
> >
> > The above is quite duplicative with what we have in lib/vsprintf.c. Have you considered
> > using something from there instead? (Yes, it might require some functions to be wrapped
> > or dropped from static.)
>
> Honestly, I can't see any reasonable way to deduplicate the code.
>
> Most of the magic in the above macros are in the value/buffer size
> detection. I do not see anything similar in vsprintf.c. The sizes
> are handled another way there.
>
> Also the internal API used in vsprintf.c is a bit tricky because
> the buffer size is passed via *end pointer and it counts the printed
> characters even behind the *end pointer.
>
> But maybe you had something particular in mind.
Yes, I was thinking of a wrapper on top of special_hex_number(). It takes size
as an argument and hence will work even for 128-bit cases.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-07-09 10:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 4:43 [PATCH V3] mm: Standardize printing for pgtable entries Anshuman Khandual
2026-07-09 7:40 ` Andy Shevchenko
2026-07-09 9:12 ` David Hildenbrand (Arm)
2026-07-09 10:09 ` Andy Shevchenko
2026-07-09 10:19 ` David Hildenbrand (Arm)
2026-07-09 9:15 ` Petr Mladek
2026-07-09 10:11 ` Andy Shevchenko [this message]
2026-07-09 10:13 ` Andy Shevchenko
2026-07-09 10:24 ` David Hildenbrand (Arm)
2026-07-09 10:43 ` Andy Shevchenko
2026-07-09 11:12 ` Anshuman Khandual
2026-07-09 11:54 ` Andy Shevchenko
2026-07-10 0:08 ` Andrew Morton
2026-07-10 3:10 ` Anshuman Khandual
2026-07-10 3:32 ` Andrew Morton
2026-07-10 8:16 ` 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=ak9z3ZRdRqGoOu-T@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=david@kernel.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pmladek@suse.com \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=willy@infradead.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