[RFC PATCH v2 23/43] arm64: Map the trampoline rodata at its aligned offset

Eric Curtin ericcurtin17 at gmail.com
Mon Nov 30 17:51:55 PST 2026


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

The trampoline rodata is now aligned to the next PAGE_SIZE_MAX boundary
after the trampoline text. map_entry_trampoline() still assumed that it
sits in the page immediately following the text, which only holds while
PAGE_SIZE equals PAGE_SIZE_MAX. With a smaller boot-time page size the
rodata would be mapped in the wrong fixmap slot.

Reserve enough fixmap slots to cover the text, the data page and the
alignment padding in the worst case (PAGE_SIZE equal to PAGE_SIZE_MIN),
replacing the FIX_ENTRY_TRAMP_TEXT1..4 slots with FIX_ENTRY_TRAMP_BEGIN
and FIX_ENTRY_TRAMP_END. Export __entry_tramp_rodata_start/end from the
linker script, and have map_entry_trampoline() compute the slot of the
rodata from the physical distance between the end of the text and the
start of the rodata. idmap_ptes and kpti_bbml3_ptes are sized and
aligned for PAGE_SIZE_MAX at the same time.

No functional change for compile-time page sizes.

Signed-off-by: Ryan Roberts <ryan.roberts at arm.com>
Signed-off-by: Eric Curtin <eric.curtin at docker.com>
(cherry picked from commit 073b8743136dc4a2b2fbe13673437eb0b065134d)
---
 arch/arm64/include/asm/fixmap.h   | 16 +++++++++++-----
 arch/arm64/include/asm/sections.h |  1 +
 arch/arm64/kernel/vmlinux.lds.S   |  4 +++-
 arch/arm64/mm/mmu.c               | 26 ++++++++++++++++----------
 4 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h
