Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] arm64/boot: Some relocation tweaks
@ 2026-11-23 14:46 Ard Biesheuvel
  2026-11-23 14:46 ` [PATCH 1/2] arm64/boot: Handle RELR relocations more efficiently Ard Biesheuvel
  2026-11-23 14:46 ` [PATCH 2/2] arm64/boot: Discard NULL relocation entries Ard Biesheuvel
  0 siblings, 2 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2026-11-23 14:46 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: will, catalin.marinas, mark.rutland, Ard Biesheuvel

From: Ard Biesheuvel <ardb@kernel.org>

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
-- 
2.56.1.750.gf70dc682cf-goog



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] arm64/boot: Handle RELR relocations more efficiently
  2026-11-23 14:46 [PATCH 0/2] arm64/boot: Some relocation tweaks Ard Biesheuvel
@ 2026-11-23 14:46 ` Ard Biesheuvel
  2026-11-23 14:46 ` [PATCH 2/2] arm64/boot: Discard NULL relocation entries Ard Biesheuvel
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2026-11-23 14:46 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: will, catalin.marinas, mark.rutland, Ard Biesheuvel

From: Ard Biesheuvel <ardb@kernel.org>

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.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/kernel/pi/relocate.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/pi/relocate.c b/arch/arm64/kernel/pi/relocate.c
index 82592f3a5c1c..aa83946193ab 100644
--- a/arch/arm64/kernel/pi/relocate.c
+++ b/arch/arm64/kernel/pi/relocate.c
@@ -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;
 		}
 	}
-- 
2.56.1.750.gf70dc682cf-goog



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] arm64/boot: Discard NULL relocation entries
  2026-11-23 14:46 [PATCH 0/2] arm64/boot: Some relocation tweaks Ard Biesheuvel
  2026-11-23 14:46 ` [PATCH 1/2] arm64/boot: Handle RELR relocations more efficiently Ard Biesheuvel
@ 2026-11-23 14:46 ` Ard Biesheuvel
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2026-11-23 14:46 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: will, catalin.marinas, mark.rutland, Ard Biesheuvel

From: Ard Biesheuvel <ardb@kernel.org>

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.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 1869b44ae190..55d5c4db8c26 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -183,6 +183,7 @@ SECTIONS
 	/DISCARD/ : {
 		*(.interp .dynamic)
 		*(.dynsym .dynstr .hash .gnu.hash)
+		*(.rela.discard.*) *(.rela.export_symbol)
 		*(.ARM.attributes)
 	}
 
-- 
2.56.1.750.gf70dc682cf-goog



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-23 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:46 [PATCH 0/2] arm64/boot: Some relocation tweaks Ard Biesheuvel
2026-11-23 14:46 ` [PATCH 1/2] arm64/boot: Handle RELR relocations more efficiently Ard Biesheuvel
2026-11-23 14:46 ` [PATCH 2/2] arm64/boot: Discard NULL relocation entries Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox