rcu: Inform KCSAN of one-byte cmpxchg() in rcu_trc_cmpxchg_need_qs()
authorPaul E. McKenney <paulmck@kernel.org>
Fri, 8 Mar 2024 21:26:26 +0000 (13:26 -0800)
committerUladzislau Rezki (Sony) <urezki@gmail.com>
Mon, 15 Apr 2024 16:12:18 +0000 (18:12 +0200)
commitfc2897d2abe5a307e3b28943bcb4c1401432ea26
tree34cc86ac65b47ca5f2b69a29e8c80020b3b90716
parentae2b217ab542d0db0ca1a6de4f442201a1982f00
rcu: Inform KCSAN of one-byte cmpxchg() in rcu_trc_cmpxchg_need_qs()

Tasks Trace RCU needs a single-byte cmpxchg(), but no such thing exists.
Therefore, rcu_trc_cmpxchg_need_qs() emulates one using field substitution
and a four-byte cmpxchg(), such that the other three bytes are always
atomically updated to their old values.  This works, but results in
false-positive KCSAN failures because as far as KCSAN knows, this
cmpxchg() operation is updating all four bytes.

This commit therefore encloses the cmpxchg() in a data_race() and adds
a single-byte instrument_atomic_read_write(), thus telling KCSAN exactly
what is going on so as to avoid the false positives.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Marco Elver <elver@google.com>
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
kernel/rcu/tasks.h