Skip to content

Commit a542d11

Browse files
paulmckrcuurezki
authored andcommitted
rcu: Mark writes to rcu_sync ->gp_count field
The rcu_sync structure's ->gp_count field is updated under the protection of ->rss_lock, but read locklessly, and KCSAN noted the data race. This commit therefore uses WRITE_ONCE() to do this update to clearly document its racy nature. Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
1 parent c90b9e4 commit a542d11

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

kernel/rcu/sync.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void rcu_sync_enter(struct rcu_sync *rsp)
122122
* we are called at early boot time but this shouldn't happen.
123123
*/
124124
}
125-
rsp->gp_count++;
125+
WRITE_ONCE(rsp->gp_count, rsp->gp_count + 1);
126126
spin_unlock_irq(&rsp->rss_lock);
127127

128128
if (gp_state == GP_IDLE) {
@@ -151,11 +151,15 @@ void rcu_sync_enter(struct rcu_sync *rsp)
151151
*/
152152
void rcu_sync_exit(struct rcu_sync *rsp)
153153
{
154+
int gpc;
155+
154156
WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_IDLE);
155157
WARN_ON_ONCE(READ_ONCE(rsp->gp_count) == 0);
156158

157159
spin_lock_irq(&rsp->rss_lock);
158-
if (!--rsp->gp_count) {
160+
gpc = rsp->gp_count - 1;
161+
WRITE_ONCE(rsp->gp_count, gpc);
162+
if (!gpc) {
159163
if (rsp->gp_state == GP_PASSED) {
160164
WRITE_ONCE(rsp->gp_state, GP_EXIT);
161165
rcu_sync_call(rsp);

0 commit comments

Comments
 (0)