Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb+git@google.com>
To: linux-arm-kernel@lists.infradead.org
Cc: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com,
	 Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 1/2] arm64/boot: Handle RELR relocations more efficiently
Date: Mon, 23 Nov 2026 15:46:35 +0100	[thread overview]
Message-ID: <20261123144633.2725921-5-ardb+git@google.com> (raw)
In-Reply-To: <20261123144633.2725921-4-ardb+git@google.com>

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



      reply	other threads:[~2026-11-23 14:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 14:46 [PATCH 0/2] arm64/boot: Some relocation tweaks Ard Biesheuvel
2026-11-23 14:46 ` Ard Biesheuvel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123144633.2725921-5-ardb+git@google.com \
    --to=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox