Skip to content

arch/arm: Color only the interrupt stack of the calling CPU. - #21463

Merged
xiaoxiang781216 merged 3 commits into
apache:masterfrom
casaroli:armv7-color-intstack-up
Nov 6, 2026
Merged

xiaoxiang781216 merged 3 commits into
apache:masterfrom
casaroli:armv7-color-intstack-up

Conversation

@casaroli

@casaroli casaroli commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

qemu-armv7a:smp aborts at boot in about 1 of 7 boots, with PC or DFAR 0xdeadbeef on the interrupt stack of CPU 0. arm_color_intstack() writes the color into the interrupt stacks of all CPUs, and qemu, imx6, goldfish, rtl8730e, cxd56 and rp2040 call it on each secondary CPU through up_irqinitialize(). So a CPU that boots writes over the register frame of a CPU that handles an interrupt.

Each CPU now colors only its own stack, before it enables its interrupts. x86_64 does the same. lc823450 does not call up_irqinitialize() on a secondary CPU, so it now colors the stack in cpu1_boot(). rp23xx never colored the stack at all, so up_check_intstack() reported all of it as used; it now does.

Impact

Only arm with CONFIG_STACK_COLORATION. Without SMP the same stack is colored as before. Until a secondary CPU starts, up_check_intstack() finds no color on its stack.

Testing

Which CPU colors which stack during boot, with a gdb breakpoint on arm_stack_color(), qemu-armv7a:smp, 4 CPUs. It does not depend on the timing:

Colorings by another CPU
master 12 (each secondary CPU colors all 4 stacks)
this PR 0 (CPU n colors stack n)

Boots to an NSH prompt, in turn, same .config, under QEMU TCG:

ok abort hang
master 254 44 2
this PR 300 0 0

ostest status 0 on qemu-armv7a:smp and qemu-armv7a:nsh. The check of apache/nuttx-apps#3982 in ostest, on qemu-armv7a:smp: each CPU takes an interrupt, then uses 488, 264, 264 and 264 bytes of 2048.

Builds with EXTRAFLAGS="-Wno-cpp -Werror": qemu-armv7a:smp, qemu-armv7a:nsh, qemu-armv7a:knsh_smp, sabre-6quad:smp. With CONFIG_STACK_COLORATION by kconfig-tweak: spresense:smp, raspberrypi-pico:smp, raspberrypi-pico-2:smp, lc823450-xgevk:nsh.

RP2350 (pimoroni-pico-2-plus:smp, 2 cores, on the board), the same check: master stops with CPU 0 "used 2048 of 2048" because the stack has no color; this PR gives 152 and 144 bytes, ostest status 0.

Not run: the other chips. Not built: goldfish (no board in the tree) and rtl8730e_evb (the SDK fetch failed here).

No CI configuration runs QEMU for this board, so no test in CI covers this.

@casaroli casaroli added the Area: OS Components OS Components issues label Nov 4, 2026
@casaroli
casaroli requested a review from jerpelea as a code owner November 4, 2026 17:56
@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Size: XS The size of the change in this PR is very small and removed Area: OS Components OS Components issues labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Add a blank line after a declaration, so that the next commit passes
tools/checkpatch.sh.  No change in code.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
arm_color_intstack() writes the color into the interrupt stacks of all
CPUs.  qemu, imx6, goldfish, rtl8730e, cxd56 and rp2040 call it on each
secondary CPU through up_irqinitialize().  So a CPU that boots writes over
the register frame of a CPU that handles an interrupt, and qemu-armv7a:smp
aborts at boot with PC or DFAR 0xdeadbeef.

Each CPU now colors only its own stack, before it enables its interrupts.
x86_64 does the same.  lc823450 does not call up_irqinitialize() on a
secondary CPU, so it now colors the stack in cpu1_boot().

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
up_irqinitialize() of rp23xx does not call arm_color_intstack(), so with
CONFIG_STACK_COLORATION up_check_intstack() finds no color and reports the
whole stack as used.  Color it as the other chips do.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli casaroli changed the title arch/arm: Color the interrupt stacks only on CPU 0. arch/arm: Color only the interrupt stack of the calling CPU. Nov 5, 2026
@casaroli
casaroli force-pushed the armv7-color-intstack-up branch from c0e8f66 to 51ea24e Compare November 5, 2026 21:17
@github-actions github-actions Bot added Size: S The size of the change in this PR is small and removed Size: XS The size of the change in this PR is very small labels Nov 5, 2026
Comment thread arch/arm/src/common/arm_checkstack.c Resolved

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @casaroli neat stuff! :-)

Do we want that also for other architectures like RISC-V etc?

@xiaoxiang781216
xiaoxiang781216 merged commit 26cc072 into apache:master Nov 6, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants