Skip to content

Commit 7104260

Browse files
committed
srcu: Hold srcu_struct ->lock when updating ->srcu_gp_seq
A read of the srcu_struct structure's ->srcu_gp_seq field should not need READ_ONCE() when that structure's ->lock is held. Except that this lock is not always held when updating this field. This commit therefore acquires the lock around updates and removes a now-unneeded READ_ONCE(). This data race was reported by KCSAN. Signed-off-by: Paul E. McKenney <[email protected]> [ paulmck: Switch from READ_ONCE() to lock per Peter Zilstra question. ] Acked-by: Peter Zijlstra (Intel) <[email protected]>
1 parent 39f9150 commit 7104260

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/rcu/srcutree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static void srcu_gp_start(struct srcu_struct *ssp)
450450
spin_unlock_rcu_node(sdp); /* Interrupts remain disabled. */
451451
smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */
452452
rcu_seq_start(&ssp->srcu_gp_seq);
453-
state = rcu_seq_state(READ_ONCE(ssp->srcu_gp_seq));
453+
state = rcu_seq_state(ssp->srcu_gp_seq);
454454
WARN_ON_ONCE(state != SRCU_STATE_SCAN1);
455455
}
456456

@@ -1130,7 +1130,9 @@ static void srcu_advance_state(struct srcu_struct *ssp)
11301130
return; /* readers present, retry later. */
11311131
}
11321132
srcu_flip(ssp);
1133+
spin_lock_irq_rcu_node(ssp);
11331134
rcu_seq_set_state(&ssp->srcu_gp_seq, SRCU_STATE_SCAN2);
1135+
spin_unlock_irq_rcu_node(ssp);
11341136
}
11351137

11361138
if (rcu_seq_state(READ_ONCE(ssp->srcu_gp_seq)) == SRCU_STATE_SCAN2) {

0 commit comments

Comments
 (0)