From 2de66c2797ef1848930f6ee5d5cded15a8a483d9 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Fri, 24 Feb 2023 23:45:42 +0100 Subject: [PATCH] babblesim: Fix invalid switch from isr to task BabbleSim triggers interrupts when exiting from critical section (i.e. interrupts are unlocked) and then we check for pending context switch. This can lead to invalid switch from isr to task context before isr has actually finished: - interrupts are unlocked - interrupt is triggered - isr calls os_* which uses critical section and triggers context switch (e.g. os_eventq_put) - when exiting critical section in isr, we check for pending context switch and immediately switch to task context before isr is completed To fix this we should only perform context switch if exiting from critical section in task context. --- babblesim/hw/bsp/nrf52_bsim/src/arch/bsim_arch/os_arch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/babblesim/hw/bsp/nrf52_bsim/src/arch/bsim_arch/os_arch.c b/babblesim/hw/bsp/nrf52_bsim/src/arch/bsim_arch/os_arch.c index 8277ae7ca..b545688cc 100644 --- a/babblesim/hw/bsp/nrf52_bsim/src/arch/bsim_arch/os_arch.c +++ b/babblesim/hw/bsp/nrf52_bsim/src/arch/bsim_arch/os_arch.c @@ -148,7 +148,7 @@ os_arch_restore_sr(os_sr_t osr) { hw_irq_ctrl_change_lock(osr); - if (!osr && bsim_pend_sv) { + if (!osr && bsim_pend_sv && !os_arch_in_isr()) { do_ctx_sw(); } }