]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
arm64: Move fixmap and kasan page tables to end of kernel image
authorArd Biesheuvel <ardb@kernel.org>
Fri, 29 May 2026 15:02:00 +0000 (17:02 +0200)
committerWill Deacon <will@kernel.org>
Tue, 2 Jun 2026 15:29:15 +0000 (16:29 +0100)
Move the fixmap and kasan page tables out of the BSS section, and place
them at the end of the image, right before the init_pg_dir section where
some of the other statically allocated page tables live.

These page tables are currently the only data objects in vmlinux that
are meant to be accessed via the kernel image's linear alias, and so
placing them together allows the remainder of the data/bss section to be
remapped read-only or unmapped entirely.

Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/mmu.h
arch/arm64/kernel/vmlinux.lds.S
arch/arm64/mm/fixmap.c
arch/arm64/mm/kasan_init.c

index 5e1211c540ab23033101b004f497391c13f5de2b..fb95754f28760b6d4512eacfbde1b9a72a871d79 100644 (file)
@@ -13,6 +13,8 @@
 
 #ifndef __ASSEMBLER__
 
+#define __pgtbl_bss __section(".pgdir.bss") __aligned(PAGE_SIZE)
+
 #include <linux/refcount.h>
 #include <asm/cpufeature.h>
 
index e1ac876200a3d6c10a8fcdef089e1a8a4ef8a6de..2b0ebfb30c63e17edc74315e023af39eb676f5c2 100644 (file)
@@ -349,9 +349,15 @@ SECTIONS
        _edata = .;
 
        /* start of zero-init region */
-       BSS_SECTION(SBSS_ALIGN, 0, 0)
+       BSS_SECTION(SBSS_ALIGN, 0, PAGE_SIZE)
        __pi___bss_start = __bss_start;
 
+       /* fixmap BSS starts here - preceding data/BSS is omitted from the linear map */
+       .pgdir.bss (NOLOAD) : ALIGN(PAGE_SIZE) {
+               *(.pgdir.bss)
+       }
+       ASSERT(ADDR(.pgdir.bss) == __bss_stop, ".pgdir.bss must follow BSS")
+
        . = ALIGN(PAGE_SIZE);
        __pi_init_pg_dir = .;
        . += INIT_DIR_SIZE;
index c5c5425791da72a01ef7ae789abd7c901b4f27b0..1a3bbd67dd762155af852fe6f4658b049f7892ba 100644 (file)
@@ -31,9 +31,9 @@ static_assert(NR_BM_PMD_TABLES == 1);
 
 #define BM_PTE_TABLE_IDX(addr) __BM_TABLE_IDX(addr, PMD_SHIFT)
 
-static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __page_aligned_bss;
-static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused;
-static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused;
+static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __pgtbl_bss;
+static pmd_t bm_pmd[PTRS_PER_PMD] __pgtbl_bss __maybe_unused;
+static pud_t bm_pud[PTRS_PER_PUD] __pgtbl_bss __maybe_unused;
 
 static inline pte_t *fixmap_pte(unsigned long addr)
 {
index abeb81bf6ebd5bb4e7dd7f5711917adaab68e54a..dbf22cae82ee0fe74136fc115b82ece107f8c5b0 100644 (file)
@@ -214,7 +214,7 @@ asmlinkage void __init kasan_early_init(void)
                 * shadow pud_t[]/p4d_t[], which could end up getting corrupted
                 * when the linear region is mapped.
                 */
-               static pte_t tbl[PTRS_PER_PTE] __page_aligned_bss;
+               static pte_t tbl[PTRS_PER_PTE] __pgtbl_bss;
                pgd_t *pgdp = pgd_offset_k(KASAN_SHADOW_START);
 
                set_pgd(pgdp, __pgd(__pa_symbol(tbl) | PGD_TYPE_TABLE));