From a7a8a64e9cdaa34a75dfd5fc991d7b63004c781d Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Mon, 21 Mar 2022 10:10:54 +0800 Subject: [PATCH] arch32: Fix incorrect exc_exit sequence The incorrect sequence will cause the thread cannot be aborted in the ISR context. The following test case failed: tests/kernel/fatal/exception/kernel.common.stack_sentinel. The stack sentinel detects the stack overflow as normal during a timer ISR exit. Note that, currently, the stack overflow detection is behind the context switch checking, and then the detection will call svc to raise a fatal error resulting in increasing the nested counter(+1). At this point, it needs a context switch to finally abort the thread. However, after the fatal error handling, the program cannot do a context switch either during the svc exit[1], or during the timer ISR exit[2]. [1] is because the svc context is in an interrupt nested state (the nested counter is 2). [2] is because the current point (after svc context pop out) is right behind the switch checking. Signed-off-by: Jaxson Han --- arch/arm/core/aarch32/cortex_a_r/exc_exit.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/core/aarch32/cortex_a_r/exc_exit.S b/arch/arm/core/aarch32/cortex_a_r/exc_exit.S index a4e864341fb..438f763be95 100644 --- a/arch/arm/core/aarch32/cortex_a_r/exc_exit.S +++ b/arch/arm/core/aarch32/cortex_a_r/exc_exit.S @@ -86,6 +86,10 @@ system_thread_exit\@: */ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_int_exit) +#ifdef CONFIG_STACK_SENTINEL + bl z_check_stack_sentinel +#endif /* CONFIG_STACK_SENTINEL */ + #ifdef CONFIG_PREEMPT_ENABLED /* Do not context switch if exiting a nested interrupt */ ldr r3, =_kernel @@ -100,10 +104,6 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_int_exit) __EXIT_INT: #endif /* CONFIG_PREEMPT_ENABLED */ -#ifdef CONFIG_STACK_SENTINEL - bl z_check_stack_sentinel -#endif /* CONFIG_STACK_SENTINEL */ - /* Disable nested interrupts while exiting */ cpsid i