kernel - Fix memory ordering race
commita9a062cd1350bbf6889b4e3b22b3331d49bf818c
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 14 Sep 2017 17:36:23 +0000 (14 10:36 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 14 Sep 2017 17:36:23 +0000 (14 10:36 -0700)
tree6745b9c4dfd644d973db6bb86c7389e202e881ff
parente0bfa1ede22ad7cf90652b53fc2cd1408629a364
kernel - Fix memory ordering race

* Fix a race in the mtx wait/wakeup code for situations where the
  releasing thread hands lock ownership to the waiter.  In this
  situation the waiter can sometimes succeed without having to do
  additional atomic ops.  However, this also allows speculative reads
  by the waiting cpu to preceed the lock handover.

* Add an mfence to fix this problem.  Add a few cpu_sfence()s (which
  are basically NOPs on Intel) to clarify other bits of code too.
sys/kern/kern_mutex.c