zephyr/kernel/include
Andy Ross 7dee7a6139 kernel/sched: Fix race with thread return values
There was a brief (but seen in practice on real apps on real
hardware!) race with the switch-based z_swap() implementation.  The
thread return value was being initialized to -EAGAIN after the
enclosing lock had been released.  But that lock is supposed to be
atomic with the thread suspend.

This opened a window for another racing thread to come by and "wake
up" our pending thread (which is fine on its own), set its return
value (e.g. to 0 for success) and then have that value clobbered by
the thread continuing to suspend itself outside the lock.

Melodramatic aside: I continue to hate this
arch_thread_return_value_set() API; it needs to die.  At best it's a
mild optimization on a handful of architectures (e.g. x86 implements
it by writing to the EAX register save slot in the context block).
Asynchronous APIs are almost always worse than synchronous ones, and
in this case it's an async operation that races against literal
context switch code that can't use traditional locking strategies.

Fixes #39575

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-10-25 12:31:06 +02: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 -ENOTSUP doc to arch_float_en-/dis-able() 2021-09-03 10:00:02 -04:00
kernel_internal.h soc: intel_adsp/cavs_v25: Add CPU halt and relaunch APIs 2021-09-03 07:19:34 -04:00
kernel_offsets.h kernel/sched: Add CONFIG_CPU_MASK_PIN_ONLY 2021-09-28 20:15:05 -04:00
kernel_tls.h kernel: tls: align tdata/tbss sections in stack 2021-02-07 23:28:43 -05:00
ksched.h kernel/sched: Remove "cooperative scheduling only" special cases 2021-05-24 23:38:16 -04:00
kswap.h kernel/sched: Fix race with thread return values 2021-10-25 12:31:06 +02:00
mmu.h kernel: mmu: z_backing_store* to k_mem_paging_backing_store* 2021-05-28 11:33:22 -04:00
offsets_short.h kernel: add common bits to support TLS 2020-10-24 10:52:00 -07:00