From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 466CD30FF2A for ; Fri, 10 Jul 2026 03:10:33 +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=1783653036; cv=none; b=uSloecd/ZHfMXLDzBn3JGvAKl220eB8d98HcnUcHd2YKUwoNiPtECKK7BbCWA734Q+FFY5lQK6pE/llPR/aL+bQSEBwfTS4dBrn6tbRT8DGBHRWn/vpIbWdsk/IsSIexi0YVOkgeHw9XSNV4KFjVGPN8rnNFmoBnxRHcgHg5hyE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783653036; c=relaxed/simple; bh=r/JqXLtVJZipeHmoQcA9Vb3tveHMo173t3JvLPsXfyg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=o9w/rMbwDlExT0QsQFw3gDOm1s8PWTjXQNUHCUVGik06UZW+2M4OZV7tI4/WTxI/ld66AqkYcHJupOyx2iqYhFeOssgcfqafmmFr5aqLsCpkLWft/k18WhKqebw0smTzcGc9buHazEa+VwZpQwrDzRgSlXN0CbsZ3LRK+HCz4Xo= 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; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=lNLmbCZA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="lNLmbCZA" 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 22CD21E7D; Thu, 9 Jul 2026 20:10:28 -0700 (PDT) Received: from [10.174.42.251] (unknown [10.174.42.251]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 462D23FC81; Thu, 9 Jul 2026 20:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1783653032; bh=r/JqXLtVJZipeHmoQcA9Vb3tveHMo173t3JvLPsXfyg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lNLmbCZAKfAuKzOWn13sCSTiJnF4tNjcdAiQw5oDxbwzYSUmw/NG2SisqM08KNOED W4v6Kh+fr07ME6UaNZNJST3Dhv3LsXj/B7AySXY13fV1vu3TAsT2KFUDHrS0JvJrwS +rVAdObC8bYH0+S5QeWHMdOhS76Fp+VkZrxh6yMg= Message-ID: <25857f58-9ef1-49e0-99f7-366d91028c02@arm.com> Date: Fri, 10 Jul 2026 08:40:25 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V3] mm: Standardize printing for pgtable entries To: Andrew Morton Cc: linux-mm@kvack.org, andriy.shevchenko@linux.intel.com, usama.arif@linux.dev, hughd@google.com, willy@infradead.org, ryan.roberts@arm.com, "David Hildenbrand (Arm)" , linux-kernel@vger.kernel.org References: <20260709044334.1741263-1-anshuman.khandual@arm.com> <20260709170816.4e876a16eef9a93f41bb1940@linux-foundation.org> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20260709170816.4e876a16eef9a93f41bb1940@linux-foundation.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/07/26 5:38 AM, Andrew Morton wrote: > On Thu, 9 Jul 2026 10:13:34 +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. > > Well grumble. It's a lot of fuss for something which nobody is hurting > from. Or are they? What's the actual utility here? Current page table entries print does not work here for 128 bits format (arm64 D128) because neither 'unsigned long long' can hold 128 bits nor printing extracts u64 from the 128 bit entries while printing with "%llx". Proposed a separate printk format %pp[te|md|ud|p4d|gd] https://lore.kernel.org/all/20260610043545.3725735-1-anshuman.khandual@arm.com/ But there after it was decided to rather have a local solution in mm/memory.c instead of adding a new print format. The proposed change here streamlines existing u32/u64 page table entries format prints but also enables for u128 which will be added later. > >> 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. >> >> --- a/mm/memory.c >> +++ b/mm/memory.c >> >> ... >> >> +#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 >> + >> static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long addr) >> { >> - unsigned long long pgdv, p4dv, pudv, pmdv; >> + char pgd_str[PTVAL_STR_MAX]; >> + char p4d_str[PTVAL_STR_MAX]; >> + char pud_str[PTVAL_STR_MAX]; >> + char pmd_str[PTVAL_STR_MAX]; > > That's another 128b of stack, in a potentially deep code path. > > Hopefully gcc can reuse the same stack space for some of these but it's > not been good at this in the past. > >> p4d_t p4d, *p4dp; >> pud_t pud, *pudp; >> pmd_t pmd, *pmdp; >> @@ -532,34 +575,34 @@ static void __print_bad_page_map_pgtable(struct mm_struct *mm, unsigned long add >> * see locking requirements for print_bad_page_map(). >> */ >> pgdp = pgd_offset(mm, addr); >> - pgdv = pgd_val(*pgdp); >> + ptval_to_str(pgd_str, pgd_val(*pgdp)); >> >> if (!pgd_present(*pgdp) || pgd_leaf(*pgdp)) { >> - pr_alert("pgd:%08llx\n", pgdv); >> + pr_alert("pgd:%s\n", pgd_str); > > can this do > pr_alert("pgd:%s\n", ptval_to_str(pgd_str, pgd_val(*pgdp))); > > and eliminate a few locals? But that would not eliminate any local variable. The helper ptval_to_str() does not return but instead fills up the provided buffer which later gets printed.