index 170c3502d723..5ec75d6daf36 100644
--- a/arch/arm64/include/asm/fixmap.h
+++ b/arch/arm64/include/asm/fixmap.h
@@ -65,13 +65,19 @@ enum fixed_addresses {
 #endif /* CONFIG_ACPI_APEI_GHES */
 
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
+#define TRAMP_TEXT_SIZE	(PAGE_SIZE_MIN * 3)
 #ifdef CONFIG_RELOCATABLE
-	FIX_ENTRY_TRAMP_TEXT4,	/* one extra slot for the data page */
+#define TRAMP_DATA_SIZE	PAGE_SIZE_MIN
+#define TRAMP_PAD_SIZE	(PAGE_SIZE_MAX - PAGE_SIZE_MIN)
+#else
+#define TRAMP_DATA_SIZE	0
+#define TRAMP_PAD_SIZE	0
 #endif
-	FIX_ENTRY_TRAMP_TEXT3,
-	FIX_ENTRY_TRAMP_TEXT2,
-	FIX_ENTRY_TRAMP_TEXT1,
-#define TRAMP_VALIAS		(__fix_to_virt(FIX_ENTRY_TRAMP_TEXT1))
+#define TRAMP_SIZE	(TRAMP_TEXT_SIZE + TRAMP_DATA_SIZE + TRAMP_PAD_SIZE)
+	FIX_ENTRY_TRAMP_END,
+	FIX_ENTRY_TRAMP_BEGIN = FIX_ENTRY_TRAMP_END +
+				DIV_ROUND_UP(TRAMP_SIZE, PAGE_SIZE_MIN) - 1,
+#define TRAMP_VALIAS		(__fix_to_virt(FIX_ENTRY_TRAMP_BEGIN))
 #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
 	__end_of_permanent_fixed_addresses,
 
diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h
index 51b0d594239e..f61cd8d9d4b1 100644
--- a/arch/arm64/include/asm/sections.h
+++ b/arch/arm64/include/asm/sections.h
@@ -22,6 +22,7 @@ extern char __exittext_begin[], __exittext_end[];
 extern char __irqentry_text_start[], __irqentry_text_end[];
 extern char __mmuoff_data_start[], __mmuoff_data_end[];
 extern char __entry_tramp_text_start[], __entry_tramp_text_end[];
+extern char __entry_tramp_rodata_start[], __entry_tramp_rodata_end[];
 extern char __relocate_new_kernel_start[], __relocate_new_kernel_end[];
 
 static inline size_t entry_tramp_text_size(void)
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index eb253341711c..31e398bdc983 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -139,7 +139,9 @@ jiffies = jiffies_64;
 	*(.entry.tramp.text)				\
 	__entry_tramp_text_end = .;			\
 	. = ALIGN(PAGE_SIZE_MAX);			\
-	*(.entry.tramp.rodata)
+	__entry_tramp_rodata_start = .;			\
+	*(.entry.tramp.rodata)				\
+	__entry_tramp_rodata_end = .;
 #else
 #define TRAMP_TEXT
 #endif
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 8cb8234cc24a..96fc6d843d34 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1398,25 +1398,31 @@ static int __init map_entry_trampoline(void)
 		return 0;
 
 	pgprot_t prot = kernel_exec_prot();
-	phys_addr_t pa_start = __pa_symbol(__entry_tramp_text_start);
+	phys_addr_t pa_text = __pa_symbol(__entry_tramp_text_start);
+	phys_addr_t pa_data = __pa_symbol(__entry_tramp_rodata_start);
+	int slot = FIX_ENTRY_TRAMP_BEGIN;
 
 	/* The trampoline is always mapped and can therefore be global */
 	pgprot_val(prot) &= ~PTE_NG;
 
 	/* Map only the text into the trampoline page table */
 	memset(tramp_pg_dir, 0, PGD_SIZE);
-	early_create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS,
+	early_create_pgd_mapping(tramp_pg_dir, pa_text, TRAMP_VALIAS,
 				 entry_tramp_text_size(), prot,
 				 pgd_pgtable_alloc_init_mm, NO_BLOCK_MAPPINGS);
 
 	/* Map both the text and data into the kernel page table */
-	for (i = 0; i < DIV_ROUND_UP(entry_tramp_text_size(), PAGE_SIZE); i++)
-		__set_fixmap(FIX_ENTRY_TRAMP_TEXT1 - i,
-			     pa_start + i * PAGE_SIZE, prot);
+	for (i = 0; i < DIV_ROUND_UP(entry_tramp_text_size(), PAGE_SIZE); i++) {
+		__set_fixmap(slot, pa_text, prot);
+		pa_text += PAGE_SIZE;
+		slot--;
+	}
 
-	if (IS_ENABLED(CONFIG_RELOCATABLE))
-		__set_fixmap(FIX_ENTRY_TRAMP_TEXT1 - i,
-			     pa_start + i * PAGE_SIZE, PAGE_KERNEL_RO);
+	if (IS_ENABLED(CONFIG_RELOCATABLE)) {
+		slot -= (pa_data - pa_text) / PAGE_SIZE;
+		VM_BUG_ON(slot < FIX_ENTRY_TRAMP_END);
+		__set_fixmap(slot, pa_data, PAGE_KERNEL_RO);
+	}
 
 	return 0;
 }
@@ -1442,8 +1448,8 @@ void __pi_map_range(phys_addr_t *pte, u64 limit, u64 start, u64 end,
 		    pgprot_t prot, int level, pte_t *tbl, bool may_use_cont,
 		    u64 va_offset);
 
-static u8 idmap_ptes[IDMAP_LEVELS_MAX - 1][PAGE_SIZE] __aligned(PAGE_SIZE) __ro_after_init,
-	  kpti_bbml3_ptes[IDMAP_LEVELS_MAX - 1][PAGE_SIZE] __aligned(PAGE_SIZE) __ro_after_init;
+static u8 idmap_ptes[IDMAP_LEVELS_MAX - 1][PAGE_SIZE_MAX] __aligned(PAGE_SIZE_MAX) __ro_after_init,
+	  kpti_bbml3_ptes[IDMAP_LEVELS_MAX - 1][PAGE_SIZE_MAX] __aligned(PAGE_SIZE_MAX) __ro_after_init;
 
 static void __init create_idmap(void)
 {



More information about the linux-arm-kernel mailing list