From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BCCE351C3C for ; Thu, 9 Jul 2026 09:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783588532; cv=none; b=bj276uBsoZmbbuJsTuxcts6yOHxvvxJ/KwJ348Lw9aRi+RONfxCxxBJIzDlZeifLA2JE2BNTBPkFM/HH/Zcwu+8PCvEqKVe1o0tFVgxEsL1dhRAPfrrQIqSLYHYN5zwYS8I6Urj7njcNBDRF+H4aWAN7XHwzIWt+Q607toAQNI4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783588532; c=relaxed/simple; bh=D2wOG9Xz27hf5IQYfj6gx2661f7lFvKjlso+6Kc4hVQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g2sm5vk9LB0jQDkfCrOR5FiKe69TpeUGME6s1QxpFkjx/jZT0W+bHkuRHzFsPzxeSBgVv5sJLtx4VW+4eMSQy12XYsWrVUNfe/T5QvS3I4R6sK7xT5FwHqGtQ9UmEVF0rs2kOu/+1nrT2LiNMxgKLIlYC/TD4vgFBJ71X5cEzQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Obg8ojwm; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Obg8ojwm" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-47df440fcd5so676919f8f.3 for ; Thu, 09 Jul 2026 02:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1783588529; x=1784193329; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=0Xo8vReeYi/VtYuebsK0R479nywgN1CS8NCBcmTm2So=; b=Obg8ojwmoA6BRAmFQF3JcYmtyViz9rvQpi5NBiFUSLMYTv55ypWsMdpPBvekkiisNo OcbpTZIjtBKjOQRu5hfPNvk7y+yniQ6bllW9vTBjpZZiDYJyROQznqz7ybv16xCsU9+V j7sStjUDnCBF95wa0lwppykduig76SNbab2xc7v+35F9QZbD8QX0pHvlvok4gFu7vUxS w5zk/Dz4v+xV7AHjyEpWem6L+DKjn+x70lcoLBeWf4aD/tVf6EdGLjjKFE7EmTvU7ICZ rPcwTF6mpf+ew2pN7B5vvh3lhmY4WCWjwBm9k8Ng34k+w8xHbjCcuQpN4vcV0NfBPZdp drew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783588529; x=1784193329; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0Xo8vReeYi/VtYuebsK0R479nywgN1CS8NCBcmTm2So=; b=LqDQrOW+Dui4d6RYdwwQZE2dHPJAORFMmNC5RgUPWkObo100j6Nla3+ECLqwZSL8AC wv8tz92CcdJSGRd0j51nZ/TUXuym/31CkEcLgkf9bzoNWJC2bqnwVuFYPLOrHo1URhhk W4MhDaLl+x0whhlPCPL5bipZ2prEQFyDTzUaiOLVOR9PT9CmcU49bJMYPGP2lSdyPOyx 9H1FTzxBMdDovJ7VwICzJva2CVDpGATxcsyKaApb7hgdicCD7h7LcLKxIi9ty0epvnhQ FZEn6LzgchUANlvU234nKg6Jk3XAUXHPmMQHS5T4+qjHT8ra3jO8egvJgay4oZ7wBxdj irDg== X-Forwarded-Encrypted: i=1; AHgh+RoOgcU/D52xnLgPdNeaiIleVcabp3lcEReoah9Ra7h2nutgGYhm0b0PCKGEA+UwooquUnF1knYGHj5ClVE=@vger.kernel.org X-Gm-Message-State: AOJu0YzTxPNE1mDNJ97AgMsqqHPLrJurQJrGKor9ZU8FWOI1+phl1mP9 jzX55UoxqBkGQ0rcr3xjruk+83a3zOccEmqM+r26HrxPoOMVRPEwm82ZhV+Whjd5qJk= X-Gm-Gg: AfdE7cnSBDXnn44D8lNkKkVyU70EJPsezeRr4/ljvV3/cNLAezBU/U1tN/mxKbTiV+Z 2OKnu6L9K9mqmDqy2JUxYXcN5eP+rO7ZThcFdpPi0C6kblK9iBwjpFjVhfr08r/8blTv2l6104B ARQorvzwtAd9uADpj4ga5Oo+TnA4zzghHxqLufxP7rhrOY9jiImDNtciyNlwL4XlqzuEUo9mvT0 8CXYD1Bp3elgZhRSVvtc/kp+n+e6FYpDBOCDFq157e8F69e+3hEy9YcPs3FR4pwt2SyJk86Dlnf PxmUs3oxH00YG8B0BknNS1kT+Fo/XBIF2rkAm8KuuGSAs04LWAF6n2jR+xhopnEet2aG1Bii8jS d4X205xRCtNVBT6Ze7golqDhNkQ++p7p1ApkIdNR071c5/zwNyPfuSea6ozrvpkJTDFCWRo4/y3 0H7J9hctWiWbdnScA= X-Received: by 2002:a5d:5f51:0:b0:474:57f0:49f8 with SMTP id ffacd0b85a97d-47df07a988fmr6128868f8f.4.1783588529359; Thu, 09 Jul 2026 02:15:29 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960816sm48024686f8f.29.2026.07.09.02.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 02:15:29 -0700 (PDT) Date: Thu, 9 Jul 2026 11:15:27 +0200 From: Petr Mladek To: Andy Shevchenko 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: On Thu 2026-07-09 10:40:43, Andy Shevchenko wrote: > +Petr, wondering your opinion about code dedup (see below). > > On Thu, Jul 09, 2026 at 10:13:34AM +0530, Anshuman Khandual wrote: > > From: "David Hildenbrand (Arm)" > > > > Bad page map reporting currently stores page table entry values in an > > unsigned long long and prints them with fixed 64-bit-oriented format > > strings. This is inconsistent across call sites and does not work well for > > architectures where page table entry values are not naturally represented > > as 64-bit values, such as 32-bit or 128-bit entries. > > > > Introduce a common helper to convert raw page table entry values into a > > fixed-width hexadecimal string based on the actual entry size. Use it for > > bad page map reporting and for dumping the page table walk in > > __print_bad_page_map_pgtable(). > > > > Pass page table entry values to the reporting path as raw bytes together > > with their size, instead of forcing them through an unsigned long long. > > It keeps the printed output consistent and avoids truncation or misleading > > formatting for non-64-bit page table entries. > > > Cc: Andrew Morton > > Cc: linux-mm@kvack.org > > Cc: linux-kernel@vger.kernel.org > > FWIW, you may move these to be after... > > > Signed-off-by: David Hildenbrand (Arm) > > Co-developed-by: Anshuman Khandual > > Signed-off-by: Anshuman Khandual > > --- > ... this cutter line with the same effect on the email. The bonus is that > it will eliminate the huge noise and churn in the commit message. > Note, many maintainers switched to this schema (especially those, who use > `b4` tool, which allows to handle this nicely). > > ... > > > +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. Best Regards, Petr