From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
rostedt@goodmis.org, "Paul E. McKenney" <paulmck@kernel.org>
Subject: [PATCH rcu 5/7] doc: Update rcu_access_pointer() advice in rcu_dereference.rst
Date: Wed, 31 Aug 2022 11:06:23 -0700 [thread overview]
Message-ID: <20220831180625.2692892-5-paulmck@kernel.org> (raw)
In-Reply-To: <20220831180617.GA2692480@paulmck-ThinkPad-P17-Gen-1>
This commit updates the rcu_access_pointer() advice, noting that its
return value should not be assigned to a local variable, and also noting
that there is little point in using rcu_access_pointer() within an RCU
read-side critical section.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
Documentation/RCU/rcu_dereference.rst | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/Documentation/RCU/rcu_dereference.rst b/Documentation/RCU/rcu_dereference.rst
index 0b418a5b243c5..81e828c8313b8 100644
--- a/Documentation/RCU/rcu_dereference.rst
+++ b/Documentation/RCU/rcu_dereference.rst
@@ -128,10 +128,16 @@ Follow these rules to keep your RCU code working properly:
This sort of comparison occurs frequently when scanning
RCU-protected circular linked lists.
- Note that if checks for being within an RCU read-side
- critical section are not required and the pointer is never
- dereferenced, rcu_access_pointer() should be used in place
- of rcu_dereference().
+ Note that if the pointer comparison is done outside
+ of an RCU read-side critical section, and the pointer
+ is never dereferenced, rcu_access_pointer() should be
+ used in place of rcu_dereference(). In most cases,
+ it is best to avoid accidental dereferences by testing
+ the rcu_access_pointer() return value directly, without
+ assigning it to a variable.
+
+ Within an RCU read-side critical section, there is little
+ reason to use rcu_access_pointer().
- The comparison is against a pointer that references memory
that was initialized "a long time ago." The reason
--
2.31.1.189.g2e36527f23
next prev parent reply other threads:[~2022-08-31 18:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 18:06 [PATCH rcu 0/7] RCU documentation updates for v6.1 Paul E. McKenney
2022-08-31 18:06 ` [PATCH rcu 1/7] doc: Emphasize the need for explicit RCU read-side markers Paul E. McKenney
2022-08-31 18:06 ` [PATCH rcu 2/7] doc: Call out queue_rcu_work() for blocking RCU callbacks Paul E. McKenney
2022-08-31 18:06 ` [PATCH rcu 3/7] doc: Use rcu_barrier() to rate-limit " Paul E. McKenney
2022-08-31 18:06 ` [PATCH rcu 4/7] doc: Fix list: rcu_access_pointer() is not lockdep-checked Paul E. McKenney
2022-08-31 18:06 ` Paul E. McKenney [this message]
2022-08-31 18:06 ` [PATCH rcu 6/7] doc: SLAB_TYPESAFE_BY_RCU uses cannot rely on spinlocks Paul E. McKenney
2022-08-31 18:06 ` [PATCH rcu 7/7] doc/rcu: Update LWN article URLs and add 2019 article 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=20220831180625.2692892-5-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®