Skip to content

Commit ecc5e6b

Browse files
paulmckrcuurezki
authored andcommitted
rcu: Add KCSAN exclusive-writer assertions for rdp->cpu_no_qs.b.exp
The value of rdp->cpu_no_qs.b.exp may be changed only by the corresponding CPU, and that CPU is not even allowed to race with itself, for example, via interrupt handlers. This commit therefore adds KCSAN exclusive-writer assertions to check this constraint. Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Cc: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
1 parent 7a32337 commit ecc5e6b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

kernel/rcu/tree_exp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static void rcu_report_exp_rdp(struct rcu_data *rdp)
262262

263263
raw_spin_lock_irqsave_rcu_node(rnp, flags);
264264
WRITE_ONCE(rdp->cpu_no_qs.b.exp, false);
265+
ASSERT_EXCLUSIVE_WRITER(rdp->cpu_no_qs.b.exp);
265266
rcu_report_exp_cpu_mult(rnp, flags, rdp->grpmask, true);
266267
}
267268

@@ -721,6 +722,7 @@ static void rcu_exp_sel_wait_wake(unsigned long s)
721722
/* Request an expedited quiescent state. */
722723
static void rcu_exp_need_qs(void)
723724
{
725+
ASSERT_EXCLUSIVE_WRITER_SCOPED(*this_cpu_ptr(&rcu_data.cpu_no_qs.b.exp));
724726
__this_cpu_write(rcu_data.cpu_no_qs.b.exp, true);
725727
/* Store .exp before .rcu_urgent_qs. */
726728
smp_store_release(this_cpu_ptr(&rcu_data.rcu_urgent_qs), true);
@@ -753,6 +755,7 @@ static void rcu_exp_handler(void *unused)
753755
* sync_sched_exp_online_cleanup() implementation being a no-op,
754756
* so warn if this does happen.
755757
*/
758+
ASSERT_EXCLUSIVE_WRITER_SCOPED(rdp->cpu_no_qs.b.exp);
756759
if (WARN_ON_ONCE(!(READ_ONCE(rnp->expmask) & rdp->grpmask) ||
757760
READ_ONCE(rdp->cpu_no_qs.b.exp)))
758761
return;
@@ -867,6 +870,7 @@ static void rcu_exp_handler(void *unused)
867870
struct rcu_node *rnp = rdp->mynode;
868871
bool preempt_bh_enabled = !(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK));
869872

873+
ASSERT_EXCLUSIVE_WRITER_SCOPED(rdp->cpu_no_qs.b.exp);
870874
if (!(READ_ONCE(rnp->expmask) & rdp->grpmask) ||
871875
__this_cpu_read(rcu_data.cpu_no_qs.b.exp))
872876
return;

kernel/rcu/tree_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ static void rcu_preempt_ctxt_queue(struct rcu_node *rnp, struct rcu_data *rdp)
275275
rcu_report_exp_rdp(rdp);
276276
else
277277
WARN_ON_ONCE(rdp->cpu_no_qs.b.exp);
278+
ASSERT_EXCLUSIVE_WRITER_SCOPED(rdp->cpu_no_qs.b.exp);
278279
}
279280

280281
/*

0 commit comments

Comments
 (0)