arm64/boot: Some relocation tweaks
cover arm64/boot: Some relocation tweaks
From: Ard Biesheuvel <[email protected]>
Fix two issues I spotted while playing with the startup relocation code.
Ard Biesheuvel (2):
arm64/boot: Handle RELR relocations more efficiently arm64/boot: Discard NULL relocation entries
arch/arm64/kernel/pi/relocate.c | 5 ++--- arch/arm64/kernel/vmlinux.lds.S | 1 + 2 files changed, 3 insertions(+), 3 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 1/2 arm64/boot: Handle RELR relocations more efficiently
From: Ard Biesheuvel <[email protected]>
The RELR format consists of anchor entries with bit #0 cleared, that describe an address in the image's address space to which the runtime load displacement must be applied, followed by any number of entries with bit #0 set, whose remaining bits each describe 63 subsequent positions in the image that need the displacement applied as well.
Iterating over those 63 bits one by one is inefficient, given that we can use the number of trailing zeroes as an array index directly, and iteratively clear the least significant 1 bit in x by AND'ing with x-1.
--- arch/arm64/kernel/pi/relocate.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm64/kernel/pi/relocate.c +2 -3
@@ -55,9 +55,8 @@ void __init relocate_kernel(u64 offset) place = (u64 *)(*relr + offset); *place++ += offset; }else { -for (u64 *p = place, r = *relr >>1 ; r; p++, r >>=1 ) -if (r &1 ) - *p += offset; +for (u64 r = *relr >>1 ; r; r &= r -1 ) + place[__ffs (r)] += offset; place +=63 ; } }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 2/2 arm64/boot: Discard NULL relocation entries
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
The arm64 vmlinux image contains preliminary RELA entries for data objects that are ultimately discarded by the linker:
Relocation section '.rela.dyn' at offset 0x25a6c28 contains 27631 entries:
Offset Info Type Symbol's Value Symbol's Name + Addend
0000000000000000 0000000000000000 R_AARCH64_NONE 0 0000000000000000 0000000000000000 R_AARCH64_NONE 0 0000000000000000 0000000000000000 R_AARCH64_NONE 0 0000000000000000 0000000000000000 R_AARCH64_NONE 0 0000000000000000 0000000000000000 R_AARCH64_NONE 0 0000000000000000 0000000000000000 R_AARCH64_NONE 0
...
These are all processed and ignored at boot when applying the KASLR offset and take up ~650 KiB of .init data for no reason.
So discard the associated .rela sections explicitly.
--- arch/arm64/kernel/vmlinux.lds.S | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kernel/vmlinux.lds.S +1 -0
@@ -183,6 +183,7 @@ SECTIONS /DISCARD/ : { *(.interp .dynamic) *(.dynsym .dynstr .hash .gnu.hash) + *(.rela.discard.*) *(.rela.export_symbol) *(.ARM.attributes) }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog