rcupdate.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /*
  2. * Read-Copy Update mechanism for mutual exclusion
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright IBM Corporation, 2001
  19. *
  20. * Author: Dipankar Sarma <dipankar@in.ibm.com>
  21. *
  22. * Based on the original work by Paul McKenney <paulmck@us.ibm.com>
  23. * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
  24. * Papers:
  25. * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
  26. * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
  27. *
  28. * For detailed explanation of Read-Copy Update mechanism see -
  29. * http://lse.sourceforge.net/locking/rcupdate.html
  30. *
  31. */
  32. #ifndef __LINUX_RCUPDATE_H
  33. #define __LINUX_RCUPDATE_H
  34. #include <linux/cache.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/threads.h>
  37. #include <linux/cpumask.h>
  38. #include <linux/seqlock.h>
  39. #include <linux/lockdep.h>
  40. #include <linux/completion.h>
  41. #include <linux/debugobjects.h>
  42. #ifdef CONFIG_RCU_TORTURE_TEST
  43. extern int rcutorture_runnable; /* for sysctl */
  44. #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
  45. /**
  46. * struct rcu_head - callback structure for use with RCU
  47. * @next: next update requests in a list
  48. * @func: actual update function to call after the grace period.
  49. */
  50. struct rcu_head {
  51. struct rcu_head *next;
  52. void (*func)(struct rcu_head *head);
  53. };
  54. /* Exported common interfaces */
  55. extern void rcu_barrier(void);
  56. extern void rcu_barrier_bh(void);
  57. extern void rcu_barrier_sched(void);
  58. extern void synchronize_sched_expedited(void);
  59. extern int sched_expedited_torture_stats(char *page);
  60. /* Internal to kernel */
  61. extern void rcu_init(void);
  62. #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
  63. #include <linux/rcutree.h>
  64. #elif defined(CONFIG_TINY_RCU)
  65. #include <linux/rcutiny.h>
  66. #else
  67. #error "Unknown RCU implementation specified to kernel configuration"
  68. #endif
  69. #define RCU_HEAD_INIT { .next = NULL, .func = NULL }
  70. #define RCU_HEAD(head) struct rcu_head head = RCU_HEAD_INIT
  71. #define INIT_RCU_HEAD(ptr) do { \
  72. (ptr)->next = NULL; (ptr)->func = NULL; \
  73. } while (0)
  74. /*
  75. * init_rcu_head_on_stack()/destroy_rcu_head_on_stack() are needed for dynamic
  76. * initialization and destruction of rcu_head on the stack. rcu_head structures
  77. * allocated dynamically in the heap or defined statically don't need any
  78. * initialization.
  79. */
  80. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  81. extern void init_rcu_head_on_stack(struct rcu_head *head);
  82. extern void destroy_rcu_head_on_stack(struct rcu_head *head);
  83. #else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  84. static inline void init_rcu_head_on_stack(struct rcu_head *head)
  85. {
  86. }
  87. static inline void destroy_rcu_head_on_stack(struct rcu_head *head)
  88. {
  89. }
  90. #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  91. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  92. extern struct lockdep_map rcu_lock_map;
  93. # define rcu_read_acquire() \
  94. lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
  95. # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_)
  96. extern struct lockdep_map rcu_bh_lock_map;
  97. # define rcu_read_acquire_bh() \
  98. lock_acquire(&rcu_bh_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
  99. # define rcu_read_release_bh() lock_release(&rcu_bh_lock_map, 1, _THIS_IP_)
  100. extern struct lockdep_map rcu_sched_lock_map;
  101. # define rcu_read_acquire_sched() \
  102. lock_acquire(&rcu_sched_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
  103. # define rcu_read_release_sched() \
  104. lock_release(&rcu_sched_lock_map, 1, _THIS_IP_)
  105. extern int debug_lockdep_rcu_enabled(void);
  106. /**
  107. * rcu_read_lock_held - might we be in RCU read-side critical section?
  108. *
  109. * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU
  110. * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC,
  111. * this assumes we are in an RCU read-side critical section unless it can
  112. * prove otherwise.
  113. *
  114. * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
  115. * and while lockdep is disabled.
  116. */
  117. static inline int rcu_read_lock_held(void)
  118. {
  119. if (!debug_lockdep_rcu_enabled())
  120. return 1;
  121. return lock_is_held(&rcu_lock_map);
  122. }
  123. /*
  124. * rcu_read_lock_bh_held() is defined out of line to avoid #include-file
  125. * hell.
  126. */
  127. extern int rcu_read_lock_bh_held(void);
  128. /**
  129. * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section?
  130. *
  131. * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an
  132. * RCU-sched read-side critical section. In absence of
  133. * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side
  134. * critical section unless it can prove otherwise. Note that disabling
  135. * of preemption (including disabling irqs) counts as an RCU-sched
  136. * read-side critical section.
  137. *
  138. * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
  139. * and while lockdep is disabled.
  140. */
  141. #ifdef CONFIG_PREEMPT
  142. static inline int rcu_read_lock_sched_held(void)
  143. {
  144. int lockdep_opinion = 0;
  145. if (!debug_lockdep_rcu_enabled())
  146. return 1;
  147. if (debug_locks)
  148. lockdep_opinion = lock_is_held(&rcu_sched_lock_map);
  149. return lockdep_opinion || preempt_count() != 0 || irqs_disabled();
  150. }
  151. #else /* #ifdef CONFIG_PREEMPT */
  152. static inline int rcu_read_lock_sched_held(void)
  153. {
  154. return 1;
  155. }
  156. #endif /* #else #ifdef CONFIG_PREEMPT */
  157. #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  158. # define rcu_read_acquire() do { } while (0)
  159. # define rcu_read_release() do { } while (0)
  160. # define rcu_read_acquire_bh() do { } while (0)
  161. # define rcu_read_release_bh() do { } while (0)
  162. # define rcu_read_acquire_sched() do { } while (0)
  163. # define rcu_read_release_sched() do { } while (0)
  164. static inline int rcu_read_lock_held(void)
  165. {
  166. return 1;
  167. }
  168. static inline int rcu_read_lock_bh_held(void)
  169. {
  170. return 1;
  171. }
  172. #ifdef CONFIG_PREEMPT
  173. static inline int rcu_read_lock_sched_held(void)
  174. {
  175. return preempt_count() != 0 || irqs_disabled();
  176. }
  177. #else /* #ifdef CONFIG_PREEMPT */
  178. static inline int rcu_read_lock_sched_held(void)
  179. {
  180. return 1;
  181. }
  182. #endif /* #else #ifdef CONFIG_PREEMPT */
  183. #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  184. #ifdef CONFIG_PROVE_RCU
  185. extern int rcu_my_thread_group_empty(void);
  186. #define __do_rcu_dereference_check(c) \
  187. do { \
  188. static bool __warned; \
  189. if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \
  190. __warned = true; \
  191. lockdep_rcu_dereference(__FILE__, __LINE__); \
  192. } \
  193. } while (0)
  194. /**
  195. * rcu_dereference_check - rcu_dereference with debug checking
  196. * @p: The pointer to read, prior to dereferencing
  197. * @c: The conditions under which the dereference will take place
  198. *
  199. * Do an rcu_dereference(), but check that the conditions under which the
  200. * dereference will take place are correct. Typically the conditions indicate
  201. * the various locking conditions that should be held at that point. The check
  202. * should return true if the conditions are satisfied.
  203. *
  204. * For example:
  205. *
  206. * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
  207. * lockdep_is_held(&foo->lock));
  208. *
  209. * could be used to indicate to lockdep that foo->bar may only be dereferenced
  210. * if either the RCU read lock is held, or that the lock required to replace
  211. * the bar struct at foo->bar is held.
  212. *
  213. * Note that the list of conditions may also include indications of when a lock
  214. * need not be held, for example during initialisation or destruction of the
  215. * target struct:
  216. *
  217. * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
  218. * lockdep_is_held(&foo->lock) ||
  219. * atomic_read(&foo->usage) == 0);
  220. */
  221. #define rcu_dereference_check(p, c) \
  222. ({ \
  223. __do_rcu_dereference_check(c); \
  224. rcu_dereference_raw(p); \
  225. })
  226. /**
  227. * rcu_dereference_protected - fetch RCU pointer when updates prevented
  228. *
  229. * Return the value of the specified RCU-protected pointer, but omit
  230. * both the smp_read_barrier_depends() and the ACCESS_ONCE(). This
  231. * is useful in cases where update-side locks prevent the value of the
  232. * pointer from changing. Please note that this primitive does -not-
  233. * prevent the compiler from repeating this reference or combining it
  234. * with other references, so it should not be used without protection
  235. * of appropriate locks.
  236. */
  237. #define rcu_dereference_protected(p, c) \
  238. ({ \
  239. __do_rcu_dereference_check(c); \
  240. (p); \
  241. })
  242. #else /* #ifdef CONFIG_PROVE_RCU */
  243. #define rcu_dereference_check(p, c) rcu_dereference_raw(p)
  244. #define rcu_dereference_protected(p, c) (p)
  245. #endif /* #else #ifdef CONFIG_PROVE_RCU */
  246. /**
  247. * rcu_access_pointer - fetch RCU pointer with no dereferencing
  248. *
  249. * Return the value of the specified RCU-protected pointer, but omit the
  250. * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful
  251. * when the value of this pointer is accessed, but the pointer is not
  252. * dereferenced, for example, when testing an RCU-protected pointer against
  253. * NULL. This may also be used in cases where update-side locks prevent
  254. * the value of the pointer from changing, but rcu_dereference_protected()
  255. * is a lighter-weight primitive for this use case.
  256. */
  257. #define rcu_access_pointer(p) ACCESS_ONCE(p)
  258. /**
  259. * rcu_read_lock - mark the beginning of an RCU read-side critical section.
  260. *
  261. * When synchronize_rcu() is invoked on one CPU while other CPUs
  262. * are within RCU read-side critical sections, then the
  263. * synchronize_rcu() is guaranteed to block until after all the other
  264. * CPUs exit their critical sections. Similarly, if call_rcu() is invoked
  265. * on one CPU while other CPUs are within RCU read-side critical
  266. * sections, invocation of the corresponding RCU callback is deferred
  267. * until after the all the other CPUs exit their critical sections.
  268. *
  269. * Note, however, that RCU callbacks are permitted to run concurrently
  270. * with RCU read-side critical sections. One way that this can happen
  271. * is via the following sequence of events: (1) CPU 0 enters an RCU
  272. * read-side critical section, (2) CPU 1 invokes call_rcu() to register
  273. * an RCU callback, (3) CPU 0 exits the RCU read-side critical section,
  274. * (4) CPU 2 enters a RCU read-side critical section, (5) the RCU
  275. * callback is invoked. This is legal, because the RCU read-side critical
  276. * section that was running concurrently with the call_rcu() (and which
  277. * therefore might be referencing something that the corresponding RCU
  278. * callback would free up) has completed before the corresponding
  279. * RCU callback is invoked.
  280. *
  281. * RCU read-side critical sections may be nested. Any deferred actions
  282. * will be deferred until the outermost RCU read-side critical section
  283. * completes.
  284. *
  285. * It is illegal to block while in an RCU read-side critical section.
  286. */
  287. static inline void rcu_read_lock(void)
  288. {
  289. __rcu_read_lock();
  290. __acquire(RCU);
  291. rcu_read_acquire();
  292. }
  293. /*
  294. * So where is rcu_write_lock()? It does not exist, as there is no
  295. * way for writers to lock out RCU readers. This is a feature, not
  296. * a bug -- this property is what provides RCU's performance benefits.
  297. * Of course, writers must coordinate with each other. The normal
  298. * spinlock primitives work well for this, but any other technique may be
  299. * used as well. RCU does not care how the writers keep out of each
  300. * others' way, as long as they do so.
  301. */
  302. /**
  303. * rcu_read_unlock - marks the end of an RCU read-side critical section.
  304. *
  305. * See rcu_read_lock() for more information.
  306. */
  307. static inline void rcu_read_unlock(void)
  308. {
  309. rcu_read_release();
  310. __release(RCU);
  311. __rcu_read_unlock();
  312. }
  313. /**
  314. * rcu_read_lock_bh - mark the beginning of a softirq-only RCU critical section
  315. *
  316. * This is equivalent of rcu_read_lock(), but to be used when updates
  317. * are being done using call_rcu_bh(). Since call_rcu_bh() callbacks
  318. * consider completion of a softirq handler to be a quiescent state,
  319. * a process in RCU read-side critical section must be protected by
  320. * disabling softirqs. Read-side critical sections in interrupt context
  321. * can use just rcu_read_lock().
  322. *
  323. */
  324. static inline void rcu_read_lock_bh(void)
  325. {
  326. __rcu_read_lock_bh();
  327. __acquire(RCU_BH);
  328. rcu_read_acquire_bh();
  329. }
  330. /*
  331. * rcu_read_unlock_bh - marks the end of a softirq-only RCU critical section
  332. *
  333. * See rcu_read_lock_bh() for more information.
  334. */
  335. static inline void rcu_read_unlock_bh(void)
  336. {
  337. rcu_read_release_bh();
  338. __release(RCU_BH);
  339. __rcu_read_unlock_bh();
  340. }
  341. /**
  342. * rcu_read_lock_sched - mark the beginning of a RCU-classic critical section
  343. *
  344. * Should be used with either
  345. * - synchronize_sched()
  346. * or
  347. * - call_rcu_sched() and rcu_barrier_sched()
  348. * on the write-side to insure proper synchronization.
  349. */
  350. static inline void rcu_read_lock_sched(void)
  351. {
  352. preempt_disable();
  353. __acquire(RCU_SCHED);
  354. rcu_read_acquire_sched();
  355. }
  356. /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */
  357. static inline notrace void rcu_read_lock_sched_notrace(void)
  358. {
  359. preempt_disable_notrace();
  360. __acquire(RCU_SCHED);
  361. }
  362. /*
  363. * rcu_read_unlock_sched - marks the end of a RCU-classic critical section
  364. *
  365. * See rcu_read_lock_sched for more information.
  366. */
  367. static inline void rcu_read_unlock_sched(void)
  368. {
  369. rcu_read_release_sched();
  370. __release(RCU_SCHED);
  371. preempt_enable();
  372. }
  373. /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */
  374. static inline notrace void rcu_read_unlock_sched_notrace(void)
  375. {
  376. __release(RCU_SCHED);
  377. preempt_enable_notrace();
  378. }
  379. /**
  380. * rcu_dereference_raw - fetch an RCU-protected pointer
  381. *
  382. * The caller must be within some flavor of RCU read-side critical
  383. * section, or must be otherwise preventing the pointer from changing,
  384. * for example, by holding an appropriate lock. This pointer may later
  385. * be safely dereferenced. It is the caller's responsibility to have
  386. * done the right thing, as this primitive does no checking of any kind.
  387. *
  388. * Inserts memory barriers on architectures that require them
  389. * (currently only the Alpha), and, more importantly, documents
  390. * exactly which pointers are protected by RCU.
  391. */
  392. #define rcu_dereference_raw(p) ({ \
  393. typeof(p) _________p1 = ACCESS_ONCE(p); \
  394. smp_read_barrier_depends(); \
  395. (_________p1); \
  396. })
  397. /**
  398. * rcu_dereference - fetch an RCU-protected pointer, checking for RCU
  399. *
  400. * Makes rcu_dereference_check() do the dirty work.
  401. */
  402. #define rcu_dereference(p) \
  403. rcu_dereference_check(p, rcu_read_lock_held())
  404. /**
  405. * rcu_dereference_bh - fetch an RCU-protected pointer, checking for RCU-bh
  406. *
  407. * Makes rcu_dereference_check() do the dirty work.
  408. */
  409. #define rcu_dereference_bh(p) \
  410. rcu_dereference_check(p, rcu_read_lock_bh_held())
  411. /**
  412. * rcu_dereference_sched - fetch RCU-protected pointer, checking for RCU-sched
  413. *
  414. * Makes rcu_dereference_check() do the dirty work.
  415. */
  416. #define rcu_dereference_sched(p) \
  417. rcu_dereference_check(p, rcu_read_lock_sched_held())
  418. /**
  419. * rcu_assign_pointer - assign (publicize) a pointer to a newly
  420. * initialized structure that will be dereferenced by RCU read-side
  421. * critical sections. Returns the value assigned.
  422. *
  423. * Inserts memory barriers on architectures that require them
  424. * (pretty much all of them other than x86), and also prevents
  425. * the compiler from reordering the code that initializes the
  426. * structure after the pointer assignment. More importantly, this
  427. * call documents which pointers will be dereferenced by RCU read-side
  428. * code.
  429. */
  430. #define rcu_assign_pointer(p, v) \
  431. ({ \
  432. if (!__builtin_constant_p(v) || \
  433. ((v) != NULL)) \
  434. smp_wmb(); \
  435. (p) = (v); \
  436. })
  437. /* Infrastructure to implement the synchronize_() primitives. */
  438. struct rcu_synchronize {
  439. struct rcu_head head;
  440. struct completion completion;
  441. };
  442. extern void wakeme_after_rcu(struct rcu_head *head);
  443. /**
  444. * call_rcu - Queue an RCU callback for invocation after a grace period.
  445. * @head: structure to be used for queueing the RCU updates.
  446. * @func: actual update function to be invoked after the grace period
  447. *
  448. * The update function will be invoked some time after a full grace
  449. * period elapses, in other words after all currently executing RCU
  450. * read-side critical sections have completed. RCU read-side critical
  451. * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
  452. * and may be nested.
  453. */
  454. extern void call_rcu(struct rcu_head *head,
  455. void (*func)(struct rcu_head *head));
  456. /**
  457. * call_rcu_bh - Queue an RCU for invocation after a quicker grace period.
  458. * @head: structure to be used for queueing the RCU updates.
  459. * @func: actual update function to be invoked after the grace period
  460. *
  461. * The update function will be invoked some time after a full grace
  462. * period elapses, in other words after all currently executing RCU
  463. * read-side critical sections have completed. call_rcu_bh() assumes
  464. * that the read-side critical sections end on completion of a softirq
  465. * handler. This means that read-side critical sections in process
  466. * context must not be interrupted by softirqs. This interface is to be
  467. * used when most of the read-side critical sections are in softirq context.
  468. * RCU read-side critical sections are delimited by :
  469. * - rcu_read_lock() and rcu_read_unlock(), if in interrupt context.
  470. * OR
  471. * - rcu_read_lock_bh() and rcu_read_unlock_bh(), if in process context.
  472. * These may be nested.
  473. */
  474. extern void call_rcu_bh(struct rcu_head *head,
  475. void (*func)(struct rcu_head *head));
  476. /*
  477. * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally
  478. * by call_rcu() and rcu callback execution, and are therefore not part of the
  479. * RCU API. Leaving in rcupdate.h because they are used by all RCU flavors.
  480. */
  481. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  482. # define STATE_RCU_HEAD_READY 0
  483. # define STATE_RCU_HEAD_QUEUED 1
  484. extern struct debug_obj_descr rcuhead_debug_descr;
  485. static inline void debug_rcu_head_queue(struct rcu_head *head)
  486. {
  487. debug_object_activate(head, &rcuhead_debug_descr);
  488. debug_object_active_state(head, &rcuhead_debug_descr,
  489. STATE_RCU_HEAD_READY,
  490. STATE_RCU_HEAD_QUEUED);
  491. }
  492. static inline void debug_rcu_head_unqueue(struct rcu_head *head)
  493. {
  494. debug_object_active_state(head, &rcuhead_debug_descr,
  495. STATE_RCU_HEAD_QUEUED,
  496. STATE_RCU_HEAD_READY);
  497. debug_object_deactivate(head, &rcuhead_debug_descr);
  498. }
  499. #else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  500. static inline void debug_rcu_head_queue(struct rcu_head *head)
  501. {
  502. }
  503. static inline void debug_rcu_head_unqueue(struct rcu_head *head)
  504. {
  505. }
  506. #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  507. #ifndef CONFIG_PROVE_RCU
  508. #define __do_rcu_dereference_check(c) do { } while (0)
  509. #endif /* #ifdef CONFIG_PROVE_RCU */
  510. #define __rcu_dereference_index_check(p, c) \
  511. ({ \
  512. typeof(p) _________p1 = ACCESS_ONCE(p); \
  513. __do_rcu_dereference_check(c); \
  514. smp_read_barrier_depends(); \
  515. (_________p1); \
  516. })
  517. /**
  518. * rcu_dereference_index_check() - rcu_dereference for indices with debug checking
  519. * @p: The pointer to read, prior to dereferencing
  520. * @c: The conditions under which the dereference will take place
  521. *
  522. * Similar to rcu_dereference_check(), but omits the sparse checking.
  523. * This allows rcu_dereference_index_check() to be used on integers,
  524. * which can then be used as array indices. Attempting to use
  525. * rcu_dereference_check() on an integer will give compiler warnings
  526. * because the sparse address-space mechanism relies on dereferencing
  527. * the RCU-protected pointer. Dereferencing integers is not something
  528. * that even gcc will put up with.
  529. *
  530. * Note that this function does not implicitly check for RCU read-side
  531. * critical sections. If this function gains lots of uses, it might
  532. * make sense to provide versions for each flavor of RCU, but it does
  533. * not make sense as of early 2010.
  534. */
  535. #define rcu_dereference_index_check(p, c) \
  536. __rcu_dereference_index_check((p), (c))
  537. #endif /* __LINUX_RCUPDATE_H */