[PATCH 1/2] arm64/boot: Handle RELR relocations more efficiently

Ard Biesheuvel ardb+git at google.com
Mon Nov 23 06:46:35 PST 2026


From: Ard Biesheuvel <ardb at 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 at 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




More information about the linux-arm-kernel mailing list