rcu: Mark additional concurrent load from ->cpu_no_qs.b.exp
authorPaul E. McKenney <paulmck@kernel.org>
Fri, 7 Apr 2023 23:05:38 +0000 (16:05 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jul 2023 06:50:33 +0000 (08:50 +0200)
commit896f4d6046b3d5faa84afd0c85f266251e5b3cbf
treef26cef2caa39fcbd20601c78fdd3a043143ef48d
parent9027d69221ff96e1356f070f7feb2ff989ae7388
rcu: Mark additional concurrent load from ->cpu_no_qs.b.exp

[ Upstream commit 9146eb25495ea8bfb5010192e61e3ed5805ce9ef ]

The per-CPU rcu_data structure's ->cpu_no_qs.b.exp field is updated
only on the instance corresponding to the current CPU, but can be read
more widely.  Unmarked accesses are OK from the corresponding CPU, but
only if interrupts are disabled, given that interrupt handlers can and
do modify this field.

Unfortunately, although the load from rcu_preempt_deferred_qs() is always
carried out from the corresponding CPU, interrupts are not necessarily
disabled.  This commit therefore upgrades this load to READ_ONCE.

Similarly, the diagnostic access from synchronize_rcu_expedited_wait()
might run with interrupts disabled and from some other CPU.  This commit
therefore marks this load with data_race().

Finally, the C-language access in rcu_preempt_ctxt_queue() is OK as
is because interrupts are disabled and this load is always from the
corresponding CPU.  This commit adds a comment giving the rationale for
this access being safe.

This data race was reported by KCSAN.  Not appropriate for backporting
due to failure being unlikely.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/rcu/tree_exp.h
kernel/rcu/tree_plugin.h