zephyr/kernel/include
Andy Ross dd43221540 kernel/sched: Fix race with switch handle
The "null out the switch handle and put it back" code in the swap
implementation is a holdover from some defensive coding (not wanting
to break the case where we picked our current thread), but it hides a
subtle SMP race: when that field goes NULL, another CPU that may have
selected that thread (which is to say, our current thread) as its next
to run will be spinning on that to detect when the field goes
non-NULL.  So it will get the signal to move on when we revert the
value, when clearly we are still running on the stack!

In practice this was found on x86 which poisons the switch context
such that it crashes instantly.

Instead, be firm about state and always set the switch handle of a
currently running thread to NULL immediately before it starts running:
right before entering arch_switch() and symmetrically on the interrupt
exit path.

Fixes #28105

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-14 16:22:45 -05:00
..
gen_offset.h aarch64: Use absolute symbols for the callee saved registers 2020-11-17 18:59:23 -05:00
kernel_arch_interface.h kernel: add demand paging arch interfaces 2021-01-23 19:47:23 -05:00
kernel_internal.h mmu: ensure gperf data is mapped 2021-01-23 19:47:23 -05:00
kernel_offsets.h Revert "device: add post-process of elf file to manage device handles" 2021-01-23 18:01:03 -05:00
kernel_tls.h kernel: tls: align tdata/tbss sections in stack 2021-02-07 23:28:43 -05:00
ksched.h kernel/sched: Add missing lock around waitq unpend calls 2021-02-10 07:43:18 -05:00
kswap.h kernel/sched: Fix race with switch handle 2021-02-14 16:22:45 -05:00
mmu.h mmu: fix ARM64 compilation by removing z_mapped_size usage 2021-02-05 17:19:56 -05:00
offsets_short.h kernel: add common bits to support TLS 2020-10-24 10:52:00 -07:00