]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rcu: Document rcu_access_pointer() feeding into cmpxchg()
authorPaul E. McKenney <paulmck@kernel.org>
Fri, 8 May 2026 17:43:53 +0000 (10:43 -0700)
committerUladzislau Rezki (Sony) <urezki@gmail.com>
Sun, 24 May 2026 07:40:02 +0000 (09:40 +0200)
This commit documents the rcu_access_pointer() use case for fetching the
old value of an RCU-protected pointer within a lockless updater for use
by an atomic cmpxchg() operation.

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Reported-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
include/linux/rcupdate.h

index bfa765132de858227563c92e052d3b34c44e87f5..5e95acc33989b64ea76db7a9dd0749aae1a56e6c 100644 (file)
@@ -592,11 +592,13 @@ context_unsafe(                                                         \
  * lockdep checks for being in an RCU read-side critical section.  This is
  * useful when the value of this pointer is accessed, but the pointer is
  * not dereferenced, for example, when testing an RCU-protected pointer
- * against NULL.  Although rcu_access_pointer() may also be used in cases
- * where update-side locks prevent the value of the pointer from changing,
- * you should instead use rcu_dereference_protected() for this use case.
- * Within an RCU read-side critical section, there is little reason to
- * use rcu_access_pointer().
+ * against NULL.  Within an RCU read-side critical section, there is little
+ * reason to use rcu_access_pointer().  Although rcu_access_pointer() may
+ * also be used in cases where update-side locks prevent the value of the
+ * pointer from changing, you should instead use rcu_dereference_protected()
+ * for this use case.  It is also permissible to use rcu_access_pointer()
+ * within lockless updaters to obtain the old value for an atomic operation,
+ * for example, for cmpxchg().
  *
  * It is usually best to test the rcu_access_pointer() return value
  * directly in order to avoid accidental dereferences being introduced