]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/rculist.h
srcu: Add grace-period number to rcutorture statistics printout
[mirror_ubuntu-jammy-kernel.git] / include / linux / rculist.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
82524746
FBH
2#ifndef _LINUX_RCULIST_H
3#define _LINUX_RCULIST_H
4
5#ifdef __KERNEL__
6
7/*
8 * RCU-protected list version
9 */
10#include <linux/list.h>
10aa9d2c 11#include <linux/rcupdate.h>
82524746 12
65e6bf48
PM
13/*
14 * Why is there no list_empty_rcu()? Because list_empty() serves this
15 * purpose. The list_empty() function fetches the RCU-protected pointer
16 * and compares it to the address of the list head, but neither dereferences
17 * this pointer itself nor provides this pointer to the caller. Therefore,
18 * it is not necessary to use rcu_dereference(), so that list_empty() can
19 * be used anywhere you would want to use a list_empty_rcu().
20 */
21
2a855b64
PM
22/*
23 * INIT_LIST_HEAD_RCU - Initialize a list_head visible to RCU readers
24 * @list: list to be initialized
25 *
26 * You should instead use INIT_LIST_HEAD() for normal initialization and
27 * cleanup tasks, when readers have no access to the list being initialized.
28 * However, if the list being initialized is visible to readers, you
29 * need to keep the compiler from being too mischievous.
30 */
31static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
32{
7d0ae808
PM
33 WRITE_ONCE(list->next, list);
34 WRITE_ONCE(list->prev, list);
2a855b64
PM
35}
36
67bdbffd
AB
37/*
38 * return the ->next pointer of a list_head in an rcu safe
39 * way, we must not access it directly
40 */
41#define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next)))
42
82524746
FBH
43/*
44 * Insert a new entry between two known consecutive entries.
45 *
46 * This is only for internal list manipulation where we know
47 * the prev/next entries already!
48 */
49static inline void __list_add_rcu(struct list_head *new,
50 struct list_head *prev, struct list_head *next)
51{
54acd439
KC
52 if (!__list_add_valid(new, prev, next))
53 return;
54
82524746
FBH
55 new->next = next;
56 new->prev = prev;
67bdbffd 57 rcu_assign_pointer(list_next_rcu(prev), new);
82524746 58 next->prev = new;
82524746
FBH
59}
60
61/**
62 * list_add_rcu - add a new entry to rcu-protected list
63 * @new: new entry to be added
64 * @head: list head to add it after
65 *
66 * Insert a new entry after the specified head.
67 * This is good for implementing stacks.
68 *
69 * The caller must take whatever precautions are necessary
70 * (such as holding appropriate locks) to avoid racing
71 * with another list-mutation primitive, such as list_add_rcu()
72 * or list_del_rcu(), running on this same list.
73 * However, it is perfectly legal to run concurrently with
74 * the _rcu list-traversal primitives, such as
75 * list_for_each_entry_rcu().
76 */
77static inline void list_add_rcu(struct list_head *new, struct list_head *head)
78{
79 __list_add_rcu(new, head, head->next);
80}
81
82/**
83 * list_add_tail_rcu - add a new entry to rcu-protected list
84 * @new: new entry to be added
85 * @head: list head to add it before
86 *
87 * Insert a new entry before the specified head.
88 * This is useful for implementing queues.
89 *
90 * The caller must take whatever precautions are necessary
91 * (such as holding appropriate locks) to avoid racing
92 * with another list-mutation primitive, such as list_add_tail_rcu()
93 * or list_del_rcu(), running on this same list.
94 * However, it is perfectly legal to run concurrently with
95 * the _rcu list-traversal primitives, such as
96 * list_for_each_entry_rcu().
97 */
98static inline void list_add_tail_rcu(struct list_head *new,
99 struct list_head *head)
100{
101 __list_add_rcu(new, head->prev, head);
102}
103
104/**
105 * list_del_rcu - deletes entry from list without re-initialization
106 * @entry: the element to delete from the list.
107 *
108 * Note: list_empty() on entry does not return true after this,
109 * the entry is in an undefined state. It is useful for RCU based
110 * lockfree traversal.
111 *
112 * In particular, it means that we can not poison the forward
113 * pointers that may still be used for walking the list.
114 *
115 * The caller must take whatever precautions are necessary
116 * (such as holding appropriate locks) to avoid racing
117 * with another list-mutation primitive, such as list_del_rcu()
118 * or list_add_rcu(), running on this same list.
119 * However, it is perfectly legal to run concurrently with
120 * the _rcu list-traversal primitives, such as
121 * list_for_each_entry_rcu().
122 *
123 * Note that the caller is not permitted to immediately free
124 * the newly deleted entry. Instead, either synchronize_rcu()
125 * or call_rcu() must be used to defer freeing until an RCU
126 * grace period has elapsed.
127 */
128static inline void list_del_rcu(struct list_head *entry)
129{
559f9bad 130 __list_del_entry(entry);
82524746
FBH
131 entry->prev = LIST_POISON2;
132}
133
6beeac76
AA
134/**
135 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
136 * @n: the element to delete from the hash list.
137 *
138 * Note: list_unhashed() on the node return true after this. It is
139 * useful for RCU based read lockfree traversal if the writer side
140 * must know if the list entry is still hashed or already unhashed.
141 *
142 * In particular, it means that we can not poison the forward pointers
143 * that may still be used for walking the hash list and we can only
144 * zero the pprev pointer so list_unhashed() will return true after
145 * this.
146 *
147 * The caller must take whatever precautions are necessary (such as
148 * holding appropriate locks) to avoid racing with another
149 * list-mutation primitive, such as hlist_add_head_rcu() or
150 * hlist_del_rcu(), running on this same list. However, it is
151 * perfectly legal to run concurrently with the _rcu list-traversal
152 * primitives, such as hlist_for_each_entry_rcu().
153 */
154static inline void hlist_del_init_rcu(struct hlist_node *n)
155{
156 if (!hlist_unhashed(n)) {
157 __hlist_del(n);
158 n->pprev = NULL;
159 }
160}
161
82524746
FBH
162/**
163 * list_replace_rcu - replace old entry by new one
164 * @old : the element to be replaced
165 * @new : the new element to insert
166 *
167 * The @old entry will be replaced with the @new entry atomically.
168 * Note: @old should not be empty.
169 */
170static inline void list_replace_rcu(struct list_head *old,
171 struct list_head *new)
172{
173 new->next = old->next;
174 new->prev = old->prev;
67bdbffd 175 rcu_assign_pointer(list_next_rcu(new->prev), new);
82524746 176 new->next->prev = new;
82524746
FBH
177 old->prev = LIST_POISON2;
178}
179
180/**
7d86dccf 181 * __list_splice_init_rcu - join an RCU-protected list into an existing list.
82524746 182 * @list: the RCU-protected list to splice
7d86dccf
PM
183 * @prev: points to the last element of the existing list
184 * @next: points to the first element of the existing list
82524746
FBH
185 * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ...
186 *
7d86dccf
PM
187 * The list pointed to by @prev and @next can be RCU-read traversed
188 * concurrently with this function.
82524746
FBH
189 *
190 * Note that this function blocks.
191 *
7d86dccf
PM
192 * Important note: the caller must take whatever action is necessary to prevent
193 * any other updates to the existing list. In principle, it is possible to
194 * modify the list as soon as sync() begins execution. If this sort of thing
195 * becomes necessary, an alternative version based on call_rcu() could be
196 * created. But only if -really- needed -- there is no shortage of RCU API
197 * members.
82524746 198 */
7d86dccf
PM
199static inline void __list_splice_init_rcu(struct list_head *list,
200 struct list_head *prev,
201 struct list_head *next,
202 void (*sync)(void))
82524746
FBH
203{
204 struct list_head *first = list->next;
205 struct list_head *last = list->prev;
82524746 206
2a855b64
PM
207 /*
208 * "first" and "last" tracking list, so initialize it. RCU readers
209 * have access to this list, so we must use INIT_LIST_HEAD_RCU()
210 * instead of INIT_LIST_HEAD().
211 */
82524746 212
2a855b64 213 INIT_LIST_HEAD_RCU(list);
82524746
FBH
214
215 /*
216 * At this point, the list body still points to the source list.
217 * Wait for any readers to finish using the list before splicing
218 * the list body into the new list. Any new readers will see
219 * an empty list.
220 */
221
222 sync();
223
224 /*
225 * Readers are finished with the source list, so perform splice.
226 * The order is important if the new list is global and accessible
227 * to concurrent RCU readers. Note that RCU readers are not
228 * permitted to traverse the prev pointers without excluding
229 * this function.
230 */
231
7d86dccf
PM
232 last->next = next;
233 rcu_assign_pointer(list_next_rcu(prev), first);
234 first->prev = prev;
235 next->prev = last;
236}
237
238/**
239 * list_splice_init_rcu - splice an RCU-protected list into an existing list,
240 * designed for stacks.
241 * @list: the RCU-protected list to splice
242 * @head: the place in the existing list to splice the first list into
243 * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ...
244 */
245static inline void list_splice_init_rcu(struct list_head *list,
246 struct list_head *head,
247 void (*sync)(void))
248{
249 if (!list_empty(list))
250 __list_splice_init_rcu(list, head, head->next, sync);
251}
252
253/**
254 * list_splice_tail_init_rcu - splice an RCU-protected list into an existing
255 * list, designed for queues.
256 * @list: the RCU-protected list to splice
257 * @head: the place in the existing list to splice the first list into
258 * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ...
259 */
260static inline void list_splice_tail_init_rcu(struct list_head *list,
261 struct list_head *head,
262 void (*sync)(void))
263{
264 if (!list_empty(list))
265 __list_splice_init_rcu(list, head->prev, head, sync);
82524746
FBH
266}
267
72c6a987
JP
268/**
269 * list_entry_rcu - get the struct for this entry
270 * @ptr: the &struct list_head pointer.
271 * @type: the type of the struct this is embedded in.
3943f42c 272 * @member: the name of the list_head within the struct.
72c6a987
JP
273 *
274 * This primitive may safely run concurrently with the _rcu list-mutation
275 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
276 */
277#define list_entry_rcu(ptr, type, member) \
506458ef 278 container_of(READ_ONCE(ptr), type, member)
72c6a987 279
27fdb35f 280/*
f88022a4
MM
281 * Where are list_empty_rcu() and list_first_entry_rcu()?
282 *
283 * Implementing those functions following their counterparts list_empty() and
284 * list_first_entry() is not advisable because they lead to subtle race
285 * conditions as the following snippet shows:
286 *
287 * if (!list_empty_rcu(mylist)) {
288 * struct foo *bar = list_first_entry_rcu(mylist, struct foo, list_member);
289 * do_something(bar);
290 * }
291 *
292 * The list may not be empty when list_empty_rcu checks it, but it may be when
293 * list_first_entry_rcu rereads the ->next pointer.
294 *
295 * Rereading the ->next pointer is not a problem for list_empty() and
296 * list_first_entry() because they would be protected by a lock that blocks
297 * writers.
298 *
299 * See list_first_or_null_rcu for an alternative.
300 */
301
302/**
303 * list_first_or_null_rcu - get the first element from a list
72c6a987
JP
304 * @ptr: the list head to take the element from.
305 * @type: the type of the struct this is embedded in.
3943f42c 306 * @member: the name of the list_head within the struct.
72c6a987 307 *
f88022a4 308 * Note that if the list is empty, it returns NULL.
72c6a987
JP
309 *
310 * This primitive may safely run concurrently with the _rcu list-mutation
311 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
312 */
f88022a4 313#define list_first_or_null_rcu(ptr, type, member) \
0adab9b9
JP
314({ \
315 struct list_head *__ptr = (ptr); \
7d0ae808 316 struct list_head *__next = READ_ONCE(__ptr->next); \
0adab9b9
JP
317 likely(__ptr != __next) ? list_entry_rcu(__next, type, member) : NULL; \
318})
72c6a987 319
ff3c44e6
TH
320/**
321 * list_next_or_null_rcu - get the first element from a list
322 * @head: the head for the list.
323 * @ptr: the list head to take the next element from.
324 * @type: the type of the struct this is embedded in.
325 * @member: the name of the list_head within the struct.
326 *
327 * Note that if the ptr is at the end of the list, NULL is returned.
328 *
329 * This primitive may safely run concurrently with the _rcu list-mutation
330 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
331 */
332#define list_next_or_null_rcu(head, ptr, type, member) \
333({ \
334 struct list_head *__head = (head); \
335 struct list_head *__ptr = (ptr); \
336 struct list_head *__next = READ_ONCE(__ptr->next); \
337 likely(__next != __head) ? list_entry_rcu(__next, type, \
338 member) : NULL; \
339})
340
82524746
FBH
341/**
342 * list_for_each_entry_rcu - iterate over rcu list of given type
343 * @pos: the type * to use as a loop cursor.
344 * @head: the head for your list.
3943f42c 345 * @member: the name of the list_head within the struct.
82524746
FBH
346 *
347 * This list-traversal primitive may safely run concurrently with
348 * the _rcu list-mutation primitives such as list_add_rcu()
349 * as long as the traversal is guarded by rcu_read_lock().
350 */
351#define list_for_each_entry_rcu(pos, head, member) \
72c6a987 352 for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \
e66eed65 353 &pos->member != (head); \
72c6a987 354 pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
82524746 355
69b90729
AK
356/**
357 * list_entry_lockless - get the struct for this entry
358 * @ptr: the &struct list_head pointer.
359 * @type: the type of the struct this is embedded in.
360 * @member: the name of the list_head within the struct.
361 *
362 * This primitive may safely run concurrently with the _rcu list-mutation
363 * primitives such as list_add_rcu(), but requires some implicit RCU
364 * read-side guarding. One example is running within a special
365 * exception-time environment where preemption is disabled and where
366 * lockdep cannot be invoked (in which case updaters must use RCU-sched,
367 * as in synchronize_sched(), call_rcu_sched(), and friends). Another
368 * example is when items are added to the list, but never deleted.
369 */
370#define list_entry_lockless(ptr, type, member) \
506458ef 371 container_of((typeof(ptr))READ_ONCE(ptr), type, member)
69b90729
AK
372
373/**
374 * list_for_each_entry_lockless - iterate over rcu list of given type
375 * @pos: the type * to use as a loop cursor.
376 * @head: the head for your list.
377 * @member: the name of the list_struct within the struct.
378 *
379 * This primitive may safely run concurrently with the _rcu list-mutation
380 * primitives such as list_add_rcu(), but requires some implicit RCU
381 * read-side guarding. One example is running within a special
382 * exception-time environment where preemption is disabled and where
383 * lockdep cannot be invoked (in which case updaters must use RCU-sched,
384 * as in synchronize_sched(), call_rcu_sched(), and friends). Another
385 * example is when items are added to the list, but never deleted.
386 */
387#define list_for_each_entry_lockless(pos, head, member) \
388 for (pos = list_entry_lockless((head)->next, typeof(*pos), member); \
389 &pos->member != (head); \
390 pos = list_entry_lockless(pos->member.next, typeof(*pos), member))
391
254245d2 392/**
393 * list_for_each_entry_continue_rcu - continue iteration over list of given type
394 * @pos: the type * to use as a loop cursor.
395 * @head: the head for your list.
3943f42c 396 * @member: the name of the list_head within the struct.
254245d2 397 *
398 * Continue to iterate over list of given type, continuing after
399 * the current position.
400 */
401#define list_for_each_entry_continue_rcu(pos, head, member) \
402 for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \
e66eed65 403 &pos->member != (head); \
254245d2 404 pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
405
ead9ad72
N
406/**
407 * list_for_each_entry_from_rcu - iterate over a list from current point
408 * @pos: the type * to use as a loop cursor.
409 * @head: the head for your list.
410 * @member: the name of the list_node within the struct.
411 *
412 * Iterate over the tail of a list starting from a given position,
413 * which must have been in the list when the RCU read lock was taken.
414 */
415#define list_for_each_entry_from_rcu(pos, head, member) \
416 for (; &(pos)->member != (head); \
417 pos = list_entry_rcu(pos->member.next, typeof(*(pos)), member))
418
82524746
FBH
419/**
420 * hlist_del_rcu - deletes entry from hash list without re-initialization
421 * @n: the element to delete from the hash list.
422 *
423 * Note: list_unhashed() on entry does not return true after this,
424 * the entry is in an undefined state. It is useful for RCU based
425 * lockfree traversal.
426 *
427 * In particular, it means that we can not poison the forward
428 * pointers that may still be used for walking the hash list.
429 *
430 * The caller must take whatever precautions are necessary
431 * (such as holding appropriate locks) to avoid racing
432 * with another list-mutation primitive, such as hlist_add_head_rcu()
433 * or hlist_del_rcu(), running on this same list.
434 * However, it is perfectly legal to run concurrently with
435 * the _rcu list-traversal primitives, such as
436 * hlist_for_each_entry().
437 */
438static inline void hlist_del_rcu(struct hlist_node *n)
439{
440 __hlist_del(n);
441 n->pprev = LIST_POISON2;
442}
443
444/**
445 * hlist_replace_rcu - replace old entry by new one
446 * @old : the element to be replaced
447 * @new : the new element to insert
448 *
449 * The @old entry will be replaced with the @new entry atomically.
450 */
451static inline void hlist_replace_rcu(struct hlist_node *old,
452 struct hlist_node *new)
453{
454 struct hlist_node *next = old->next;
455
456 new->next = next;
457 new->pprev = old->pprev;
67bdbffd 458 rcu_assign_pointer(*(struct hlist_node __rcu **)new->pprev, new);
82524746
FBH
459 if (next)
460 new->next->pprev = &new->next;
82524746
FBH
461 old->pprev = LIST_POISON2;
462}
463
67bdbffd
AB
464/*
465 * return the first or the next element in an RCU protected hlist
466 */
467#define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first)))
468#define hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next)))
469#define hlist_pprev_rcu(node) (*((struct hlist_node __rcu **)((node)->pprev)))
470
82524746
FBH
471/**
472 * hlist_add_head_rcu
473 * @n: the element to add to the hash list.
474 * @h: the list to add to.
475 *
476 * Description:
477 * Adds the specified element to the specified hlist,
478 * while permitting racing traversals.
479 *
480 * The caller must take whatever precautions are necessary
481 * (such as holding appropriate locks) to avoid racing
482 * with another list-mutation primitive, such as hlist_add_head_rcu()
483 * or hlist_del_rcu(), running on this same list.
484 * However, it is perfectly legal to run concurrently with
485 * the _rcu list-traversal primitives, such as
486 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
487 * problems on Alpha CPUs. Regardless of the type of CPU, the
488 * list-traversal primitive must be guarded by rcu_read_lock().
489 */
490static inline void hlist_add_head_rcu(struct hlist_node *n,
491 struct hlist_head *h)
492{
493 struct hlist_node *first = h->first;
10aa9d2c 494
82524746
FBH
495 n->next = first;
496 n->pprev = &h->first;
67bdbffd 497 rcu_assign_pointer(hlist_first_rcu(h), n);
82524746
FBH
498 if (first)
499 first->pprev = &n->next;
82524746
FBH
500}
501
1602f49b
DM
502/**
503 * hlist_add_tail_rcu
504 * @n: the element to add to the hash list.
505 * @h: the list to add to.
506 *
507 * Description:
508 * Adds the specified element to the specified hlist,
509 * while permitting racing traversals.
510 *
511 * The caller must take whatever precautions are necessary
512 * (such as holding appropriate locks) to avoid racing
513 * with another list-mutation primitive, such as hlist_add_head_rcu()
514 * or hlist_del_rcu(), running on this same list.
515 * However, it is perfectly legal to run concurrently with
516 * the _rcu list-traversal primitives, such as
517 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
518 * problems on Alpha CPUs. Regardless of the type of CPU, the
519 * list-traversal primitive must be guarded by rcu_read_lock().
520 */
521static inline void hlist_add_tail_rcu(struct hlist_node *n,
522 struct hlist_head *h)
523{
524 struct hlist_node *i, *last = NULL;
525
48ac3466
MT
526 /* Note: write side code, so rcu accessors are not needed. */
527 for (i = h->first; i; i = i->next)
1602f49b
DM
528 last = i;
529
530 if (last) {
531 n->next = last->next;
532 n->pprev = &last->next;
533 rcu_assign_pointer(hlist_next_rcu(last), n);
534 } else {
535 hlist_add_head_rcu(n, h);
536 }
537}
538
82524746
FBH
539/**
540 * hlist_add_before_rcu
541 * @n: the new element to add to the hash list.
542 * @next: the existing element to add the new element before.
543 *
544 * Description:
545 * Adds the specified element to the specified hlist
546 * before the specified node while permitting racing traversals.
547 *
548 * The caller must take whatever precautions are necessary
549 * (such as holding appropriate locks) to avoid racing
550 * with another list-mutation primitive, such as hlist_add_head_rcu()
551 * or hlist_del_rcu(), running on this same list.
552 * However, it is perfectly legal to run concurrently with
553 * the _rcu list-traversal primitives, such as
554 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
555 * problems on Alpha CPUs.
556 */
557static inline void hlist_add_before_rcu(struct hlist_node *n,
558 struct hlist_node *next)
559{
560 n->pprev = next->pprev;
561 n->next = next;
67bdbffd 562 rcu_assign_pointer(hlist_pprev_rcu(n), n);
82524746 563 next->pprev = &n->next;
82524746
FBH
564}
565
566/**
1d023284 567 * hlist_add_behind_rcu
82524746 568 * @n: the new element to add to the hash list.
1d023284 569 * @prev: the existing element to add the new element after.
82524746
FBH
570 *
571 * Description:
572 * Adds the specified element to the specified hlist
573 * after the specified node while permitting racing traversals.
574 *
575 * The caller must take whatever precautions are necessary
576 * (such as holding appropriate locks) to avoid racing
577 * with another list-mutation primitive, such as hlist_add_head_rcu()
578 * or hlist_del_rcu(), running on this same list.
579 * However, it is perfectly legal to run concurrently with
580 * the _rcu list-traversal primitives, such as
581 * hlist_for_each_entry_rcu(), used to prevent memory-consistency
582 * problems on Alpha CPUs.
583 */
1d023284
KH
584static inline void hlist_add_behind_rcu(struct hlist_node *n,
585 struct hlist_node *prev)
82524746
FBH
586{
587 n->next = prev->next;
588 n->pprev = &prev->next;
67bdbffd 589 rcu_assign_pointer(hlist_next_rcu(prev), n);
82524746
FBH
590 if (n->next)
591 n->next->pprev = &n->next;
592}
593
67bdbffd
AB
594#define __hlist_for_each_rcu(pos, head) \
595 for (pos = rcu_dereference(hlist_first_rcu(head)); \
75d65a42 596 pos; \
67bdbffd 597 pos = rcu_dereference(hlist_next_rcu(pos)))
1cc52327 598
82524746
FBH
599/**
600 * hlist_for_each_entry_rcu - iterate over rcu list of given type
b67bfe0d 601 * @pos: the type * to use as a loop cursor.
82524746
FBH
602 * @head: the head for your list.
603 * @member: the name of the hlist_node within the struct.
604 *
605 * This list-traversal primitive may safely run concurrently with
606 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
607 * as long as the traversal is guarded by rcu_read_lock().
608 */
b67bfe0d
SL
609#define hlist_for_each_entry_rcu(pos, head, member) \
610 for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\
611 typeof(*(pos)), member); \
612 pos; \
613 pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\
614 &(pos)->member)), typeof(*(pos)), member))
82524746 615
12bcbe66
SR
616/**
617 * hlist_for_each_entry_rcu_notrace - iterate over rcu list of given type (for tracing)
618 * @pos: the type * to use as a loop cursor.
619 * @head: the head for your list.
620 * @member: the name of the hlist_node within the struct.
621 *
622 * This list-traversal primitive may safely run concurrently with
623 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
624 * as long as the traversal is guarded by rcu_read_lock().
625 *
626 * This is the same as hlist_for_each_entry_rcu() except that it does
627 * not do any RCU debugging or tracing.
628 */
629#define hlist_for_each_entry_rcu_notrace(pos, head, member) \
630 for (pos = hlist_entry_safe (rcu_dereference_raw_notrace(hlist_first_rcu(head)),\
631 typeof(*(pos)), member); \
632 pos; \
633 pos = hlist_entry_safe(rcu_dereference_raw_notrace(hlist_next_rcu(\
634 &(pos)->member)), typeof(*(pos)), member))
635
4f70ecca
ED
636/**
637 * hlist_for_each_entry_rcu_bh - iterate over rcu list of given type
b67bfe0d 638 * @pos: the type * to use as a loop cursor.
4f70ecca
ED
639 * @head: the head for your list.
640 * @member: the name of the hlist_node within the struct.
641 *
642 * This list-traversal primitive may safely run concurrently with
643 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
644 * as long as the traversal is guarded by rcu_read_lock().
645 */
b67bfe0d
SL
646#define hlist_for_each_entry_rcu_bh(pos, head, member) \
647 for (pos = hlist_entry_safe(rcu_dereference_bh(hlist_first_rcu(head)),\
648 typeof(*(pos)), member); \
649 pos; \
650 pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu(\
651 &(pos)->member)), typeof(*(pos)), member))
4f70ecca 652
5c578aed 653/**
654 * hlist_for_each_entry_continue_rcu - iterate over a hlist continuing after current point
b67bfe0d 655 * @pos: the type * to use as a loop cursor.
5c578aed 656 * @member: the name of the hlist_node within the struct.
657 */
b67bfe0d 658#define hlist_for_each_entry_continue_rcu(pos, member) \
f520c98e
YX
659 for (pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \
660 &(pos)->member)), typeof(*(pos)), member); \
b67bfe0d 661 pos; \
f520c98e
YX
662 pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \
663 &(pos)->member)), typeof(*(pos)), member))
5c578aed 664
4f70ecca
ED
665/**
666 * hlist_for_each_entry_continue_rcu_bh - iterate over a hlist continuing after current point
b67bfe0d 667 * @pos: the type * to use as a loop cursor.
4f70ecca
ED
668 * @member: the name of the hlist_node within the struct.
669 */
b67bfe0d 670#define hlist_for_each_entry_continue_rcu_bh(pos, member) \
f520c98e
YX
671 for (pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu( \
672 &(pos)->member)), typeof(*(pos)), member); \
b67bfe0d 673 pos; \
f520c98e
YX
674 pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu( \
675 &(pos)->member)), typeof(*(pos)), member))
4f70ecca 676
97ede29e
YX
677/**
678 * hlist_for_each_entry_from_rcu - iterate over a hlist continuing from current point
679 * @pos: the type * to use as a loop cursor.
680 * @member: the name of the hlist_node within the struct.
681 */
682#define hlist_for_each_entry_from_rcu(pos, member) \
683 for (; pos; \
f517700c
YX
684 pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \
685 &(pos)->member)), typeof(*(pos)), member))
5c578aed 686
82524746
FBH
687#endif /* __KERNEL__ */
688#endif