zephyr/kernel
Andy Ross 312b43f145 kernel/sched: Don't reschedule inside a nested lock
The internal "reschedule" API has always understood the idea that it
might run in a ISR context where it can't swap.  But it has always
been happy to swap away when in thread mode, even when the environment
contains an outer lock that would NOT be expecting to swap!  As it
happened, the way irq locks are implemented (they store flag state
that can be restored without context) this would "work" even though it
was completely breaking the synchronization promise made by the outer
lock.

But now, with spinlocks, the error gets detected (albeit in a clumsy
way) in debug builds.  The unexpected swap triggers SPIN_VALIDATE
failures in later threads (this gets reported as a "recursive" lock,
but what actually happened is that another thread got to run before
the lock was released and tried to grab the same lock).

Fix this so that swap can only be called in a situation where the irq
lock key it was passed would have the effect of unmasking interrupts.
Note that this is a real behavioral change that affects when swaps
occur: it's not impossible that there is code out there that actually
relies on this "lock breaking reschedule" for correct behavior.  But
our previous implementation was irredeemably broken and I don't know
how to address that.

Fixes #16273

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-06-03 12:03:48 -07:00
..
include misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>. 2019-05-14 19:53:30 -05:00
atomic_c.c kernel: fix atomic ops in user mode on some arches 2019-03-18 09:18:00 -04:00
CMakeLists.txt x86: remove unused and x86 only latency benchmark 2019-06-03 09:42:00 -07:00
compiler_stack_protect.c all: Update reserved function names 2019-03-11 13:48:42 -04:00
device.c all: Add 'U' suffix when using unsigned variables 2019-03-28 17:15:58 -05:00
errno.c all: Update reserved function names 2019-03-11 13:48:42 -04:00
idle.c power: clean up system power managment function names 2019-03-26 13:27:55 -04:00
init.c kernel/init.c: remove needless casts 2019-05-30 09:16:35 -04:00
Kconfig x86: remove unused and x86 only latency benchmark 2019-06-03 09:42:00 -07:00
Kconfig.power_mgmt power: modify HAS_STATE_SLEEP_ Kconfig options 2019-03-26 13:27:55 -04:00
mailbox.c all: Add 'U' suffix when using unsigned variables 2019-03-28 17:15:58 -05:00
mem_domain.c kernel: mem_domain: update name/doc of API function for partition add 2019-05-02 11:37:38 -04:00
mem_slab.c all: Add 'U' suffix when using unsigned variables 2019-03-28 17:15:58 -05:00
mempool.c misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>. 2019-05-14 19:53:30 -05:00
msg_q.c misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>. 2019-05-14 19:53:30 -05:00
mutex.c all: Add 'U' suffix when using unsigned variables 2019-03-28 17:15:58 -05:00
pipes.c all: Add 'U' suffix when using unsigned variables 2019-03-28 17:15:58 -05:00
poll.c misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>. 2019-05-14 19:53:30 -05:00
queue.c all: Update reserved function names 2019-03-11 13:48:42 -04:00
sched.c kernel/sched: Don't reschedule inside a nested lock 2019-06-03 12:03:48 -07:00
sem.c all: Update reserved function names 2019-03-11 13:48:42 -04:00
smp.c kernel/sched: arch/x86_64: Support synchronous k_thread_abort() in SMP 2019-03-13 19:15:20 +01:00
stack.c kernel: fix k_stack_alloc_init() 2019-05-06 19:47:01 -04:00
system_work_q.c kernel: system_work_q: Set dedicated "sysworkq" name. 2018-10-19 07:58:45 -04:00
thread_abort.c kernel/thread_abort: Swap, don't reschedule when aborting _current 2019-06-03 12:03:48 -07:00
thread.c thread_cpu: make it 64-bit compatible 2019-05-30 09:42:23 -04:00
timeout.c kernel: timeout: add syscall for runtime clk freq 2019-05-22 23:33:55 +02:00
timer.c all: Add 'U' suffix when using unsigned variables 2019-03-28 17:15:58 -05:00
userspace_handler.c all: Update reserved function names 2019-03-11 13:48:42 -04:00
userspace.c misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>. 2019-05-14 19:53:30 -05:00
version.c doc: add kernel version API to doxygen 2018-12-08 17:24:53 -05:00
work_q.c kernel: Fix usage of CONFIG_SYS_CLOCK_EXISTS 2019-05-15 10:44:59 +02:00