Commit cba5ce6
committed
OS/ThreadX: fix multi-core deadlock in Nuclei RISC-V SMP port
Fix a real multi-core deadlock in the ThreadX SMP port for Nuclei
RISC-V CPU (OS/ThreadX/ports_smp/nuclei). The issue was reported by a
customer, who also provided the initial patch.
Bug scenario:
When a thread on a secondary core entered the sleep/suspend flow, the
generic ThreadX SMP layer released the interrupt posture (TX_RESTORE)
before calling _tx_thread_system_return, keeping the SMP protection
held with interrupts enabled. The port then cleared
_tx_thread_preempt_disable before releasing _tx_thread_smp_protection.
An IRQ landing in this narrow window could trigger scheduling from the
IRQ exit path (_tx_thread_irq_exit_schedule_check) while the core
still held the SMP protection: the core found no ready thread and spun
forever in the scheduler waiting for a ready thread, while other cores
spun forever waiting for the SMP protection, hanging the whole system.
Fix:
Move the _tx_thread_preempt_disable = 0 clearing out of
_tx_thread_system_return into _tx_thread_smp_force_unprotect, right
after interrupts are disabled (MSTATUS.MIE cleared). This guarantees
preempt_disable is only cleared once the local core can no longer be
interrupted, so an IRQ can never trigger scheduling while the core is
still in the middle of releasing the SMP protection. This matches the
ARM SMP port behavior.
Verification:
- Reproduced the deadlock and verified the patch on N900FD and NX900FD
with SMPx4
- Full ThreadX regression suite still passes with the patch applied
Signed-off-by: Huaqi Fang <578567190@qq.com>1 parent 0b21ce8 commit cba5ce6
2 files changed
Lines changed: 22 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
243 | 249 | | |
244 | 250 | | |
245 | 251 | | |
| |||
260 | 266 | | |
261 | 267 | | |
262 | 268 | | |
263 | | - | |
264 | | - | |
265 | 269 | | |
266 | 270 | | |
267 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
35 | 51 | | |
36 | 52 | | |
37 | 53 | | |
| |||
0 commit comments