Skip to content

Commit 0f11ad3

Browse files
committed
rcu: Mark rcu_state.gp_seq to detect 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. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 3d05031 commit 0f11ad3

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

kernel/rcu/tree.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ static bool rcu_start_this_gp(struct rcu_node *rnp_start, struct rcu_data *rdp,
12091209
trace_rcu_this_gp(rnp, rdp, gp_seq_req, TPS("NoGPkthread"));
12101210
goto unlock_out;
12111211
}
1212-
trace_rcu_grace_period(rcu_state.name, READ_ONCE(rcu_state.gp_seq), TPS("newreq"));
1212+
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("newreq"));
12131213
ret = true; /* Caller must wake GP kthread. */
12141214
unlock_out:
12151215
/* Push furthest requested GP to leaf node and rcu_data structure. */
@@ -1657,8 +1657,7 @@ static void rcu_gp_fqs_loop(void)
16571657
WRITE_ONCE(rcu_state.jiffies_kick_kthreads,
16581658
jiffies + (j ? 3 * j : 2));
16591659
}
1660-
trace_rcu_grace_period(rcu_state.name,
1661-
READ_ONCE(rcu_state.gp_seq),
1660+
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16621661
TPS("fqswait"));
16631662
rcu_state.gp_state = RCU_GP_WAIT_FQS;
16641663
ret = swait_event_idle_timeout_exclusive(
@@ -1672,13 +1671,11 @@ static void rcu_gp_fqs_loop(void)
16721671
/* If time for quiescent-state forcing, do it. */
16731672
if (ULONG_CMP_GE(jiffies, rcu_state.jiffies_force_qs) ||
16741673
(gf & RCU_GP_FLAG_FQS)) {
1675-
trace_rcu_grace_period(rcu_state.name,
1676-
READ_ONCE(rcu_state.gp_seq),
1674+
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16771675
TPS("fqsstart"));
16781676
rcu_gp_fqs(first_gp_fqs);
16791677
first_gp_fqs = false;
1680-
trace_rcu_grace_period(rcu_state.name,
1681-
READ_ONCE(rcu_state.gp_seq),
1678+
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16821679
TPS("fqsend"));
16831680
cond_resched_tasks_rcu_qs();
16841681
WRITE_ONCE(rcu_state.gp_activity, jiffies);
@@ -1689,8 +1686,7 @@ static void rcu_gp_fqs_loop(void)
16891686
cond_resched_tasks_rcu_qs();
16901687
WRITE_ONCE(rcu_state.gp_activity, jiffies);
16911688
WARN_ON(signal_pending(current));
1692-
trace_rcu_grace_period(rcu_state.name,
1693-
READ_ONCE(rcu_state.gp_seq),
1689+
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16941690
TPS("fqswaitsig"));
16951691
ret = 1; /* Keep old FQS timing. */
16961692
j = jiffies;
@@ -1782,7 +1778,7 @@ static void rcu_gp_cleanup(void)
17821778
WRITE_ONCE(rcu_state.gp_flags, RCU_GP_FLAG_INIT);
17831779
WRITE_ONCE(rcu_state.gp_req_activity, jiffies);
17841780
trace_rcu_grace_period(rcu_state.name,
1785-
READ_ONCE(rcu_state.gp_seq),
1781+
rcu_state.gp_seq,
17861782
TPS("newreq"));
17871783
} else {
17881784
WRITE_ONCE(rcu_state.gp_flags,
@@ -1801,8 +1797,7 @@ static int __noreturn rcu_gp_kthread(void *unused)
18011797

18021798
/* Handle grace-period start. */
18031799
for (;;) {
1804-
trace_rcu_grace_period(rcu_state.name,
1805-
READ_ONCE(rcu_state.gp_seq),
1800+
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
18061801
TPS("reqwait"));
18071802
rcu_state.gp_state = RCU_GP_WAIT_GPS;
18081803
swait_event_idle_exclusive(rcu_state.gp_wq,
@@ -1815,8 +1810,7 @@ static int __noreturn rcu_gp_kthread(void *unused)
18151810
cond_resched_tasks_rcu_qs();
18161811
WRITE_ONCE(rcu_state.gp_activity, jiffies);
18171812
WARN_ON(signal_pending(current));
1818-
trace_rcu_grace_period(rcu_state.name,
1819-
READ_ONCE(rcu_state.gp_seq),
1813+
trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
18201814
TPS("reqwaitsig"));
18211815
}
18221816

0 commit comments

Comments
 (0)