* [PATCH 0/2] ARM: v7m: reset loader-set CONTROL and M33 ACTLR at boot @ 2026-11-25 2:58 Brad Hawthorne 2026-11-25 2:58 ` [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC Brad Hawthorne 2026-11-25 2:58 ` [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot Brad Hawthorne 0 siblings, 2 replies; 7+ messages in thread From: Brad Hawthorne @ 2026-11-25 2:58 UTC (permalink / raw) To: linux, linux-arm-kernel Cc: vladimir.murzin, linusw, arnd, envzhu, linux-kernel Two fixes to __v7m_setup for state a boot loader can leave behind. Both came up while bringing Linux up on an RP2350 (Cortex-M33), booted from a Raspberry Pi pico-sdk loader; it is the board I tested the deprecation series on. Patch 1 affects any v7-M or v8-M kernel whose loader ran an FP instruction, and reproduces under QEMU (mps2-an505). Patch 2 affects a Cortex-M33 kernel built without CONFIG_ARM_MPU whose loader set ACTLR.EXTEXCLALL, which the pico-sdk does by default; it is tested on the RP2350, as QEMU does not model ACTLR. I know the Cortex-M platforms are going in 7.5. These are for the stable kernels that still carry them, and for the v8-M core while its future is discussed. These patches were written with an AI coding assistant (Claude Opus 5.5, Anthropic), as each patch says; I reviewed the reasoning and the test results. Brad Hawthorne (2): ARM: v7m: clear CONTROL.FPCA before the boot SVC ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot arch/arm/include/asm/v7m.h | 3 +++ arch/arm/mm/proc-v7m.S | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3 -- 2.43.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC 2026-11-25 2:58 [PATCH 0/2] ARM: v7m: reset loader-set CONTROL and M33 ACTLR at boot Brad Hawthorne @ 2026-11-25 2:58 ` Brad Hawthorne 2026-11-25 7:41 ` Arnd Bergmann 2026-11-25 10:50 ` Vladimir Murzin 2026-11-25 2:58 ` [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot Brad Hawthorne 1 sibling, 2 replies; 7+ messages in thread From: Brad Hawthorne @ 2026-11-25 2:58 UTC (permalink / raw) To: linux, linux-arm-kernel Cc: vladimir.murzin, linusw, arnd, envzhu, linux-kernel __v7m_setup writes CONTROL only after the SVC it uses to enter Handler mode. If the boot loader ran FP code, CONTROL.FPCA can still be set, so the SVC stacks an extended frame, and its EXC_RETURN has FType clear. Since commit 72cd4064fcca ("ARM: 8830/1: NOMMU: Toggle only bits in EXC_RETURN we are really care of"), that EXC_RETURN is saved in exc_ret, which every return to user space uses, so each return expects an extended frame that ret_to_user never builds. init then starts with a corrupted stack. Write CONTROL to its reset value, 0, before the SVC. That clears FPCA, and also selects the main stack, which the code after the SVC reads. Tested under QEMU (mps2-an505) with a boot shim that runs a VMOV before jumping to the kernel: without this patch init loses its arguments; with it init starts with them. It also boots on an RP2350 board. This patch was written with an AI coding assistant (Claude Opus 5.5, Anthropic): it wrote the change, the boot shim and this changelog, and ran the QEMU and board tests; I reviewed the reasoning and the test results. Fixes: 72cd4064fcca ("ARM: 8830/1: NOMMU: Toggle only bits in EXC_RETURN we are really care of") Cc: Vladimir Murzin <vladimir.murzin@arm.com> Cc: stable@vger.kernel.org Signed-off-by: Brad Hawthorne <brad@sim.vu> --- arch/arm/mm/proc-v7m.S | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S index d4675603593b..6d0532abc086 100644 --- a/arch/arm/mm/proc-v7m.S +++ b/arch/arm/mm/proc-v7m.S @@ -124,6 +124,11 @@ __v7m_setup_cont: mov r5, #0x00800000 str r5, [r0, V7M_SCB_SHPR3] @ set PendSV priority + @ Clear CONTROL: a boot loader may leave FPCA or SPSEL set + mov r5, #0 + msr control, r5 + isb + @ SVC to switch to handler mode. Notice that this requires sp to @ point to writeable memory because the processor saves @ some registers to the stack. -- 2.43.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC 2026-11-25 2:58 ` [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC Brad Hawthorne @ 2026-11-25 7:41 ` Arnd Bergmann 2026-11-25 10:50 ` Vladimir Murzin 1 sibling, 0 replies; 7+ messages in thread From: Arnd Bergmann @ 2026-11-25 7:41 UTC (permalink / raw) To: Brad Hawthorne, Russell King, linux-arm-kernel Cc: Vladimir Murzin, Linus Walleij, envzhu, linux-kernel On Wed, Nov 25, 2026, at 03:58, Brad Hawthorne wrote: > __v7m_setup writes CONTROL only after the SVC it uses to enter Handler > mode. If the boot loader ran FP code, CONTROL.FPCA can still be set, > so the SVC stacks an extended frame, and its EXC_RETURN has FType > clear. Since commit 72cd4064fcca ("ARM: 8830/1: NOMMU: Toggle only > bits in EXC_RETURN we are really care of"), that EXC_RETURN is saved in > exc_ret, which every return to user space uses, so each return expects > an extended frame that ret_to_user never builds. init then starts with > a corrupted stack. > > Write CONTROL to its reset value, 0, before the SVC. That clears FPCA, > and also selects the main stack, which the code after the SVC reads. > > Tested under QEMU (mps2-an505) with a boot shim that runs a VMOV > before jumping to the kernel: without this patch init loses its > arguments; with it init starts with them. It also boots on an RP2350 > board. Should this perhaps be addressed by documenting the state of the CPU core in Documentation/arch/arm/booting.rst? We already have similar requirements for normal CPUs there, in particular about errata workarounds and the state of MMU, cache, privilege level, instruction set etc, so this seems like something that should be handled by the loader as well. Arnd ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC 2026-11-25 2:58 ` [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC Brad Hawthorne 2026-11-25 7:41 ` Arnd Bergmann @ 2026-11-25 10:50 ` Vladimir Murzin 1 sibling, 0 replies; 7+ messages in thread From: Vladimir Murzin @ 2026-11-25 10:50 UTC (permalink / raw) To: Brad Hawthorne, linux, linux-arm-kernel Cc: linusw, arnd, envzhu, linux-kernel On 11/25/26 02:58, Brad Hawthorne wrote: > __v7m_setup writes CONTROL only after the SVC it uses to enter Handler > mode. If the boot loader ran FP code, CONTROL.FPCA can still be set, > so the SVC stacks an extended frame, and its EXC_RETURN has FType > clear. Since commit 72cd4064fcca ("ARM: 8830/1: NOMMU: Toggle only > bits in EXC_RETURN we are really care of"), that EXC_RETURN is saved in > exc_ret, which every return to user space uses, so each return expects > an extended frame that ret_to_user never builds. init then starts with > a corrupted stack. > > Write CONTROL to its reset value, 0, before the SVC. That clears FPCA, > and also selects the main stack, which the code after the SVC reads. > Cannot boot loader do that before passing control to Linux? Cheers Vladimir ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot 2026-11-25 2:58 [PATCH 0/2] ARM: v7m: reset loader-set CONTROL and M33 ACTLR at boot Brad Hawthorne 2026-11-25 2:58 ` [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC Brad Hawthorne @ 2026-11-25 2:58 ` Brad Hawthorne 2026-11-25 7:35 ` Arnd Bergmann 2026-11-25 10:55 ` Vladimir Murzin 1 sibling, 2 replies; 7+ messages in thread From: Brad Hawthorne @ 2026-11-25 2:58 UTC (permalink / raw) To: linux, linux-arm-kernel Cc: vladimir.murzin, linusw, arnd, envzhu, linux-kernel With ACTLR.EXTEXCLALL set and the MPU off, a Cortex-M33 sends every exclusive access to the system's global monitor. The bit resets to 0, but the Raspberry Pi pico-sdk sets it for its multicore spin locks (spinlock_set_extexclall() in hardware_sync_spin_lock/sync_spin_lock.c), so a kernel started by a pico-sdk loader inherits it. On the RP2350, the PSRAM where the kernel runs is not covered by the global monitor, so every STREX there fails, and the kernel's atomics, which loop until STREX succeeds, never finish. The kernel never reaches its console. The bit only has an effect while the MPU is off (RP2350 datasheet, ACTLR: "External Exclusives Allowed with no MPU"), so this affects kernels built without CONFIG_ARM_MPU. With the bit clear, the core handles exclusives in its local monitor, which is all a uniprocessor kernel needs. Clear it in a Cortex-M33 setup function before __v7m_setup, which already sets other state a loader may have changed (VTOR, the fault enables, the exception priorities). Tested on an RP2350 board booted by such a loader: without this patch the kernel hangs before its console; with it, it boots. QEMU does not model ACTLR, so there it only shows the boot is unaffected. This patch was written with an AI coding assistant (Claude Opus 5.5, Anthropic): it wrote the change, the board probe and this changelog, and ran the QEMU and board tests; I reviewed the reasoning and the test results. Signed-off-by: Brad Hawthorne <brad@sim.vu> --- arch/arm/include/asm/v7m.h | 3 +++ arch/arm/mm/proc-v7m.S | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/v7m.h b/arch/arm/include/asm/v7m.h index 4512f7e1918f..505f75deeea9 100644 --- a/arch/arm/include/asm/v7m.h +++ b/arch/arm/include/asm/v7m.h @@ -5,6 +5,9 @@ #define V7M_SCS_ICTR IOMEM(0xe000e004) #define V7M_SCS_ICTR_INTLINESNUM_MASK 0x0000000f +#define V7M_SCS_ACTLR IOMEM(0xe000e008) +#define V7M_SCS_ACTLR_CM33_EXTEXCLALL (1 << 29) + #define BASEADDR_V7M_SCB IOMEM(0xe000ed00) #define V7M_SCB_CPUID 0x00 diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S index 6d0532abc086..7d830fa5bf86 100644 --- a/arch/arm/mm/proc-v7m.S +++ b/arch/arm/mm/proc-v7m.S @@ -96,6 +96,16 @@ SYM_FUNC_END(cpu_cm7_proc_fin) .section ".init.text", "ax" +/* Cortex-M33: clear ACTLR.EXTEXCLALL so that exclusives use the local monitor */ +__v7m_cm33_setup: + ldr r0, =V7M_SCS_ACTLR + ldr r1, [r0] + bic r1, r1, #V7M_SCS_ACTLR_CM33_EXTEXCLALL + str r1, [r0] + dsb + isb + b __v7m_setup + __v7m_cm7_setup: mov r8, #(V7M_SCB_CCR_DC | V7M_SCB_CCR_IC| V7M_SCB_CCR_BP) b __v7m_setup_cont @@ -216,7 +226,7 @@ __v7m_cm55_proc_info: __v7m_cm33_proc_info: .long 0x410fd210 /* ARM Cortex-M33 0xD21 */ .long 0xff0ffff0 /* Mask off revision, patch release */ - __v7m_proc __v7m_cm33_proc_info, __v7m_setup, hwcaps = HWCAP_EDSP + __v7m_proc __v7m_cm33_proc_info, __v7m_cm33_setup, hwcaps = HWCAP_EDSP .size __v7m_cm33_proc_info, . - __v7m_cm33_proc_info /* -- 2.43.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot 2026-11-25 2:58 ` [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot Brad Hawthorne @ 2026-11-25 7:35 ` Arnd Bergmann 2026-11-25 10:55 ` Vladimir Murzin 1 sibling, 0 replies; 7+ messages in thread From: Arnd Bergmann @ 2026-11-25 7:35 UTC (permalink / raw) To: Brad Hawthorne, Russell King, linux-arm-kernel Cc: Vladimir Murzin, Linus Walleij, envzhu, linux-kernel On Wed, Nov 25, 2026, at 03:58, Brad Hawthorne wrote: > +/* Cortex-M33: clear ACTLR.EXTEXCLALL so that exclusives use the local > monitor */ > +__v7m_cm33_setup: > + ldr r0, =V7M_SCS_ACTLR > + ldr r1, [r0] > + bic r1, r1, #V7M_SCS_ACTLR_CM33_EXTEXCLALL > + str r1, [r0] > + dsb > + isb > + b __v7m_setup Doesn't this prevent using Cortex-M33 on SMP configurations? Arnd ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot 2026-11-25 2:58 ` [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot Brad Hawthorne 2026-11-25 7:35 ` Arnd Bergmann @ 2026-11-25 10:55 ` Vladimir Murzin 1 sibling, 0 replies; 7+ messages in thread From: Vladimir Murzin @ 2026-11-25 10:55 UTC (permalink / raw) To: Brad Hawthorne, linux, linux-arm-kernel Cc: linusw, arnd, envzhu, linux-kernel On 11/25/26 02:58, Brad Hawthorne wrote: > so a kernel started by a pico-sdk loader inherits it. On the RP2350, > the PSRAM where the kernel runs is not covered by the global monitor, > so every STREX there fails, and the kernel's atomics, which loop until > STREX succeeds, never finish. The kernel never reaches its console. This suggests that boot loader is the place for handling such platform implementation detail, so why boot loader cannot do that? Cheers Vladimir ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-25 10:55 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-25 2:58 [PATCH 0/2] ARM: v7m: reset loader-set CONTROL and M33 ACTLR at boot Brad Hawthorne 2026-11-25 2:58 ` [PATCH 1/2] ARM: v7m: clear CONTROL.FPCA before the boot SVC Brad Hawthorne 2026-11-25 7:41 ` Arnd Bergmann 2026-11-25 10:50 ` Vladimir Murzin 2026-11-25 2:58 ` [PATCH 2/2] ARM: v7m: clear the Cortex-M33's ACTLR.EXTEXCLALL at boot Brad Hawthorne 2026-11-25 7:35 ` Arnd Bergmann 2026-11-25 10:55 ` Vladimir Murzin
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®