Skip to content

Commit d541708

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: fix .idmap.text assertion for large kernels
When building a kernel with many debug options enabled (which happens in test configurations use by myself and syzbot), the kernel can become large enough that portions of .text can be more than 128M away from .idmap.text (which is placed inside the .rodata section). Where idmap code branches into .text, the linker will place veneers in the .idmap.text section to make those branches possible. Unfortunately, as Ard reports, GNU LD has bseen observed to add 4K of padding when adding such veneers, e.g. | .idmap.text 0xffffffc01e48e5c0 0x32c arch/arm64/mm/proc.o | 0xffffffc01e48e5c0 idmap_cpu_replace_ttbr1 | 0xffffffc01e48e600 idmap_kpti_install_ng_mappings | 0xffffffc01e48e800 __cpu_setup | *fill* 0xffffffc01e48e8ec 0x4 | .idmap.text.stub | 0xffffffc01e48e8f0 0x18 linker stubs | 0xffffffc01e48f8f0 __idmap_text_end = . | 0xffffffc01e48f000 . = ALIGN (0x1000) | *fill* 0xffffffc01e48f8f0 0x710 | 0xffffffc01e490000 idmap_pg_dir = . This makes the __idmap_text_start .. __idmap_text_end region bigger than the 4K we require it to fit within, and triggers an assertion in arm64's vmlinux.lds.S, which breaks the build: | LD .tmp_vmlinux.kallsyms1 | aarch64-linux-gnu-ld: ID map text too big or misaligned | make[1]: *** [scripts/Makefile.vmlinux:35: vmlinux] Error 1 | make: *** [Makefile:1264: vmlinux] Error 2 Avoid this by using an `ADRP+ADD+BLR` sequence for branches out of .idmap.text, which avoids the need for veneers. These branches are only executed once per boot, and only when the MMU is on, so there should be no noticeable performance penalty in replacing `BL` with `ADRP+ADD+BLR`. At the same time, remove the "x" and "w" attributes when placing code in .idmap.text, as these are not necessary, and this will prevent the linker from assuming that it is safe to place PLTs into .idmap.text, causing it to warn if and when there are out-of-range branches within .idmap.text, e.g. | LD .tmp_vmlinux.kallsyms1 | arch/arm64/kernel/head.o: in function `primary_entry': | (.idmap.text+0x1c): relocation truncated to fit: R_AARCH64_CALL26 against symbol `dcache_clean_poc' defined in .text section in arch/arm64/mm/cache.o | arch/arm64/kernel/head.o: in function `init_el2': | (.idmap.text+0x88): relocation truncated to fit: R_AARCH64_CALL26 against symbol `dcache_clean_poc' defined in .text section in arch/arm64/mm/cache.o | make[1]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1 | make: *** [Makefile:1252: vmlinux] Error 2 Thus, if future changes add out-of-range branches in .idmap.text, it should be easy enough to identify those from the resulting linker errors. Reported-by: [email protected] Link: https://lore.kernel.org/linux-arm-kernel/[email protected]/ Signed-off-by: Mark Rutland <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Will Deacon <[email protected]> Tested-by: Ard Biesheuvel <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent ad4a4d3 commit d541708

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

arch/arm64/kernel/head.S

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
__EFI_PE_HEADER
7272

73-
.section ".idmap.text","awx"
73+
.section ".idmap.text","a"
7474

7575
/*
7676
* The following callee saved general purpose registers are used on the
@@ -99,7 +99,8 @@ SYM_CODE_START(primary_entry)
9999
cbz x19, 0f
100100
adrp x0, __idmap_text_start
101101
adr_l x1, __idmap_text_end
102-
bl dcache_clean_poc
102+
adr_l x2, dcache_clean_poc
103+
blr x2
103104
0: mov x0, x19
104105
bl init_kernel_el // w0=cpu_boot_mode
105106
mov x20, x0
@@ -527,7 +528,7 @@ SYM_FUNC_END(__primary_switched)
527528
* end early head section, begin head code that is also used for
528529
* hotplug and needs to have the same protections as the text region
529530
*/
530-
.section ".idmap.text","awx"
531+
.section ".idmap.text","a"
531532

532533
/*
533534
* Starting from EL2 or EL1, configure the CPU to execute at the highest
@@ -566,7 +567,8 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
566567
cbz x0, 0f
567568
adrp x0, __hyp_idmap_text_start
568569
adr_l x1, __hyp_text_end
569-
bl dcache_clean_poc
570+
adr_l x2, dcache_clean_poc
571+
blr x2
570572
0:
571573
mov_q x0, HCR_HOST_NVHE_FLAGS
572574
msr hcr_el2, x0
@@ -728,7 +730,7 @@ SYM_FUNC_END(set_cpu_boot_mode_flag)
728730
* Checks if the selected granule size is supported by the CPU.
729731
* If it isn't, park the CPU
730732
*/
731-
.section ".idmap.text","awx"
733+
.section ".idmap.text","a"
732734
SYM_FUNC_START(__enable_mmu)
733735
mrs x3, ID_AA64MMFR0_EL1
734736
ubfx x3, x3, #ID_AA64MMFR0_EL1_TGRAN_SHIFT, 4

0 commit comments

Comments
 (0)