* [RFC PATCH v2 01/43] mm: Add macros ahead of supporting boot-time page size selection
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 ` Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, Catalin Marinas, Will Deacon, linux-kernel,
linux-arch
From: Ryan Roberts <ryan.roberts@arm.com>
arm64 can support several base page sizes. To let the page size be
chosen on the kernel command line instead of at build time, PAGE_SHIFT,
PAGE_SIZE and PAGE_MASK can no longer be compile-time constants, and
code that needs a constant has to be converted.
Introduce PAGE_{SHIFT,SIZE,MASK}_{MIN,MAX}, which bound the range of
possible page sizes and are always compile-time constants. An arch must
define all of them or none. When it defines none, they are set equal to
PAGE_SHIFT, PAGE_SIZE and PAGE_MASK, so existing behaviour is unchanged.
Introduce DEFINE_GLOBAL_PAGE_SIZE_VAR(), _CONST() and _ATTR() to wrap
definitions of globals whose initialiser depends on PAGE_SIZE. With a
fixed page size they expand to a plain definition. With a boot-time page
size the variable is assigned by a function marked with the constructor
attribute. Constructors are used rather than initcalls because a module
is limited to one initcall but may have any number of constructors.
To make this work, call do_ctors() early in start_kernel() instead of
from do_basic_setup(), and run module constructors before module
parameters are parsed so that the parameters can override the defaults.
An arch enabling boot-time page size must select CONFIG_CONSTRUCTORS.
Also add BUILD_BUG_ON_FIXED_PAGE_SIZE(), which is BUILD_BUG_ON() when
PAGE_SIZE_MIN equals PAGE_SIZE_MAX and VM_BUG_ON() otherwise.
The macros live in a new asm-generic/pgtable-geometry.h, included from
each arch's page header next to PAGE_SHIFT, as there is no common header
to hook into.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 2e4f93099407da931c07e4bd7aec9ff5696207fa)
---
arch/alpha/include/asm/page.h | 1 +
arch/arc/include/asm/page.h | 1 +
arch/arm/include/asm/page.h | 1 +
arch/arm64/include/asm/page-def.h | 2 +
arch/csky/include/asm/page.h | 3 +
arch/hexagon/include/asm/page.h | 2 +
arch/loongarch/include/asm/page.h | 2 +
arch/m68k/include/asm/page.h | 1 +
arch/microblaze/include/asm/page.h | 1 +
arch/mips/include/asm/page.h | 1 +
arch/nios2/include/asm/page.h | 2 +
arch/openrisc/include/asm/page.h | 1 +
arch/parisc/include/asm/page.h | 1 +
arch/powerpc/include/asm/page.h | 2 +
arch/riscv/include/asm/page.h | 1 +
arch/s390/include/asm/page.h | 1 +
arch/sh/include/asm/page.h | 1 +
arch/sparc/include/asm/page.h | 3 +
arch/um/include/asm/page.h | 2 +
arch/x86/include/asm/page_types.h | 2 +
arch/xtensa/include/asm/page.h | 1 +
include/asm-generic/pgtable-geometry.h | 86 ++++++++++++++++++++++++++
init/main.c | 5 +-
kernel/module/main.c | 4 +-
24 files changed, 125 insertions(+), 2 deletions(-)
create mode 100644 include/asm-generic/pgtable-geometry.h
diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h
index 67053c52953f..f5468f52b281 100644
--- a/arch/alpha/include/asm/page.h
+++ b/arch/alpha/include/asm/page.h
@@ -96,5 +96,6 @@ typedef struct page *pgtable_t;
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* _ALPHA_PAGE_H */
diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index facc7a03b250..844ade515d4d 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -6,6 +6,7 @@
#define __ASM_ARC_PAGE_H
#include <uapi/asm/page.h>
+#include <asm-generic/pgtable-geometry.h>
#ifdef CONFIG_ARC_HAS_PAE40
diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
index fa4c1225dde5..fab78b35823f 100644
--- a/arch/arm/include/asm/page.h
+++ b/arch/arm/include/asm/page.h
@@ -188,5 +188,6 @@ extern int pfn_valid(unsigned long);
#include <asm-generic/getorder.h>
#include <asm-generic/memory_model.h>
+#include <asm-generic/pgtable-geometry.h>
#endif
diff --git a/arch/arm64/include/asm/page-def.h b/arch/arm64/include/asm/page-def.h
index d402e08442ee..e0ef167519e6 100644
--- a/arch/arm64/include/asm/page-def.h
+++ b/arch/arm64/include/asm/page-def.h
@@ -12,4 +12,6 @@
#include <vdso/page.h>
+#include <asm-generic/pgtable-geometry.h>
+
#endif /* __ASM_PAGE_DEF_H */
diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
index 76774dbce869..cc223a7c25b2 100644
--- a/arch/csky/include/asm/page.h
+++ b/arch/csky/include/asm/page.h
@@ -85,4 +85,7 @@ static inline unsigned long virt_to_pfn(const void *kaddr)
#include <asm-generic/getorder.h>
#endif /* !__ASSEMBLER__ */
+
+#include <asm-generic/pgtable-geometry.h>
+
#endif /* __ASM_CSKY_PAGE_H */
diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h
index 6d82572a7f21..b2e38f1132b9 100644
--- a/arch/hexagon/include/asm/page.h
+++ b/arch/hexagon/include/asm/page.h
@@ -130,4 +130,6 @@ static inline unsigned long virt_to_pfn(const void *kaddr)
#endif /* ifdef __ASSEMBLY__ */
#endif /* ifdef __KERNEL__ */
+#include <asm-generic/pgtable-geometry.h>
+
#endif
diff --git a/arch/loongarch/include/asm/page.h b/arch/loongarch/include/asm/page.h
index b9d61f7c032c..c446799933a0 100644
--- a/arch/loongarch/include/asm/page.h
+++ b/arch/loongarch/include/asm/page.h
@@ -107,4 +107,6 @@ extern int __virt_addr_valid(volatile void *kaddr);
#endif /* !__ASSEMBLER__ */
+#include <asm-generic/pgtable-geometry.h>
+
#endif /* _ASM_PAGE_H */
diff --git a/arch/m68k/include/asm/page.h b/arch/m68k/include/asm/page.h
index d30f8b2f1592..d4dc0147e47c 100644
--- a/arch/m68k/include/asm/page.h
+++ b/arch/m68k/include/asm/page.h
@@ -58,5 +58,6 @@ extern unsigned long _ramend;
#include <asm-generic/getorder.h>
#include <asm-generic/memory_model.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* _M68K_PAGE_H */
diff --git a/arch/microblaze/include/asm/page.h b/arch/microblaze/include/asm/page.h
index e1e396367ba7..4d3c1cc0073c 100644
--- a/arch/microblaze/include/asm/page.h
+++ b/arch/microblaze/include/asm/page.h
@@ -137,5 +137,6 @@ static inline const void *pfn_to_virt(unsigned long pfn)
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* _ASM_MICROBLAZE_PAGE_H */
diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
index 50a382a0d8f6..9cdc0b8cb966 100644
--- a/arch/mips/include/asm/page.h
+++ b/arch/mips/include/asm/page.h
@@ -223,5 +223,6 @@ static inline unsigned long kaslr_offset(void)
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* _ASM_PAGE_H */
diff --git a/arch/nios2/include/asm/page.h b/arch/nios2/include/asm/page.h
index 71eb7c1b67d4..27c4c68e8aea 100644
--- a/arch/nios2/include/asm/page.h
+++ b/arch/nios2/include/asm/page.h
@@ -93,4 +93,6 @@ extern struct page *mem_map;
#endif /* !__ASSEMBLER__ */
+#include <asm-generic/pgtable-geometry.h>
+
#endif /* _ASM_NIOS2_PAGE_H */
diff --git a/arch/openrisc/include/asm/page.h b/arch/openrisc/include/asm/page.h
index d2cdbf3579bb..ce3a6d921d8d 100644
--- a/arch/openrisc/include/asm/page.h
+++ b/arch/openrisc/include/asm/page.h
@@ -76,5 +76,6 @@ static inline unsigned long virt_to_pfn(const void *kaddr)
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* __ASM_OPENRISC_PAGE_H */
diff --git a/arch/parisc/include/asm/page.h b/arch/parisc/include/asm/page.h
index 3630b36d07da..4dffa850d30a 100644
--- a/arch/parisc/include/asm/page.h
+++ b/arch/parisc/include/asm/page.h
@@ -169,6 +169,7 @@ extern int npmem_ranges;
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#include <asm/pdc.h>
#define PAGE0 ((struct zeropage *)absolute_pointer(__PAGE_OFFSET))
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index 281f25e071a3..e5c01c11f26b 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -293,4 +293,6 @@ static inline unsigned long kaslr_offset(void)
#include <asm-generic/memory_model.h>
#endif /* __ASSEMBLER__ */
+#include <asm-generic/pgtable-geometry.h>
+
#endif /* _ASM_POWERPC_PAGE_H */
diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index b4bbae55e931..2e68929ac15c 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -176,5 +176,6 @@ static __always_inline void *pfn_to_kaddr(unsigned long pfn)
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* _ASM_RISCV_PAGE_H */
diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h
index 56da819a79e6..46f340d25b74 100644
--- a/arch/s390/include/asm/page.h
+++ b/arch/s390/include/asm/page.h
@@ -283,6 +283,7 @@ static inline unsigned long virt_to_pfn(const void *kaddr)
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#define AMODE31_SIZE (3 * PAGE_SIZE)
diff --git a/arch/sh/include/asm/page.h b/arch/sh/include/asm/page.h
index def4205491ec..13e13e900586 100644
--- a/arch/sh/include/asm/page.h
+++ b/arch/sh/include/asm/page.h
@@ -159,5 +159,6 @@ typedef struct page *pgtable_t;
#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* __ASM_SH_PAGE_H */
diff --git a/arch/sparc/include/asm/page.h b/arch/sparc/include/asm/page.h
index 1a00cc0a1893..8f46b7a38ccd 100644
--- a/arch/sparc/include/asm/page.h
+++ b/arch/sparc/include/asm/page.h
@@ -7,4 +7,7 @@
#else
#include <asm/page_32.h>
#endif
+
+#include <asm-generic/pgtable-geometry.h>
+
#endif
diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
index e348ff489b89..6eb5a5cdbcf0 100644
--- a/arch/um/include/asm/page.h
+++ b/arch/um/include/asm/page.h
@@ -95,4 +95,6 @@ extern unsigned long uml_physmem;
#endif /* __ASSEMBLER__ */
+#include <asm-generic/pgtable-geometry.h>
+
#endif /* __UM_PAGE_H */
diff --git a/arch/x86/include/asm/page_types.h b/arch/x86/include/asm/page_types.h
index 3e0801a0f782..99145b56714c 100644
--- a/arch/x86/include/asm/page_types.h
+++ b/arch/x86/include/asm/page_types.h
@@ -66,4 +66,6 @@ extern void initmem_init(void);
#endif /* !__ASSEMBLER__ */
+#include <asm-generic/pgtable-geometry.h>
+
#endif /* _ASM_X86_PAGE_DEFS_H */
diff --git a/arch/xtensa/include/asm/page.h b/arch/xtensa/include/asm/page.h
index 059493256765..6fb8bfbd0f45 100644
--- a/arch/xtensa/include/asm/page.h
+++ b/arch/xtensa/include/asm/page.h
@@ -174,4 +174,5 @@ static inline unsigned long ___pa(unsigned long va)
#endif /* __ASSEMBLER__ */
#include <asm-generic/memory_model.h>
+#include <asm-generic/pgtable-geometry.h>
#endif /* _XTENSA_PAGE_H */
diff --git a/include/asm-generic/pgtable-geometry.h b/include/asm-generic/pgtable-geometry.h
new file mode 100644
index 000000000000..89609cab425f
--- /dev/null
+++ b/include/asm-generic/pgtable-geometry.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ASM_GENERIC_PGTABLE_GEOMETRY_H
+#define ASM_GENERIC_PGTABLE_GEOMETRY_H
+
+#if defined(PAGE_SHIFT_MAX) && defined(PAGE_SIZE_MAX) && defined(PAGE_MASK_MAX) && \
+ defined(PAGE_SHIFT_MIN) && defined(PAGE_SIZE_MIN) && defined(PAGE_MASK_MIN)
+/* Arch supports boot-time page size selection. */
+#elif defined(PAGE_SHIFT_MAX) || defined(PAGE_SIZE_MAX) || defined(PAGE_MASK_MAX) || \
+ defined(PAGE_SHIFT_MIN) || defined(PAGE_SIZE_MIN) || defined(PAGE_MASK_MIN)
+#error Arch must define all or none of the boot-time page size macros
+#else
+/* Arch does not support boot-time page size selection. */
+#define PAGE_SHIFT_MIN PAGE_SHIFT
+#define PAGE_SIZE_MIN PAGE_SIZE
+#define PAGE_MASK_MIN PAGE_MASK
+#define PAGE_SHIFT_MAX PAGE_SHIFT
+#define PAGE_SIZE_MAX PAGE_SIZE
+#define PAGE_MASK_MAX PAGE_MASK
+#endif
+
+/*
+ * Define a global variable (scalar or struct), whose value is derived from
+ * PAGE_SIZE and friends. When PAGE_SIZE is a compile-time constant, the global
+ * variable is simply defined with the static value. When PAGE_SIZE is
+ * determined at boot-time, a constructor is registered and run before any
+ * initcalls or module params are parsed to initialize the variable.
+ *
+ * @type: Unqualified type. Do not include "const"; implied by macro variant.
+ * @name: Variable name.
+ * @attrib: Variable attributes (DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR only).
+ * @...: Initialization value. May be scalar or initializer.
+ *
+ * "static" is declared by placing "static" before the macro.
+ *
+ * Example:
+ *
+ * struct my_struct {
+ * int a;
+ * char b;
+ * };
+ *
+ * static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct my_struct, my_variable, {
+ * .a = 10,
+ * .b = 'e',
+ * });
+ */
+#if PAGE_SIZE_MIN != PAGE_SIZE_MAX
+#define __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, attrib, ...) \
+ type name attrib; \
+ static void __init __attribute__((constructor)) __##name##_init(void) \
+ { \
+ name = (type)__VA_ARGS__; \
+ }
+
+#define DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, ...) \
+ __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, , __VA_ARGS__)
+
+#define DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(type, name, ...) \
+ __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, __ro_after_init, __VA_ARGS__)
+#else /* PAGE_SIZE_MIN == PAGE_SIZE_MAX */
+#define __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, attrib, ...) \
+ type name attrib = __VA_ARGS__; \
+
+#define DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, ...) \
+ __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, , __VA_ARGS__)
+
+#define DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(type, name, ...) \
+ __DEFINE_GLOBAL_PAGE_SIZE_VAR(const type, name, , __VA_ARGS__)
+#endif
+
+#define DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR(type, name, attrib, ...) \
+ __DEFINE_GLOBAL_PAGE_SIZE_VAR(type, name, attrib, __VA_ARGS__)
+
+#ifndef __ASSEMBLY__
+/*
+ * Compile-time check when the page size is fixed. With boot-time page size
+ * the condition is only known at boot, so check it at run-time instead.
+ */
+#if PAGE_SIZE_MIN == PAGE_SIZE_MAX
+#define BUILD_BUG_ON_FIXED_PAGE_SIZE(cond) BUILD_BUG_ON(cond)
+#else
+#define BUILD_BUG_ON_FIXED_PAGE_SIZE(cond) VM_BUG_ON(cond)
+#endif
+#endif /* __ASSEMBLY__ */
+
+#endif /* ASM_GENERIC_PGTABLE_GEOMETRY_H */
diff --git a/init/main.c b/init/main.c
index f14780345051..3d619be281aa 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1053,6 +1053,8 @@ static void __init print_kernel_cmdline(const char *cmdline)
pr_notice("%s%s\n", KERNEL_CMDLINE_PREFIX, cmdline);
}
+static __init void do_ctors(void);
+
asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector
void start_kernel(void)
{
@@ -1064,6 +1066,8 @@ void start_kernel(void)
debug_objects_early_init();
init_vmlinux_build_id();
+ do_ctors();
+
cgroup_init_early();
local_irq_disable();
@@ -1526,7 +1530,6 @@ static void __init do_basic_setup(void)
ksysfs_init();
driver_init();
init_irq_proc();
- do_ctors();
do_initcalls();
}
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 34e0204ea37c..17145dc9c009 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -3127,7 +3127,6 @@ static noinline int do_init_module(struct module *mod)
freeinit->init_data = mod->mem[MOD_INIT_DATA].base;
freeinit->init_rodata = mod->mem[MOD_INIT_RODATA].base;
- do_mod_ctors(mod);
/* Start the module */
if (mod->init != NULL)
ret = do_one_initcall(mod->init);
@@ -3575,6 +3574,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
mod->async_probe_requested = async_probe;
+ /* Constructors may set defaults that module params must override. */
+ do_mod_ctors(mod);
+
/* Module is ready to execute: parsing args may do that. */
after_dashes = parse_args(mod->name, args, mod->kp, mod->num_kp,
-32768, 32767, mod,
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX
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 ` 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
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, Arnd Bergmann, Dennis Zhou, Tejun Heo,
Christoph Lameter, linux-arch, linux-kernel, linux-mm
From: Ryan Roberts <ryan.roberts@arm.com>
Data that must be page aligned is laid out at build time, so it cannot
be aligned to a PAGE_SIZE that is only known at boot.
Use PAGE_SIZE_MAX for the alignment in vmlinux.lds.h (init text, rodata,
nosave, BTF, bss, percpu and the other page-aligned sections), in
__page_aligned_data and __page_aligned_bss, and in
DECLARE/DEFINE_PER_CPU_PAGE_ALIGNED(). This keeps the data aligned for
whichever page size is selected at boot.
PAGE_SIZE_MAX equals PAGE_SIZE when the page size is fixed, so there is
no change for compile-time page sizes.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit bb504904abc5ead0ce74f9e9c7d868f4f13c3815)
---
include/asm-generic/vmlinux.lds.h | 38 +++++++++++++++----------------
include/linux/linkage.h | 4 ++--
include/linux/percpu-defs.h | 4 ++--
3 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 3eb732942d69..2a86599cb620 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -13,7 +13,7 @@
* . = START;
* __init_begin = .;
* HEAD_TEXT_SECTION
- * INIT_TEXT_SECTION(PAGE_SIZE)
+ * INIT_TEXT_SECTION(PAGE_SIZE_MAX)
* INIT_DATA_SECTION(...)
* PERCPU_SECTION(CACHELINE_SIZE)
* __init_end = .;
@@ -23,7 +23,7 @@
* _etext = .;
*
* _sdata = .;
- * RO_DATA(PAGE_SIZE)
+ * RO_DATA(PAGE_SIZE_MAX)
* RW_DATA(...)
* _edata = .;
*
@@ -397,10 +397,10 @@
* Data section helpers
*/
#define NOSAVE_DATA \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
__nosave_begin = .; \
*(.data..nosave) \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
__nosave_end = .;
#define CACHE_HOT_DATA(align) \
@@ -603,7 +603,7 @@
*(.text.unknown .text.unknown.*) \
TEXT_SPLIT \
TEXT_UNLIKELY \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
TEXT_HOT \
*(TEXT_MAIN .text.fixup) \
NOINSTR_TEXT \
@@ -677,7 +677,7 @@
*/
#ifdef CONFIG_DEBUG_INFO_BTF_INLINE
#define BTF_INLINE \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
.BTF.inline : AT(ADDR(.BTF.inline) - LOAD_OFFSET) { \
BOUNDED_SECTION_BY(.BTF.inline, _BTF_inline) \
}
@@ -693,7 +693,7 @@
#define BTF_LINK_SIZE (64 - 4 + 32 + 4)
#endif
#define BTF_INLINE_LINK \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
.BTF.inline.link : AT(ADDR(.BTF.inline.link) - LOAD_OFFSET) { \
__start_BTF_inline_link = .; \
BYTE(0) \
@@ -706,13 +706,13 @@
#ifdef CONFIG_DEBUG_INFO_BTF
#define BTF \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
.BTF : AT(ADDR(.BTF) - LOAD_OFFSET) { \
BOUNDED_SECTION_BY(.BTF, _BTF) \
} \
BTF_INLINE \
BTF_INLINE_LINK \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
*(.BTF_ids) \
}
@@ -807,9 +807,9 @@
. = ALIGN(bss_align); \
.bss : AT(ADDR(.bss) - LOAD_OFFSET) { \
BSS_FIRST_SECTIONS \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
*(.bss..page_aligned) \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
*(.dynbss) \
*(BSS_MAIN) \
*(COMMON) \
@@ -1046,9 +1046,9 @@
*/
#ifdef CONFIG_AMD_MEM_ENCRYPT
#define PERCPU_DECRYPTED_SECTION \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
*(.data..percpu..decrypted) \
- . = ALIGN(PAGE_SIZE);
+ . = ALIGN(PAGE_SIZE_MAX);
#else
#define PERCPU_DECRYPTED_SECTION
#endif
@@ -1132,7 +1132,7 @@
*/
#define PERCPU_INPUT(cacheline) \
__per_cpu_start = .; \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
*(.data..percpu..page_aligned) \
. = ALIGN(cacheline); \
__per_cpu_hot_start = .; \
@@ -1156,7 +1156,7 @@
* sharing between subsections for different purposes.
*/
#define PERCPU_SECTION(cacheline) \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
.data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \
PERCPU_INPUT(cacheline) \
}
@@ -1173,15 +1173,15 @@
* All sections are combined in a single .data section.
* The sections following CONSTRUCTORS are arranged so their
* typical alignment matches.
- * A cacheline is typical/always less than a PAGE_SIZE so
+ * A cacheline is typical/always less than a PAGE_SIZE_MAX so
* the sections that has this restriction (or similar)
- * is located before the ones requiring PAGE_SIZE alignment.
- * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
+ * is located before the ones requiring PAGE_SIZE_MAX alignment.
+ * NOSAVE_DATA starts and ends with a PAGE_SIZE_MAX alignment which
* matches the requirement of PAGE_ALIGNED_DATA.
*
* use 0 as page_align if page_aligned data is not used */
#define RW_DATA(cacheline, pagealigned, inittask) \
- . = ALIGN(PAGE_SIZE); \
+ . = ALIGN(PAGE_SIZE_MAX); \
.data : AT(ADDR(.data) - LOAD_OFFSET) { \
INIT_TASK_DATA(inittask) \
NOSAVE_DATA \
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 53fe1f48fd28..3673440789c3 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -36,8 +36,8 @@
__stringify(name))
#endif
-#define __page_aligned_data __section(".data..page_aligned") __aligned(PAGE_SIZE)
-#define __page_aligned_bss __section(".bss..page_aligned") __aligned(PAGE_SIZE)
+#define __page_aligned_data __section(".data..page_aligned") __aligned(PAGE_SIZE_MAX)
+#define __page_aligned_bss __section(".bss..page_aligned") __aligned(PAGE_SIZE_MAX)
#ifndef __bss_pgtbl
#define __bss_pgtbl __page_aligned_bss
diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h
index dbe3267a0a13..9e15c10ca6a5 100644
--- a/include/linux/percpu-defs.h
+++ b/include/linux/percpu-defs.h
@@ -153,11 +153,11 @@
*/
#define DECLARE_PER_CPU_PAGE_ALIGNED(type, name) \
DECLARE_PER_CPU_SECTION(type, name, "..page_aligned") \
- __aligned(PAGE_SIZE)
+ __aligned(PAGE_SIZE_MAX)
#define DEFINE_PER_CPU_PAGE_ALIGNED(type, name) \
DEFINE_PER_CPU_SECTION(type, name, "..page_aligned") \
- __aligned(PAGE_SIZE)
+ __aligned(PAGE_SIZE_MAX)
/*
* Declaration/definition used for per-CPU variables that must be read mostly.
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 05/43] mm: Avoid split pmd ptl if pmd level is run-time folded
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 ` Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters Eric Curtin
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Kees Cook, Andrew Morton, linux-mm, linux-kernel
From: Ryan Roberts <ryan.roberts@arm.com>
If there are only two levels of translation, the first level (pgd) may
not be an entire page and so may not have a ptdesc backing it (this can
be the case on arm64, depending on VA size and page size). Even if it
does have a ptdesc, pagetable_pmd_ctor() is not called for it, since it
is a pgd and not a pmd table, so the per-ptdesc ptl fields are not
initialised.
So far this has been fine: the arch knows at compile time whether the
pmd level is folded and, if so, does not select
CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK. With boot-time page size selection
the number of levels is not known at compile time, so the choice has to
be made at boot.
When CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK is selected, make
pmd_lockptr() return mm->page_table_lock if mm_pmd_folded() is true, and
have pmd_huge_pte() use mm->pmd_huge_pte in that case. Add
CONFIG_ARCH_RUNTIME_PMD_FOLD for arches that fold at run time, and
CONFIG_MM_PMD_HUGE_PTE to describe when mm_struct needs the pmd_huge_pte
member (THP without split pmd ptlocks, or with run-time pmd folding).
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 78715f47a6259f419370cf8089bd79361516be26)
---
include/linux/mm.h | 17 ++++++++++++++++-
include/linux/mm_types.h | 2 +-
kernel/fork.c | 4 ++--
mm/Kconfig | 8 ++++++++
4 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 040cff64381b..14a35440c806 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4208,6 +4208,8 @@ static inline struct ptdesc *pmd_ptdesc(pmd_t *pmd)
static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
{
+ if (mm_pmd_folded(mm))
+ return &mm->page_table_lock;
return ptlock_ptr(pmd_ptdesc(pmd));
}
@@ -4219,7 +4221,20 @@ static inline bool pmd_ptlock_init(struct ptdesc *ptdesc)
return ptlock_init(ptdesc);
}
-#define pmd_huge_pte(mm, pmd) (pmd_ptdesc(pmd)->pmd_huge_pte)
+static inline pgtable_t *__pmd_huge_pte(struct mm_struct *mm, pmd_t *pmd)
+{
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+#ifdef CONFIG_ARCH_RUNTIME_PMD_FOLD
+ if (mm_pmd_folded(mm))
+ return &mm->pmd_huge_pte;
+#endif
+ return &pmd_ptdesc(pmd)->pmd_huge_pte;
+#else
+ return NULL;
+#endif
+}
+
+#define pmd_huge_pte(mm, pmd) (*__pmd_huge_pte(mm, pmd))
#else
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 1ed35d258d2e..ed9277798631 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -1382,7 +1382,7 @@ struct mm_struct {
#ifdef CONFIG_MMU_NOTIFIER
struct mmu_notifier_subscriptions *notifier_subscriptions;
#endif
-#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !defined(CONFIG_SPLIT_PMD_PTLOCKS)
+#ifdef CONFIG_MM_PMD_HUGE_PTE
pgtable_t pmd_huge_pte; /* protected by page_table_lock */
#endif
#ifdef CONFIG_NUMA_BALANCING
diff --git a/kernel/fork.c b/kernel/fork.c
index d55a7d21a8fb..5a0db5a89615 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -647,7 +647,7 @@ static void check_mm(struct mm_struct *mm)
pr_alert("BUG: non-zero pgtables_bytes on freeing mm: %ld\n",
mm_pgtables_bytes(mm));
-#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !defined(CONFIG_SPLIT_PMD_PTLOCKS)
+#ifdef CONFIG_MM_PMD_HUGE_PTE
VM_BUG_ON_MM(mm->pmd_huge_pte, mm);
#endif
}
@@ -1110,7 +1110,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
RCU_INIT_POINTER(mm->exe_file, NULL);
mmu_notifier_subscriptions_init(mm);
init_tlb_flush_pending(mm);
-#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !defined(CONFIG_SPLIT_PMD_PTLOCKS)
+#ifdef CONFIG_MM_PMD_HUGE_PTE
mm->pmd_huge_pte = NULL;
#endif
mm_init_uprobes_state(mm);
diff --git a/mm/Kconfig b/mm/Kconfig
index afff1b25b543..f0868970b367 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -611,10 +611,18 @@ config SPLIT_PTE_PTLOCKS
config ARCH_ENABLE_SPLIT_PMD_PTLOCK
bool
+config ARCH_RUNTIME_PMD_FOLD
+ bool
+
config SPLIT_PMD_PTLOCKS
def_bool y
depends on SPLIT_PTE_PTLOCKS && ARCH_ENABLE_SPLIT_PMD_PTLOCK
+config MM_PMD_HUGE_PTE
+ def_bool y
+ depends on TRANSPARENT_HUGEPAGE
+ depends on !SPLIT_PMD_PTLOCKS || ARCH_RUNTIME_PMD_FOLD
+
#
# support for memory balloon
config BALLOON
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (2 preceding siblings ...)
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 ` Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, linux-mm,
linux-kernel
From: Ryan Roberts <ryan.roberts@arm.com>
THREAD_SIZE depends on PAGE_SIZE when boot-time page size selection is
used, so it is not a compile-time constant and cannot be used in C
preprocessor conditionals.
Test THREAD_SIZE_MAX instead in the #if directives that decide which
KSTACK_nK vm event items exist, in vm_event_item.h, vmstat_text[] in
mm/vmstat.c, and kstack_histogram() in kernel/exit.c. With a smaller
runtime THREAD_SIZE, the counters for sizes above it are still defined
but simply never incremented.
No functional change for compile-time page sizes.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit bf0856284bb664002b756e3785d35aa050d766c9)
---
include/linux/vm_event_item.h | 14 +++++++-------
kernel/exit.c | 14 +++++++-------
mm/vmstat.c | 14 +++++++-------
3 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 2628ccda076a..d1bca28052ef 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -153,25 +153,25 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
#endif
#ifdef CONFIG_DEBUG_STACK_USAGE
KSTACK_1K,
-#if THREAD_SIZE > 1024
+#if THREAD_SIZE_MAX > 1024
KSTACK_2K,
#endif
-#if THREAD_SIZE > 2048
+#if THREAD_SIZE_MAX > 2048
KSTACK_4K,
#endif
-#if THREAD_SIZE > 4096
+#if THREAD_SIZE_MAX > 4096
KSTACK_8K,
#endif
-#if THREAD_SIZE > 8192
+#if THREAD_SIZE_MAX > 8192
KSTACK_16K,
#endif
-#if THREAD_SIZE > 16384
+#if THREAD_SIZE_MAX > 16384
KSTACK_32K,
#endif
-#if THREAD_SIZE > 32768
+#if THREAD_SIZE_MAX > 32768
KSTACK_64K,
#endif
-#if THREAD_SIZE > 65536
+#if THREAD_SIZE_MAX > 65536
KSTACK_REST,
#endif
#endif /* CONFIG_DEBUG_STACK_USAGE */
diff --git a/kernel/exit.c b/kernel/exit.c
index d5e7bc2af804..a8453363d1fd 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -813,31 +813,31 @@ static inline void kstack_histogram(unsigned long used_stack)
#ifdef CONFIG_VM_EVENT_COUNTERS
if (used_stack <= 1024)
count_vm_event(KSTACK_1K);
-#if THREAD_SIZE > 1024
+#if THREAD_SIZE_MAX > 1024
else if (used_stack <= 2048)
count_vm_event(KSTACK_2K);
#endif
-#if THREAD_SIZE > 2048
+#if THREAD_SIZE_MAX > 2048
else if (used_stack <= 4096)
count_vm_event(KSTACK_4K);
#endif
-#if THREAD_SIZE > 4096
+#if THREAD_SIZE_MAX > 4096
else if (used_stack <= 8192)
count_vm_event(KSTACK_8K);
#endif
-#if THREAD_SIZE > 8192
+#if THREAD_SIZE_MAX > 8192
else if (used_stack <= 16384)
count_vm_event(KSTACK_16K);
#endif
-#if THREAD_SIZE > 16384
+#if THREAD_SIZE_MAX > 16384
else if (used_stack <= 32768)
count_vm_event(KSTACK_32K);
#endif
-#if THREAD_SIZE > 32768
+#if THREAD_SIZE_MAX > 32768
else if (used_stack <= 65536)
count_vm_event(KSTACK_64K);
#endif
-#if THREAD_SIZE > 65536
+#if THREAD_SIZE_MAX > 65536
else
count_vm_event(KSTACK_REST);
#endif
diff --git a/mm/vmstat.c b/mm/vmstat.c
index c6beac6be2bc..248ab936410c 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1481,25 +1481,25 @@ const char * const vmstat_text[] = {
#endif
#ifdef CONFIG_DEBUG_STACK_USAGE
[I(KSTACK_1K)] = "kstack_1k",
-#if THREAD_SIZE > 1024
+#if THREAD_SIZE_MAX > 1024
[I(KSTACK_2K)] = "kstack_2k",
#endif
-#if THREAD_SIZE > 2048
+#if THREAD_SIZE_MAX > 2048
[I(KSTACK_4K)] = "kstack_4k",
#endif
-#if THREAD_SIZE > 4096
+#if THREAD_SIZE_MAX > 4096
[I(KSTACK_8K)] = "kstack_8k",
#endif
-#if THREAD_SIZE > 8192
+#if THREAD_SIZE_MAX > 8192
[I(KSTACK_16K)] = "kstack_16k",
#endif
-#if THREAD_SIZE > 16384
+#if THREAD_SIZE_MAX > 16384
[I(KSTACK_32K)] = "kstack_32k",
#endif
-#if THREAD_SIZE > 32768
+#if THREAD_SIZE_MAX > 32768
[I(KSTACK_64K)] = "kstack_64k",
#endif
-#if THREAD_SIZE > 65536
+#if THREAD_SIZE_MAX > 65536
[I(KSTACK_REST)] = "kstack_rest",
#endif
#endif /* CONFIG_DEBUG_STACK_USAGE */
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (3 preceding siblings ...)
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 ` 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
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, Vlastimil Babka, Arnd Bergmann, Ingo Molnar,
Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
K Prateek Nayak, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Michal Hocko, Kees Cook,
Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov,
Dmitry Vyukov, Vincenzo Frascino, Andrew Morton, linux-arch,
linux-kernel, linux-mm, kasan-dev
From: Ryan Roberts <ryan.roberts@arm.com>
THREAD_SIZE is the size of a kernel thread stack. It has been a
compile-time constant, but with vmap stacks it must be a multiple of
PAGE_SIZE, so with boot-time page size selection it can no longer be
fixed at build time.
Defining THREAD_SIZE for the largest supported page size would waste
memory with smaller pages. For example, arm64 needs 16K stacks, but 64K
pages with a vmap stack require 64K; paying that with 4K or 16K pages
would waste 48K per kernel thread.
So allow THREAD_SIZE to be a runtime value. Add THREAD_SIZE_MAX and
THREAD_ALIGN_MAX, defaulting to THREAD_SIZE and
max(THREAD_ALIGN, THREAD_SIZE_MAX), and use THREAD_SIZE_MAX to size
init_stack, thread_union and the init stack in the linker script.
In fork.c, replace the compile-time split between the page allocator
and the kmem_cache based stack allocator with run-time checks of
THREAD_SIZE >= PAGE_SIZE, and make thread_stack_cache_init() return
early when stacks are page based. The weak stub in init/main.c is now
conditional on CONFIG_VMAP_STACK. KASAN's init_task_stack_addr() uses
THREAD_SIZE rather than sizeof() of the stack array.
No functional change when THREAD_SIZE is a compile-time constant.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 13e7b56091910f3533cee539b7c1ef857f61fe4d)
---
include/asm-generic/vmlinux.lds.h | 6 +++-
include/linux/sched.h | 4 +--
include/linux/thread_info.h | 10 +++++-
init/main.c | 2 +-
kernel/fork.c | 53 ++++++++++---------------------
mm/kasan/report.c | 3 +-
6 files changed, 35 insertions(+), 43 deletions(-)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 2a86599cb620..4df6c8fd38cb 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -56,6 +56,10 @@
#define LOAD_OFFSET 0
#endif
+#ifndef THREAD_SIZE_MAX
+#define THREAD_SIZE_MAX THREAD_SIZE
+#endif
+
/*
* Only some architectures want to have the .notes segment visible in
* a separate PT_NOTE ELF Program Header. When this happens, it needs
@@ -428,7 +432,7 @@
init_thread_union = .; \
init_stack = .; \
KEEP(*(.data..init_thread_info)) \
- . = __start_init_stack + THREAD_SIZE; \
+ . = __start_init_stack + THREAD_SIZE_MAX; \
__end_init_stack = .;
#define JUMP_TABLE_DATA \
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e4f6323d7855..2b649bbd668a 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1998,14 +1998,14 @@ union thread_union {
#ifndef CONFIG_THREAD_INFO_IN_TASK
struct thread_info thread_info;
#endif
- unsigned long stack[THREAD_SIZE/sizeof(long)];
+ unsigned long stack[THREAD_SIZE_MAX/sizeof(long)];
};
#ifndef CONFIG_THREAD_INFO_IN_TASK
extern struct thread_info init_thread_info;
#endif
-extern unsigned long init_stack[THREAD_SIZE / sizeof(unsigned long)];
+extern unsigned long init_stack[THREAD_SIZE_MAX / sizeof(unsigned long)];
#ifdef CONFIG_THREAD_INFO_IN_TASK
# define task_thread_info(task) (&(task)->thread_info)
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 307b8390fc67..73d0a77a3c2c 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -89,7 +89,15 @@ static inline long set_restart_fn(struct restart_block *restart,
}
#ifndef THREAD_ALIGN
-#define THREAD_ALIGN THREAD_SIZE
+#define THREAD_ALIGN THREAD_SIZE
+#endif
+
+#ifndef THREAD_SIZE_MAX
+#define THREAD_SIZE_MAX THREAD_SIZE
+#endif
+
+#ifndef THREAD_ALIGN_MAX
+#define THREAD_ALIGN_MAX max(THREAD_ALIGN, THREAD_SIZE_MAX)
#endif
#define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_SKIP_KASAN)
diff --git a/init/main.c b/init/main.c
index 3d619be281aa..2a44990521eb 100644
--- a/init/main.c
+++ b/init/main.c
@@ -849,7 +849,7 @@ void __init __weak smp_prepare_boot_cpu(void)
{
}
-# if THREAD_SIZE >= PAGE_SIZE
+#ifdef CONFIG_VMAP_STACK
void __init __weak thread_stack_cache_init(void)
{
}
diff --git a/kernel/fork.c b/kernel/fork.c
index 5a0db5a89615..87c102ea8d62 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -393,45 +393,15 @@ static void free_thread_stack(struct task_struct *tsk)
* Allocate pages if THREAD_SIZE is >= PAGE_SIZE, otherwise use a
* kmemcache based allocator.
*/
-#if THREAD_SIZE >= PAGE_SIZE
-
-static void thread_stack_free_rcu(struct rcu_head *rh)
-{
- __free_pages(virt_to_page(rh), THREAD_SIZE_ORDER);
-}
-
-static void thread_stack_delayed_free(struct task_struct *tsk)
-{
- struct rcu_head *rh = tsk->stack;
-
- call_rcu(rh, thread_stack_free_rcu);
-}
-
-static int alloc_thread_stack_node(struct task_struct *tsk, int node)
-{
- struct page *page = alloc_pages_node(node, THREADINFO_GFP,
- THREAD_SIZE_ORDER);
-
- if (likely(page)) {
- tsk->stack = kasan_reset_tag(page_address(page));
- return 0;
- }
- return -ENOMEM;
-}
-
-static void free_thread_stack(struct task_struct *tsk)
-{
- thread_stack_delayed_free(tsk);
- tsk->stack = NULL;
-}
-
-#else /* !(THREAD_SIZE >= PAGE_SIZE) */
static struct kmem_cache *thread_stack_cache;
static void thread_stack_free_rcu(struct rcu_head *rh)
{
- kmem_cache_free(thread_stack_cache, rh);
+ if (THREAD_SIZE >= PAGE_SIZE)
+ __free_pages(virt_to_page(rh), THREAD_SIZE_ORDER);
+ else
+ kmem_cache_free(thread_stack_cache, rh);
}
static void thread_stack_delayed_free(struct task_struct *tsk)
@@ -444,7 +414,16 @@ static void thread_stack_delayed_free(struct task_struct *tsk)
static int alloc_thread_stack_node(struct task_struct *tsk, int node)
{
unsigned long *stack;
- stack = kmem_cache_alloc_node(thread_stack_cache, THREADINFO_GFP, node);
+ struct page *page;
+
+ if (THREAD_SIZE >= PAGE_SIZE) {
+ page = alloc_pages_node(node, THREADINFO_GFP, THREAD_SIZE_ORDER);
+ stack = likely(page) ? page_address(page) : NULL;
+ } else {
+ stack = kmem_cache_alloc_node(thread_stack_cache,
+ THREADINFO_GFP, node);
+ }
+
stack = kasan_reset_tag(stack);
tsk->stack = stack;
return stack ? 0 : -ENOMEM;
@@ -458,13 +437,15 @@ static void free_thread_stack(struct task_struct *tsk)
void thread_stack_cache_init(void)
{
+ if (THREAD_SIZE >= PAGE_SIZE)
+ return;
+
thread_stack_cache = kmem_cache_create_usercopy("thread_stack",
THREAD_SIZE, THREAD_SIZE, 0, 0,
THREAD_SIZE, NULL);
BUG_ON(thread_stack_cache == NULL);
}
-#endif /* THREAD_SIZE >= PAGE_SIZE */
#endif /* CONFIG_VMAP_STACK */
/* SLAB cache for signal_struct structures (tsk->signal) */
diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index e804b1e1f886..7b170efd224b 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -366,8 +366,7 @@ static inline bool kernel_or_module_addr(const void *addr)
static inline bool init_task_stack_addr(const void *addr)
{
return addr >= (void *)&init_thread_union.stack &&
- (addr <= (void *)&init_thread_union.stack +
- sizeof(init_thread_union.stack));
+ (addr <= (void *)&init_thread_union.stack + THREAD_SIZE);
}
static void print_address_description(void *addr, u8 tag,
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 11/43] perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (4 preceding siblings ...)
2026-12-01 1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
@ 2026-12-01 1:51 ` Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 16/43] arm64: Introduce macros required for boot-time page size selection Eric Curtin
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, linux-perf-users, linux-kernel
From: Ryan Roberts <ryan.roberts@arm.com>
With boot-time page size selection PAGE_SIZE is not a compile-time
constant.
In the PMU_FORMAT_ATTR() show function, compare sizeof(_format) against
PAGE_SIZE_MIN in BUILD_BUG_ON(). The format string does not depend on
the page size, so checking it fits the smallest page is sufficient.
Define sysctl_perf_event_mlock, whose default is derived from PAGE_SIZE,
with DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR() so that it is initialised at
boot for boot-time page size builds.
No functional change for compile-time page sizes.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 6e83c7d00396aa8d86ae2a50b6f7ce156c01d7cc)
---
include/linux/perf_event.h | 2 +-
kernel/events/core.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index b52348eca6ef..e09498c9379e 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -2098,7 +2098,7 @@ _name##_show(struct device *dev, \
struct device_attribute *attr, \
char *page) \
{ \
- BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
+ BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE_MIN); \
return sprintf(page, _format "\n"); \
} \
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4ab3919ac78e..41c372980e0c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -496,7 +496,8 @@ static __always_inline bool is_guest_mediated_pmu_loaded(void)
int sysctl_perf_event_paranoid __read_mostly = 2;
/* Minimum for 512 kiB + 1 user control page. 'free' kiB per user. */
-static int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024);
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR(int, sysctl_perf_event_mlock, __read_mostly,
+ 512 + (PAGE_SIZE / 1024));
/*
* max perf event sample rate
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 16/43] arm64: Introduce macros required for boot-time page size selection
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (5 preceding siblings ...)
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
2026-12-01 1:51 ` [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, Catalin Marinas, Will Deacon, Mark Rutland,
linux-kernel
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))
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (6 preceding siblings ...)
2026-12-01 1:51 ` [RFC PATCH v2 16/43] arm64: Introduce macros required for boot-time page size selection Eric Curtin
@ 2026-12-01 1:51 ` 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
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly,
Steffen Eiden, Suzuki K Poulose, Zenghui Yu, Catalin Marinas,
Will Deacon, Mark Rutland, Muchun Song, Mike Rapoport,
David Hildenbrand, Andrey Ryabinin, Alexander Potapenko,
Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino,
Thomas Gleixner, Radu Rendec, kvmarm, linux-mm, kasan-dev,
linux-kernel
From: Ryan Roberts <ryan.roberts@arm.com>
With boot-time page size selection the page size is no longer known at
compile time, so macros and code that are conditional on the
CONFIG_ARM64_4K_PAGES, CONFIG_ARM64_16K_PAGES and CONFIG_ARM64_64K_PAGES
options cannot keep making that decision in the preprocessor.
Convert the simple cases to compare PAGE_SIZE with SZ_4K/SZ_16K/SZ_64K,
mostly with the ternary operator. This still folds to a compile-time
constant when the page size is fixed at build time, but also works once
PAGE_SIZE is a runtime value. The affected definitions are
VTCR_EL2_TGRAN and VTCR_EL2_TGRAN_SL0_BASE, KVM_PGTABLE_MIN_BLOCK_LEVEL,
IOREMAP_MAX_ORDER, TASK_SIZE_32, SECTION_SIZE_BITS, the
ID_AA64MMFR0_EL1_TGRAN_* helpers, ARM64_MEMSTART_SHIFT,
ARM64_MEMSTART_ALIGN and SHADOW_ALIGN. The remaining
IS_ENABLED(CONFIG_ARM64_*K_PAGES) tests in fixmap.c, kasan_init.c,
mmu.c and irq-gic-v3-its.c become PAGE_SIZE comparisons as well.
The ARM64_HAS_VA52 capability now uses a new has_va52() match function
which selects the ID register field to check (VARange for 64K, TGRAN16
or TGRAN4 for LPA2) from PAGE_SIZE, so the unused cases are removed by
the compiler for a compile-time page size. has_lpa2() is now always
built and returns false for 64K pages. As a result the single
"52-bit Virtual Addressing" description replaces the separate LVA and
LPA2 descriptions.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 1be465f97e3039e3ecd46594b3441b70b0ae9bfb)
---
arch/arm64/include/asm/kvm_arm.h | 23 ++++--------
arch/arm64/include/asm/kvm_pgtable.h | 6 +---
arch/arm64/include/asm/memory.h | 7 ++--
arch/arm64/include/asm/processor.h | 10 +++---
arch/arm64/include/asm/sparsemem.h | 11 ++----
arch/arm64/include/asm/sysreg.h | 54 ++++++++++++++++++----------
arch/arm64/kernel/cpufeature.c | 43 +++++++++++++---------
arch/arm64/mm/fixmap.c | 2 +-
arch/arm64/mm/init.c | 20 +++++------
arch/arm64/mm/kasan_init.c | 8 ++---
arch/arm64/mm/mmu.c | 2 +-
drivers/irqchip/irq-gic-v3-its.c | 2 +-
12 files changed, 95 insertions(+), 93 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 3e1c9e31028e..497d7202f978 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -85,22 +85,13 @@
* Entry_Level = 4 - Number_of_levels.
*
*/
-#ifdef CONFIG_ARM64_64K_PAGES
+#define VTCR_EL2_TGRAN \
+ (PAGE_SIZE == SZ_64K ? \
+ VTCR_EL2_TG0_64K : \
+ (PAGE_SIZE == SZ_16K ? VTCR_EL2_TG0_16K : VTCR_EL2_TG0_4K))
-#define VTCR_EL2_TGRAN 64K
-#define VTCR_EL2_TGRAN_SL0_BASE 3UL
-
-#elif defined(CONFIG_ARM64_16K_PAGES)
-
-#define VTCR_EL2_TGRAN 16K
-#define VTCR_EL2_TGRAN_SL0_BASE 3UL
-
-#else /* 4K */
-
-#define VTCR_EL2_TGRAN 4K
-#define VTCR_EL2_TGRAN_SL0_BASE 2UL
-
-#endif
+#define VTCR_EL2_TGRAN_SL0_BASE \
+ (PAGE_SIZE == SZ_64K ? 3UL : (PAGE_SIZE == SZ_16K ? 3UL : 2UL))
#define VTCR_EL2_LVLS_TO_SL0(levels) \
FIELD_PREP(VTCR_EL2_SL0, (VTCR_EL2_TGRAN_SL0_BASE - (4 - (levels))))
@@ -112,7 +103,7 @@
#define VTCR_EL2_FLAGS (SYS_FIELD_PREP_ENUM(VTCR_EL2, SH0, INNER) | \
SYS_FIELD_PREP_ENUM(VTCR_EL2, ORGN0, WBWA) | \
SYS_FIELD_PREP_ENUM(VTCR_EL2, IRGN0, WBWA) | \
- SYS_FIELD_PREP_ENUM(VTCR_EL2, TG0, VTCR_EL2_TGRAN) | \
+ FIELD_PREP(VTCR_EL2_TG0_MASK, VTCR_EL2_TGRAN) | \
VTCR_EL2_RES1)
#define VTCR_EL2_IPA(vtcr) (64 - FIELD_GET(VTCR_EL2_T0SZ, (vtcr)))
diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h
index 6d6ed8596847..24ff90459a8c 100644
--- a/arch/arm64/include/asm/kvm_pgtable.h
+++ b/arch/arm64/include/asm/kvm_pgtable.h
@@ -28,11 +28,7 @@ struct kvm_s2_mmu;
* - 16K (level 2): 32MB
* - 64K (level 2): 512MB
*/
-#ifdef CONFIG_ARM64_4K_PAGES
-#define KVM_PGTABLE_MIN_BLOCK_LEVEL 1
-#else
-#define KVM_PGTABLE_MIN_BLOCK_LEVEL 2
-#endif
+#define KVM_PGTABLE_MIN_BLOCK_LEVEL (PAGE_SIZE == SZ_4K ? 1 : 2)
#define kvm_lpa2_is_enabled() system_supports_lpa2()
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index a2b7a33966ff..a6df911206ff 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -194,11 +194,8 @@
#define MT_S2_FWB_DEVICE_nGnRE 1
#define MT_S2_FWB_AS_S1 7
-#ifdef CONFIG_ARM64_4K_PAGES
-#define IOREMAP_MAX_ORDER (PUD_SHIFT)
-#else
-#define IOREMAP_MAX_ORDER (PMD_SHIFT)
-#endif
+#define IOREMAP_MAX_ORDER \
+ (PAGE_SIZE == SZ_4K ? PUD_SHIFT : PMD_SHIFT)
/*
* Open-coded (swapper_pg_dir - reserved_pg_dir) as this cannot be calculated
diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 481f1999f7c1..9ca6fd0f409b 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -57,15 +57,15 @@
#define TASK_SIZE_MAX (UL(1) << VA_BITS)
#ifdef CONFIG_COMPAT
-#if defined(CONFIG_ARM64_64K_PAGES) && defined(CONFIG_KUSER_HELPERS)
+#if defined(CONFIG_KUSER_HELPERS)
/*
- * With CONFIG_ARM64_64K_PAGES enabled, the last page is occupied
- * by the compat vectors page.
+ * With 64K pages in use, the last page is occupied by the compat vectors page.
*/
-#define TASK_SIZE_32 UL(0x100000000)
+#define TASK_SIZE_32 \
+ (PAGE_SIZE == SZ_64K ? UL(0x100000000) : (UL(0x100000000) - PAGE_SIZE))
#else
#define TASK_SIZE_32 (UL(0x100000000) - PAGE_SIZE)
-#endif /* CONFIG_ARM64_64K_PAGES */
+#endif /* CONFIG_KUSER_HELPERS */
#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
TASK_SIZE_32 : TASK_SIZE_64)
#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
diff --git a/arch/arm64/include/asm/sparsemem.h b/arch/arm64/include/asm/sparsemem.h
index 84783efdc9d1..4148f2440831 100644
--- a/arch/arm64/include/asm/sparsemem.h
+++ b/arch/arm64/include/asm/sparsemem.h
@@ -14,19 +14,12 @@
* Section size must be at least 512MB for 64K base
* page size config. Otherwise it will be less than
* MAX_PAGE_ORDER and the build process will fail.
- */
-#ifdef CONFIG_ARM64_64K_PAGES
-#define SECTION_SIZE_BITS 29
-
-#else
-
-/*
+ *
* Section size must be at least 128MB for 4K base
* page size config. Otherwise PMD based huge page
* entries could not be created for vmemmap mappings.
* 16K follows 4K for simplicity.
*/
-#define SECTION_SIZE_BITS 27
-#endif /* CONFIG_ARM64_64K_PAGES */
+#define SECTION_SIZE_BITS (PAGE_SIZE == SZ_64K ? 29 : 27)
#endif
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 7cba1216efd2..c301e943ecb1 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -10,11 +10,13 @@
#define __ASM_SYSREG_H
#include <linux/bits.h>
+#include <linux/sizes.h>
#include <linux/stringify.h>
#include <linux/kasan-tags.h>
#include <linux/kconfig.h>
#include <asm/gpr-num.h>
+#include <asm/page-def.h>
#if ARM64_S390_COMMON == 1
@@ -887,24 +889,40 @@
#define ID_AA64MMFR0_EL1_PARANGE_MAX ID_AA64MMFR0_EL1_PARANGE_48
#endif
-#if defined(CONFIG_ARM64_4K_PAGES)
-#define ID_AA64MMFR0_EL1_TGRAN_SHIFT ID_AA64MMFR0_EL1_TGRAN4_SHIFT
-#define ID_AA64MMFR0_EL1_TGRAN_LPA2 ID_AA64MMFR0_EL1_TGRAN4_52_BIT
-#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MIN ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MIN
-#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MAX ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MAX
-#define ID_AA64MMFR0_EL1_TGRAN_2_SHIFT ID_AA64MMFR0_EL1_TGRAN4_2_SHIFT
-#elif defined(CONFIG_ARM64_16K_PAGES)
-#define ID_AA64MMFR0_EL1_TGRAN_SHIFT ID_AA64MMFR0_EL1_TGRAN16_SHIFT
-#define ID_AA64MMFR0_EL1_TGRAN_LPA2 ID_AA64MMFR0_EL1_TGRAN16_52_BIT
-#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MIN ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MIN
-#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MAX ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MAX
-#define ID_AA64MMFR0_EL1_TGRAN_2_SHIFT ID_AA64MMFR0_EL1_TGRAN16_2_SHIFT
-#elif defined(CONFIG_ARM64_64K_PAGES)
-#define ID_AA64MMFR0_EL1_TGRAN_SHIFT ID_AA64MMFR0_EL1_TGRAN64_SHIFT
-#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MIN ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MIN
-#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MAX ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MAX
-#define ID_AA64MMFR0_EL1_TGRAN_2_SHIFT ID_AA64MMFR0_EL1_TGRAN64_2_SHIFT
-#endif
+#define ID_AA64MMFR0_EL1_TGRAN_SHIFT \
+ (PAGE_SIZE == SZ_4K ? \
+ ID_AA64MMFR0_EL1_TGRAN4_SHIFT : \
+ (PAGE_SIZE == SZ_16K ? \
+ ID_AA64MMFR0_EL1_TGRAN16_SHIFT : \
+ ID_AA64MMFR0_EL1_TGRAN64_SHIFT))
+
+#define ID_AA64MMFR0_EL1_TGRAN_LPA2 \
+ (PAGE_SIZE == SZ_4K ? \
+ ID_AA64MMFR0_EL1_TGRAN4_52_BIT : \
+ (PAGE_SIZE == SZ_16K ? \
+ ID_AA64MMFR0_EL1_TGRAN16_52_BIT : \
+ -1))
+
+#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MIN \
+ (PAGE_SIZE == SZ_4K ? \
+ ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MIN : \
+ (PAGE_SIZE == SZ_16K ? \
+ ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MIN : \
+ ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MIN))
+
+#define ID_AA64MMFR0_EL1_TGRAN_SUPPORTED_MAX \
+ (PAGE_SIZE == SZ_4K ? \
+ ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED_MAX : \
+ (PAGE_SIZE == SZ_16K ? \
+ ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED_MAX : \
+ ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED_MAX))
+
+#define ID_AA64MMFR0_EL1_TGRAN_2_SHIFT \
+ (PAGE_SIZE == SZ_4K ? \
+ ID_AA64MMFR0_EL1_TGRAN4_2_SHIFT : \
+ (PAGE_SIZE == SZ_16K ? \
+ ID_AA64MMFR0_EL1_TGRAN16_2_SHIFT : \
+ ID_AA64MMFR0_EL1_TGRAN64_2_SHIFT))
#define CPACR_EL1_FPEN_EL1EN (BIT(20)) /* enable EL1 access */
#define CPACR_EL1_FPEN_EL0EN (BIT(21)) /* enable EL0 access, if EL1EN set */
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 866385b490eb..0090ec390cf8 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1780,11 +1780,13 @@ static bool has_nv1(const struct arm64_cpu_capabilities *entry, int scope)
is_midr_in_range_list(nv1_ni_list)));
}
-#if defined(ID_AA64MMFR0_EL1_TGRAN_LPA2)
static bool has_lpa2_at_stage1(u64 mmfr0)
{
unsigned int tgran;
+ if (PAGE_SIZE == SZ_64K)
+ return false;
+
tgran = cpuid_feature_extract_unsigned_field(mmfr0,
ID_AA64MMFR0_EL1_TGRAN_SHIFT);
return tgran == ID_AA64MMFR0_EL1_TGRAN_LPA2;
@@ -1794,6 +1796,9 @@ static bool has_lpa2_at_stage2(u64 mmfr0)
{
unsigned int tgran;
+ if (PAGE_SIZE == SZ_64K)
+ return false;
+
tgran = cpuid_feature_extract_unsigned_field(mmfr0,
ID_AA64MMFR0_EL1_TGRAN_2_SHIFT);
return tgran == ID_AA64MMFR0_EL1_TGRAN_2_SUPPORTED_LPA2;
@@ -1806,10 +1811,26 @@ static bool has_lpa2(const struct arm64_cpu_capabilities *entry, int scope)
mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
return has_lpa2_at_stage1(mmfr0) && has_lpa2_at_stage2(mmfr0);
}
-#else
-static bool has_lpa2(const struct arm64_cpu_capabilities *entry, int scope)
+
+#ifdef CONFIG_ARM64_VA_BITS_52
+static bool has_va52(const struct arm64_cpu_capabilities *entry, int scope)
{
- return false;
+ const struct arm64_cpu_capabilities entry_64k = {
+ ARM64_CPUID_FIELDS(ID_AA64MMFR2_EL1, VARange, 52)
+ };
+ const struct arm64_cpu_capabilities entry_16k = {
+ ARM64_CPUID_FIELDS(ID_AA64MMFR0_EL1, TGRAN16, 52_BIT)
+ };
+ const struct arm64_cpu_capabilities entry_4k = {
+ ARM64_CPUID_FIELDS(ID_AA64MMFR0_EL1, TGRAN4, 52_BIT)
+ };
+
+ if (PAGE_SIZE == SZ_64K)
+ return has_cpuid_feature(&entry_64k, scope);
+ else if (PAGE_SIZE == SZ_16K)
+ return has_cpuid_feature(&entry_16k, scope);
+ else
+ return has_cpuid_feature(&entry_4k, scope);
}
#endif
@@ -2978,20 +2999,10 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
},
#ifdef CONFIG_ARM64_VA_BITS_52
{
+ .desc = "52-bit Virtual Addressing",
.capability = ARM64_HAS_VA52,
.type = ARM64_CPUCAP_BOOT_CPU_FEATURE,
- .matches = has_cpuid_feature,
-#ifdef CONFIG_ARM64_64K_PAGES
- .desc = "52-bit Virtual Addressing (LVA)",
- ARM64_CPUID_FIELDS(ID_AA64MMFR2_EL1, VARange, 52)
-#else
- .desc = "52-bit Virtual Addressing (LPA2)",
-#ifdef CONFIG_ARM64_4K_PAGES
- ARM64_CPUID_FIELDS(ID_AA64MMFR0_EL1, TGRAN4, 52_BIT)
-#else
- ARM64_CPUID_FIELDS(ID_AA64MMFR0_EL1, TGRAN16, 52_BIT)
-#endif
-#endif
+ .matches = has_va52,
},
#endif
{
diff --git a/arch/arm64/mm/fixmap.c b/arch/arm64/mm/fixmap.c
index c8a0d008cf2a..bd48a21a98f9 100644
--- a/arch/arm64/mm/fixmap.c
+++ b/arch/arm64/mm/fixmap.c
@@ -84,7 +84,7 @@ static void __init early_fixmap_init_pud(p4d_t *p4dp, unsigned long addr,
* share the top level pgd entry, which should only happen on
* 16k/4 levels configurations.
*/
- BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES));
+ BUG_ON(PAGE_SIZE != SZ_16K);
}
if (p4d_none(p4d))
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 4e7682dfe366..70393e4d2d82 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -77,13 +77,10 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit;
* (64k granule), or a multiple that can be mapped using contiguous bits
* in the page tables: 32 * PMD_SIZE (16k granule)
*/
-#if defined(CONFIG_ARM64_4K_PAGES)
-#define ARM64_MEMSTART_SHIFT PUD_SHIFT
-#elif defined(CONFIG_ARM64_16K_PAGES)
-#define ARM64_MEMSTART_SHIFT CONT_PMD_SHIFT
-#else
-#define ARM64_MEMSTART_SHIFT PMD_SHIFT
-#endif
+#define ARM64_MEMSTART_SHIFT \
+ (PAGE_SIZE == SZ_4K ? \
+ PUD_SHIFT : \
+ (PAGE_SIZE == SZ_16K ? CONT_PMD_SHIFT : PMD_SHIFT))
/*
* sparsemem vmemmap imposes an additional requirement on the alignment of
@@ -91,11 +88,10 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit;
* has a direct correspondence, and needs to appear sufficiently aligned
* in the virtual address space.
*/
-#if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
-#define ARM64_MEMSTART_ALIGN (1UL << SECTION_SIZE_BITS)
-#else
-#define ARM64_MEMSTART_ALIGN (1UL << ARM64_MEMSTART_SHIFT)
-#endif
+#define ARM64_MEMSTART_ALIGN \
+ (ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS ? \
+ (1UL << SECTION_SIZE_BITS) : \
+ (1UL << ARM64_MEMSTART_SHIFT))
static void __init arch_reserve_crashkernel(void)
{
diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
index 45fbdce684c8..638882f90ad5 100644
--- a/arch/arm64/mm/kasan_init.c
+++ b/arch/arm64/mm/kasan_init.c
@@ -178,10 +178,10 @@ static void __init kasan_pgd_populate(unsigned long addr, unsigned long end,
} while (pgdp++, addr = next, addr != end);
}
-#if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS > 4
+#if CONFIG_PGTABLE_LEVELS > 4
#define SHADOW_ALIGN P4D_SIZE
#else
-#define SHADOW_ALIGN PUD_SIZE
+#define SHADOW_ALIGN (PAGE_SIZE == SZ_64K ? P4D_SIZE : PUD_SIZE)
#endif
/*
@@ -243,8 +243,8 @@ static int __init root_level_idx(u64 addr)
* not implemented. This means we need to index the table as usual,
* instead of masking off bits based on vabits_actual.
*/
- u64 vabits = IS_ENABLED(CONFIG_ARM64_64K_PAGES) ? VA_BITS
- : vabits_actual;
+ u64 vabits = PAGE_SIZE == SZ_64K ? VA_BITS
+ : vabits_actual;
int shift = (ARM64_HW_PGTABLE_LEVELS(vabits) - 1) * PTDESC_TABLE_SHIFT;
return (addr & ~_PAGE_OFFSET(vabits)) >> (shift + PAGE_SHIFT);
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 1567f76607d9..8cb8234cc24a 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1846,7 +1846,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
/* [start, end] should be within one section */
WARN_ON_ONCE(end - start > PAGES_PER_SECTION * sizeof(struct page));
- if (!IS_ENABLED(CONFIG_ARM64_4K_PAGES) ||
+ if (PAGE_SIZE != SZ_4K ||
(end - start < PAGES_PER_SECTION * sizeof(struct page)))
return vmemmap_populate_basepages(start, end, node, altmap);
else
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index c952c069f937..928cba93d8b2 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -2410,7 +2410,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
baser_phys = virt_to_phys(base);
/* Check if the physical address of the memory is above 48bits */
- if (IS_ENABLED(CONFIG_ARM64_64K_PAGES) && (baser_phys >> 48)) {
+ if (PAGE_SIZE == SZ_64K && (baser_phys >> 48)) {
/* 52bit PA is supported only when PageSize=64K */
if (psz != SZ_64K) {
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 37/43] vdso: Lay out the data pages in VDSO_PAGE_SIZE units
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (7 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:52 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Eric Curtin, Andy Lutomirski, Thomas Gleixner, Vincenzo Frascino,
linux-kernel
From: Eric Curtin <eric.curtin@docker.com>
The vDSO is built with CONFIG_PAGE_SHIFT, so the data page layout it
uses can differ from the runtime PAGE_SIZE when the page size is chosen
at boot. The kernel side must lay out and map the data pages exactly as
the vDSO code expects.
Add VDSO_PAGE_SHIFT and VDSO_PAGE_SIZE, defined from CONFIG_PAGE_SHIFT,
and use them for the vDSO data layout: the VDSO_ARCH_DATA_* sizes, the
vdso_u_* symbol offsets, vdso_initdata, the vvar mapping length, and the
timens page offsets in gettimeofday.c. Indexes of the vDSO data pages
are converted to PAGE_SIZE page offsets with the new VDSO_PGOFF() macro
when addressing vdso_data_pages, and vvar_fault() shifts the faulting
page offset back to a vDSO data page index. The static assertions on
the size of struct vdso_time_data and struct vdso_rng_data use
PAGE_SIZE_MIN.
For a compile-time page size VDSO_PAGE_SIZE equals PAGE_SIZE and the
layout does not change.
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit a870d11aaf0fbcb9e4c7d19f8169832cc676b685)
---
include/vdso/datapage.h | 10 +++++-----
include/vdso/page.h | 4 ++++
lib/vdso/datastore.c | 34 +++++++++++++++++++---------------
lib/vdso/gettimeofday.c | 4 ++--
4 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h
index 09897f76ae07..d999f10032b6 100644
--- a/include/vdso/datapage.h
+++ b/include/vdso/datapage.h
@@ -164,8 +164,8 @@ extern struct vdso_time_data *vdso_k_time_data;
extern struct vdso_rng_data *vdso_k_rng_data;
extern struct vdso_arch_data *vdso_k_arch_data;
-#define VDSO_ARCH_DATA_SIZE ALIGN(sizeof(struct vdso_arch_data), PAGE_SIZE)
-#define VDSO_ARCH_DATA_PAGES (VDSO_ARCH_DATA_SIZE >> PAGE_SHIFT)
+#define VDSO_ARCH_DATA_SIZE ALIGN(sizeof(struct vdso_arch_data), VDSO_PAGE_SIZE)
+#define VDSO_ARCH_DATA_PAGES (VDSO_ARCH_DATA_SIZE >> VDSO_PAGE_SHIFT)
enum vdso_pages {
VDSO_TIME_PAGE_OFFSET,
@@ -179,19 +179,19 @@ enum vdso_pages {
#else /* !__ASSEMBLER__ */
#ifdef CONFIG_VDSO_GETRANDOM
-#define __vdso_u_rng_data PROVIDE(vdso_u_rng_data = vdso_u_data + 2 * PAGE_SIZE);
+#define __vdso_u_rng_data PROVIDE(vdso_u_rng_data = vdso_u_data + 2 * VDSO_PAGE_SIZE);
#else
#define __vdso_u_rng_data
#endif
#ifdef CONFIG_ARCH_HAS_VDSO_ARCH_DATA
-#define __vdso_u_arch_data PROVIDE(vdso_u_arch_data = vdso_u_data + 3 * PAGE_SIZE);
+#define __vdso_u_arch_data PROVIDE(vdso_u_arch_data = vdso_u_data + 3 * VDSO_PAGE_SIZE);
#else
#define __vdso_u_arch_data
#endif
#define VDSO_VVAR_SYMS \
- PROVIDE(vdso_u_data = . - __VDSO_PAGES * PAGE_SIZE); \
+ PROVIDE(vdso_u_data = . - __VDSO_PAGES * VDSO_PAGE_SIZE);\
PROVIDE(vdso_u_time_data = vdso_u_data); \
__vdso_u_rng_data \
__vdso_u_arch_data \
diff --git a/include/vdso/page.h b/include/vdso/page.h
index bc47186c07fc..b79e1c8c8363 100644
--- a/include/vdso/page.h
+++ b/include/vdso/page.h
@@ -14,6 +14,10 @@
#define PAGE_SIZE (_AC(1,UL) << CONFIG_PAGE_SHIFT)
+/* Granule of the vDSO data layout; constant even with boot-time PAGE_SIZE. */
+#define VDSO_PAGE_SHIFT CONFIG_PAGE_SHIFT
+#define VDSO_PAGE_SIZE (_AC(1,UL) << VDSO_PAGE_SHIFT)
+
#if !defined(CONFIG_64BIT)
/*
* Applies only to 32-bit architectures.
diff --git a/lib/vdso/datastore.c b/lib/vdso/datastore.c
index 1426bf4e0c12..74ad8d71f6c8 100644
--- a/lib/vdso/datastore.c
+++ b/lib/vdso/datastore.c
@@ -8,32 +8,35 @@
#include <linux/vdso_datastore.h>
#include <vdso/datapage.h>
-static u8 vdso_initdata[VDSO_NR_PAGES * PAGE_SIZE] __aligned(PAGE_SIZE) __initdata = {};
+/* Convert a vDSO data page index to a PAGE_SIZE page offset. */
+#define VDSO_PGOFF(i) ((unsigned long)(i) << (VDSO_PAGE_SHIFT - PAGE_SHIFT))
+
+static u8 vdso_initdata[VDSO_NR_PAGES * VDSO_PAGE_SIZE] __aligned(VDSO_PAGE_SIZE) __initdata = {};
#ifdef CONFIG_GENERIC_GETTIMEOFDAY
struct vdso_time_data *vdso_k_time_data __ro_after_init =
- (void *)&vdso_initdata[VDSO_TIME_PAGE_OFFSET * PAGE_SIZE];
+ (void *)&vdso_initdata[VDSO_TIME_PAGE_OFFSET * VDSO_PAGE_SIZE];
-static_assert(sizeof(struct vdso_time_data) <= PAGE_SIZE);
+static_assert(sizeof(struct vdso_time_data) <= PAGE_SIZE_MIN);
#endif /* CONFIG_GENERIC_GETTIMEOFDAY */
#ifdef CONFIG_VDSO_GETRANDOM
struct vdso_rng_data *vdso_k_rng_data __ro_after_init =
- (void *)&vdso_initdata[VDSO_RNG_PAGE_OFFSET * PAGE_SIZE];
+ (void *)&vdso_initdata[VDSO_RNG_PAGE_OFFSET * VDSO_PAGE_SIZE];
-static_assert(sizeof(struct vdso_rng_data) <= PAGE_SIZE);
+static_assert(sizeof(struct vdso_rng_data) <= PAGE_SIZE_MIN);
#endif /* CONFIG_VDSO_GETRANDOM */
#ifdef CONFIG_ARCH_HAS_VDSO_ARCH_DATA
struct vdso_arch_data *vdso_k_arch_data __ro_after_init =
- (void *)&vdso_initdata[VDSO_ARCH_PAGES_START * PAGE_SIZE];
+ (void *)&vdso_initdata[VDSO_ARCH_PAGES_START * VDSO_PAGE_SIZE];
#endif /* CONFIG_ARCH_HAS_VDSO_ARCH_DATA */
static struct page *vdso_data_pages __ro_after_init;
void __init vdso_setup_data_pages(void)
{
- unsigned int order = get_order(VDSO_NR_PAGES * PAGE_SIZE);
+ unsigned int order = get_order(VDSO_NR_PAGES * VDSO_PAGE_SIZE);
/*
* Allocate the data pages dynamically. SPARC does not support mapping
@@ -51,16 +54,16 @@ void __init vdso_setup_data_pages(void)
split_page(vdso_data_pages, order);
/* Move the data already written by other subsystems to the new pages */
- memcpy(page_address(vdso_data_pages), vdso_initdata, VDSO_NR_PAGES * PAGE_SIZE);
+ memcpy(page_address(vdso_data_pages), vdso_initdata, VDSO_NR_PAGES * VDSO_PAGE_SIZE);
if (IS_ENABLED(CONFIG_GENERIC_GETTIMEOFDAY))
- vdso_k_time_data = page_address(vdso_data_pages + VDSO_TIME_PAGE_OFFSET);
+ vdso_k_time_data = page_address(vdso_data_pages + VDSO_PGOFF(VDSO_TIME_PAGE_OFFSET));
if (IS_ENABLED(CONFIG_VDSO_GETRANDOM))
- vdso_k_rng_data = page_address(vdso_data_pages + VDSO_RNG_PAGE_OFFSET);
+ vdso_k_rng_data = page_address(vdso_data_pages + VDSO_PGOFF(VDSO_RNG_PAGE_OFFSET));
if (IS_ENABLED(CONFIG_ARCH_HAS_VDSO_ARCH_DATA))
- vdso_k_arch_data = page_address(vdso_data_pages + VDSO_ARCH_PAGES_START);
+ vdso_k_arch_data = page_address(vdso_data_pages + VDSO_PGOFF(VDSO_ARCH_PAGES_START));
}
static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
@@ -74,7 +77,8 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
page = vdso_data_pages + vmf->pgoff;
timens_page = find_timens_vvar_page(vma);
- switch (vmf->pgoff) {
+ /* Only the first page of each vDSO data page holds data. */
+ switch (vmf->pgoff >> (VDSO_PAGE_SHIFT - PAGE_SHIFT)) {
case VDSO_TIME_PAGE_OFFSET:
if (!IS_ENABLED(CONFIG_GENERIC_GETTIMEOFDAY) || !timens_page)
break;
@@ -85,7 +89,7 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
unsigned long addr;
vm_fault_t err;
- addr = vmf->address + VDSO_TIMENS_PAGE_OFFSET * PAGE_SIZE;
+ addr = vmf->address + VDSO_TIMENS_PAGE_OFFSET * VDSO_PAGE_SIZE;
err = vmf_insert_page(vma, addr, page);
if (unlikely(err & VM_FAULT_ERROR))
return err;
@@ -101,7 +105,7 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
*/
if (!IS_ENABLED(CONFIG_TIME_NS) || !timens_page)
break;
- page = vdso_data_pages + VDSO_TIME_PAGE_OFFSET;
+ page = vdso_data_pages + VDSO_PGOFF(VDSO_TIME_PAGE_OFFSET);
break;
case VDSO_RNG_PAGE_OFFSET:
case VDSO_ARCH_PAGES_START ... VDSO_ARCH_PAGES_END:
@@ -122,7 +126,7 @@ const struct vm_special_mapping vdso_vvar_mapping = {
struct vm_area_struct *vdso_install_vvar_mapping(struct mm_struct *mm, unsigned long addr)
{
- return _install_special_mapping(mm, addr, VDSO_NR_PAGES * PAGE_SIZE,
+ return _install_special_mapping(mm, addr, VDSO_NR_PAGES * VDSO_PAGE_SIZE,
VM_READ | VM_MAYREAD | VM_DONTDUMP |
VM_MIXEDMAP | VM_SEALED_SYSMAP,
&vdso_vvar_mapping);
diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index a324b2f2ec6c..e3ea7df41fe4 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -136,13 +136,13 @@ bool vdso_get_timestamp(const struct vdso_time_data *vd, const struct vdso_clock
static __always_inline
const struct vdso_time_data *vdso_timens_data(const struct vdso_time_data *vd)
{
- return (void *)vd + PAGE_SIZE;
+ return (void *)vd + VDSO_PAGE_SIZE;
}
static __always_inline
const struct vdso_clock *vdso_timens_clock(const struct vdso_clock *vc)
{
- return (void *)vc + PAGE_SIZE;
+ return (void *)vc + VDSO_PAGE_SIZE;
}
static __always_inline
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 39/43] crash: Size the vmcoreinfo page array for the smallest page size
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (8 preceding siblings ...)
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 ` Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 41/43] exit: Use THREAD_SIZE_MAX for lowest_to_date Eric Curtin
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:52 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Eric Curtin, Andrew Morton, Baoquan He, Mike Rapoport,
Pasha Tatashin, Pratyush Yadav, linux-kernel, kexec
From: Eric Curtin <eric.curtin@docker.com>
kimage_crash_copy_vmcoreinfo() keeps the vmcoreinfo pages in an on-stack
array whose length is computed from VMCOREINFO_BYTES and PAGE_SIZE, both
of which are runtime values with arm64 boot-time page size selection.
Add VMCOREINFO_BYTES_MAX, defined as PAGE_SIZE_MAX, and size the array
as DIV_ROUND_UP(VMCOREINFO_BYTES_MAX, PAGE_SIZE_MIN), which is the
largest number of pages the buffer can span.
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 08a51916386a159aeb15a6e51605740a895b7bb5)
---
include/linux/vmcore_info.h | 1 +
kernel/crash_core.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/vmcore_info.h b/include/linux/vmcore_info.h
index e71518caacdf..f5d49e71ac7b 100644
--- a/include/linux/vmcore_info.h
+++ b/include/linux/vmcore_info.h
@@ -21,6 +21,7 @@
CRASH_CORE_NOTE_DESC_BYTES)
#define VMCOREINFO_BYTES PAGE_SIZE
+#define VMCOREINFO_BYTES_MAX PAGE_SIZE_MAX
#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
#define VMCOREINFO_NOTE_SIZE ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index c7eb72748fee..ca7252fda848 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -43,7 +43,7 @@ note_buf_t __percpu *crash_notes;
int kimage_crash_copy_vmcoreinfo(struct kimage *image)
{
struct page *vmcoreinfo_base;
- struct page *vmcoreinfo_pages[DIV_ROUND_UP(VMCOREINFO_BYTES, PAGE_SIZE)];
+ struct page *vmcoreinfo_pages[DIV_ROUND_UP(VMCOREINFO_BYTES_MAX, PAGE_SIZE_MIN)];
unsigned int order, nr_pages;
int i;
void *safecopy;
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 41/43] exit: Use THREAD_SIZE_MAX for lowest_to_date
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (9 preceding siblings ...)
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 ` 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
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:52 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: Eric Curtin, linux-kernel
From: Eric Curtin <eric.curtin@docker.com>
With arm64 boot-time page size selection THREAD_SIZE may depend on the
page size and is not a compile-time constant, so it cannot initialise
the static lowest_to_date in check_stack_usage().
Use THREAD_SIZE_MAX, which is an upper bound on the stack size and so a
valid initial value for the lowest free stack seen so far.
No functional change for compile-time page sizes.
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit e4b475ad2b5c70b4fa666356ca309ed3ec0528ed)
---
kernel/exit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/exit.c b/kernel/exit.c
index a8453363d1fd..4a7d792f69ed 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -847,7 +847,7 @@ static inline void kstack_histogram(unsigned long used_stack)
static void check_stack_usage(void)
{
static DEFINE_SPINLOCK(low_water_lock);
- static int lowest_to_date = THREAD_SIZE;
+ static int lowest_to_date = THREAD_SIZE_MAX;
unsigned long free;
free = stack_not_used(current);
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 42/43] tracing: Use PAGE_SIZE_MIN/MAX in the uprobe check and undefsyms page
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (10 preceding siblings ...)
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 ` 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)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:52 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Eric Curtin, Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
linux-kernel, linux-trace-kernel
From: Eric Curtin <eric.curtin@docker.com>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time
constant, so it cannot be used in BUILD_BUG_ON() or as an array size or
alignment.
In trace_uprobe.c, MAX_UCB_BUFFER_SIZE is PAGE_SIZE, so the build check
against MAX_PROBE_EVENT_SIZE now uses PAGE_SIZE_MIN directly. In
undefsyms_base.c, size and align the static page[] with PAGE_SIZE_MAX;
the memset() keeps using the run-time PAGE_SIZE.
No functional change for compile-time page sizes.
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit f68b4569af533a62d3da83ffb3141256868d1c70)
---
kernel/trace/trace_uprobe.c | 2 +-
kernel/trace/undefsyms_base.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index fb7991543db7..d7ae99294bd0 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -1019,7 +1019,7 @@ static struct uprobe_cpu_buffer *prepare_uprobe_buffer(struct trace_uprobe *tu,
ucb = uprobe_buffer_get();
ucb->dsize = tu->tp.size + dsize;
- BUILD_BUG_ON(MAX_UCB_BUFFER_SIZE < MAX_PROBE_EVENT_SIZE);
+ BUILD_BUG_ON(PAGE_SIZE_MIN < MAX_PROBE_EVENT_SIZE);
if (WARN_ON_ONCE(ucb->dsize > MAX_UCB_BUFFER_SIZE)) {
ucb->dsize = MAX_UCB_BUFFER_SIZE;
dsize = MAX_UCB_BUFFER_SIZE - tu->tp.size;
diff --git a/kernel/trace/undefsyms_base.c b/kernel/trace/undefsyms_base.c
index 37310baf706b..01b4f1913d61 100644
--- a/kernel/trace/undefsyms_base.c
+++ b/kernel/trace/undefsyms_base.c
@@ -14,13 +14,14 @@
void undefsyms_base(void *p, int n);
-static char page[PAGE_SIZE] __aligned(PAGE_SIZE);
+static char page[PAGE_SIZE_MAX] __aligned(PAGE_SIZE_MAX);
void undefsyms_base(void *p, int n)
{
char buffer[256] = { 0 };
u32 u = 0;
+ /* PAGE_SIZE may be a variable, which the hypervisor provides */
memset((char * volatile)page, 8, PAGE_SIZE);
memset((char * volatile)buffer, 8, sizeof(buffer));
memcpy((void * volatile)p, buffer, sizeof(buffer));
^ permalink raw reply related [flat|nested] 15+ messages in thread* [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (11 preceding siblings ...)
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 ` Eric Curtin
2026-12-01 10:41 ` [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Lorenzo Stoakes (ARM)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:52 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Ryan Roberts, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Catalin Marinas, Will Deacon, Mark Rutland, Marc Zyngier,
Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
Suzuki K Poulose, Zenghui Yu, Muchun Song, Mike Rapoport,
David Hildenbrand, Ard Biesheuvel, Ilias Apalodimas, linux-doc,
kvmarm, linux-mm, linux-kernel, linux-efi
From: Ryan Roberts <ryan.roberts@arm.com>
Introduce a new Kconfig, ARM64_BOOT_TIME_PAGE_SIZE, which can be
selected instead of a fixed page size. When selected, the page size (4K,
16K or 64K) is chosen at boot with the arm64.pagesize= command line
option, falling back to ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT and then to
the largest size the CPU supports.
PAGE_SHIFT, PxD_SHIFT and the associated macros resolve to the ptg_*
variables, which are set by ptg_init() in early_map_kernel() before the
kernel is mapped. PTRS_PER_PMD, PTRS_PER_PUD and PTRS_PER_P4D, and
pgtable_l3/l4/l5_enabled(), are derived from ptg_pgtable_levels, and
folded levels are handled at run time. The variables are also exported
to the EL2 code via kvm_nvhe_sym() and to the position-independent code
via PI_EXPORT_SYM(). Because they are needed by modules, export them
with EXPORT_SYMBOL(), following powerpc and using the non-GPL variant.
Limitations: only 48-bit VA is supported for now, since more work is
required for LPA2. MMAP_RND_BITS, SECTION_SIZE_BITS and
ARCH_FORCE_MAX_ORDER are configured for the worst case (64K pages); they
could be made boot-time values later. The image header reports an
unspecified page size, and the EFI stub no longer checks for 16K or 64K
support. Add documentation for the new option and the header flag.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 38c7974ea05c55b9583b12510f903a3c64968869)
---
.../admin-guide/kernel-parameters.txt | 11 ++++
Documentation/arch/arm64/booting.rst | 4 +-
Documentation/arch/arm64/memory.rst | 21 ++++++++
arch/arm64/Kconfig | 54 +++++++++++++++++--
arch/arm64/include/asm/kvm_hyp.h | 11 ++++
arch/arm64/include/asm/pgtable-geometry.h | 22 +++++++-
arch/arm64/include/asm/pgtable-hwdef.h | 9 ++--
arch/arm64/include/asm/pgtable.h | 10 +++-
arch/arm64/include/asm/sparsemem.h | 4 ++
arch/arm64/kernel/image-vars.h | 11 ++++
arch/arm64/kernel/image.h | 4 ++
arch/arm64/kernel/pi/map_kernel.c | 45 ++++++++++++++++
arch/arm64/kvm/arm.c | 10 ++++
arch/arm64/kvm/hyp/nvhe/Makefile | 1 +
arch/arm64/kvm/hyp/nvhe/pgtable-geometry.c | 16 ++++++
arch/arm64/mm/Makefile | 1 +
arch/arm64/mm/pgd.c | 10 ++--
arch/arm64/mm/pgtable-geometry.c | 32 +++++++++++
drivers/firmware/efi/libstub/arm64.c | 3 +-
19 files changed, 262 insertions(+), 17 deletions(-)
create mode 100644 arch/arm64/kvm/hyp/nvhe/pgtable-geometry.c
create mode 100644 arch/arm64/mm/pgtable-geometry.c
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index dce9b8f3ae98..fce8dbfad329 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -589,6 +589,17 @@ Kernel parameters
arm64.nowfxt [ARM64] Unconditionally disable Wait For Event with
Timeout and Wait For Interrupt with Timeout support
+ arm64.pagesize= [ARM64] Select the page size (translation granule)
+ of a kernel built with CONFIG_ARM64_BOOT_TIME_PAGE_SIZE.
+ Format: { 4k | 16k | 64k }
+ If the option is absent, invalid, or names a size that
+ the CPU does not support, the size configured by
+ CONFIG_ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT is used,
+ or the largest size the CPU supports if it does not
+ support that either. Ignored by kernels built for a
+ fixed page size. See
+ Documentation/arch/arm64/memory.rst
+
ataflop= [HW,M68k]
atkbd.extra= [HW] Enable extra LEDs and keys on IBM RapidAccess,
diff --git a/Documentation/arch/arm64/booting.rst b/Documentation/arch/arm64/booting.rst
index dae5ff9fae26..2fe72b58b088 100644
--- a/Documentation/arch/arm64/booting.rst
+++ b/Documentation/arch/arm64/booting.rst
@@ -113,7 +113,9 @@ Header notes:
Bit 0 Kernel endianness. 1 if BE, 0 if LE.
Bit 1-2 Kernel Page size.
- * 0 - Unspecified.
+ * 0 - Unspecified (always the case for images built
+ with CONFIG_ARM64_BOOT_TIME_PAGE_SIZE, see
+ Documentation/arch/arm64/memory.rst).
* 1 - 4K
* 2 - 16K
* 3 - 64K
diff --git a/Documentation/arch/arm64/memory.rst b/Documentation/arch/arm64/memory.rst
index 678fbb418c3a..8207096bc7e7 100644
--- a/Documentation/arch/arm64/memory.rst
+++ b/Documentation/arch/arm64/memory.rst
@@ -33,6 +33,27 @@ ARM64_SPECTRE_V3A is enabled for particular CPUs.
When using KVM with the Virtualization Host Extensions, no additional
mappings are created, since the host kernel runs directly in EL2.
+Boot-time page size selection
+-----------------------------
+An image built with CONFIG_ARM64_BOOT_TIME_PAGE_SIZE supports all of the 4KB,
+16KB and 64KB page sizes and chooses one at boot with the ``arm64.pagesize=``
+kernel command line option (``4k``, ``16k`` or ``64k``). Kernels built with a
+fixed page size are unaffected. Such an image reports "Unspecified" in the page
+size field of the Image header flags, so a boot loader must not rely on it, and
+it is limited to 48-bit virtual and physical addresses.
+
+The selected granule must be implemented by the CPU (ID_AA64MMFR0_EL1.TGRAN4,
+TGRAN16 and TGRAN64). The kernel checks this itself, and when entered with the
+MMU on (for example from the EFI stub) it switches to the selected granule
+early in boot, so firmware does not need to use the same one. If the option is
+absent, invalid, or names a granule the CPU lacks, the kernel falls back to
+CONFIG_ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT, and then to the largest granule the
+CPU supports. The CPU is parked if it implements none of them.
+
+State that depends on the page size, such as swap, hibernation images and
+kexec handover data, can only be reused by a kernel running with the same
+page size.
+
52-bit VA support in the kernel
-------------------------------
If the ARMv8.2-LVA optional feature is present, and we are running
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9b08b2457a55..36dab5543e75 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -110,6 +110,7 @@ config ARM64
select BUILDTIME_TABLE_SORT
select CLONE_BACKWARDS
select COMMON_CLK
+ select CONSTRUCTORS if ARM64_BOOT_TIME_PAGE_SIZE
select CPU_PM if (SUSPEND || CPU_IDLE)
select CPUMASK_OFFSTACK if NR_CPUS > 256
select DCACHE_WORD_ACCESS
@@ -280,12 +281,14 @@ config MMU
config ARM64_CONT_PTE_SHIFT
int
+ depends on !ARM64_BOOT_TIME_PAGE_SIZE
default 5 if PAGE_SIZE_64KB
default 7 if PAGE_SIZE_16KB
default 4
config ARM64_CONT_PMD_SHIFT
int
+ depends on !ARM64_BOOT_TIME_PAGE_SIZE
default 5 if PAGE_SIZE_64KB
default 5 if PAGE_SIZE_16KB
default 4
@@ -302,10 +305,10 @@ config ARCH_MMAP_RND_BITS_MAX
default 24 if ARM64_VA_BITS=39
default 27 if ARM64_VA_BITS=42
default 30 if ARM64_VA_BITS=47
- default 29 if (ARM64_VA_BITS=48 || ARM64_VA_BITS=52) && ARM64_64K_PAGES
+ default 29 if (ARM64_VA_BITS=48 || ARM64_VA_BITS=52) && PAGE_SIZE_64KB
default 31 if (ARM64_VA_BITS=48 || ARM64_VA_BITS=52) && ARM64_16K_PAGES
default 33 if (ARM64_VA_BITS=48 || ARM64_VA_BITS=52)
- default 14 if ARM64_64K_PAGES
+ default 14 if PAGE_SIZE_64KB
default 16 if ARM64_16K_PAGES
default 18
@@ -318,7 +321,7 @@ config ARCH_MMAP_RND_BITS
default 28 if (ARM64_VA_BITS=48 || ARM64_VA_BITS=52)
config ARCH_MMAP_RND_COMPAT_BITS_MIN
- default 7 if ARM64_64K_PAGES
+ default 7 if PAGE_SIZE_64KB
default 9 if ARM64_16K_PAGES
default 11
@@ -366,6 +369,7 @@ config FIX_EARLYCON_MEM
config PGTABLE_LEVELS
int
+ default 4 if ARM64_BOOT_TIME_PAGE_SIZE # Advertise max supported levels
default 2 if ARM64_16K_PAGES && ARM64_VA_BITS_36
default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42
default 3 if ARM64_64K_PAGES && (ARM64_VA_BITS_48 || ARM64_VA_BITS_52)
@@ -1598,8 +1602,46 @@ config ARM64_64K_PAGES
look-up. AArch32 emulation requires applications compiled
with 64K aligned segments.
+config ARM64_BOOT_TIME_PAGE_SIZE
+ bool "Boot-time selection"
+ select ARCH_RUNTIME_PMD_FOLD
+ select HAVE_PAGE_SIZE_64KB # Advertise largest page size to core
+ help
+ Select desired page size (4KB, 16KB or 64KB) at boot-time via the
+ kernel command line option "arm64.pagesize=4k", "arm64.pagesize=16k"
+ or "arm64.pagesize=64k".
+
+ Limitations: only 48-bit virtual and physical addresses are
+ supported (no LPA/LPA2), and ARCH_WANT_HUGE_PMD_SHARE and
+ ARCH_WANTS_THP_SWAP are not enabled.
+
endchoice
+choice
+ prompt "Default page size for boot-time selection"
+ depends on ARM64_BOOT_TIME_PAGE_SIZE
+ default ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT_4K
+ help
+ Page size to use when "arm64.pagesize=" is not given. If the CPU
+ does not support it, the largest page size it supports is used.
+
+config ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT_4K
+ bool "4KB"
+
+config ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT_16K
+ bool "16KB"
+
+config ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT_64K
+ bool "64KB"
+
+endchoice
+
+config ARM64_BOOT_TIME_PAGE_SHIFT_DEFAULT
+ int
+ default 16 if ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT_64K
+ default 14 if ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT_16K
+ default 12
+
choice
prompt "Virtual address space size"
default ARM64_VA_BITS_52
@@ -1629,6 +1671,7 @@ config ARM64_VA_BITS_48
config ARM64_VA_BITS_52
bool "52-bit"
+ depends on !ARM64_BOOT_TIME_PAGE_SIZE
help
Enable 52-bit virtual addressing for userspace when explicitly
requested via a hint to mmap(). The kernel will also use 52-bit
@@ -1828,9 +1871,10 @@ config XEN
# 4K | 27 | 12 | 15 | 10 |
# 16K | 27 | 14 | 13 | 11 |
# 64K | 29 | 16 | 13 | 13 |
+# BOOT| 29 | 16 (max) | 13 | 13 |
config ARCH_FORCE_MAX_ORDER
int
- default "13" if ARM64_64K_PAGES
+ default "13" if PAGE_SIZE_64KB
default "11" if ARM64_16K_PAGES
default "10"
help
@@ -1889,7 +1933,7 @@ config ARM64_TAGGED_ADDR_ABI
menuconfig COMPAT
bool "Kernel support for 32-bit EL0"
- depends on ARM64_4K_PAGES || EXPERT
+ depends on ARM64_4K_PAGES || ARM64_BOOT_TIME_PAGE_SIZE || EXPERT
select HAVE_UID16
select OLD_SIGSUSPEND3
select COMPAT_OLD_SIGACTION
diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
index b0e42be3d9ee..1394dc2de129 100644
--- a/arch/arm64/include/asm/kvm_hyp.h
+++ b/arch/arm64/include/asm/kvm_hyp.h
@@ -161,4 +161,15 @@ extern unsigned int kvm_nvhe_sym(kvm_host_sve_max_vl);
extern unsigned long kvm_nvhe_sym(hyp_nr_cpus);
extern unsigned int kvm_nvhe_sym(hyp_gicv3_nr_lr);
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+extern int kvm_nvhe_sym(ptg_page_shift);
+extern int kvm_nvhe_sym(ptg_pmd_shift);
+extern int kvm_nvhe_sym(ptg_pud_shift);
+extern int kvm_nvhe_sym(ptg_p4d_shift);
+extern int kvm_nvhe_sym(ptg_pgdir_shift);
+extern int kvm_nvhe_sym(ptg_cont_pte_shift);
+extern int kvm_nvhe_sym(ptg_cont_pmd_shift);
+extern int kvm_nvhe_sym(ptg_pgtable_levels);
+#endif /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
+
#endif /* __ARM64_KVM_HYP_H__ */
diff --git a/arch/arm64/include/asm/pgtable-geometry.h b/arch/arm64/include/asm/pgtable-geometry.h
index 62fe125909c0..18a8c8d499ec 100644
--- a/arch/arm64/include/asm/pgtable-geometry.h
+++ b/arch/arm64/include/asm/pgtable-geometry.h
@@ -6,16 +6,33 @@
#define ARM64_PAGE_SHIFT_16K 14
#define ARM64_PAGE_SHIFT_64K 16
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+#define PAGE_SHIFT_MIN ARM64_PAGE_SHIFT_4K
+#define PAGE_SHIFT_MAX ARM64_PAGE_SHIFT_64K
+#else /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
#define PAGE_SHIFT_MIN CONFIG_PAGE_SHIFT
+#define PAGE_SHIFT_MAX CONFIG_PAGE_SHIFT
+#endif /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
+
#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>
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+#ifndef __ASSEMBLY__
+extern int ptg_page_shift;
+extern int ptg_pmd_shift;
+extern int ptg_pud_shift;
+extern int ptg_p4d_shift;
+extern int ptg_pgdir_shift;
+extern int ptg_cont_pte_shift;
+extern int ptg_cont_pmd_shift;
+extern int ptg_pgtable_levels;
+#endif /* __ASSEMBLY__ */
+#else /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
#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)
@@ -24,5 +41,6 @@
#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 /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
#endif /* ASM_PGTABLE_GEOMETRY_H */
diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h
index 02373c4ea474..21e9c8e76651 100644
--- a/arch/arm64/include/asm/pgtable-hwdef.h
+++ b/arch/arm64/include/asm/pgtable-hwdef.h
@@ -61,7 +61,8 @@
#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 PTRS_PER_PMD (ptg_pgtable_levels > 2 ? \
+ (1 << PTDESC_TABLE_SHIFT) : 1)
#define MAX_PTRS_PER_PMD (1 << (PAGE_SHIFT_MAX - PTDESC_ORDER))
#endif
@@ -72,7 +73,8 @@
#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 PTRS_PER_PUD (ptg_pgtable_levels > 3 ? \
+ (1 << PTDESC_TABLE_SHIFT) : 1)
#define MAX_PTRS_PER_PUD (1 << (PAGE_SHIFT_MAX - PTDESC_ORDER))
#endif
@@ -80,7 +82,8 @@
#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 PTRS_PER_P4D (ptg_pgtable_levels > 4 ? \
+ (1 << PTDESC_TABLE_SHIFT) : 1)
#define MAX_PTRS_PER_P4D (1 << (PAGE_SHIFT_MAX - PTDESC_ORDER))
#endif
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 7cdff90a3b7e..7fd4e6356297 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -822,7 +822,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
static __always_inline bool pgtable_l3_enabled(void)
{
- return true;
+ return ptg_pgtable_levels > 2;
}
static inline bool mm_pmd_folded(const struct mm_struct *mm)
@@ -955,6 +955,8 @@ static inline bool pgtable_l3_enabled(void) { return false; }
static __always_inline bool pgtable_l4_enabled(void)
{
+ if (IS_ENABLED(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE))
+ return ptg_pgtable_levels > 3;
if (CONFIG_PGTABLE_LEVELS > 4 || !IS_ENABLED(CONFIG_ARM64_LPA2))
return true;
if (!alternative_has_cap_likely(ARM64_ALWAYS_BOOT))
@@ -1003,6 +1005,8 @@ static inline pud_t *p4d_to_folded_pud(p4d_t *p4dp, unsigned long addr)
/* Ensure that 'p4dp' indexes a page table according to 'addr' */
VM_BUG_ON(((addr >> P4D_SHIFT) ^ ((u64)p4dp >> 3)) % PTRS_PER_P4D);
+ if (IS_ENABLED(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE))
+ return (pud_t *)p4dp;
return (pud_t *)PTR_ALIGN_DOWN(p4dp, PAGE_SIZE) + pud_index(addr);
}
@@ -1082,6 +1086,8 @@ static inline bool pgtable_l4_enabled(void) { return false; }
static __always_inline bool pgtable_l5_enabled(void)
{
+ if (IS_ENABLED(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE))
+ return ptg_pgtable_levels > 4;
if (!alternative_has_cap_likely(ARM64_ALWAYS_BOOT))
return vabits_actual == VA_BITS;
return alternative_has_cap_unlikely(ARM64_HAS_VA52);
@@ -1128,6 +1134,8 @@ static inline p4d_t *pgd_to_folded_p4d(pgd_t *pgdp, unsigned long addr)
/* Ensure that 'pgdp' indexes a page table according to 'addr' */
VM_BUG_ON(((addr >> PGDIR_SHIFT) ^ ((u64)pgdp >> 3)) % PTRS_PER_PGD);
+ if (IS_ENABLED(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE))
+ return (p4d_t *)pgdp;
return (p4d_t *)PTR_ALIGN_DOWN(pgdp, PAGE_SIZE) + p4d_index(addr);
}
diff --git a/arch/arm64/include/asm/sparsemem.h b/arch/arm64/include/asm/sparsemem.h
index 4148f2440831..1e196360ae70 100644
--- a/arch/arm64/include/asm/sparsemem.h
+++ b/arch/arm64/include/asm/sparsemem.h
@@ -20,6 +20,10 @@
* entries could not be created for vmemmap mappings.
* 16K follows 4K for simplicity.
*/
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+#define SECTION_SIZE_BITS 29
+#else
#define SECTION_SIZE_BITS (PAGE_SIZE == SZ_64K ? 29 : 27)
+#endif
#endif
diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
index 9c9215847d26..1774f75d0cb7 100644
--- a/arch/arm64/kernel/image-vars.h
+++ b/arch/arm64/kernel/image-vars.h
@@ -46,6 +46,17 @@ PROVIDE(__pi___memcpy = __pi_memcpy);
PROVIDE(__pi___memmove = __pi_memmove);
PROVIDE(__pi___memset = __pi_memset);
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+PI_EXPORT_SYM(ptg_page_shift);
+PI_EXPORT_SYM(ptg_pmd_shift);
+PI_EXPORT_SYM(ptg_pud_shift);
+PI_EXPORT_SYM(ptg_p4d_shift);
+PI_EXPORT_SYM(ptg_pgdir_shift);
+PI_EXPORT_SYM(ptg_cont_pte_shift);
+PI_EXPORT_SYM(ptg_cont_pmd_shift);
+PI_EXPORT_SYM(ptg_pgtable_levels);
+#endif /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
+
PI_EXPORT_SYM(id_aa64isar1_override);
PI_EXPORT_SYM(id_aa64isar2_override);
PI_EXPORT_SYM(id_aa64mmfr0_override);
diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h
index 5c10ca773363..0cfa5bc5e90f 100644
--- a/arch/arm64/kernel/image.h
+++ b/arch/arm64/kernel/image.h
@@ -33,7 +33,11 @@
#define __HEAD_FLAG_BE ARM64_IMAGE_FLAG_LE
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+#define __HEAD_FLAG_PAGE_SIZE 0
+#else
#define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2)
+#endif
#define __HEAD_FLAG_PHYS_BASE 1
diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_kernel.c
index 16f12fa8c890..a74a17fbd0bd 100644
--- a/arch/arm64/kernel/pi/map_kernel.c
+++ b/arch/arm64/kernel/pi/map_kernel.c
@@ -260,6 +260,49 @@ static bool __init ng_mappings_allowed(void)
return true;
}
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+static void __init ptg_init(int page_shift)
+{
+ ptg_pgtable_levels =
+ __ARM64_HW_PGTABLE_LEVELS(page_shift, CONFIG_ARM64_VA_BITS);
+
+ ptg_pgdir_shift = __ARM64_HW_PGTABLE_LEVEL_SHIFT(page_shift,
+ 4 - ptg_pgtable_levels);
+
+ ptg_p4d_shift = ptg_pgtable_levels >= 5 ?
+ __ARM64_HW_PGTABLE_LEVEL_SHIFT(page_shift, 0) :
+ ptg_pgdir_shift;
+
+ ptg_pud_shift = ptg_pgtable_levels >= 4 ?
+ __ARM64_HW_PGTABLE_LEVEL_SHIFT(page_shift, 1) :
+ ptg_pgdir_shift;
+
+ ptg_pmd_shift = ptg_pgtable_levels >= 3 ?
+ __ARM64_HW_PGTABLE_LEVEL_SHIFT(page_shift, 2) :
+ ptg_pgdir_shift;
+
+ ptg_page_shift = page_shift;
+
+ switch (page_shift) {
+ case ARM64_PAGE_SHIFT_64K:
+ ptg_cont_pte_shift = ptg_page_shift + 5;
+ ptg_cont_pmd_shift = ptg_pmd_shift + 5;
+ break;
+ case ARM64_PAGE_SHIFT_16K:
+ ptg_cont_pte_shift = ptg_page_shift + 7;
+ ptg_cont_pmd_shift = ptg_pmd_shift + 5;
+ break;
+ default: /* ARM64_PAGE_SHIFT_4K */
+ ptg_cont_pte_shift = ptg_page_shift + 4;
+ ptg_cont_pmd_shift = ptg_pmd_shift + 4;
+ }
+}
+#else /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
+static inline void ptg_init(int page_shift)
+{
+}
+#endif /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
+
asmlinkage void __init early_map_kernel(u64 boot_status, phys_addr_t fdt)
{
static char const chosen_str[] __initconst = "/chosen";
@@ -291,6 +334,8 @@ asmlinkage void __init early_map_kernel(u64 boot_status, phys_addr_t fdt)
if (!page_shift)
page_shift = early_page_shift;
+ ptg_init(page_shift);
+
if (va_bits > 48) {
u64 page_size = early_page_size(page_shift);
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index a148e80d0aef..37ccceda65ea 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -2847,6 +2847,16 @@ static void kvm_hyp_init_symbols(void)
kvm_nvhe_sym(id_aa64smfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64SMFR0_EL1);
kvm_nvhe_sym(__icache_flags) = __icache_flags;
kvm_nvhe_sym(kvm_arm_vmid_bits) = kvm_arm_vmid_bits;
+#ifdef CONFIG_ARM64_BOOT_TIME_PAGE_SIZE
+ kvm_nvhe_sym(ptg_page_shift) = ptg_page_shift;
+ kvm_nvhe_sym(ptg_pmd_shift) = ptg_pmd_shift;
+ kvm_nvhe_sym(ptg_pud_shift) = ptg_pud_shift;
+ kvm_nvhe_sym(ptg_p4d_shift) = ptg_p4d_shift;
+ kvm_nvhe_sym(ptg_pgdir_shift) = ptg_pgdir_shift;
+ kvm_nvhe_sym(ptg_cont_pte_shift) = ptg_cont_pte_shift;
+ kvm_nvhe_sym(ptg_cont_pmd_shift) = ptg_cont_pmd_shift;
+ kvm_nvhe_sym(ptg_pgtable_levels) = ptg_pgtable_levels;
+#endif /* CONFIG_ARM64_BOOT_TIME_PAGE_SIZE */
kvm_nvhe_sym(spectre_v2_state) = arm64_get_spectre_v2_state();
kvm_nvhe_sym(spectre_v4_state) = arm64_get_spectre_v4_state();
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
index 56a7e2c05f73..af36e8ef2006 100644
--- a/arch/arm64/kvm/hyp/nvhe/Makefile
+++ b/arch/arm64/kvm/hyp/nvhe/Makefile
@@ -28,6 +28,7 @@ hyp-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o
hyp-obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
../hyp-entry.o ../exception.o ../pgtable.o ../vgic-v5-sr.o
hyp-obj-y += ../../../kernel/smccc-call.o
+hyp-obj-$(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE) += pgtable-geometry.o
hyp-obj-$(CONFIG_LIST_HARDENED) += list_debug.o
hyp-obj-$(CONFIG_NVHE_EL2_TRACING) += clock.o trace.o events.o
hyp-obj-y += $(lib-objs)
diff --git a/arch/arm64/kvm/hyp/nvhe/pgtable-geometry.c b/arch/arm64/kvm/hyp/nvhe/pgtable-geometry.c
new file mode 100644
index 000000000000..17f807450a31
--- /dev/null
+++ b/arch/arm64/kvm/hyp/nvhe/pgtable-geometry.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 ARM Ltd.
+ */
+
+#include <linux/cache.h>
+#include <asm/pgtable-geometry.h>
+
+int ptg_page_shift __ro_after_init;
+int ptg_pmd_shift __ro_after_init;
+int ptg_pud_shift __ro_after_init;
+int ptg_p4d_shift __ro_after_init;
+int ptg_pgdir_shift __ro_after_init;
+int ptg_cont_pte_shift __ro_after_init;
+int ptg_cont_pmd_shift __ro_after_init;
+int ptg_pgtable_levels __ro_after_init;
diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile
index c26489cf96cd..160ef2da4629 100644
--- a/arch/arm64/mm/Makefile
+++ b/arch/arm64/mm/Makefile
@@ -3,6 +3,7 @@ obj-y := dma-mapping.o extable.o fault.o init.o \
cache.o copypage.o flush.o \
ioremap.o mmap.o pgd.o mem_encrypt.o mmu.o \
context.o proc.o pageattr.o fixmap.o
+obj-$(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE) += pgtable-geometry.o
obj-$(CONFIG_ARM64_CONTPTE) += contpte.o
obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
obj-$(CONFIG_PTDUMP) += ptdump.o
diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c
index 5d40ce1eab3f..072e1b821b2a 100644
--- a/arch/arm64/mm/pgd.c
+++ b/arch/arm64/mm/pgd.c
@@ -21,10 +21,12 @@ static bool pgdir_is_page_size(void)
{
if (PGD_SIZE == PAGE_SIZE)
return true;
- if (CONFIG_PGTABLE_LEVELS == 4)
- return !pgtable_l4_enabled();
- if (CONFIG_PGTABLE_LEVELS == 5)
- return !pgtable_l5_enabled();
+ if (!IS_ENABLED(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE)) {
+ if (CONFIG_PGTABLE_LEVELS == 4)
+ return !pgtable_l4_enabled();
+ if (CONFIG_PGTABLE_LEVELS == 5)
+ return !pgtable_l5_enabled();
+ }
return false;
}
diff --git a/arch/arm64/mm/pgtable-geometry.c b/arch/arm64/mm/pgtable-geometry.c
new file mode 100644
index 000000000000..645b722ced55
--- /dev/null
+++ b/arch/arm64/mm/pgtable-geometry.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 ARM Ltd.
+ */
+
+#include <linux/cache.h>
+#include <asm/pgtable-geometry.h>
+
+/*
+ * TODO: These should be __ro_after_init, but we need to write to them from the
+ * pi code where they are mapped in the early page table as read-only.
+ * __ro_after_init doesn't become writable until later when the swapper pgtable
+ * is fully set up. We should update the early page table to map __ro_after_init
+ * as read-write.
+ */
+
+int ptg_page_shift __read_mostly;
+EXPORT_SYMBOL(ptg_page_shift);
+int ptg_pmd_shift __read_mostly;
+EXPORT_SYMBOL(ptg_pmd_shift);
+int ptg_pud_shift __read_mostly;
+EXPORT_SYMBOL(ptg_pud_shift);
+int ptg_p4d_shift __read_mostly;
+EXPORT_SYMBOL(ptg_p4d_shift);
+int ptg_pgdir_shift __read_mostly;
+EXPORT_SYMBOL(ptg_pgdir_shift);
+int ptg_cont_pte_shift __read_mostly;
+EXPORT_SYMBOL(ptg_cont_pte_shift);
+int ptg_cont_pmd_shift __read_mostly;
+EXPORT_SYMBOL(ptg_cont_pmd_shift);
+int ptg_pgtable_levels __read_mostly;
+EXPORT_SYMBOL(ptg_pgtable_levels);
diff --git a/drivers/firmware/efi/libstub/arm64.c b/drivers/firmware/efi/libstub/arm64.c
index d35c6dd76601..b50674fcf40d 100644
--- a/drivers/firmware/efi/libstub/arm64.c
+++ b/drivers/firmware/efi/libstub/arm64.c
@@ -68,7 +68,8 @@ efi_status_t check_platform_features(void)
efi_novamap = true;
/* UEFI mandates support for 4 KB granularity, no need to check */
- if (IS_ENABLED(CONFIG_ARM64_4K_PAGES))
+ if (IS_ENABLED(CONFIG_ARM64_4K_PAGES) ||
+ IS_ENABLED(CONFIG_ARM64_BOOT_TIME_PAGE_SIZE))
return EFI_SUCCESS;
tg = (read_cpuid(ID_AA64MMFR0_EL1) >> ID_AA64MMFR0_EL1_TGRAN_SHIFT) & 0xf;
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core)
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
` (12 preceding siblings ...)
2026-12-01 1:52 ` [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection Eric Curtin
@ 2026-12-01 10:41 ` Lorenzo Stoakes (ARM)
13 siblings, 0 replies; 15+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-12-01 10:41 UTC (permalink / raw)
To: Eric Curtin
Cc: linux-arm-kernel, Eric Curtin, Ryan Roberts, Andrew Morton,
Anshuman Khandual, Ard Biesheuvel, Catalin Marinas,
David Hildenbrand (Arm), Greg Marsden, Ivan Ivanov, Kalesh Singh,
Marc Zyngier, Mark Rutland, Matthias Brugger, Miroslav Benes,
Will Deacon, Vlastimil Babka, linux-kernel, linux-mm,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Guo Ren, linux-riscv, bpf, linux-csky
(Please always refresh emails, David for instance has not been at redhat
for a while now, updated that one at least :)
On Tue, Dec 01, 2026 at 01:51:32AM +0000, Eric Curtin wrote:
> From: Eric Curtin <eric.curtin@docker.com>
>
> This is a continuation of Ryan Roberts's boot-time page size selection
> series [1]. I have rebased it onto v7.4-rc5, folded in the feedback from
> the v1 thread and Ryan's v2 work-in-progress branches [2], and split it
> up as Ryan proposed. This posting is the core: the PAGE_SIZE_MIN/MAX
> infrastructure, the mm and kernel changes it needs and the arm64
> implementation. The conversions of individual subsystems and drivers
> (fs, net, sound, drm, block, ...) follow as separate series to the
> relevant maintainers; they only depend on patch 1. Ryan, I hope you are
> happy for me to carry this forward; shout if you would rather post it
> yourself.
Thanks.
Speaking generally, in mm we expect people to gradually build their way
towards larger changes before we'd consider more invasive changes.
I therefore wouldn't recommend taking a previously sent RFC and re-sending
it yourself :) This is obviously even moreso the case given that LLM
tooling now makes this kind of task fairly trivial.
This work previously got stalled, as I gather (Ryan can correct me :),
because drivers also need updating to reflect the change.
So it moving forward would require a concerted community-wide effort, which
given on-list volume in mm and more generally I can't imagine is likely to
happen any time soon.
Finally, mm is in 'firefighting mode' [0] so we're not taking major changes
currently.
--
Cheers, Lorenzo
[0]: https://lore.kernel.org/linux-mm/a2f584f6-e382-4876-aa6d-d5a34de6ee59@kernel.org/
^ permalink raw reply [flat|nested] 15+ messages in thread