Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: mm: fold alternatives into .init

Currently we treat the alternatives separately from other data that's
only used during initialisation, using separate .altinstructions and
.altinstr_replacement linker sections. These are freed for general
allocation separately from .init*. This is problematic as:

* We do not remove execute permissions, as we do for .init, leaving the
memory executable.

* We pad between them, making the kernel Image bianry up to PAGE_SIZE
bytes larger than necessary.

This patch moves the two sections into the contiguous region used for
.init*. This saves some memory, ensures that we remove execute
permissions, and allows us to remove some code made redundant by this
reorganisation.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andre Przywara <andre.przywara@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Jeremy Linton <jeremy.linton@arm.com>
Cc: Laura Abbott <labbott@fedoraproject.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>

authored by

Mark Rutland and committed by
Will Deacon
9aa4ec15 5b28cd9d

+2 -11
-1
arch/arm64/include/asm/alternative.h
··· 19 19 20 20 void __init apply_alternatives_all(void); 21 21 void apply_alternatives(void *start, size_t length); 22 - void free_alternatives_memory(void); 23 22 24 23 #define ALTINSTR_ENTRY(feature) \ 25 24 " .word 661b - .\n" /* label */ \
-6
arch/arm64/kernel/alternative.c
··· 158 158 159 159 __apply_alternatives(&region); 160 160 } 161 - 162 - void free_alternatives_memory(void) 163 - { 164 - free_reserved_area(__alt_instructions, __alt_instructions_end, 165 - 0, "alternatives"); 166 - }
+2 -3
arch/arm64/kernel/vmlinux.lds.S
··· 140 140 141 141 PERCPU_SECTION(64) 142 142 143 - . = ALIGN(PAGE_SIZE); 144 - __init_end = .; 145 - 146 143 . = ALIGN(4); 147 144 .altinstructions : { 148 145 __alt_instructions = .; ··· 151 154 } 152 155 153 156 . = ALIGN(PAGE_SIZE); 157 + __init_end = .; 158 + 154 159 _data = .; 155 160 _sdata = .; 156 161 RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
-1
arch/arm64/mm/init.c
··· 360 360 { 361 361 fixup_init(); 362 362 free_initmem_default(0); 363 - free_alternatives_memory(); 364 363 } 365 364 366 365 #ifdef CONFIG_BLK_DEV_INITRD