This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 535d4765a7fca9991c73de433b9962af660b6068
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 5 20:21:54 2026 +0100

    arch/arm: Color only the interrupt stack of the calling CPU.
    
    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 <[email protected]>
---
 arch/arm/src/common/arm_checkstack.c      | 17 +++++------------
 arch/arm/src/lc823450/lc823450_cpustart.c |  2 ++
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/arch/arm/src/common/arm_checkstack.c 
b/arch/arm/src/common/arm_checkstack.c
index 7bfc5e6c343..4b1f3a46f4f 100644
--- a/arch/arm/src/common/arm_checkstack.c
+++ b/arch/arm/src/common/arm_checkstack.c
@@ -53,24 +53,17 @@
  * Name: arm_color_intstack
  *
  * Description:
- *   Set the interrupt stack to a value so that later we can determine how
- *   much stack space was used by interrupt handling logic
+ *   Set the interrupt stack of the calling CPU to a value so that later we
+ *   can determine how much stack space was used by interrupt handling logic.
+ *   Another CPU can be in an interrupt handler at this time, so its stack
+ *   is not touched.  Each CPU calls this before it enables its interrupts.
  *
  ****************************************************************************/
 
 #if defined(CONFIG_ARCH_INTERRUPTSTACK) && CONFIG_ARCH_INTERRUPTSTACK > 3
 void arm_color_intstack(void)
 {
-#ifdef CONFIG_SMP
-  int cpu;
-
-  for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++)
-    {
-      arm_stack_color((void *)up_get_intstackbase(cpu), INTSTACK_SIZE);
-    }
-#else
-  arm_stack_color((void *)g_intstackalloc, INTSTACK_SIZE);
-#endif
+  arm_stack_color((void *)up_get_intstackbase(this_cpu()), INTSTACK_SIZE);
 }
 #endif
 
diff --git a/arch/arm/src/lc823450/lc823450_cpustart.c 
b/arch/arm/src/lc823450/lc823450_cpustart.c
index 16e20ce2947..c72776e9064 100644
--- a/arch/arm/src/lc823450/lc823450_cpustart.c
+++ b/arch/arm/src/lc823450/lc823450_cpustart.c
@@ -96,6 +96,8 @@ static void cpu1_boot(void)
   arm_initialize_stack();
 #endif
 
+  arm_color_intstack();
+
   if (cpu == 1)
     {
       putreg32((uint32_t)_stext, NVIC_VECTAB); /* use CPU0 vectors */

Reply via email to