mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: linux-arm-kernel@lists.infradead.org
Cc: bcm-kernel-feedback-list@broadcom.com,
	Farhad Hussain <farhad.hussain@broadcom.com>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Russell King <linux@armlinux.org.uk>,
	Karl Mehltretter <kmehltretter@gmail.com>,
	Ard Biesheuvel <ardb@kernel.org>, Sasha Levin <sashal@kernel.org>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] ARM: use a register-indirect load for TEXT_OFFSET in head.S
Date: Tue,  1 Dec 2026 11:18:41 -0800	[thread overview]
Message-ID: <20261201191842.4115983-1-florian.fainelli@broadcom.com> (raw)

From: Farhad Hussain <farhad.hussain@broadcom.com>

add/sub with #TEXT_OFFSET requires TEXT_OFFSET to fit ARM's 8-bit
rotated immediate encoding. Platforms that need to run the kernel
from a start address above the default (e.g. to avoid colliding with
a firmware-reserved low-memory region) can end up with a TEXT_OFFSET
that no longer fits, breaking the build. Load it into a register with
ldr =TEXT_OFFSET instead, which works unconditionally and has no
effect on normal configurations where the immediate already fit.

Signed-off-by: Farhad Hussain <farhad.hussain@broadcom.com>
[florian: commit message, forward porting]
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 arch/arm/boot/compressed/head.S | 3 ++-
 arch/arm/kernel/head.S          | 6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 9f406e9c0ea6..8b54af9b5140 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -309,7 +309,8 @@ not_angel:
 1:
 #endif /* CONFIG_USE_OF */
 		/* Determine final kernel image address. */
-		add	r4, r0, #TEXT_OFFSET
+		ldr	r3, =TEXT_OFFSET
+		add	r4, r0, r3
 #else
 		ldr	r4, =zreladdr
 #endif
diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index a22403a629ef..71c15c1f9b52 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -65,7 +65,8 @@ kernel_sec_end:
 	.popsection
 
 	.macro	pgtbl, rd, phys
-	add	\rd, \phys, #TEXT_OFFSET
+	ldr	r3, =TEXT_OFFSET
+	add	\rd, \phys, r3
 	sub	\rd, \rd, #PG_DIR_SIZE
 	.endm
 
@@ -120,7 +121,8 @@ ENTRY(stext)
 
 #ifndef CONFIG_XIP_KERNEL
 	adr_l	r8, _text			@ __pa(_text)
-	sub	r8, r8, #TEXT_OFFSET		@ PHYS_OFFSET
+	ldr	r3, =TEXT_OFFSET
+	sub	r8, r8, r3			@ PHYS_OFFSET
 #else
 	ldr	r8, =PLAT_PHYS_OFFSET		@ always constant in this case
 #endif
-- 
2.34.1


             reply	other threads:[~2026-12-01 19:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 19:18 Florian Fainelli [this message]
2026-12-01 22:06 ` Ard Biesheuvel
2026-12-01 22:25   ` Florian Fainelli

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=20261201191842.4115983-1-florian.fainelli@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=ardb@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=farhad.hussain@broadcom.com \
    --cc=kmehltretter@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=sashal@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

all inboxes | Powered by JetHome®