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

x86: Sanitize linker script

The section ordering in the text section is more than suboptimal:

ALIGN_ENTRY_TEXT_BEGIN
ENTRY_TEXT
ALIGN_ENTRY_TEXT_END
SOFTIRQENTRY_TEXT
STATIC_CALL_TEXT
INDIRECT_THUNK_TEXT

ENTRY_TEXT is in a seperate PMD so it can be mapped into the cpu entry area
when KPTI is enabled. That means the sections after it are also in a
seperate PMD. That's wasteful especially as the indirect thunk text is a
hotpath on retpoline enabled systems and the static call text is fairly hot
on 32bit.

Move the entry text section last so that the other sections share a PMD
with the text before it. This is obviously just best effort and not
guaranteed when the previous text is just at a PMD boundary.

The text section placement needs an overhaul in general. There is e.g. no
point to have debugfs, sysfs, cpuhotplug and other rarely used functions
next to hot path text.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220915111143.614728935@infradead.org

authored by

Thomas Gleixner and committed by
Peter Zijlstra
24a9c543 b26d66f8

+7 -6
+7 -6
arch/x86/kernel/vmlinux.lds.S
··· 132 132 CPUIDLE_TEXT 133 133 LOCK_TEXT 134 134 KPROBES_TEXT 135 - ALIGN_ENTRY_TEXT_BEGIN 136 - ENTRY_TEXT 137 - ALIGN_ENTRY_TEXT_END 138 135 SOFTIRQENTRY_TEXT 139 - STATIC_CALL_TEXT 140 - *(.gnu.warning) 141 - 142 136 #ifdef CONFIG_RETPOLINE 143 137 __indirect_thunk_start = .; 144 138 *(.text.__x86.*) 145 139 __indirect_thunk_end = .; 146 140 #endif 141 + STATIC_CALL_TEXT 142 + 143 + ALIGN_ENTRY_TEXT_BEGIN 144 + ENTRY_TEXT 145 + ALIGN_ENTRY_TEXT_END 146 + *(.gnu.warning) 147 + 147 148 } :text =0xcccc 148 149 149 150 /* End of text section, which should occupy whole number of pages */