You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2023/02/27 13:10:30 UTC

[mynewt-nimble] 02/04: babblesim: Fix invalid switch from isr to task

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 2de66c2797ef1848930f6ee5d5cded15a8a483d9
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Feb 24 23:45:42 2023 +0100

    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 8277ae7c..b545688c 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();
     }
 }