Linux RCU subsystem development
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	rostedt@goodmis.org, Zilin Guan <zilinguan811@gmail.com>,
	"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH rcu 2/5] rcu: Remove READ_ONCE() for rdp->gpwrap access in __note_gp_changes()
Date: Thu, 16 Jan 2025 12:05:40 -0800	[thread overview]
Message-ID: <20250116200543.3782539-2-paulmck@kernel.org> (raw)
In-Reply-To: <7b24a850-7d56-4386-8544-be5e643b6b9f@paulmck-laptop>

From: Zilin Guan <zilinguan811@gmail.com>

There is one access to the per-CPU rdp->gpwrap field in the
__note_gp_changes() function that does not use READ_ONCE(), but all other
accesses do use READ_ONCE().  When using the 8*TREE03 and CONFIG_NR_CPUS=8
configuration, KCSAN found no data races at that point.  This is because
all calls to __note_gp_changes() hold rnp->lock, which excludes writes
to the rdp->gpwrap fields for all CPUs associated with that same leaf
rcu_node structure.

This commit therefore removes READ_ONCE() from rdp->gpwrap accesses
within the __note_gp_changes() function.

Signed-off-by: Zilin Guan <zilinguan811@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 kernel/rcu/tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 229f427b8c821..e49bcb86b6d3c 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1275,7 +1275,7 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp)
 
 	/* Handle the ends of any preceding grace periods first. */
 	if (rcu_seq_completed_gp(rdp->gp_seq, rnp->gp_seq) ||
-	    unlikely(READ_ONCE(rdp->gpwrap))) {
+	    unlikely(rdp->gpwrap)) {
 		if (!offloaded)
 			ret = rcu_advance_cbs(rnp, rdp); /* Advance CBs. */
 		rdp->core_needs_qs = false;
@@ -1289,7 +1289,7 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp)
 
 	/* Now handle the beginnings of any new-to-this-CPU grace periods. */
 	if (rcu_seq_new_gp(rdp->gp_seq, rnp->gp_seq) ||
-	    unlikely(READ_ONCE(rdp->gpwrap))) {
+	    unlikely(rdp->gpwrap)) {
 		/*
 		 * If the current grace period is waiting for this CPU,
 		 * set up to detect a quiescent state, otherwise don't
@@ -1304,7 +1304,7 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp)
 	rdp->gp_seq = rnp->gp_seq;  /* Remember new grace-period state. */
 	if (ULONG_CMP_LT(rdp->gp_seq_needed, rnp->gp_seq_needed) || rdp->gpwrap)
 		WRITE_ONCE(rdp->gp_seq_needed, rnp->gp_seq_needed);
-	if (IS_ENABLED(CONFIG_PROVE_RCU) && READ_ONCE(rdp->gpwrap))
+	if (IS_ENABLED(CONFIG_PROVE_RCU) && rdp->gpwrap)
 		WRITE_ONCE(rdp->last_sched_clock, jiffies);
 	WRITE_ONCE(rdp->gpwrap, false);
 	rcu_gpnum_ovf(rnp, rdp);
-- 
2.40.1


  parent reply	other threads:[~2025-01-16 20:05 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16 20:05 [PATCH rcu 0/5] Miscellaneous fixes Paul E. McKenney
2025-01-16 20:05 ` [PATCH rcu 1/5] rcu: Split rcu_report_exp_cpu_mult() mask parameter and use for tracing Paul E. McKenney
2025-01-16 20:05 ` Paul E. McKenney [this message]
2025-01-16 20:05 ` [PATCH rcu 3/5] rcu: Fix get_state_synchronize_rcu_full() GP-start detection Paul E. McKenney
2025-01-16 20:05 ` [PATCH rcu 4/5] rcu-tasks: Move RCU Tasks self-tests to core_initcall() Paul E. McKenney
2025-01-16 20:05 ` [PATCH rcu 5/5] rcu/nocb: Print segment lengths in show_rcu_nocb_gp_state() Paul E. McKenney
2025-01-30 18:53 ` [PATCH rcu 0/5] Miscellaneous fixes Paul E. McKenney
2025-01-30 18:53   ` [PATCH rcu v2] 1/5] rcu: Split rcu_report_exp_cpu_mult() mask parameter and use for tracing Paul E. McKenney
2025-01-30 18:53   ` [PATCH rcu v2] 2/5] rcu: Remove READ_ONCE() for rdp->gpwrap access in __note_gp_changes() Paul E. McKenney
2025-01-30 18:53   ` [PATCH rcu v2] 3/5] rcu: Fix get_state_synchronize_rcu_full() GP-start detection Paul E. McKenney
2025-01-30 18:53   ` [PATCH rcu v2] 4/5] rcu-tasks: Move RCU Tasks self-tests to core_initcall() Paul E. McKenney
2025-02-04 10:26     ` Sebastian Andrzej Siewior
2025-02-04 11:51       ` Paul E. McKenney
2025-02-04 16:34         ` Sebastian Andrzej Siewior
2025-02-04 20:20           ` Paul E. McKenney
2025-02-05 14:50             ` Paul E. McKenney
2025-02-05 19:54               ` John Ogness
2025-02-05 20:10                 ` Paul E. McKenney
2025-02-05 20:31                   ` Paul E. McKenney
2025-02-05 21:22                     ` John Ogness
2025-02-05 21:55                       ` Paul E. McKenney
2025-02-05 22:20                         ` John Ogness
2025-02-05 22:31                           ` John Ogness
2025-02-05 23:50                             ` Paul E. McKenney
2025-02-06  8:28                               ` John Ogness
2025-02-06  9:58                                 ` Paul E. McKenney
2025-02-06  9:02                               ` Sebastian Andrzej Siewior
2025-02-06  9:59                                 ` Paul E. McKenney
2025-02-06 10:18                                   ` Paul E. McKenney
2025-02-06 11:06                               ` Petr Mladek
2025-02-06 16:32                                 ` Paul E. McKenney
2025-01-30 18:53   ` [PATCH rcu v2] 5/5] rcu/nocb: Print segment lengths in show_rcu_nocb_gp_state() Paul E. McKenney
2025-02-06 10:15   ` [PATCH rcu 6/5] Make RCU watch ct_kernel_exit_state() warning Paul E. McKenney
2025-02-06 17:38     ` Boqun Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250116200543.3782539-2-paulmck@kernel.org \
    --to=paulmck@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=zilinguan811@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox