rculist.h 24 KB

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