Skip to content

Commit 4527106

Browse files
joelagnelpaulmckrcu
authored andcommitted
doc: Update list_for_each_entry_rcu() documentation
This commit updates the documentation with information about usage of lockdep with list_for_each_entry_rcu(). Signed-off-by: Joel Fernandes (Google) <[email protected]> [ paulmck: Wordsmithing. ] Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 71cb46a commit 4527106

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Documentation/RCU/lockdep.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@ other flavors of rcu_dereference(). On the other hand, it is illegal
9696
to use rcu_dereference_protected() if either the RCU-protected pointer
9797
or the RCU-protected data that it points to can change concurrently.
9898

99-
There are currently only "universal" versions of the rcu_assign_pointer()
100-
and RCU list-/tree-traversal primitives, which do not (yet) check for
101-
being in an RCU read-side critical section. In the future, separate
102-
versions of these primitives might be created.
99+
Like rcu_dereference(), when lockdep is enabled, RCU list and hlist
100+
traversal primitives check for being called from within an RCU read-side
101+
critical section. However, a lockdep expression can be passed to them
102+
as a additional optional argument. With this lockdep expression, these
103+
traversal primitives will complain only if the lockdep expression is
104+
false and they are called from outside any RCU read-side critical section.
105+
106+
For example, the workqueue for_each_pwq() macro is intended to be used
107+
either within an RCU read-side critical section or with wq->mutex held.
108+
It is thus implemented as follows:
109+
110+
#define for_each_pwq(pwq, wq)
111+
list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node,
112+
lock_is_held(&(wq->mutex).dep_map))

Documentation/RCU/whatisRCU.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ rcu_dereference()
290290
at any time, including immediately after the rcu_dereference().
291291
And, again like rcu_assign_pointer(), rcu_dereference() is
292292
typically used indirectly, via the _rcu list-manipulation
293-
primitives, such as list_for_each_entry_rcu().
293+
primitives, such as list_for_each_entry_rcu() [2].
294294

295295
[1] The variant rcu_dereference_protected() can be used outside
296296
of an RCU read-side critical section as long as the usage is
@@ -305,6 +305,14 @@ rcu_dereference()
305305
a lockdep splat is emitted. See Documentation/RCU/Design/Requirements/Requirements.rst
306306
and the API's code comments for more details and example usage.
307307

308+
[2] If the list_for_each_entry_rcu() instance might be used by
309+
update-side code as well as by RCU readers, then an additional
310+
lockdep expression can be added to its list of arguments.
311+
For example, given an additional "lock_is_held(&mylock)" argument,
312+
the RCU lockdep code would complain only if this instance was
313+
invoked outside of an RCU read-side critical section and without
314+
the protection of mylock.
315+
308316
The following diagram shows how each API communicates among the
309317
reader, updater, and reclaimer.
310318

0 commit comments

Comments
 (0)