From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FCCC3B83F0 for ; Thu, 9 Jul 2026 10:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783591907; cv=none; b=DKxUx8lBWpoZ2LPjc48VOLzU1MRjG5jDxxwdodp8Q5e6Hk5J8s33jkwtIqpHfJkwbabmyGpHVsQcE8FPeGyMbBTmVDYnx1eGHAb3QMKaGxdgaYlfByay+S+OCNcZzPB0/sRlgaTbHY2U989UNj8eKRp6k1tpWTgHWIia/Aez9FM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783591907; c=relaxed/simple; bh=Dbwwr9k82STNamZXgOjXS9u4NcnIXxUNduxqyI391KU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=An2OaErJoRjLIZwe+ywQVhJl5GmisfsaEpkYZeHBN+SANCBOHEViGf7G6lFUx+3D0q0xb68eAAnUPYYkRgWOpJhkM1MoIUTOisc9w2HLT2b40WGvrRtDkg4z2EBgZ7TsxehQEgWG2FxpJRCIu5oi1qlPKNqsd8eH7OHfN6gdUQM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Wu6+01cy; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Wu6+01cy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783591906; x=1815127906; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Dbwwr9k82STNamZXgOjXS9u4NcnIXxUNduxqyI391KU=; b=Wu6+01cy68vsPXx6EHw51r48//ULP2xRNcC1VboghMI+4mTAjKS59nd6 G8OV6qVeDayvYVEnXghVM6f1+qjkqYFt0QXAi8+mn+A9Y/N2HoZmHGt6U Ite14KEKfVKDJLaGwxOKearI5UvzJcw8ymrquq6e1V+vT60J6K3x4YRCJ 1Rc9GKs64L58jpbcsFGZMMSnMZwSj1NH3ywkP2bZHLs9H88WAxyLmjTTM HAUFneV8nJOmWbN+Qr1PLuxmFP8M51ln9y+BvX7gm2xF//ih4bAxf0ri+ AAmGXGhR9xT6N5H77PuGCox8cDiNrlSKadbDQizaauCR86Xq9wj7ygn+Z g==; X-CSE-ConnectionGUID: b5nZAMEIQ0qAUFZJHCr6vQ== X-CSE-MsgGUID: ozLYMDgfRW2QHsvlXYoy8Q== X-IronPort-AV: E=McAfee;i="6800,10657,11841"; a="84126085" X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="84126085" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jul 2026 03:11:46 -0700 X-CSE-ConnectionGUID: tRcVs3+CTk2aMSzqxpeHRA== X-CSE-MsgGUID: fZLwjXclT++l6clJRMfZlw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="258411968" Received: from ettammin-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.235]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jul 2026 03:11:43 -0700 Date: Thu, 9 Jul 2026 13:11:41 +0300 From: Andy Shevchenko To: Petr Mladek Cc: Anshuman Khandual , linux-mm@kvack.org, usama.arif@linux.dev, hughd@google.com, willy@infradead.org, ryan.roberts@arm.com, "David Hildenbrand (Arm)" , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH V3] mm: Standardize printing for pgtable entries Message-ID: References: <20260709044334.1741263-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo 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