[RFC PATCH v2 14/43] arm64: Make INIT_DIR_SIZE and INIT_IDMAP_DIR_SIZE usable from C

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


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

INIT_DIR_SIZE and INIT_IDMAP_DIR_SIZE use the symbols _end and
kimage_limit as the end of the kernel image. In the linker script these
resolve to integers holding the link-time virtual address. In C they
resolve to the address of the symbol in the image as loaded, which can
differ from the address it was linked at, so combining them with
KIMAGE_VADDR gives the wrong image size.

Add KIMAGE_VADDR_END and KIMAGE_VADDR_LIMIT, which compute the link-time
virtual address of _end and kimage_limit as _AT(u64, sym) - _AT(u64,
_text) + KIMAGE_VADDR. This is valid both in the linker script and in C.
Use them in INIT_DIR_SIZE and INIT_IDMAP_DIR_PAGES.

Signed-off-by: Ryan Roberts <ryan.roberts at arm.com>
Signed-off-by: Eric Curtin <eric.curtin at docker.com>
(cherry picked from commit 39baea4f61f9134940df5053a53befa0a894270f)
---
 arch/arm64/include/asm/kernel-pgtable.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
index 229ee7976f69..91f3b6691c9f 100644
--- a/arch/arm64/include/asm/kernel-pgtable.h
+++ b/arch/arm64/include/asm/kernel-pgtable.h
@@ -34,6 +34,9 @@
 #define IDMAP_LEVELS		ARM64_HW_PGTABLE_LEVELS(IDMAP_VA_BITS)
 #define IDMAP_ROOT_LEVEL	(4 - IDMAP_LEVELS)
 
+#define KIMAGE_VADDR_END	(_AT(u64, _end) - _AT(u64, _text) + KIMAGE_VADDR)
+#define KIMAGE_VADDR_LIMIT	(_AT(u64, kimage_limit) - _AT(u64, _text) + KIMAGE_VADDR)
+
 /*
  * A relocatable kernel may execute from an address that differs from the one at
  * which it was linked. In the worst case, its runtime placement may intersect
@@ -55,10 +58,10 @@
 	+ EARLY_LEVEL(3, (lvls), (vstart), (vend), add) /* each entry needs a next level page table */	\
 	+ EARLY_LEVEL(2, (lvls), (vstart), (vend), add)	/* each entry needs a next level page table */	\
 	+ EARLY_LEVEL(1, (lvls), (vstart), (vend), add))/* each entry needs a next level page table */
-#define INIT_DIR_SIZE (PAGE_SIZE * (EARLY_PAGES(SWAPPER_PGTABLE_LEVELS, KIMAGE_VADDR, _end, EXTRA_PAGE) \
+#define INIT_DIR_SIZE (PAGE_SIZE * (EARLY_PAGES(SWAPPER_PGTABLE_LEVELS, KIMAGE_VADDR, KIMAGE_VADDR_END, EXTRA_PAGE) \
 				    + EARLY_SEGMENT_EXTRA_PAGES))
 
-#define INIT_IDMAP_DIR_PAGES	(EARLY_PAGES(INIT_IDMAP_PGTABLE_LEVELS, KIMAGE_VADDR, kimage_limit, 1))
+#define INIT_IDMAP_DIR_PAGES	(EARLY_PAGES(INIT_IDMAP_PGTABLE_LEVELS, KIMAGE_VADDR, KIMAGE_VADDR_LIMIT, 1))
 #define INIT_IDMAP_DIR_SIZE	((INIT_IDMAP_DIR_PAGES + EARLY_IDMAP_EXTRA_PAGES) * PAGE_SIZE)
 
 #define INIT_IDMAP_FDT_PAGES	(EARLY_PAGES(INIT_IDMAP_PGTABLE_LEVELS, 0UL, UL(MAX_FDT_SIZE), 1) - 1)



More information about the linux-arm-kernel mailing list