RCU Archive mirror
 help / color / mirror / Atom feed
From: Alan Huang <mmpgouride@gmail.com>
To: paulmck@kernel.org, frederic@kernel.org,
	neeraj.upadhyay@kernel.org, joel@joelfernandes.org,
	josh@joshtriplett.org, boqun.feng@gmail.com, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com,
	qiang.zhang1211@gmail.com
Cc: rcu@vger.kernel.org, Alan Huang <mmpgouride@gmail.com>
Subject: [PATCH] rcu: Remove unnecessary READ_ONCE in rcu_preempt_read_enter/exit
Date: Sun, 31 Mar 2024 09:19:32 +0000	[thread overview]
Message-ID: <20240331091932.129617-1-mmpgouride@gmail.com> (raw)

The two READ_ONCEs here imply that there might be updater concurrently
modifies rcu_read_lock_nesting, although it's true there could be
interrupt handlers enter rcu RSCS, but rcu_read_lock_nesting should
remain unchanged after they finished. That is, READ_ONCE and then
WRITE_ONCE the same variable is not a valid pattern, this patch thus
removes the two READ_ONCEs.

Signed-off-by: Alan Huang <mmpgouride@gmail.com>
---
 kernel/rcu/tree_plugin.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 340bbefe5f65..c90edbb7fa40 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -376,12 +376,12 @@ static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
 
 static void rcu_preempt_read_enter(void)
 {
-	WRITE_ONCE(current->rcu_read_lock_nesting, READ_ONCE(current->rcu_read_lock_nesting) + 1);
+	WRITE_ONCE(current->rcu_read_lock_nesting, current->rcu_read_lock_nesting + 1);
 }
 
 static int rcu_preempt_read_exit(void)
 {
-	int ret = READ_ONCE(current->rcu_read_lock_nesting) - 1;
+	int ret = current->rcu_read_lock_nesting - 1;
 
 	WRITE_ONCE(current->rcu_read_lock_nesting, ret);
 	return ret;
-- 
2.34.1


             reply	other threads:[~2024-03-31  9:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-31  9:19 Alan Huang [this message]
2024-04-09 20:10 ` [PATCH] rcu: Remove unnecessary READ_ONCE in rcu_preempt_read_enter/exit Paul E. McKenney

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=20240331091932.129617-1-mmpgouride@gmail.com \
    --to=mmpgouride@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=qiang.zhang1211@gmail.com \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).