* [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core)
@ 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
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: Eric Curtin @ 2026-12-01 1:51 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Eric Curtin, Ryan Roberts, Andrew Morton, Anshuman Khandual,
Ard Biesheuvel, Catalin Marinas, David Hildenbrand, 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
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.
arm64 supports 4K, 16K and 64K base pages, but the size is fixed at
compile time, so distributions that want several sizes ship several
kernels. With CONFIG_ARM64_BOOT_TIME_PAGE_SIZE=y the size is chosen at
boot with arm64.pagesize=4k|16k|64k (default set by
ARM64_BOOT_TIME_PAGE_SIZE_DEFAULT), and PAGE_SIZE, PAGE_SHIFT, PAGE_MASK
and the pgtable geometry macros become __ro_after_init variables. Where
a constant is unavoidable (static arrays, struct layouts, BUILD_BUG_ON(),
case labels) code uses PAGE_SIZE_MIN/PAGE_SIZE_MAX. For fixed page size
configurations these collapse to the old constants and the generated
code is meant to be unchanged.
Patches 1-13 are generic: the macros (patch 1), section alignment,
page_frag, the split pmd lock, THREAD_SIZE and a few core users. Patches
14-33 and 40 are the arm64 plumbing, 34-39, 41 and 42 are further core
conversions found while building, and patch 43 adds the Kconfig option
and documentation last, so every patch builds with fixed page sizes.
Changes since v1:
- Rebased onto v7.4-rc5; picked up Ryan's v2-1-wip fixes and the review
comments from the v1 thread.
- Split into this core series plus per-subsystem series.
- Fixed bugs found in an independent review of the whole series (KVM
stage-2 mapping size on demotion, map_fdt() state, hibernate image
buffers, module constructor ordering vs module_param, others).
- Added -Werror=undef when the option is enabled. #if PAGE_SIZE ...
otherwise silently evaluates the runtime variable as 0.
- Added arm64.pagesize= documentation and a Kconfig default size.
- Dropped patches that are already upstream.
Testing:
- arm64 defconfig with the option enabled builds and boots to userspace
with 4K, 16K and 64K, under QEMU/KVM on an NVIDIA GB10 (DGX Spark),
and with 4K and 16K under QEMU/HVF on an Apple M1. A small userspace
test (fork/COW, mremap, mincore, memfd, THP, tmpfs and ext4-on-loop
I/O) passes at each size; the kernel log is checked for warnings.
- allmodconfig with the option enabled (KASAN off) builds cleanly with
all the per-subsystem conversions applied.
- defconfig builds with fixed 4K, 16K and 64K pages are unchanged, and
this series alone builds at all three.
- Not done: mm selftests, LTP, KASAN or LPA2 runs, and no new
performance numbers; Ryan's v1 numbers [1] still stand as a guide. Most
driver conversions are compile-tested only.
Known limitations: 48-bit VA only, MMAP_RND_BITS, SECTION_SIZE_BITS and
ARCH_FORCE_MAX_ORDER are sized for the worst case (64K) and the image
carries the static buffers for the largest page size.
The full tree, including the subsystem conversions, is at:
https://github.com/ericcurtin/linux/tree/boot-time-page-size-v2
Tool use: the rebase conflict resolution, most of the build-fix
conversions in the subsystem series, the review pass and the commit
message drafting were done with an LLM coding assistant (opencode with
Claude Sonnet), driven and tested as described above. Ryan's original
patches keep his authorship and sign-off; I have not hand-reviewed every
driver change, so please read them with that in mind.
[1] https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/
[2] https://gitlab.arm.com/linux-arm/linux-rr, features/boot-time-page-size-v2-1-wip
Eric Curtin (9):
mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE
arm64: pi: Clear the FDT ptes on every remap in map_fdt()
arm64: Convert remaining page-size switches to if/else
vdso: Lay out the data pages in VDSO_PAGE_SIZE units
mm: Use fixed sizes for shmem str_dup and swap cache PFN bits
crash: Size the vmcoreinfo page array for the smallest page size
arm64: Size kasan and pKVM stacktrace arrays for PAGE_SIZE_MAX
exit: Use THREAD_SIZE_MAX for lowest_to_date
tracing: Use PAGE_SIZE_MIN/MAX in the uprobe check and undefsyms page
Ryan Roberts (34):
mm: Add macros ahead of supporting boot-time page size selection
vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX
mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache
mm: Avoid split pmd ptl if pmd level is run-time folded
mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters
fork: Permit boot-time THREAD_SIZE determination
cgroup: Use DEFINE_GLOBAL_PAGE_SIZE_VAR for the kernfs_ops tables
bpf: Do not embed page-aligned members in struct bpf_ringbuf
PM: hibernate: Do not size swap structures to exactly PAGE_SIZE
perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock
KVM: Check struct kvm_run against PAGE_SIZE_MIN
crash: Check crash_notes size against PAGE_SIZE_MIN
arm64: Make INIT_DIR_SIZE and INIT_IDMAP_DIR_SIZE usable from C
arm64: pi: Pass the early pgtable allocation limit to map_range()
arm64: Introduce macros required for boot-time page size selection
arm64: Parameterise early pgtable size macros by page shift
arm64: Add arm64.pagesize= command line override
arm64: pi: Select the page size at runtime during early boot
arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES
arm64: Align image sections to PAGE_SIZE_MAX
arm64: Map the trampoline rodata at its aligned offset
arm64: fixmap: Size slots and page tables for PAGE_SIZE_MIN
arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX
arm64: Convert KVM and hugetlb size switches to if/else
arm64: mm: Make page size dependent BUILD_BUG_ON() checks runtime
arm64: cpufeature: Add capabilities for the page size in use
arm64: Look up the page size at runtime in assembly code
arm64: Support runtime folding of the pmd level
arm64: Support runtime folding in idmap_kpti_install_ng_mappings
arm64: Patch TRAMP_VALIAS into instructions at boot
arm64: Determine THREAD_SIZE at boot time
mm/damon/lru_sort: Initialise the stub access pattern at boot
mm/zsmalloc: Size static limits for the worst-case page size
arm64: Enable boot-time page size selection
.../admin-guide/kernel-parameters.txt | 11 +
Documentation/arch/arm64/booting.rst | 4 +-
Documentation/arch/arm64/memory.rst | 21 ++
arch/alpha/include/asm/page.h | 1 +
arch/arc/include/asm/page.h | 1 +
arch/arm/include/asm/page.h | 1 +
arch/arm64/Kconfig | 54 ++++-
arch/arm64/Makefile | 5 +
arch/arm64/include/asm/assembler.h | 78 ++++++-
arch/arm64/include/asm/cpufeature.h | 44 +++-
arch/arm64/include/asm/efi.h | 2 +-
arch/arm64/include/asm/fixmap.h | 28 ++-
arch/arm64/include/asm/hugetlb.h | 15 +-
arch/arm64/include/asm/kernel-pgtable.h | 153 +++++++++----
arch/arm64/include/asm/kvm_arm.h | 23 +-
arch/arm64/include/asm/kvm_hyp.h | 11 +
arch/arm64/include/asm/kvm_pgtable.h | 6 +-
arch/arm64/include/asm/linkage.h | 2 +-
arch/arm64/include/asm/memory.h | 55 +++--
arch/arm64/include/asm/page-def.h | 9 +
arch/arm64/include/asm/pgalloc.h | 15 +-
arch/arm64/include/asm/pgtable-geometry.h | 46 ++++
arch/arm64/include/asm/pgtable-hwdef.h | 34 ++-
arch/arm64/include/asm/pgtable-prot.h | 2 +-
arch/arm64/include/asm/pgtable.h | 147 ++++++++----
arch/arm64/include/asm/processor.h | 10 +-
arch/arm64/include/asm/sections.h | 1 +
arch/arm64/include/asm/smp.h | 1 +
arch/arm64/include/asm/sparsemem.h | 15 +-
arch/arm64/include/asm/stacktrace/nvhe.h | 2 +-
arch/arm64/include/asm/sysreg.h | 54 +++--
arch/arm64/include/asm/tlb.h | 3 +
arch/arm64/kernel/asm-offsets.c | 2 +-
arch/arm64/kernel/cpu_errata.c | 53 +++++
arch/arm64/kernel/cpufeature.c | 68 ++++--
arch/arm64/kernel/efi.c | 2 +-
arch/arm64/kernel/entry.S | 48 +++-
arch/arm64/kernel/head.S | 46 +++-
arch/arm64/kernel/hibernate-asm.S | 6 +-
arch/arm64/kernel/image-vars.h | 14 ++
arch/arm64/kernel/image.h | 4 +
arch/arm64/kernel/pi/idreg-override.c | 50 +++-
arch/arm64/kernel/pi/map_kernel.c | 186 +++++++++++----
arch/arm64/kernel/pi/map_range.c | 214 ++++++++++++++++--
arch/arm64/kernel/pi/pi.h | 68 +++++-
arch/arm64/kernel/relocate_kernel.S | 10 +-
arch/arm64/kernel/vdso-wrap.S | 4 +-
arch/arm64/kernel/vdso.c | 4 +-
arch/arm64/kernel/vdso32-wrap.S | 4 +-
arch/arm64/kernel/vmlinux.lds.S | 56 ++---
arch/arm64/kvm/arm.c | 10 +
arch/arm64/kvm/hyp/nvhe/Makefile | 1 +
arch/arm64/kvm/hyp/nvhe/host.S | 12 +
arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 4 +-
arch/arm64/kvm/hyp/nvhe/mm.c | 30 ++-
arch/arm64/kvm/hyp/nvhe/pgtable-geometry.c | 16 ++
arch/arm64/kvm/hyp/nvhe/stacktrace.c | 3 +-
arch/arm64/kvm/mmu.c | 31 +--
arch/arm64/lib/copy_page.S | 59 +++--
arch/arm64/lib/mte.S | 27 ++-
arch/arm64/mm/Makefile | 1 +
arch/arm64/mm/fault.c | 12 +-
arch/arm64/mm/fixmap.c | 38 ++--
arch/arm64/mm/hugetlbpage.c | 55 ++---
arch/arm64/mm/init.c | 27 +--
arch/arm64/mm/kasan_init.c | 25 +-
arch/arm64/mm/mmu.c | 126 +++++++++--
arch/arm64/mm/pgd.c | 12 +-
arch/arm64/mm/pgtable-geometry.c | 32 +++
arch/arm64/mm/proc.S | 131 +++++++----
arch/arm64/mm/ptdump.c | 6 +-
arch/arm64/tools/cpucaps | 3 +
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 +
drivers/firmware/efi/libstub/arm64.c | 3 +-
drivers/irqchip/irq-gic-v3-its.c | 2 +-
include/asm-generic/pgtable-geometry.h | 86 +++++++
include/asm-generic/vmlinux.lds.h | 44 ++--
include/linux/linkage.h | 4 +-
include/linux/mm.h | 17 +-
include/linux/mm_types.h | 2 +-
include/linux/mm_types_task.h | 4 +-
include/linux/page_frag_cache.h | 2 +-
include/linux/percpu-defs.h | 4 +-
include/linux/perf_event.h | 2 +-
include/linux/pgtable.h | 2 +-
include/linux/sched.h | 4 +-
include/linux/thread_info.h | 10 +-
include/linux/vm_event_item.h | 14 +-
include/linux/vmcore_info.h | 1 +
include/vdso/datapage.h | 10 +-
include/vdso/page.h | 4 +
init/main.c | 7 +-
kernel/bpf/core.c | 11 +-
kernel/bpf/ringbuf.c | 67 +++---
kernel/cgroup/cgroup.c | 8 +-
kernel/crash_core.c | 4 +-
kernel/events/core.c | 3 +-
kernel/exit.c | 16 +-
kernel/fork.c | 57 ++---
kernel/module/main.c | 4 +-
kernel/power/power.h | 3 +-
kernel/power/snapshot.c | 10 +-
kernel/power/swap.c | 129 +++++++++--
kernel/trace/trace_uprobe.c | 2 +-
kernel/trace/undefsyms_base.c | 3 +-
lib/vdso/datastore.c | 34 +--
lib/vdso/gettimeofday.c | 4 +-
mm/Kconfig | 8 +
mm/damon/lru_sort.c | 4 +-
mm/kasan/report.c | 3 +-
mm/mm_init.c | 2 +-
mm/page_frag_cache.c | 17 +-
mm/shmem.c | 4 +-
mm/swap.h | 7 +-
mm/vmstat.c | 14 +-
mm/zsmalloc.c | 18 +-
virt/kvm/kvm_main.c | 2 +-
133 files changed, 2244 insertions(+), 793 deletions(-)
create mode 100644 arch/arm64/include/asm/pgtable-geometry.h
create mode 100644 arch/arm64/kvm/hyp/nvhe/pgtable-geometry.c
create mode 100644 arch/arm64/mm/pgtable-geometry.c
create mode 100644 include/asm-generic/pgtable-geometry.h
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
^ permalink raw reply [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 ` Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 03/43] mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache 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, 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 03/43] mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache
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 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 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE 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, Vlastimil Babka, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Michal Hocko, Johannes Weiner,
Suren Baghdasaryan, Brendan Jackman, Zi Yan, Andrew Morton,
linux-mm
From: Ryan Roberts <ryan.roberts@arm.com>
With boot-time page size selection, PAGE_SIZE and PAGE_MASK are not
compile-time constants, but struct page_frag_cache, the order mask and
the BUILD_BUG_ON() checks in encoded_page_create() need constants.
Define PAGE_FRAG_CACHE_MAX_SIZE with PAGE_MASK_MIN. Choose the layout of
struct page_frag_cache using PAGE_SIZE_MAX, and choose
PAGE_FRAG_CACHE_ORDER_MASK using PAGE_SIZE_MIN. Make the
BUILD_BUG_ON() checks in encoded_page_create() use PAGE_SHIFT_MIN and
PAGE_SIZE_MIN.
In __page_frag_cache_refill(), turn the #if on PAGE_SIZE into a C if
statement so that the large-order attempt is decided at run time and is
dead-code eliminated when the page size is fixed.
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 c15bbe772338e7c74cd1eaa8d1034a0c9ad0c0f9)
---
include/linux/mm_types_task.h | 4 ++--
include/linux/page_frag_cache.h | 2 +-
mm/page_frag_cache.c | 17 +++++++++--------
3 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
index 11bf319d78ec..704c3c31d11d 100644
--- a/include/linux/mm_types_task.h
+++ b/include/linux/mm_types_task.h
@@ -44,7 +44,7 @@ struct page_frag {
#endif
};
-#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
+#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK_MIN)
#define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
struct page_frag_cache {
/* encoded_page consists of the virtual address, pfmemalloc bit and
@@ -55,7 +55,7 @@ struct page_frag_cache {
/* we maintain a pagecount bias, so that we dont dirty cache line
* containing page->_refcount every time we allocate a fragment.
*/
-#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) && (BITS_PER_LONG <= 32)
+#if (PAGE_SIZE_MAX < PAGE_FRAG_CACHE_MAX_SIZE) && (BITS_PER_LONG <= 32)
__u16 offset;
__u16 pagecnt_bias;
#else
diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h
index 41a91df82631..49a0b0b51446 100644
--- a/include/linux/page_frag_cache.h
+++ b/include/linux/page_frag_cache.h
@@ -8,7 +8,7 @@
#include <linux/mm_types_task.h>
#include <linux/types.h>
-#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
+#if (PAGE_SIZE_MIN < PAGE_FRAG_CACHE_MAX_SIZE)
/* Use a full byte here to enable assembler optimization as the shift
* operation is usually expecting a byte.
*/
diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c
index 8914437ddc51..d4419caa0c06 100644
--- a/mm/page_frag_cache.c
+++ b/mm/page_frag_cache.c
@@ -23,8 +23,9 @@
static unsigned long encoded_page_create(struct page *page, unsigned int order,
bool pfmemalloc)
{
- BUILD_BUG_ON(PAGE_FRAG_CACHE_MAX_ORDER > PAGE_FRAG_CACHE_ORDER_MASK);
- BUILD_BUG_ON(PAGE_FRAG_CACHE_PFMEMALLOC_BIT >= PAGE_SIZE);
+ BUILD_BUG_ON(order_base_2(PAGE_FRAG_CACHE_MAX_SIZE >> PAGE_SHIFT_MIN) >
+ PAGE_FRAG_CACHE_ORDER_MASK);
+ BUILD_BUG_ON(PAGE_FRAG_CACHE_PFMEMALLOC_BIT >= PAGE_SIZE_MIN);
return (unsigned long)page_address(page) |
(order & PAGE_FRAG_CACHE_ORDER_MASK) |
@@ -53,12 +54,12 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc,
struct page *page = NULL;
gfp_t gfp = gfp_mask;
-#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
- gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP |
- __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC;
- page = __alloc_pages(gfp_mask, PAGE_FRAG_CACHE_MAX_ORDER,
- numa_mem_id(), NULL, ALLOC_DEFAULT);
-#endif
+ if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) {
+ gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP |
+ __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC;
+ page = __alloc_pages(gfp_mask, PAGE_FRAG_CACHE_MAX_ORDER,
+ numa_mem_id(), NULL, ALLOC_DEFAULT);
+ }
if (unlikely(!page)) {
page = __alloc_pages(gfp, 0, numa_mem_id(), NULL, ALLOC_DEFAULT);
order = 0;
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE
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 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 03/43] mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache 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
` (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: Eric Curtin, Vlastimil Babka, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Michal Hocko, Johannes Weiner,
Suren Baghdasaryan, Brendan Jackman, Zi Yan, Andrew Morton,
linux-mm
From: Eric Curtin <eric.curtin@docker.com>
PAGE_FRAG_CACHE_MAX_SIZE is derived from PAGE_MASK and, with boot-time
page size selection, is not a compile-time constant. It is needed both
where a constant is required (struct layout, preprocessor conditionals,
BUILD_BUG_ON()) and to compute the allocation order at run time.
Make PAGE_FRAG_CACHE_MAX_SIZE, and hence PAGE_FRAG_CACHE_MAX_ORDER,
follow the runtime PAGE_MASK, and add PAGE_FRAG_CACHE_MAX_SIZE_MIN and
PAGE_FRAG_CACHE_MAX_SIZE_MAX, computed from PAGE_MASK_MIN and
PAGE_MASK_MAX. Use the _MAX variant for the struct page_frag_cache
layout and the _MIN variant for PAGE_FRAG_CACHE_ORDER_MASK and the
encoded_page_create() order check.
No functional change for compile-time page sizes.
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 ef68b4f691a7bb68097fb285c111ac88caeb107c)
---
include/linux/mm_types_task.h | 6 ++++--
include/linux/page_frag_cache.h | 2 +-
mm/page_frag_cache.c | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
index 704c3c31d11d..2f760f472e19 100644
--- a/include/linux/mm_types_task.h
+++ b/include/linux/mm_types_task.h
@@ -44,7 +44,9 @@ struct page_frag {
#endif
};
-#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK_MIN)
+#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK)
+#define PAGE_FRAG_CACHE_MAX_SIZE_MIN __ALIGN_MASK(32768, ~PAGE_MASK_MIN)
+#define PAGE_FRAG_CACHE_MAX_SIZE_MAX __ALIGN_MASK(32768, ~PAGE_MASK_MAX)
#define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE)
struct page_frag_cache {
/* encoded_page consists of the virtual address, pfmemalloc bit and
@@ -55,7 +57,7 @@ struct page_frag_cache {
/* we maintain a pagecount bias, so that we dont dirty cache line
* containing page->_refcount every time we allocate a fragment.
*/
-#if (PAGE_SIZE_MAX < PAGE_FRAG_CACHE_MAX_SIZE) && (BITS_PER_LONG <= 32)
+#if (PAGE_SIZE_MAX < PAGE_FRAG_CACHE_MAX_SIZE_MAX) && (BITS_PER_LONG <= 32)
__u16 offset;
__u16 pagecnt_bias;
#else
diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h
index 49a0b0b51446..5ce206c892f7 100644
--- a/include/linux/page_frag_cache.h
+++ b/include/linux/page_frag_cache.h
@@ -8,7 +8,7 @@
#include <linux/mm_types_task.h>
#include <linux/types.h>
-#if (PAGE_SIZE_MIN < PAGE_FRAG_CACHE_MAX_SIZE)
+#if (PAGE_SIZE_MIN < PAGE_FRAG_CACHE_MAX_SIZE_MIN)
/* Use a full byte here to enable assembler optimization as the shift
* operation is usually expecting a byte.
*/
diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c
index d4419caa0c06..7f1eca0b9955 100644
--- a/mm/page_frag_cache.c
+++ b/mm/page_frag_cache.c
@@ -23,7 +23,7 @@
static unsigned long encoded_page_create(struct page *page, unsigned int order,
bool pfmemalloc)
{
- BUILD_BUG_ON(order_base_2(PAGE_FRAG_CACHE_MAX_SIZE >> PAGE_SHIFT_MIN) >
+ BUILD_BUG_ON(order_base_2(PAGE_FRAG_CACHE_MAX_SIZE_MIN >> PAGE_SHIFT_MIN) >
PAGE_FRAG_CACHE_ORDER_MASK);
BUILD_BUG_ON(PAGE_FRAG_CACHE_PFMEMALLOC_BIT >= PAGE_SIZE_MIN);
^ 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
` (2 preceding siblings ...)
2026-12-01 1:51 ` [RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE 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
` (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, 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
` (3 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
` (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, 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
` (4 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 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES 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, 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 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
` (5 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 25/43] arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX 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, 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 25/43] arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX
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 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
@ 2026-12-01 1:51 ` Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 30/43] arm64: Support runtime folding of the pmd level 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, Catalin Marinas, Will Deacon, Mark Rutland,
David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, linux-mm
From: Ryan Roberts <ryan.roberts@arm.com>
The zero page and the page table buffer used to map the FDT during early
boot have to be big enough and aligned for whichever page size is
selected at boot, so declare them for PAGE_SIZE_MAX instead of
PAGE_SIZE. This affects empty_zero_page and its declaration in
linux/pgtable.h, and the ptes array in map_fdt().
For a compile-time page size PAGE_SIZE_MAX equals PAGE_SIZE and there is
no functional change. For a boot-time page size, unused memory could be
freed once the page size is known, but that is not done here.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 5394b3c8ab37b41a0e4943c2b0f8220fc63a07a6)
---
arch/arm64/kernel/pi/map_kernel.c | 2 +-
include/linux/pgtable.h | 2 +-
mm/mm_init.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kernel/pi/map_kernel.c b/arch/arm64/kernel/pi/map_kernel.c
index fa3549701927..16f12fa8c890 100644
--- a/arch/arm64/kernel/pi/map_kernel.c
+++ b/arch/arm64/kernel/pi/map_kernel.c
@@ -213,7 +213,7 @@ static void __init remap_idmap(bool use_lpa2, int page_shift)
static void *__init map_fdt(phys_addr_t fdt, int page_shift)
{
- static u8 ptes[INIT_IDMAP_FDT_SIZE_MAX] __initdata __aligned(PAGE_SIZE);
+ static u8 ptes[INIT_IDMAP_FDT_SIZE_MAX] __initdata __aligned(PAGE_SIZE_MAX);
static bool first_time __initdata = true;
u64 limit = (u64)&ptes[INIT_IDMAP_FDT_SIZE_MAX];
phys_addr_t efdt = fdt + MAX_FDT_SIZE;
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 66d369870a74..e3544dd7871d 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -2075,7 +2075,7 @@ static inline unsigned long zero_pfn(unsigned long addr)
return zero_page_pfn;
}
-extern const uint8_t empty_zero_page[PAGE_SIZE];
+extern const uint8_t empty_zero_page[PAGE_SIZE_MAX];
extern struct page *__zero_page;
static inline struct page *_zero_page(unsigned long addr)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index d99af80ec752..0abbe36f5667 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -62,7 +62,7 @@ unsigned long zero_page_pfn __ro_after_init;
EXPORT_SYMBOL(zero_page_pfn);
#ifndef __HAVE_COLOR_ZERO_PAGE
-const uint8_t empty_zero_page[PAGE_SIZE] __aligned(PAGE_SIZE);
+const uint8_t empty_zero_page[PAGE_SIZE_MAX] __aligned(PAGE_SIZE_MAX);
EXPORT_SYMBOL(empty_zero_page);
struct page *__zero_page __ro_after_init;
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [RFC PATCH v2 30/43] arm64: Support runtime folding of the pmd level
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 25/43] arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX Eric Curtin
@ 2026-12-01 1:52 ` Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 34/43] mm/damon/lru_sort: Initialise the stub access pattern at boot 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: Ryan Roberts, Catalin Marinas, Will Deacon, Mark Rutland,
Aneesh Kumar K.V, Andrew Morton, Nick Piggin, Peter Zijlstra,
Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
Suzuki K Poulose, Zenghui Yu, linux-arch, linux-mm, kvmarm
From: Ryan Roberts <ryan.roberts@arm.com>
For a given VA size the number of translation levels depends on the
page size, so with boot-time page size selection it is not known until
boot how many levels are needed. 16K pages with 36-bit VAs and 64K pages
with 42-bit VAs, for example, need only two levels. The p4d and pud
levels can already be folded at runtime for the LPA2 fallback paths, and
the pmd level now needs the same treatment.
Add pgtable_l3_enabled() and use it, as the p4d and pud equivalents are
used, to make the pud_* helpers, set_pmd(), pmd_offset() and friends,
pmd_set_fixmap(), pmd_free(), __pmd_free_tlb() and mm_pmd_folded()
behave as folded when the pmd level is absent. The same check replaces
__PAGETABLE_PMD_FOLDED and CONFIG_PGTABLE_LEVELS tests in the KVM
stage-2 VMA size code, the hugetlb size helpers, the fixmap, the KPTI
level count, free_empty_pmd_table() and the ptdump level fixup. The
levels check in arch_mm_preinit() uses ptg_pgtable_levels.
pgtable_l3_enabled() is only the compile-time answer for now, so there
is no functional change.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 203ac9561f66a4947887e902541b403935c4fa1f)
---
arch/arm64/include/asm/pgalloc.h | 15 +++-
arch/arm64/include/asm/pgtable.h | 115 +++++++++++++++++++++++--------
arch/arm64/include/asm/tlb.h | 3 +
arch/arm64/kvm/mmu.c | 6 +-
arch/arm64/mm/fixmap.c | 2 +-
arch/arm64/mm/hugetlbpage.c | 9 +--
arch/arm64/mm/init.c | 5 +-
arch/arm64/mm/mmu.c | 6 +-
arch/arm64/mm/ptdump.c | 6 +-
9 files changed, 120 insertions(+), 47 deletions(-)
diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
index 1b4509d3382c..c79c7f43234b 100644
--- a/arch/arm64/include/asm/pgalloc.h
+++ b/arch/arm64/include/asm/pgalloc.h
@@ -15,6 +15,7 @@
#define __HAVE_ARCH_PGD_FREE
#define __HAVE_ARCH_PUD_FREE
+#define __HAVE_ARCH_PMD_FREE
#include <asm-generic/pgalloc.h>
#define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
@@ -23,7 +24,8 @@
static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
{
- set_pud(pudp, __pud(__phys_to_pud_val(pmdp) | prot));
+ if (pgtable_l3_enabled())
+ set_pud(pudp, __pud(__phys_to_pud_val(pmdp) | prot));
}
static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
@@ -33,6 +35,17 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
pudval |= (mm == &init_mm) ? PUD_TABLE_UXN : PUD_TABLE_PXN;
__pud_populate(pudp, __pa(pmdp), pudval);
}
+
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
+{
+ struct ptdesc *ptdesc = virt_to_ptdesc(pmd);
+
+ if (!pgtable_l3_enabled())
+ return;
+
+ BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
+ pagetable_dtor_free(ptdesc);
+}
#else
static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
{
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index a474c9fb485a..c625fe7f8452 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -760,12 +760,14 @@ static inline int pmd_trans_huge(pmd_t pmd)
}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
-#if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3
-static inline bool pud_table(pud_t pud) { return true; }
-#else
-#define pud_table(pud) ((pud_val(pud) & PUD_TYPE_MASK) == \
- PUD_TYPE_TABLE)
-#endif
+static inline bool pgtable_l3_enabled(void);
+
+static inline bool pud_table(pud_t pud)
+{
+ if (PAGE_SIZE == SZ_64K || !pgtable_l3_enabled())
+ return true;
+ return (pud_val(pud) & PUD_TYPE_MASK) == PUD_TYPE_TABLE;
+}
extern pgd_t swapper_pg_dir[];
extern pgd_t idmap_pg_dir[];
@@ -782,12 +784,10 @@ static inline bool in_swapper_pgdir(void *addr)
static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
{
-#ifdef __PAGETABLE_PMD_FOLDED
- if (in_swapper_pgdir(pmdp)) {
+ if (!pgtable_l3_enabled() && in_swapper_pgdir(pmdp)) {
set_swapper_pgd((pgd_t *)pmdp, __pgd(pmd_val(pmd)));
return;
}
-#endif /* __PAGETABLE_PMD_FOLDED */
WRITE_ONCE(*pmdp, pmd);
@@ -824,22 +824,29 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
#if CONFIG_PGTABLE_LEVELS > 2
-#define pud_none(pud) (!pud_val(pud))
-#define pud_bad(pud) ((pud_val(pud) & PUD_TYPE_MASK) != \
- PUD_TYPE_TABLE)
-#define pud_present(pud) pte_present(pud_pte(pud))
-#ifndef __PAGETABLE_PMD_FOLDED
+static __always_inline bool pgtable_l3_enabled(void)
+{
+ return true;
+}
+
+static inline bool mm_pmd_folded(const struct mm_struct *mm)
+{
+ return !pgtable_l3_enabled();
+}
+#define mm_pmd_folded mm_pmd_folded
+
+#define pud_none(pud) (pgtable_l3_enabled() && !pud_val(pud))
+#define pud_bad(pud) (pgtable_l3_enabled() && !pud_table(pud))
+#define pud_present(pud) (!pgtable_l3_enabled() || pte_present(pud_pte(pud)))
#define pud_leaf pud_leaf
static inline bool pud_leaf(pud_t pud)
{
- return pud_present(pud) && !pud_table(pud);
+ return pgtable_l3_enabled() && pte_present(pud_pte(pud)) &&
+ !pud_table(pud);
}
-#else
-#define pud_leaf(pud) false
-#endif
-#define pud_valid(pud) pte_valid(pud_pte(pud))
-#define pud_user(pud) pte_user(pud_pte(pud))
-#define pud_user_exec(pud) pte_user_exec(pud_pte(pud))
+#define pud_valid(pud) (pgtable_l3_enabled() && pte_valid(pud_pte(pud)))
+#define pud_user(pud) (pgtable_l3_enabled() && pte_user(pud_pte(pud)))
+#define pud_user_exec(pud) (pgtable_l3_enabled() && pte_user_exec(pud_pte(pud)))
static inline bool pgtable_l4_enabled(void);
@@ -858,7 +865,8 @@ static inline void set_pud(pud_t *pudp, pud_t pud)
static inline void pud_clear(pud_t *pudp)
{
- set_pud(pudp, __pud(0));
+ if (pgtable_l3_enabled())
+ set_pud(pudp, __pud(0));
}
static inline phys_addr_t pud_page_paddr(pud_t pud)
@@ -866,25 +874,74 @@ static inline phys_addr_t pud_page_paddr(pud_t pud)
return __pud_to_phys(pud);
}
+#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+
+static inline pmd_t *pud_to_folded_pmd(pud_t *pudp, unsigned long addr)
+{
+ return (pmd_t *)pudp;
+}
+
static inline pmd_t *pud_pgtable(pud_t pud)
{
return (pmd_t *)__va(pud_page_paddr(pud));
}
-/* Find an entry in the second-level page table. */
-#define pmd_offset_phys(dir, addr) (pud_page_paddr(READ_ONCE(*(dir))) + pmd_index(addr) * sizeof(pmd_t))
+static inline phys_addr_t pmd_offset_phys(pud_t *pudp, unsigned long addr)
+{
+ BUG_ON(!pgtable_l3_enabled());
-#define pmd_set_fixmap(addr) ((pmd_t *)set_fixmap_offset(FIX_PMD, addr))
-#define pmd_set_fixmap_offset(pud, addr) pmd_set_fixmap(pmd_offset_phys(pud, addr))
-#define pmd_clear_fixmap() clear_fixmap(FIX_PMD)
+ return pud_page_paddr(READ_ONCE(*pudp)) + pmd_index(addr) * sizeof(pmd_t);
+}
-#define pud_page(pud) phys_to_page(__pud_to_phys(pud))
+static inline pmd_t *pmd_offset_lockless(pud_t *pudp, pud_t pud,
+ unsigned long addr)
+{
+ if (!pgtable_l3_enabled())
+ return pud_to_folded_pmd(pudp, addr);
+ return (pmd_t *)__va(pud_page_paddr(pud)) + pmd_index(addr);
+}
+#define pmd_offset_lockless pmd_offset_lockless
+
+static inline pmd_t *pmd_offset(pud_t *pudp, unsigned long addr)
+{
+ return pmd_offset_lockless(pudp, READ_ONCE(*pudp), addr);
+}
+#define pmd_offset pmd_offset
+
+static inline pmd_t *pmd_set_fixmap(unsigned long addr)
+{
+ if (!pgtable_l3_enabled())
+ return NULL;
+ return (pmd_t *)set_fixmap_offset(FIX_PMD, addr);
+}
+
+static inline pmd_t *pmd_set_fixmap_offset(pud_t *pudp, unsigned long addr)
+{
+ if (!pgtable_l3_enabled())
+ return pud_to_folded_pmd(pudp, addr);
+ return pmd_set_fixmap(pmd_offset_phys(pudp, addr));
+}
+
+static inline void pmd_clear_fixmap(void)
+{
+ if (pgtable_l3_enabled())
+ clear_fixmap(FIX_PMD);
+}
/* use ONLY for statically allocated translation tables */
-#define pmd_offset_kimg(dir,addr) ((pmd_t *)__phys_to_kimg(pmd_offset_phys((dir), (addr))))
+static inline pmd_t *pmd_offset_kimg(pud_t *pudp, u64 addr)
+{
+ if (!pgtable_l3_enabled())
+ return pud_to_folded_pmd(pudp, addr);
+ return (pmd_t *)__phys_to_kimg(pmd_offset_phys(pudp, addr));
+}
+
+#define pud_page(pud) phys_to_page(__pud_to_phys(pud))
#else
+static inline bool pgtable_l3_enabled(void) { return false; }
+
#define pud_valid(pud) false
#define pud_page_paddr(pud) ({ BUILD_BUG(); 0; })
#define pud_user_exec(pud) pud_user(pud) /* Always 0 with folding */
diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h
index 751bd57bc3ba..3197ed0702b4 100644
--- a/arch/arm64/include/asm/tlb.h
+++ b/arch/arm64/include/asm/tlb.h
@@ -87,6 +87,9 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
{
struct ptdesc *ptdesc = virt_to_ptdesc(pmdp);
+ if (!pgtable_l3_enabled())
+ return;
+
tlb_remove_ptdesc(tlb, ptdesc);
}
#endif
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index c3a5ee486ae8..b15d59ec0bee 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1929,13 +1929,11 @@ static short kvm_s2_resolve_vma_size(const struct kvm_s2_fault_desc *s2fd,
vma_shift = get_vma_page_shift(vma);
}
-#ifndef __PAGETABLE_PMD_FOLDED
- if (vma_shift == PUD_SHIFT) {
+ if (pgtable_l3_enabled() && vma_shift == PUD_SHIFT) {
if (!fault_supports_stage2_huge_mapping(s2fd, PUD_SIZE))
vma_shift = PMD_SHIFT;
}
-#endif
- if (vma_shift == CONT_PMD_SHIFT) {
+ if (vma_shift == CONT_PMD_SHIFT)
vma_shift = PMD_SHIFT;
if ((vma_shift == PMD_SHIFT &&
!fault_supports_stage2_huge_mapping(s2fd, PMD_SIZE)) ||
diff --git a/arch/arm64/mm/fixmap.c b/arch/arm64/mm/fixmap.c
index 46e08631d08e..0d1c1798e52c 100644
--- a/arch/arm64/mm/fixmap.c
+++ b/arch/arm64/mm/fixmap.c
@@ -89,7 +89,7 @@ static void __init early_fixmap_init_pud(p4d_t *p4dp, unsigned long addr,
p4d_t p4d = READ_ONCE(*p4dp);
pud_t *pudp;
- if (CONFIG_PGTABLE_LEVELS > 3 && !p4d_none(p4d) &&
+ if (ptg_pgtable_levels > 3 && !p4d_none(p4d) &&
p4d_page_paddr(p4d) != __pa_symbol(bm_pud)) {
/*
* We only end up here if the kernel mapping and the fixmap
diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 447e832ad512..efe0f90e041e 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -47,10 +47,9 @@ unsigned int arch_hugetlb_cma_order(void)
static bool __hugetlb_valid_size(unsigned long size)
{
-#ifndef __PAGETABLE_PMD_FOLDED
- if (size == PUD_SIZE)
+ if (pgtable_l3_enabled() && size == PUD_SIZE)
return pud_sect_supported();
-#endif
+
if (size == CONT_PMD_SIZE || size == PMD_SIZE || size == CONT_PTE_SIZE)
return true;
@@ -314,10 +313,8 @@ unsigned long hugetlb_mask_last_page(struct hstate *h)
{
unsigned long hp_size = huge_page_size(h);
-#ifndef __PAGETABLE_PMD_FOLDED
- if (hp_size == PUD_SIZE && pud_sect_supported())
+ if (pgtable_l3_enabled() && hp_size == PUD_SIZE && pud_sect_supported())
return PGDIR_SIZE - PUD_SIZE;
-#endif
if (hp_size == CONT_PMD_SIZE)
return PUD_SIZE - CONT_PMD_SIZE;
if (hp_size == PMD_SIZE)
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index f3229c921d9c..e6c15b06dc46 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -362,8 +362,9 @@ void __init arch_mm_preinit(void)
* Selected page table levels should match when derived from
* scratch using the virtual address range and page size.
*/
- VM_BUG_ON(ARM64_HW_PGTABLE_LEVELS(CONFIG_ARM64_VA_BITS) !=
- CONFIG_PGTABLE_LEVELS);
+ BUILD_BUG_ON_FIXED_PAGE_SIZE(
+ ARM64_HW_PGTABLE_LEVELS(CONFIG_ARM64_VA_BITS) !=
+ ptg_pgtable_levels);
if (PAGE_SIZE >= 16384 && get_num_physpages() <= 128) {
extern int sysctl_overcommit_memory;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 9bc4c0b4b4d5..731633c64557 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1322,8 +1322,10 @@ static int __init __kpti_install_ng_mappings(void *__unused)
if (levels == 5 && !pgtable_l5_enabled())
levels = 4;
- else if (levels == 4 && !pgtable_l4_enabled())
+ if (levels == 4 && !pgtable_l4_enabled())
levels = 3;
+ if (levels == 3 && !pgtable_l3_enabled())
+ levels = 2;
remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings);
@@ -1726,7 +1728,7 @@ static void free_empty_pmd_table(pud_t *pudp, unsigned long addr,
free_empty_pte_table(pmdp, addr, next, floor, ceiling);
} while (addr = next, addr < end);
- if (CONFIG_PGTABLE_LEVELS <= 2)
+ if (!pgtable_l3_enabled())
return;
if (!pgtable_range_aligned(start, end, floor, ceiling, PUD_MASK))
diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c
index 9d9bcb6738f4..6f9ddaa5da7b 100644
--- a/arch/arm64/mm/ptdump.c
+++ b/arch/arm64/mm/ptdump.c
@@ -197,8 +197,10 @@ void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
ptval_t prot = 0;
/* check if the current level has been folded dynamically */
- if (st->mm && ((level == 1 && mm_p4d_folded(st->mm)) ||
- (level == 2 && mm_pud_folded(st->mm))))
+ if (st->mm &&
+ ((level == 1 && mm_p4d_folded(st->mm)) ||
+ (level == 2 && mm_pud_folded(st->mm)) ||
+ (level == 3 && mm_pmd_folded(st->mm))))
level = 0;
if (level >= 0)
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [RFC PATCH v2 34/43] mm/damon/lru_sort: Initialise the stub access pattern at boot
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 30/43] arm64: Support runtime folding of the pmd level Eric Curtin
@ 2026-12-01 1:52 ` Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 35/43] mm/zsmalloc: Size static limits for the worst-case page size 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: Ryan Roberts, SJ Park, Andrew Morton, damon, linux-mm
From: Ryan Roberts <ryan.roberts@arm.com>
damon_lru_sort_stub_pattern sets min_sz_region to PAGE_SIZE in a static
initialiser. PAGE_SIZE is not a constant expression with arm64
boot-time page size selection.
Define the pattern with DEFINE_GLOBAL_PAGE_SIZE_VAR(), which keeps the
plain initialiser for a fixed page size and otherwise fills it in once
the page size is known at boot.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit fed214a06106c320f2e46950b5b6672966952196)
---
mm/damon/lru_sort.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 64e086985eb5..37215e9b956c 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -170,7 +170,7 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_lru_sort_cold_stat,
lru_sort_tried_cold_regions, lru_sorted_cold_regions,
cold_quota_exceeds);
-static struct damos_access_pattern damon_lru_sort_stub_pattern = {
+static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct damos_access_pattern, damon_lru_sort_stub_pattern, {
/* Find regions having PAGE_SIZE or larger size */
.min_sz_region = PAGE_SIZE,
.max_sz_region = ULONG_MAX,
@@ -180,7 +180,7 @@ static struct damos_access_pattern damon_lru_sort_stub_pattern = {
/* no matter its age */
.min_age_region = 0,
.max_age_region = UINT_MAX,
-};
+});
static struct damon_ctx *ctx;
static struct damon_target *target;
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [RFC PATCH v2 35/43] mm/zsmalloc: Size static limits for the worst-case page size
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 34/43] mm/damon/lru_sort: Initialise the stub access pattern at boot Eric Curtin
@ 2026-12-01 1:52 ` Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 38/43] mm: Use fixed sizes for shmem str_dup and swap cache PFN bits 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: Ryan Roberts, Minchan Kim, Sergey Senozhatsky, Andrew Morton,
linux-mm
From: Ryan Roberts <ryan.roberts@arm.com>
zsmalloc uses PAGE_SIZE and PAGE_SHIFT in constants and in the size of
an array in struct zs_pool, none of which are compile-time constants
with arm64 boot-time page size selection.
Take the worst case where a constant is needed: _PFN_BITS uses
PAGE_SHIFT_MIN, since the smallest page gives the most PFN bits,
ZS_OBJS_PER_PAGE_BITS uses PAGE_SHIFT_MAX, and the 24-bit first object
offset check in set_first_obj_offset() uses PAGE_SIZE_MAX.
ZS_SIZE_CLASSES now depends on the runtime page size, so the size_class
array in struct zs_pool becomes a pointer that zs_create_pool()
allocates with kcalloc() and zs_destroy_pool() frees.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit dca1629b5374efd825c6a5bc6d4f210dae3b861f)
---
mm/zsmalloc.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 7ef80e0da626..09d131da22ac 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -72,13 +72,13 @@
#else
/*
* If this definition of MAX_PHYSMEM_BITS is used, ZS_OBJ_PFN_SHIFT will
- * just be PAGE_SHIFT
+ * just be PAGE_SHIFT_MIN
*/
#define MAX_POSSIBLE_PHYSMEM_BITS BITS_PER_LONG
#endif
#endif
-#define _PFN_BITS (MAX_POSSIBLE_PHYSMEM_BITS - PAGE_SHIFT)
+#define _PFN_BITS (MAX_POSSIBLE_PHYSMEM_BITS - PAGE_SHIFT_MIN)
/*
* Head in allocated object should have OBJ_ALLOCATED_TAG
@@ -137,7 +137,7 @@
* possible object size: log2(PAGE_SIZE / 32) = PAGE_SHIFT - 5.
* 32 is the hard floor of ZS_MIN_ALLOC_SIZE.
*/
-#define ZS_OBJS_PER_PAGE_BITS (PAGE_SHIFT - 5)
+#define ZS_OBJS_PER_PAGE_BITS (PAGE_SHIFT_MAX - 5)
/*
* Bits to index any object in the densest possible zspage. Below this,
@@ -270,7 +270,7 @@ static struct kmem_cache *zspage_cachep;
struct zs_pool {
const char *name;
- struct size_class *size_class[ZS_SIZE_CLASSES];
+ struct size_class **size_class;
atomic_long_t pages_allocated;
@@ -502,7 +502,7 @@ static inline unsigned int get_first_obj_offset(struct zpdesc *zpdesc)
static inline void set_first_obj_offset(struct zpdesc *zpdesc, unsigned int offset)
{
/* With 24 bits available, we can support offsets into 16 MiB pages. */
- BUILD_BUG_ON(PAGE_SIZE > SZ_16M);
+ BUILD_BUG_ON(PAGE_SIZE_MAX > SZ_16M);
VM_WARN_ON_ONCE(!PageZsmalloc(zpdesc_page(zpdesc)));
VM_WARN_ON_ONCE(offset & ~FIRST_OBJ_PAGE_TYPE_MASK);
zpdesc->first_obj_offset &= ~FIRST_OBJ_PAGE_TYPE_MASK;
@@ -2151,6 +2151,13 @@ struct zs_pool *zs_create_pool(const char *name)
rwlock_init(&pool->lock);
atomic_set(&pool->compaction_in_progress, 0);
+ pool->size_class = kcalloc(ZS_SIZE_CLASSES,
+ sizeof(*pool->size_class), GFP_KERNEL);
+ if (!pool->size_class) {
+ kfree(pool);
+ return NULL;
+ }
+
pool->name = kstrdup(name, GFP_KERNEL);
if (!pool->name)
goto err;
@@ -2276,6 +2283,7 @@ void zs_destroy_pool(struct zs_pool *pool)
kfree(class);
}
+ kfree(pool->size_class);
kfree(pool->name);
kfree(pool);
}
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [RFC PATCH v2 38/43] mm: Use fixed sizes for shmem str_dup and swap cache PFN bits
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 35/43] mm/zsmalloc: Size static limits for the worst-case page size 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, Hugh Dickins, David Hildenbrand, Baolin Wang,
Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, linux-mm
From: Eric Curtin <eric.curtin@docker.com>
str_dup in mm/shmem.c is a static buffer sized with PAGE_SIZE, and
SWAP_CACHE_PFN_BITS in mm/swap.h is computed from PAGE_SHIFT. Neither is
a compile-time constant with arm64 boot-time page size selection.
Size str_dup as SZ_4K, along with the matching length check in
setup_thp_shmem(), which is large enough for the command line option
that it copies. Compute SWAP_CACHE_PFN_BITS with PAGE_SHIFT_MIN, as the
smallest page size needs the most PFN bits.
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit 54043747407a2dc56dcd60bc2b1f29ce193ee804)
---
mm/shmem.c | 4 ++--
mm/swap.h | 7 ++++---
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index a5713109c843..757b0906caae 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -5942,7 +5942,7 @@ static int __init setup_transparent_hugepage_tmpfs(char *str)
}
__setup("transparent_hugepage_tmpfs=", setup_transparent_hugepage_tmpfs);
-static char str_dup[PAGE_SIZE] __initdata;
+static char str_dup[SZ_4K] __initdata;
static int __init setup_thp_shmem(char *str)
{
char *token, *range, *policy, *subtoken;
@@ -5951,7 +5951,7 @@ static int __init setup_thp_shmem(char *str)
int start, end, nr;
char *p;
- if (!str || strlen(str) + 1 > PAGE_SIZE)
+ if (!str || strlen(str) + 1 > SZ_4K)
goto err;
strscpy(str_dup, str);
diff --git a/mm/swap.h b/mm/swap.h
index d5bf21f517dc..6dab19c1fac9 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -12,12 +12,13 @@ struct swap_iocb;
struct swap_memcg_table;
struct swap_io_ctx;
+/* Worst case (most PFN bits) for boot-time page size. */
#if defined(MAX_POSSIBLE_PHYSMEM_BITS)
-#define SWAP_CACHE_PFN_BITS (MAX_POSSIBLE_PHYSMEM_BITS - PAGE_SHIFT)
+#define SWAP_CACHE_PFN_BITS (MAX_POSSIBLE_PHYSMEM_BITS - PAGE_SHIFT_MIN)
#elif defined(MAX_PHYSMEM_BITS)
-#define SWAP_CACHE_PFN_BITS (MAX_PHYSMEM_BITS - PAGE_SHIFT)
+#define SWAP_CACHE_PFN_BITS (MAX_PHYSMEM_BITS - PAGE_SHIFT_MIN)
#else
-#define SWAP_CACHE_PFN_BITS (BITS_PER_LONG - PAGE_SHIFT)
+#define SWAP_CACHE_PFN_BITS (BITS_PER_LONG - PAGE_SHIFT_MIN)
#endif
/* Swap table marker, 0x1 means shadow, 0x2 means PFN (SWP_TB_PFN_MARK) */
^ 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 38/43] mm: Use fixed sizes for shmem str_dup and swap cache PFN bits 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
end of thread, other threads:[~2026-12-01 10:41 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 03/43] mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 05/43] mm: Avoid split pmd ptl if pmd level is run-time folded Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 25/43] arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 30/43] arm64: Support runtime folding of the pmd level Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 34/43] mm/damon/lru_sort: Initialise the stub access pattern at boot Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 35/43] mm/zsmalloc: Size static limits for the worst-case page size Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 38/43] mm: Use fixed sizes for shmem str_dup and swap cache PFN bits 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)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox