Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
	Fuad Tabba <fuad.tabba@linux.dev>,
	Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	kvmarm@lists.linux.dev
Subject: [RFC PATCH v2 22/43] arm64: Align image sections to PAGE_SIZE_MAX
Date: Tue,  1 Dec 2026 01:51:54 +0000	[thread overview]
Message-ID: <20261201015240.1017259-23-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com>

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

With boot-time page size selection the sections that are mapped with
page granularity, such as the hyp sections, the vDSO images, the page
table directories and the data and BSS regions, must be aligned for the
largest page size that may be selected. PAGE_SIZE is not a constant in
the linker script or assembly, so use PAGE_SIZE_MAX instead.

Switch ALIGN(), RO_DATA(), RW_DATA(), BSS_SECTION(), the reserved,
swapper and trampoline directory offsets, the hyp.lds.S percpu section
and the vDSO .balign directives from PAGE_SIZE to PAGE_SIZE_MAX. The
vDSO data mapping length in vdso.c is changed to match. The
trampoline text, which has to fit the smallest page, keeps a limit
based on PAGE_SIZE_MIN in the "HYP init code too big" and "Entry
trampoline text too big" assertions, and the alignment that followed the
trampoline text is moved to after __entry_tramp_text_end.

For a compile-time page size PAGE_SIZE_MAX equals PAGE_SIZE and the
image is unchanged. For a boot-time page size build the image is
comparable in size to one built for 64K pages.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit f2ff15f09dae013f6c02715972759154ae9a000c)
---
 arch/arm64/include/asm/memory.h   |  4 +--
 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   | 46 +++++++++++++++----------------
 arch/arm64/kvm/hyp/nvhe/hyp.lds.S |  2 +-
 6 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index a6df911206ff..05a8efc6810d 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -201,13 +201,13 @@
  *  Open-coded (swapper_pg_dir - reserved_pg_dir) as this cannot be calculated
  *  until link time.
  */
-#define RESERVED_SWAPPER_OFFSET	(PAGE_SIZE)
+#define RESERVED_SWAPPER_OFFSET	(PAGE_SIZE_MAX)
 
 /*
  *  Open-coded (swapper_pg_dir - tramp_pg_dir) as this cannot be calculated
  *  until link time.
  */
-#define TRAMP_SWAPPER_OFFSET	(2 * PAGE_SIZE)
+#define TRAMP_SWAPPER_OFFSET	(2 * PAGE_SIZE_MAX)
 
 #ifndef __ASSEMBLER__
 
diff --git a/arch/arm64/kernel/vdso-wrap.S b/arch/arm64/kernel/vdso-wrap.S
index c4b1990bf2be..79fa77628199 100644
--- a/arch/arm64/kernel/vdso-wrap.S
+++ b/arch/arm64/kernel/vdso-wrap.S
@@ -13,10 +13,10 @@
 
 	.globl vdso_start, vdso_end
 	.section .rodata
-	.balign PAGE_SIZE
+	.balign PAGE_SIZE_MAX
 vdso_start:
 	.incbin "arch/arm64/kernel/vdso/vdso.so"
-	.balign PAGE_SIZE
+	.balign PAGE_SIZE_MAX
 vdso_end:
 
 	.previous
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 50596dab23f9..8459ac3288cf 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -108,7 +108,7 @@ static int __setup_additional_pages(enum vdso_abi abi,
 
 	vdso_text_len = vdso_info[abi].vdso_pages << PAGE_SHIFT;
 	/* Be sure to map the data page */
-	vdso_mapping_len = vdso_text_len + VDSO_NR_PAGES * PAGE_SIZE;
+	vdso_mapping_len = vdso_text_len + VDSO_NR_PAGES * PAGE_SIZE_MAX;
 
 	vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
 	if (IS_ERR_VALUE(vdso_base)) {
@@ -123,7 +123,7 @@ static int __setup_additional_pages(enum vdso_abi abi,
 	if (system_supports_bti_kernel())
 		gp_flags = VM_ARM64_BTI;
 
-	vdso_base += VDSO_NR_PAGES * PAGE_SIZE;
+	vdso_base += VDSO_NR_PAGES * PAGE_SIZE_MAX;
 	mm->context.vdso = (void *)vdso_base;
 	ret = _install_special_mapping(mm, vdso_base, vdso_text_len,
 				       VM_READ|VM_EXEC|gp_flags|
diff --git a/arch/arm64/kernel/vdso32-wrap.S b/arch/arm64/kernel/vdso32-wrap.S
index e72ac7bc4c04..1c6069d6c457 100644
--- a/arch/arm64/kernel/vdso32-wrap.S
+++ b/arch/arm64/kernel/vdso32-wrap.S
@@ -10,10 +10,10 @@
 
 	.globl vdso32_start, vdso32_end
 	.section .rodata
-	.balign PAGE_SIZE
+	.balign PAGE_SIZE_MAX
 vdso32_start:
 	.incbin "arch/arm64/kernel/vdso32/vdso.so"
-	.balign PAGE_SIZE
+	.balign PAGE_SIZE_MAX
 vdso32_end:
 
 	.previous
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index ca3016f284d5..eb253341711c 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -25,26 +25,26 @@
 
 #define HYPERVISOR_RODATA_SECTIONS				\
 	HYP_SECTION_NAME(.rodata) : {				\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(PAGE_SIZE_MAX);			\
 		__hyp_rodata_start = .;				\
 		*(HYP_SECTION_NAME(.data..ro_after_init))	\
 		*(HYP_SECTION_NAME(.rodata))			\
 		HYPERVISOR_EVENT_IDS				\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(PAGE_SIZE_MAX);			\
 		__hyp_rodata_end = .;				\
 	}
 
 #define HYPERVISOR_DATA_SECTION					\
 	HYP_SECTION_NAME(.data) : {				\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(PAGE_SIZE_MAX);			\
 		__hyp_data_start = .;				\
 		*(HYP_SECTION_NAME(.data))			\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(PAGE_SIZE_MAX);			\
 		__hyp_data_end = .;				\
 	}
 
 #define HYPERVISOR_PERCPU_SECTION				\
-	. = ALIGN(PAGE_SIZE);					\
+	. = ALIGN(PAGE_SIZE_MAX);				\
 	HYP_SECTION_NAME(.data..percpu) : {			\
 		*(HYP_SECTION_NAME(.data..percpu))		\
 	}
@@ -59,7 +59,7 @@
 #define BSS_FIRST_SECTIONS					\
 	__hyp_bss_start = .;					\
 	*(HYP_SECTION_NAME(.bss))				\
-	. = ALIGN(PAGE_SIZE);					\
+	. = ALIGN(PAGE_SIZE_MAX);				\
 	__hyp_bss_end = .;
 
 /*
@@ -68,7 +68,7 @@
  * between them, which can in some cases cause the linker to misalign them. To
  * work around the issue, force a page alignment for __bss_start.
  */
-#define SBSS_ALIGN			PAGE_SIZE
+#define SBSS_ALIGN			PAGE_SIZE_MAX
 #else /* CONFIG_KVM */
 #define HYPERVISOR_EXTABLE
 #define HYPERVISOR_RODATA_SECTIONS
@@ -96,14 +96,14 @@ ENTRY(_text)
 jiffies = jiffies_64;
 
 #define HYPERVISOR_TEXT					\
-	. = ALIGN(PAGE_SIZE);				\
+	. = ALIGN(PAGE_SIZE_MAX);			\
 	__hyp_idmap_text_start = .;			\
 	*(.hyp.idmap.text)				\
 	__hyp_idmap_text_end = .;			\
 	__hyp_text_start = .;				\
 	*(.hyp.text)					\
 	HYPERVISOR_EXTABLE				\
-	. = ALIGN(PAGE_SIZE);				\
+	. = ALIGN(PAGE_SIZE_MAX);			\
 	__hyp_text_end = .;
 
 #define IDMAP_TEXT					\
@@ -134,11 +134,11 @@ jiffies = jiffies_64;
 
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
 #define TRAMP_TEXT					\
-	. = ALIGN(PAGE_SIZE);				\
+	. = ALIGN(PAGE_SIZE_MAX);			\
 	__entry_tramp_text_start = .;			\
 	*(.entry.tramp.text)				\
-	. = ALIGN(PAGE_SIZE);				\
 	__entry_tramp_text_end = .;			\
+	. = ALIGN(PAGE_SIZE_MAX);			\
 	*(.entry.tramp.rodata)
 #else
 #define TRAMP_TEXT
@@ -210,7 +210,7 @@ SECTIONS
 	_etext = .;			/* End of text section */
 
 	/* everything from this point to __init_begin will be marked RO NX */
-	RO_DATA(PAGE_SIZE)
+	RO_DATA(PAGE_SIZE_MAX)
 
 	HYPERVISOR_RODATA_SECTIONS
 
@@ -237,22 +237,22 @@ SECTIONS
 		HIBERNATE_TEXT
 		KEXEC_TEXT
 		IDMAP_TEXT
-		. = ALIGN(PAGE_SIZE);
+		. = ALIGN(PAGE_SIZE_MAX);
 	}
 
 	idmap_pg_dir = .;
-	. += PAGE_SIZE;
+	. += PAGE_SIZE_MAX;
 
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
 	tramp_pg_dir = .;
-	. += PAGE_SIZE;
+	. += PAGE_SIZE_MAX;
 #endif
 
 	reserved_pg_dir = .;
-	. += PAGE_SIZE;
+	. += PAGE_SIZE_MAX;
 
 	swapper_pg_dir = .;
-	. += PAGE_SIZE;
+	. += PAGE_SIZE_MAX;
 
 	. = ALIGN(SEGMENT_ALIGN);
 	__init_begin = .;
@@ -323,7 +323,7 @@ SECTIONS
 
 	_data = .;
 	_sdata = .;
-	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
+	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE_MAX, THREAD_ALIGN)
 
 	HYPERVISOR_DATA_SECTION
 
@@ -357,16 +357,16 @@ SECTIONS
 	_edata = .;
 
 	/* start of zero-init region */
-	BSS_SECTION(SBSS_ALIGN, 0, PAGE_SIZE)
+	BSS_SECTION(SBSS_ALIGN, 0, PAGE_SIZE_MAX)
 	__pi___bss_start = __bss_start;
 
 	/* page table BSS starts here - preceding data/BSS is omitted from the linear map */
-	.pgtbl : ALIGN(PAGE_SIZE) {
+	.pgtbl : ALIGN(PAGE_SIZE_MAX) {
 		*(.bss..pgtbl)
 	}
 	ASSERT(ADDR(.pgtbl) == __bss_stop, ".pgtbl must follow BSS")
 
-	. = ALIGN(PAGE_SIZE);
+	. = ALIGN(PAGE_SIZE_MAX);
 	__pi_init_pg_dir = .;
 	. += INIT_DIR_SIZE_MAX;
 	__pi_init_pg_end = .;
@@ -405,7 +405,7 @@ SECTIONS
  * former is page-aligned, but the latter may not be with 16K or 64K pages, so
  * it should also not cross a page boundary.
  */
-ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
+ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE_MIN,
 	"HYP init code too big")
 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
 	"ID map text too big or misaligned")
@@ -416,7 +416,7 @@ ASSERT(__hibernate_exit_text_start == swsusp_arch_suspend_exit,
        "Hibernate exit text does not start with swsusp_arch_suspend_exit")
 #endif
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
-ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
+ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3 * PAGE_SIZE_MIN,
 	"Entry trampoline text too big")
 #endif
 #ifdef CONFIG_KVM
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
index 89222425359a..69b8fdbc977e 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
@@ -26,7 +26,7 @@ SECTIONS {
 	 * .hyp..data..percpu needs to be page aligned to maintain the same
 	 * alignment for when linking into vmlinux.
 	 */
-	. = ALIGN(PAGE_SIZE);
+	. = ALIGN(PAGE_SIZE_MAX);
 	BEGIN_HYP_SECTION(.data..percpu)
 		PERCPU_INPUT(L1_CACHE_BYTES)
 	END_HYP_SECTION


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

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 01/43] mm: Add macros ahead of supporting boot-time page size selection Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 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 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 08/43] cgroup: Use DEFINE_GLOBAL_PAGE_SIZE_VAR for the kernfs_ops tables Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 10/43] PM: hibernate: Do not size swap structures to exactly PAGE_SIZE Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 12/43] KVM: Check struct kvm_run against PAGE_SIZE_MIN Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 13/43] crash: Check crash_notes size " Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 14/43] arm64: Make INIT_DIR_SIZE and INIT_IDMAP_DIR_SIZE usable from C Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 15/43] arm64: pi: Pass the early pgtable allocation limit to map_range() Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 16/43] arm64: Introduce macros required for boot-time page size selection Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 17/43] arm64: Parameterise early pgtable size macros by page shift Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 18/43] arm64: Add arm64.pagesize= command line override Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 19/43] arm64: pi: Select the page size at runtime during early boot Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 20/43] arm64: pi: Clear the FDT ptes on every remap in map_fdt() 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 ` Eric Curtin [this message]
2026-12-01  1:51 ` [RFC PATCH v2 23/43] arm64: Map the trampoline rodata at its aligned offset Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 24/43] arm64: fixmap: Size slots and page tables for PAGE_SIZE_MIN 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:51 ` [RFC PATCH v2 26/43] arm64: Convert KVM and hugetlb size switches to if/else Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 27/43] arm64: mm: Make page size dependent BUILD_BUG_ON() checks runtime Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 29/43] arm64: Look up the page size at runtime in assembly code 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 31/43] arm64: Support runtime folding in idmap_kpti_install_ng_mappings Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 32/43] arm64: Patch TRAMP_VALIAS into instructions at boot Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 33/43] arm64: Determine THREAD_SIZE at boot time 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 36/43] arm64: Convert remaining page-size switches to if/else Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 37/43] vdso: Lay out the data pages in VDSO_PAGE_SIZE units Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 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 39/43] crash: Size the vmcoreinfo page array for the smallest page size Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 40/43] arm64: Size kasan and pKVM stacktrace arrays for PAGE_SIZE_MAX Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 41/43] exit: Use THREAD_SIZE_MAX for lowest_to_date Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 42/43] tracing: Use PAGE_SIZE_MIN/MAX in the uprobe check and undefsyms page Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection Eric Curtin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201015240.1017259-23-ericcurtin17@gmail.com \
    --to=ericcurtin17@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox