rculist.h 24 KB

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