micropython/ports
Damien George dc2a4e3cbd rp2/mpthreadport: Fix race with IRQ when entering atomic section.
Prior to this commit there is a potential deadlock in
mp_thread_begin_atomic_section(), when obtaining the atomic_mutex, in the
following situation:
- main thread calls mp_thread_begin_atomic_section() (for whatever reason,
  doesn't matter)
- the second core is running so the main thread grabs the mutex via the
  call mp_thread_mutex_lock(&atomic_mutex, 1), and this succeeds
- before the main thread has a chance to run save_and_disable_interrupts()
  a USB IRQ comes in and the main thread jumps off to process this IRQ
- that USB processing triggers a call to the dcd_event_handler() wrapper
  from commit bcbdee2357
- that then calls mp_sched_schedule_node()
- that then attempts to obtain the atomic section, calling
  mp_thread_begin_atomic_section()
- that call then blocks trying to obtain atomic_mutex
- core0 is now deadlocked on itself, because the main thread has the mutex
  but the IRQ handler (which preempted the main thread) is blocked waiting
  for the mutex, which will never be free

The solution in this commit is to use mutex enter/exit functions that also
atomically disable/restore interrupts.

Fixes issues #12980 and #13288.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-03 15:59:11 +11:00
..
bare-arm
cc3200
embed
esp32 extmod/nimble: Do not set GAP device name after sync. 2023-12-22 16:07:02 +11:00
esp8266
mimxrt mimxrt/mpbthciport: Add missing extmod/modmachine.h header. 2024-01-02 18:24:19 +11:00
minimal
nrf
pic16bit
powerpc
qemu-arm
renesas-ra
rp2 rp2/mpthreadport: Fix race with IRQ when entering atomic section. 2024-01-03 15:59:11 +11:00
samd samd/mcu: Fix wrong EIC table entries in pin-af-table.csv. 2024-01-02 18:48:17 +11:00
stm32
unix
webassembly
windows
zephyr