zephyr/kernel/include
Andy Ross 3235451880 kernel/swap: Add SMP "wait for switch" synchronization
On SMP, there is an inherent race when swapping: the old thread adds
itself back to the run queue before calling into the arch layer to do
the context switch.  The former is properly synchronized under the
scheduler lock, and the later operates with interrupts locally
disabled.  But until somewhere in the middle of arch_switch(), the old
thread (that is in the run queue!) does not have complete saved state
that can be restored.

So it's possible for another CPU to grab a thread before it is saved
and try to restore its unsaved register contents (which are garbage --
typically whatever state it had at the last interrupt).

Fix this by leveraging the "swapped_from" pointer already passed to
arch_switch() as a synchronization primitive.  When the switch
implementation writes the new handle value, we know the switch is
complete.  Then we can wait for that in z_swap() and at interrupt
exit.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-01-21 14:47:52 -08:00
..
gen_offset.h
kernel_arch_interface.h kernel: arch: Clarify output switch handle requirements in arch_switch 2020-01-21 14:47:52 -08:00
kernel_internal.h kernel: thread: Fix randomness problem with stack pointer random 2019-11-15 13:43:32 -08:00
kernel_offsets.h arch/x86/intel64: Fix assumption with dummy threads 2019-10-19 12:09:32 -07:00
ksched.h tracing: better positioning of tracing points 2020-01-09 11:21:19 -05:00
kswap.h kernel/swap: Add SMP "wait for switch" synchronization 2020-01-21 14:47:52 -08:00
offsets_short.h x86: implement interrupt stack trampoline 2019-02-14 12:46:36 -05:00