The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 16/43] arm64: Introduce macros required for boot-time page size selection
Date: Tue,  1 Dec 2026 01:51:48 +0000	[thread overview]
Message-ID: <20261201015240.1017259-17-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com>

From: Ryan Roberts <ryan.roberts@arm.com>

Supporting a page size that is chosen at boot time needs the page and
page table geometry to be expressed in terms of values that can later
become variables, along with compile-time limits for code that needs a
constant.

Add asm/pgtable-geometry.h, which defines PAGE_SHIFT_MIN/MAX,
PAGE_SIZE_MIN/MAX and PAGE_MASK_MIN/MAX, together with ptg_*
definitions for the page, PMD, PUD, P4D and PGD shifts, the contiguous
PTE/PMD shifts and the number of page table levels. PAGE_SHIFT,
PMD_SHIFT, PUD_SHIFT, P4D_SHIFT, PGDIR_SHIFT, CONT_PTE_SHIFT and
CONT_PMD_SHIFT are now defined through them. Add MAX_PTRS_PER_PTE/PMD/
PUD/P4D for code that needs the largest possible table size as a
constant.

For now every ptg_* value is derived from the compile-time page size
configuration and both limits equal CONFIG_PAGE_SHIFT, so there is no
functional change. Later patches turn them into runtime values.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 9c901bc468652489bb381b43d47fa122b9faa392)
---
 arch/arm64/include/asm/page-def.h         |  9 +++++++-
 arch/arm64/include/asm/pgtable-geometry.h | 28 +++++++++++++++++++++++
 arch/arm64/include/asm/pgtable-hwdef.h    | 16 ++++++++-----
 3 files changed, 46 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/include/asm/pgtable-geometry.h

diff --git a/arch/arm64/include/asm/page-def.h b/arch/arm64/include/asm/page-def.h
index e0ef167519e6..dd9e164e1978 100644
--- a/arch/arm64/include/asm/page-def.h
+++ b/arch/arm64/include/asm/page-def.h
@@ -9,9 +9,16 @@
 #define __ASM_PAGE_DEF_H
 
 #include <linux/const.h>
+#include <asm/pgtable-geometry.h>
 
 #include <vdso/page.h>
 
-#include <asm-generic/pgtable-geometry.h>
+/* PAGE_SHIFT determines the page size */
+#undef PAGE_SHIFT
+#undef PAGE_SIZE
+#undef PAGE_MASK
+#define PAGE_SHIFT		ptg_page_shift
+#define PAGE_SIZE		(_AC(1, UL) << PAGE_SHIFT)
+#define PAGE_MASK		(~(PAGE_SIZE-1))
 
 #endif /* __ASM_PAGE_DEF_H */
diff --git a/arch/arm64/include/asm/pgtable-geometry.h b/arch/arm64/include/asm/pgtable-geometry.h
new file mode 100644
index 000000000000..62fe125909c0
--- /dev/null
+++ b/arch/arm64/include/asm/pgtable-geometry.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef ASM_PGTABLE_GEOMETRY_H
+#define ASM_PGTABLE_GEOMETRY_H
+
+#define ARM64_PAGE_SHIFT_4K	12
+#define ARM64_PAGE_SHIFT_16K	14
+#define ARM64_PAGE_SHIFT_64K	16
+
+#define PAGE_SHIFT_MIN		CONFIG_PAGE_SHIFT
+#define PAGE_SIZE_MIN		(_AC(1, UL) << PAGE_SHIFT_MIN)
+#define PAGE_MASK_MIN		(~(PAGE_SIZE_MIN-1))
+
+#define PAGE_SHIFT_MAX		CONFIG_PAGE_SHIFT
+#define PAGE_SIZE_MAX		(_AC(1, UL) << PAGE_SHIFT_MAX)
+#define PAGE_MASK_MAX		(~(PAGE_SIZE_MAX-1))
+
+#include <asm-generic/pgtable-geometry.h>
+
+#define ptg_page_shift		CONFIG_PAGE_SHIFT
+#define ptg_pmd_shift		ARM64_HW_PGTABLE_LEVEL_SHIFT(2)
+#define ptg_pud_shift		ARM64_HW_PGTABLE_LEVEL_SHIFT(1)
+#define ptg_p4d_shift		ARM64_HW_PGTABLE_LEVEL_SHIFT(0)
+#define ptg_pgdir_shift		ARM64_HW_PGTABLE_LEVEL_SHIFT(4 - CONFIG_PGTABLE_LEVELS)
+#define ptg_cont_pte_shift	(CONFIG_ARM64_CONT_PTE_SHIFT + PAGE_SHIFT)
+#define ptg_cont_pmd_shift	(CONFIG_ARM64_CONT_PMD_SHIFT + PMD_SHIFT)
+#define ptg_pgtable_levels	CONFIG_PGTABLE_LEVELS
+
+#endif /* ASM_PGTABLE_GEOMETRY_H */
diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h
index 72f31800c703..60e34018d5fa 100644
--- a/arch/arm64/include/asm/pgtable-hwdef.h
+++ b/arch/arm64/include/asm/pgtable-hwdef.h
@@ -47,39 +47,43 @@
 #define ARM64_HW_PGTABLE_LEVEL_SHIFT(n)	(PTDESC_TABLE_SHIFT * (4 - (n)) + PTDESC_ORDER)
 
 #define PTRS_PER_PTE		(1 << PTDESC_TABLE_SHIFT)
