From 41070c3b35f510c82ecffde66bce5b07633cf98b Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Wed, 6 Jun 2018 09:59:01 -0700 Subject: [PATCH] arch/arm: Fix locking in __pendsv The PendSV handler sits below the priority of other OS interrupts, but it was inspecting kernel state before masking those interrupts out! Move the locking to the top. Signed-off-by: Andy Ross --- arch/arm/core/swap_helper.S | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/arm/core/swap_helper.S b/arch/arm/core/swap_helper.S index f481e8f534e..da89a48be4d 100644 --- a/arch/arm/core/swap_helper.S +++ b/arch/arm/core/swap_helper.S @@ -54,6 +54,16 @@ SECTION_FUNC(TEXT, __pendsv) #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ #endif /* CONFIG_KERNEL_EVENT_LOGGER_CONTEXT_SWITCH */ + /* protect the kernel state while we play with the thread lists */ +#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) + cpsid i +#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) + movs.n r0, #_EXC_IRQ_DEFAULT_PRIO + msr BASEPRI, r0 +#else +#error Unknown ARM architecture +#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ + /* load _kernel into r1 and current k_thread into r2 */ ldr r1, =_kernel ldr r2, [r1, #_kernel_offset_to_current] @@ -96,16 +106,6 @@ SECTION_FUNC(TEXT, __pendsv) ldr v4, =_SCS_ICSR ldr v3, =_SCS_ICSR_UNPENDSV - /* protect the kernel state while we play with the thread lists */ -#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) - cpsid i -#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) - movs.n r0, #_EXC_IRQ_DEFAULT_PRIO - msr BASEPRI, r0 -#else -#error Unknown ARM architecture -#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ - /* _kernel is still in r1 */ /* fetch the thread to run from the ready queue cache */