Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: use a register-indirect load for TEXT_OFFSET in head.S
@ 2026-12-01 19:18 Florian Fainelli
  2026-12-01 22:06 ` Ard Biesheuvel
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2026-12-01 19:18 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: bcm-kernel-feedback-list, Farhad Hussain, Florian Fainelli,
	Russell King, Karl Mehltretter, Ard Biesheuvel, Sasha Levin,
	open list

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



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

* Re: [PATCH] ARM: use a register-indirect load for TEXT_OFFSET in head.S
  2026-12-01 19:18 [PATCH] ARM: use a register-indirect load for TEXT_OFFSET in head.S Florian Fainelli
@ 2026-12-01 22:06 ` Ard Biesheuvel
  2026-12-01 22:25   ` Florian Fainelli
  0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2026-12-01 22:06 UTC (permalink / raw)
  To: Florian Fainelli, linux-arm-kernel
  Cc: Broadcom Kernel List, Farhad Hussain, Russell King,
	Karl Mehltretter, Sasha Levin, open list

Hi Florian,

On Tue, 1 Dec 2026, at 20:18, Florian Fainelli wrote:
> 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(-)
>

We currently have

arch/arm/Makefile:textofs-y     := 0x00008000
arch/arm/Makefile:textofs-$(CONFIG_ARCH_REALTEK)  := 0x00108000
arch/arm/Makefile:textofs-$(CONFIG_SA1111) := 0x00208000
arch/arm/Makefile:textofs-$(CONFIG_ARCH_QCOM_RESERVE_SMEM) := 0x00208000
arch/arm/Makefile:textofs-$(CONFIG_ARCH_MESON) := 0x00208000
arch/arm/Makefile:textofs-$(CONFIG_ARCH_AXXIA) := 0x00308000

none of which appear to need this. So which value of TEXT_OFFSET
are you using, and is this platform supported upstream?


> 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

Would the following work as well?

add	r4, r0, #TEXT_OFFSET & 0x7fffff
.if   TEXT_OFFSET > 0x7fffff
add     r4, r4, #TEXT_OFFSET & 0xff800000
.endif


>  #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

Please don't use R3 like that - it might happen to work but it's
fragile.

>  	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

Same as above but with sub

>  #else
>  	ldr	r8, =PLAT_PHYS_OFFSET		@ always constant in this case
>  #endif
> -- 
> 2.34.1


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

* Re: [PATCH] ARM: use a register-indirect load for TEXT_OFFSET in head.S
  2026-12-01 22:06 ` Ard Biesheuvel
@ 2026-12-01 22:25   ` Florian Fainelli
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2026-12-01 22:25 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-arm-kernel, William (Zhenghao) Zhang
  Cc: Broadcom Kernel List, Farhad Hussain, Russell King,
	Karl Mehltretter, Sasha Levin, open list

CC William,

On 12/1/26 14:06, Ard Biesheuvel wrote:
> Hi Florian,
> 
> On Tue, 1 Dec 2026, at 20:18, Florian Fainelli wrote:
>> 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(-)
>>
> 
> We currently have
> 
> arch/arm/Makefile:textofs-y     := 0x00008000
> arch/arm/Makefile:textofs-$(CONFIG_ARCH_REALTEK)  := 0x00108000
> arch/arm/Makefile:textofs-$(CONFIG_SA1111) := 0x00208000
> arch/arm/Makefile:textofs-$(CONFIG_ARCH_QCOM_RESERVE_SMEM) := 0x00208000
> arch/arm/Makefile:textofs-$(CONFIG_ARCH_MESON) := 0x00208000
> arch/arm/Makefile:textofs-$(CONFIG_ARCH_AXXIA) := 0x00308000
> 
> none of which appear to need this. So which value of TEXT_OFFSET
> are you using, and is this platform supported upstream?

The value that triggered this was 0x01008000 with ARCH_BCMBCA using 
OP-TEE and it was using a local textofs-y override rather than what is 
currently upstream.

Thanks to your message this had me go back to the SDK's history and it 
looks like this was corrected earlier this year to 0x8000.

Let's drop this for now, unless you object William?
-- 
Florian


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

end of thread, other threads:[~2026-12-01 22:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:18 [PATCH] ARM: use a register-indirect load for TEXT_OFFSET in head.S Florian Fainelli
2026-12-01 22:06 ` Ard Biesheuvel
2026-12-01 22:25   ` Florian Fainelli

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