+#define MAX_PTRS_PER_PTE	(1 << (PAGE_SHIFT_MAX - PTDESC_ORDER))
 
 /*
  * PMD_SHIFT determines the size a level 2 page table entry can map.
  */
 #if CONFIG_PGTABLE_LEVELS > 2
-#define PMD_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(2)
+#define PMD_SHIFT		ptg_pmd_shift
 #define PMD_SIZE		(_AC(1, UL) << PMD_SHIFT)
 #define PMD_MASK		(~(PMD_SIZE-1))
 #define PTRS_PER_PMD		(1 << PTDESC_TABLE_SHIFT)
+#define MAX_PTRS_PER_PMD	(1 << (PAGE_SHIFT_MAX - PTDESC_ORDER))
 #endif
 
 /*
  * PUD_SHIFT determines the size a level 1 page table entry can map.
  */
 #if CONFIG_PGTABLE_LEVELS > 3
-#define PUD_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(1)
+#define PUD_SHIFT		ptg_pud_shift
 #define PUD_SIZE		(_AC(1, UL) << PUD_SHIFT)
 #define PUD_MASK		(~(PUD_SIZE-1))
 #define PTRS_PER_PUD		(1 << PTDESC_TABLE_SHIFT)
+#define MAX_PTRS_PER_PUD	(1 << (PAGE_SHIFT_MAX - PTDESC_ORDER))
 #endif
 
 #if CONFIG_PGTABLE_LEVELS > 4
-#define P4D_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(0)
+#define P4D_SHIFT		ptg_p4d_shift
 #define P4D_SIZE		(_AC(1, UL) << P4D_SHIFT)
 #define P4D_MASK		(~(P4D_SIZE-1))
 #define PTRS_PER_P4D		(1 << PTDESC_TABLE_SHIFT)
+#define MAX_PTRS_PER_P4D	(1 << (PAGE_SHIFT_MAX - PTDESC_ORDER))
 #endif
 
 /*
  * PGDIR_SHIFT determines the size a top-level page table entry can map
  * (depending on the configuration, this level can be -1, 0, 1 or 2).
  */
-#define PGDIR_SHIFT		ARM64_HW_PGTABLE_LEVEL_SHIFT(4 - CONFIG_PGTABLE_LEVELS)
+#define PGDIR_SHIFT		ptg_pgdir_shift
 #define PGDIR_SIZE		(_AC(1, UL) << PGDIR_SHIFT)
 #define PGDIR_MASK		(~(PGDIR_SIZE-1))
 #define PTRS_PER_PGD		(1 << (VA_BITS - PGDIR_SHIFT))
@@ -87,12 +91,12 @@
 /*
  * Contiguous page definitions.
  */
-#define CONT_PTE_SHIFT		(CONFIG_ARM64_CONT_PTE_SHIFT + PAGE_SHIFT)
+#define CONT_PTE_SHIFT		ptg_cont_pte_shift
 #define CONT_PTES		(1 << (CONT_PTE_SHIFT - PAGE_SHIFT))
 #define CONT_PTE_SIZE		(CONT_PTES * PAGE_SIZE)
 #define CONT_PTE_MASK		(~(CONT_PTE_SIZE - 1))
 
-#define CONT_PMD_SHIFT		(CONFIG_ARM64_CONT_PMD_SHIFT + PMD_SHIFT)
+#define CONT_PMD_SHIFT		ptg_cont_pmd_shift
 #define CONT_PMDS		(1 << (CONT_PMD_SHIFT - PMD_SHIFT))
 #define CONT_PMD_SIZE		(CONT_PMDS * PMD_SIZE)
 #define CONT_PMD_MASK		(~(CONT_PMD_SIZE - 1))

  parent reply	other threads:[~2026-12-01  1:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 01/43] mm: Add macros ahead of supporting boot-time page size selection Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 05/43] mm: Avoid split pmd ptl if pmd level is run-time folded Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 11/43] perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock Eric Curtin
2026-12-01  1:51 ` Eric Curtin [this message]
2026-12-01  1:51 ` [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 37/43] vdso: Lay out the data pages in VDSO_PAGE_SIZE units Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 39/43] crash: Size the vmcoreinfo page array for the smallest page size Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 41/43] exit: Use THREAD_SIZE_MAX for lowest_to_date Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 42/43] tracing: Use PAGE_SIZE_MIN/MAX in the uprobe check and undefsyms page Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection Eric Curtin
2026-12-01 10:41 ` [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Lorenzo Stoakes (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=20261201015240.1017259-17-ericcurtin17@gmail.com \
    --to=ericcurtin17@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ryan.roberts@arm.com \
    --cc=will@kernel.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