Skip to content

Commit 62ae195

Browse files
committed
rcu: Mark rcu_state.gp_seq to detect more concurrent writes
The rcu_state structure's gp_seq field is only to be modified by the RCU grace-period kthread, which is single-threaded. This commit therefore enlists KCSAN's help in enforcing this restriction. This commit applies KCSAN-specific primitives, so cannot go upstream until KCSAN does. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent c28d5c0 commit 62ae195

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/rcu/tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ static bool rcu_start_this_gp(struct rcu_node *rnp_start, struct rcu_data *rdp,
12301230
trace_rcu_this_gp(rnp, rdp, gp_seq_req, TPS("NoGPkthread"));
12311231
goto unlock_out;
12321232
}
1233-
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("newreq"));
1233+
trace_rcu_grace_period(rcu_state.name, data_race(rcu_state.gp_seq), TPS("newreq"));
12341234
ret = true; /* Caller must wake GP kthread. */
12351235
unlock_out:
12361236
/* Push furthest requested GP to leaf node and rcu_data structure. */
@@ -1519,6 +1519,7 @@ static bool rcu_gp_init(void)
15191519
record_gp_stall_check_time();
15201520
/* Record GP times before starting GP, hence rcu_seq_start(). */
15211521
rcu_seq_start(&rcu_state.gp_seq);
1522+
ASSERT_EXCLUSIVE_WRITER(rcu_state.gp_seq);
15221523
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("start"));
15231524
raw_spin_unlock_irq_rcu_node(rnp);
15241525

@@ -1805,6 +1806,7 @@ static void rcu_gp_cleanup(void)
18051806
/* Declare grace period done, trace first to use old GP number. */
18061807
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("end"));
18071808
rcu_seq_end(&rcu_state.gp_seq);
1809+
ASSERT_EXCLUSIVE_WRITER(rcu_state.gp_seq);
18081810
rcu_state.gp_state = RCU_GP_IDLE;
18091811
/* Check for GP requests since above loop. */
18101812
rdp = this_cpu_ptr(&rcu_data);

0 commit comments

Comments
 (0)