SMP: fix crash when switch to new task which is still running

Situation:

Assume we have 2 cpus, and busy run task0.

CPU0                                CPU1
task0 -> task1                      task2 -> task0
1. remove task0 form runninglist
2. take task1 as new tcb
3. add task0 to blocklist
4. clear spinlock
                                    4.1 remove task2 form runninglist
                                    4.2 take task0 as new tcb
                                    4.3 add task2 to blocklist
                                    4.4 use svc ISR swith to task0
                                    4.5 crash
5. use svc ISR swith to task1

Fix:
Move clear spinlock to the end of svc ISR

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2022-08-10 17:22:48 +08:00
committed by Masayuki Ishikawa
parent 615bc9f0e2
commit e2df52390a
23 changed files with 224 additions and 63 deletions
+20
View File
@@ -219,6 +219,26 @@ void leave_critical_section(irqstate_t flags);
# define leave_critical_section(f) up_irq_restore(f)
#endif
/****************************************************************************
* Name: restore_critical_section
*
* Description:
* Restore the critical_section
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_SMP
void restore_critical_section(void);
#else
# define restore_critical_section()
#endif
#undef EXTERN
#ifdef __cplusplus
}