rcupdate.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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, you can access it online at
  16. * http://www.gnu.org/licenses/gpl-2.0.html.
  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/types.h>
  35. #include <linux/cache.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/threads.h>
  38. #include <linux/cpumask.h>
  39. #include <linux/seqlock.h>
  40. #include <linux/lockdep.h>
  41. #include <linux/completion.h>
  42. #include <linux/debugobjects.h>
  43. #include <linux/bug.h>
  44. #include <linux/compiler.h>
  45. #include <linux/percpu.h>
  46. #include <asm/barrier.h>
  47. extern int rcu_expedited; /* for sysctl */
  48. #ifdef CONFIG_RCU_TORTURE_TEST
  49. extern int rcutorture_runnable; /* for sysctl */
  50. #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
  51. enum rcutorture_type {
  52. RCU_FLAVOR,
  53. RCU_BH_FLAVOR,
  54. RCU_SCHED_FLAVOR,
  55. SRCU_FLAVOR,
  56. INVALID_RCU_FLAVOR
  57. };
  58. #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
  59. void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
  60. unsigned long *gpnum, unsigned long *completed);
  61. void rcutorture_record_test_transition(void);
  62. void rcutorture_record_progress(unsigned long vernum);
  63. void do_trace_rcu_torture_read(const char *rcutorturename,
  64. struct rcu_head *rhp,
  65. unsigned long secs,
  66. unsigned long c_old,
  67. unsigned long c);
  68. #else
  69. static inline void rcutorture_get_gp_data(enum rcutorture_type test_type,
  70. int *flags,
  71. unsigned long *gpnum,
  72. unsigned long *completed)
  73. {
  74. *flags = 0;
  75. *gpnum = 0;
  76. *completed = 0;
  77. }
  78. static inline void rcutorture_record_test_transition(void)
  79. {
  80. }
  81. static inline void rcutorture_record_progress(unsigned long vernum)
  82. {
  83. }
  84. #ifdef CONFIG_RCU_TRACE
  85. void do_trace_rcu_torture_read(const char *rcutorturename,
  86. struct rcu_head *rhp,
  87. unsigned long secs,
  88. unsigned long c_old,
  89. unsigned long c);
  90. #else
  91. #define do_trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c) \
  92. do { } while (0)
  93. #endif
  94. #endif
  95. #define UINT_CMP_GE(a, b) (UINT_MAX / 2 >= (a) - (b))
  96. #define UINT_CMP_LT(a, b) (UINT_MAX / 2 < (a) - (b))
  97. #define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b))
  98. #define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
  99. #define ulong2long(a) (*(long *)(&(a)))
  100. /* Exported common interfaces */
  101. #ifdef CONFIG_PREEMPT_RCU
  102. /**
  103. * call_rcu() - Queue an RCU callback for invocation after a grace period.
  104. * @head: structure to be used for queueing the RCU updates.
  105. * @func: actual callback function to be invoked after the grace period
  106. *
  107. * The callback function will be invoked some time after a full grace
  108. * period elapses, in other words after all pre-existing RCU read-side
  109. * critical sections have completed. However, the callback function
  110. * might well execute concurrently with RCU read-side critical sections
  111. * that started after call_rcu() was invoked. RCU read-side critical
  112. * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
  113. * and may be nested.
  114. *
  115. * Note that all CPUs must agree that the grace period extended beyond
  116. * all pre-existing RCU read-side critical section. On systems with more
  117. * than one CPU, this means that when "func()" is invoked, each CPU is
  118. * guaranteed to have executed a full memory barrier since the end of its
  119. * last RCU read-side critical section whose beginning preceded the call
  120. * to call_rcu(). It also means that each CPU executing an RCU read-side
  121. * critical section that continues beyond the start of "func()" must have
  122. * executed a memory barrier after the call_rcu() but before the beginning
  123. * of that RCU read-side critical section. Note that these guarantees
  124. * include CPUs that are offline, idle, or executing in user mode, as
  125. * well as CPUs that are executing in the kernel.
  126. *
  127. * Furthermore, if CPU A invoked call_rcu() and CPU B invoked the
  128. * resulting RCU callback function "func()", then both CPU A and CPU B are
  129. * guaranteed to execute a full memory barrier during the time interval
  130. * between the call to call_rcu() and the invocation of "func()" -- even
  131. * if CPU A and CPU B are the same CPU (but again only if the system has
  132. * more than one CPU).
  133. */
  134. void call_rcu(struct rcu_head *head,
  135. void (*func)(struct rcu_head *head));
  136. #else /* #ifdef CONFIG_PREEMPT_RCU */
  137. /* In classic RCU, call_rcu() is just call_rcu_sched(). */
  138. #define call_rcu call_rcu_sched
  139. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  140. /**
  141. * call_rcu_bh() - Queue an RCU for invocation after a quicker grace period.
  142. * @head: structure to be used for queueing the RCU updates.
  143. * @func: actual callback function to be invoked after the grace period
  144. *
  145. * The callback function will be invoked some time after a full grace
  146. * period elapses, in other words after all currently executing RCU
  147. * read-side critical sections have completed. call_rcu_bh() assumes
  148. * that the read-side critical sections end on completion of a softirq
  149. * handler. This means that read-side critical sections in process
  150. * context must not be interrupted by softirqs. This interface is to be
  151. * used when most of the read-side critical sections are in softirq context.
  152. * RCU read-side critical sections are delimited by :
  153. * - rcu_read_lock() and rcu_read_unlock(), if in interrupt context.
  154. * OR
  155. * - rcu_read_lock_bh() and rcu_read_unlock_bh(), if in process context.
  156. * These may be nested.
  157. *
  158. * See the description of call_rcu() for more detailed information on
  159. * memory ordering guarantees.
  160. */
  161. void call_rcu_bh(struct rcu_head *head,
  162. void (*func)(struct rcu_head *head));
  163. /**
  164. * call_rcu_sched() - Queue an RCU for invocation after sched grace period.
  165. * @head: structure to be used for queueing the RCU updates.
  166. * @func: actual callback function to be invoked after the grace period
  167. *
  168. * The callback function will be invoked some time after a full grace
  169. * period elapses, in other words after all currently executing RCU
  170. * read-side critical sections have completed. call_rcu_sched() assumes
  171. * that the read-side critical sections end on enabling of preemption
  172. * or on voluntary preemption.
  173. * RCU read-side critical sections are delimited by :
  174. * - rcu_read_lock_sched() and rcu_read_unlock_sched(),
  175. * OR
  176. * anything that disables preemption.
  177. * These may be nested.
  178. *
  179. * See the description of call_rcu() for more detailed information on
  180. * memory ordering guarantees.
  181. */
  182. void call_rcu_sched(struct rcu_head *head,
  183. void (*func)(struct rcu_head *rcu));
  184. void synchronize_sched(void);
  185. #ifdef CONFIG_PREEMPT_RCU
  186. void __rcu_read_lock(void);
  187. void __rcu_read_unlock(void);
  188. void rcu_read_unlock_special(struct task_struct *t);
  189. void synchronize_rcu(void);
  190. /*
  191. * Defined as a macro as it is a very low level header included from
  192. * areas that don't even know about current. This gives the rcu_read_lock()
  193. * nesting depth, but makes sense only if CONFIG_PREEMPT_RCU -- in other
  194. * types of kernel builds, the rcu_read_lock() nesting depth is unknowable.
  195. */
  196. #define rcu_preempt_depth() (current->rcu_read_lock_nesting)
  197. #else /* #ifdef CONFIG_PREEMPT_RCU */
  198. static inline void __rcu_read_lock(void)
  199. {
  200. preempt_disable();
  201. }
  202. static inline void __rcu_read_unlock(void)
  203. {
  204. preempt_enable();
  205. }
  206. static inline void synchronize_rcu(void)
  207. {
  208. synchronize_sched();
  209. }
  210. static inline int rcu_preempt_depth(void)
  211. {
  212. return 0;
  213. }
  214. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  215. /* Internal to kernel */
  216. void rcu_init(void);
  217. void rcu_sched_qs(int cpu);
  218. void rcu_bh_qs(int cpu);
  219. void rcu_check_callbacks(int cpu, int user);
  220. struct notifier_block;
  221. void rcu_idle_enter(void);
  222. void rcu_idle_exit(void);
  223. void rcu_irq_enter(void);
  224. void rcu_irq_exit(void);
  225. #ifdef CONFIG_RCU_STALL_COMMON
  226. void rcu_sysrq_start(void);
  227. void rcu_sysrq_end(void);
  228. #else /* #ifdef CONFIG_RCU_STALL_COMMON */
  229. static inline void rcu_sysrq_start(void)
  230. {
  231. }
  232. static inline void rcu_sysrq_end(void)
  233. {
  234. }
  235. #endif /* #else #ifdef CONFIG_RCU_STALL_COMMON */
  236. #ifdef CONFIG_RCU_USER_QS
  237. void rcu_user_enter(void);
  238. void rcu_user_exit(void);
  239. #else
  240. static inline void rcu_user_enter(void) { }
  241. static inline void rcu_user_exit(void) { }
  242. static inline void rcu_user_hooks_switch(struct task_struct *prev,
  243. struct task_struct *next) { }
  244. #endif /* CONFIG_RCU_USER_QS */
  245. /**
  246. * RCU_NONIDLE - Indicate idle-loop code that needs RCU readers
  247. * @a: Code that RCU needs to pay attention to.
  248. *
  249. * RCU, RCU-bh, and RCU-sched read-side critical sections are forbidden
  250. * in the inner idle loop, that is, between the rcu_idle_enter() and
  251. * the rcu_idle_exit() -- RCU will happily ignore any such read-side
  252. * critical sections. However, things like powertop need tracepoints
  253. * in the inner idle loop.
  254. *
  255. * This macro provides the way out: RCU_NONIDLE(do_something_with_RCU())
  256. * will tell RCU that it needs to pay attending, invoke its argument
  257. * (in this example, a call to the do_something_with_RCU() function),
  258. * and then tell RCU to go back to ignoring this CPU. It is permissible
  259. * to nest RCU_NONIDLE() wrappers, but the nesting level is currently
  260. * quite limited. If deeper nesting is required, it will be necessary
  261. * to adjust DYNTICK_TASK_NESTING_VALUE accordingly.
  262. */
  263. #define RCU_NONIDLE(a) \
  264. do { \
  265. rcu_irq_enter(); \
  266. do { a; } while (0); \
  267. rcu_irq_exit(); \
  268. } while (0)
  269. #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_RCU_TRACE) || defined(CONFIG_SMP)
  270. bool __rcu_is_watching(void);
  271. #endif /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_RCU_TRACE) || defined(CONFIG_SMP) */
  272. /*
  273. * Hooks for cond_resched() and friends to avoid RCU CPU stall warnings.
  274. */
  275. #define RCU_COND_RESCHED_LIM 256 /* ms vs. 100s of ms. */
  276. DECLARE_PER_CPU(int, rcu_cond_resched_count);
  277. void rcu_resched(void);
  278. /*
  279. * Is it time to report RCU quiescent states?
  280. *
  281. * Note unsynchronized access to rcu_cond_resched_count. Yes, we might
  282. * increment some random CPU's count, and possibly also load the result from
  283. * yet another CPU's count. We might even clobber some other CPU's attempt
  284. * to zero its counter. This is all OK because the goal is not precision,
  285. * but rather reasonable amortization of rcu_note_context_switch() overhead
  286. * and extremely high probability of avoiding RCU CPU stall warnings.
  287. * Note that this function has to be preempted in just the wrong place,
  288. * many thousands of times in a row, for anything bad to happen.
  289. */
  290. static inline bool rcu_should_resched(void)
  291. {
  292. return raw_cpu_inc_return(rcu_cond_resched_count) >=
  293. RCU_COND_RESCHED_LIM;
  294. }
  295. /*
  296. * Report quiscent states to RCU if it is time to do so.
  297. */
  298. static inline void rcu_cond_resched(void)
  299. {
  300. if (unlikely(rcu_should_resched()))
  301. rcu_resched();
  302. }
  303. /*
  304. * Infrastructure to implement the synchronize_() primitives in
  305. * TREE_RCU and rcu_barrier_() primitives in TINY_RCU.
  306. */
  307. typedef void call_rcu_func_t(struct rcu_head *head,
  308. void (*func)(struct rcu_head *head));
  309. void wait_rcu_gp(call_rcu_func_t crf);
  310. #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
  311. #include <linux/rcutree.h>
  312. #elif defined(CONFIG_TINY_RCU)
  313. #include <linux/rcutiny.h>
  314. #else
  315. #error "Unknown RCU implementation specified to kernel configuration"
  316. #endif
  317. /*
  318. * init_rcu_head_on_stack()/destroy_rcu_head_on_stack() are needed for dynamic
  319. * initialization and destruction of rcu_head on the stack. rcu_head structures
  320. * allocated dynamically in the heap or defined statically don't need any
  321. * initialization.
  322. */
  323. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  324. void init_rcu_head_on_stack(struct rcu_head *head);
  325. void destroy_rcu_head_on_stack(struct rcu_head *head);
  326. #else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  327. static inline void init_rcu_head_on_stack(struct rcu_head *head)
  328. {
  329. }
  330. static inline void destroy_rcu_head_on_stack(struct rcu_head *head)
  331. {
  332. }
  333. #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  334. #if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PROVE_RCU)
  335. bool rcu_lockdep_current_cpu_online(void);
  336. #else /* #if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PROVE_RCU) */
  337. static inline bool rcu_lockdep_current_cpu_online(void)
  338. {
  339. return 1;
  340. }
  341. #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PROVE_RCU) */
  342. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  343. static inline void rcu_lock_acquire(struct lockdep_map *map)
  344. {
  345. lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_);
  346. }
  347. static inline void rcu_lock_release(struct lockdep_map *map)
  348. {
  349. lock_release(map, 1, _THIS_IP_);
  350. }
  351. extern struct lockdep_map rcu_lock_map;
  352. extern struct lockdep_map rcu_bh_lock_map;
  353. extern struct lockdep_map rcu_sched_lock_map;
  354. extern struct lockdep_map rcu_callback_map;
  355. int debug_lockdep_rcu_enabled(void);
  356. /**
  357. * rcu_read_lock_held() - might we be in RCU read-side critical section?
  358. *
  359. * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU
  360. * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC,
  361. * this assumes we are in an RCU read-side critical section unless it can
  362. * prove otherwise. This is useful for debug checks in functions that
  363. * require that they be called within an RCU read-side critical section.
  364. *
  365. * Checks debug_lockdep_rcu_enabled() to prevent false positives during boot
  366. * and while lockdep is disabled.
  367. *
  368. * Note that rcu_read_lock() and the matching rcu_read_unlock() must
  369. * occur in the same context, for example, it is illegal to invoke
  370. * rcu_read_unlock() in process context if the matching rcu_read_lock()
  371. * was invoked from within an irq handler.
  372. *
  373. * Note that rcu_read_lock() is disallowed if the CPU is either idle or
  374. * offline from an RCU perspective, so check for those as well.
  375. */
  376. static inline int rcu_read_lock_held(void)
  377. {
  378. if (!debug_lockdep_rcu_enabled())
  379. return 1;
  380. if (!rcu_is_watching())
  381. return 0;
  382. if (!rcu_lockdep_current_cpu_online())
  383. return 0;
  384. return lock_is_held(&rcu_lock_map);
  385. }
  386. /*
  387. * rcu_read_lock_bh_held() is defined out of line to avoid #include-file
  388. * hell.
  389. */
  390. int rcu_read_lock_bh_held(void);
  391. /**
  392. * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section?
  393. *
  394. * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an
  395. * RCU-sched read-side critical section. In absence of
  396. * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side
  397. * critical section unless it can prove otherwise. Note that disabling
  398. * of preemption (including disabling irqs) counts as an RCU-sched
  399. * read-side critical section. This is useful for debug checks in functions
  400. * that required that they be called within an RCU-sched read-side
  401. * critical section.
  402. *
  403. * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
  404. * and while lockdep is disabled.
  405. *
  406. * Note that if the CPU is in the idle loop from an RCU point of
  407. * view (ie: that we are in the section between rcu_idle_enter() and
  408. * rcu_idle_exit()) then rcu_read_lock_held() returns false even if the CPU
  409. * did an rcu_read_lock(). The reason for this is that RCU ignores CPUs
  410. * that are in such a section, considering these as in extended quiescent
  411. * state, so such a CPU is effectively never in an RCU read-side critical
  412. * section regardless of what RCU primitives it invokes. This state of
  413. * affairs is required --- we need to keep an RCU-free window in idle
  414. * where the CPU may possibly enter into low power mode. This way we can
  415. * notice an extended quiescent state to other CPUs that started a grace
  416. * period. Otherwise we would delay any grace period as long as we run in
  417. * the idle task.
  418. *
  419. * Similarly, we avoid claiming an SRCU read lock held if the current
  420. * CPU is offline.
  421. */
  422. #ifdef CONFIG_PREEMPT_COUNT
  423. static inline int rcu_read_lock_sched_held(void)
  424. {
  425. int lockdep_opinion = 0;
  426. if (!debug_lockdep_rcu_enabled())
  427. return 1;
  428. if (!rcu_is_watching())
  429. return 0;
  430. if (!rcu_lockdep_current_cpu_online())
  431. return 0;
  432. if (debug_locks)
  433. lockdep_opinion = lock_is_held(&rcu_sched_lock_map);
  434. return lockdep_opinion || preempt_count() != 0 || irqs_disabled();
  435. }
  436. #else /* #ifdef CONFIG_PREEMPT_COUNT */
  437. static inline int rcu_read_lock_sched_held(void)
  438. {
  439. return 1;
  440. }
  441. #endif /* #else #ifdef CONFIG_PREEMPT_COUNT */
  442. #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  443. # define rcu_lock_acquire(a) do { } while (0)
  444. # define rcu_lock_release(a) do { } while (0)
  445. static inline int rcu_read_lock_held(void)
  446. {
  447. return 1;
  448. }
  449. static inline int rcu_read_lock_bh_held(void)
  450. {
  451. return 1;
  452. }
  453. #ifdef CONFIG_PREEMPT_COUNT
  454. static inline int rcu_read_lock_sched_held(void)
  455. {
  456. return preempt_count() != 0 || irqs_disabled();
  457. }
  458. #else /* #ifdef CONFIG_PREEMPT_COUNT */
  459. static inline int rcu_read_lock_sched_held(void)
  460. {
  461. return 1;
  462. }
  463. #endif /* #else #ifdef CONFIG_PREEMPT_COUNT */
  464. #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  465. #ifdef CONFIG_PROVE_RCU
  466. /**
  467. * rcu_lockdep_assert - emit lockdep splat if specified condition not met
  468. * @c: condition to check
  469. * @s: informative message
  470. */
  471. #define rcu_lockdep_assert(c, s) \
  472. do { \
  473. static bool __section(.data.unlikely) __warned; \
  474. if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \
  475. __warned = true; \
  476. lockdep_rcu_suspicious(__FILE__, __LINE__, s); \
  477. } \
  478. } while (0)
  479. #if defined(CONFIG_PROVE_RCU) && !defined(CONFIG_PREEMPT_RCU)
  480. static inline void rcu_preempt_sleep_check(void)
  481. {
  482. rcu_lockdep_assert(!lock_is_held(&rcu_lock_map),
  483. "Illegal context switch in RCU read-side critical section");
  484. }
  485. #else /* #ifdef CONFIG_PROVE_RCU */
  486. static inline void rcu_preempt_sleep_check(void)
  487. {
  488. }
  489. #endif /* #else #ifdef CONFIG_PROVE_RCU */
  490. #define rcu_sleep_check() \
  491. do { \
  492. rcu_preempt_sleep_check(); \
  493. rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map), \
  494. "Illegal context switch in RCU-bh read-side critical section"); \
  495. rcu_lockdep_assert(!lock_is_held(&rcu_sched_lock_map), \
  496. "Illegal context switch in RCU-sched read-side critical section"); \
  497. } while (0)
  498. #else /* #ifdef CONFIG_PROVE_RCU */
  499. #define rcu_lockdep_assert(c, s) do { } while (0)
  500. #define rcu_sleep_check() do { } while (0)
  501. #endif /* #else #ifdef CONFIG_PROVE_RCU */
  502. /*
  503. * Helper functions for rcu_dereference_check(), rcu_dereference_protected()
  504. * and rcu_assign_pointer(). Some of these could be folded into their
  505. * callers, but they are left separate in order to ease introduction of
  506. * multiple flavors of pointers to match the multiple flavors of RCU
  507. * (e.g., __rcu_bh, * __rcu_sched, and __srcu), should this make sense in
  508. * the future.
  509. */
  510. #ifdef __CHECKER__
  511. #define rcu_dereference_sparse(p, space) \
  512. ((void)(((typeof(*p) space *)p) == p))
  513. #else /* #ifdef __CHECKER__ */
  514. #define rcu_dereference_sparse(p, space)
  515. #endif /* #else #ifdef __CHECKER__ */
  516. #define __rcu_access_pointer(p, space) \
  517. ({ \
  518. typeof(*p) *_________p1 = (typeof(*p) *__force)ACCESS_ONCE(p); \
  519. rcu_dereference_sparse(p, space); \
  520. ((typeof(*p) __force __kernel *)(_________p1)); \
  521. })
  522. #define __rcu_dereference_check(p, c, space) \
  523. ({ \
  524. typeof(*p) *_________p1 = (typeof(*p) *__force)ACCESS_ONCE(p); \
  525. rcu_lockdep_assert(c, "suspicious rcu_dereference_check() usage"); \
  526. rcu_dereference_sparse(p, space); \
  527. smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
  528. ((typeof(*p) __force __kernel *)(_________p1)); \
  529. })
  530. #define __rcu_dereference_protected(p, c, space) \
  531. ({ \
  532. rcu_lockdep_assert(c, "suspicious rcu_dereference_protected() usage"); \
  533. rcu_dereference_sparse(p, space); \
  534. ((typeof(*p) __force __kernel *)(p)); \
  535. })
  536. #define __rcu_access_index(p, space) \
  537. ({ \
  538. typeof(p) _________p1 = ACCESS_ONCE(p); \
  539. rcu_dereference_sparse(p, space); \
  540. (_________p1); \
  541. })
  542. #define __rcu_dereference_index_check(p, c) \
  543. ({ \
  544. typeof(p) _________p1 = ACCESS_ONCE(p); \
  545. rcu_lockdep_assert(c, \
  546. "suspicious rcu_dereference_index_check() usage"); \
  547. smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
  548. (_________p1); \
  549. })
  550. /**
  551. * RCU_INITIALIZER() - statically initialize an RCU-protected global variable
  552. * @v: The value to statically initialize with.
  553. */
  554. #define RCU_INITIALIZER(v) (typeof(*(v)) __force __rcu *)(v)
  555. /**
  556. * rcu_assign_pointer() - assign to RCU-protected pointer
  557. * @p: pointer to assign to
  558. * @v: value to assign (publish)
  559. *
  560. * Assigns the specified value to the specified RCU-protected
  561. * pointer, ensuring that any concurrent RCU readers will see
  562. * any prior initialization.
  563. *
  564. * Inserts memory barriers on architectures that require them
  565. * (which is most of them), and also prevents the compiler from
  566. * reordering the code that initializes the structure after the pointer
  567. * assignment. More importantly, this call documents which pointers
  568. * will be dereferenced by RCU read-side code.
  569. *
  570. * In some special cases, you may use RCU_INIT_POINTER() instead
  571. * of rcu_assign_pointer(). RCU_INIT_POINTER() is a bit faster due
  572. * to the fact that it does not constrain either the CPU or the compiler.
  573. * That said, using RCU_INIT_POINTER() when you should have used
  574. * rcu_assign_pointer() is a very bad thing that results in
  575. * impossible-to-diagnose memory corruption. So please be careful.
  576. * See the RCU_INIT_POINTER() comment header for details.
  577. *
  578. * Note that rcu_assign_pointer() evaluates each of its arguments only
  579. * once, appearances notwithstanding. One of the "extra" evaluations
  580. * is in typeof() and the other visible only to sparse (__CHECKER__),
  581. * neither of which actually execute the argument. As with most cpp
  582. * macros, this execute-arguments-only-once property is important, so
  583. * please be careful when making changes to rcu_assign_pointer() and the
  584. * other macros that it invokes.
  585. */
  586. #define rcu_assign_pointer(p, v) smp_store_release(&p, RCU_INITIALIZER(v))
  587. /**
  588. * rcu_access_pointer() - fetch RCU pointer with no dereferencing
  589. * @p: The pointer to read
  590. *
  591. * Return the value of the specified RCU-protected pointer, but omit the
  592. * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful
  593. * when the value of this pointer is accessed, but the pointer is not
  594. * dereferenced, for example, when testing an RCU-protected pointer against
  595. * NULL. Although rcu_access_pointer() may also be used in cases where
  596. * update-side locks prevent the value of the pointer from changing, you
  597. * should instead use rcu_dereference_protected() for this use case.
  598. *
  599. * It is also permissible to use rcu_access_pointer() when read-side
  600. * access to the pointer was removed at least one grace period ago, as
  601. * is the case in the context of the RCU callback that is freeing up
  602. * the data, or after a synchronize_rcu() returns. This can be useful
  603. * when tearing down multi-linked structures after a grace period
  604. * has elapsed.
  605. */
  606. #define rcu_access_pointer(p) __rcu_access_pointer((p), __rcu)
  607. /**
  608. * rcu_dereference_check() - rcu_dereference with debug checking
  609. * @p: The pointer to read, prior to dereferencing
  610. * @c: The conditions under which the dereference will take place
  611. *
  612. * Do an rcu_dereference(), but check that the conditions under which the
  613. * dereference will take place are correct. Typically the conditions
  614. * indicate the various locking conditions that should be held at that
  615. * point. The check should return true if the conditions are satisfied.
  616. * An implicit check for being in an RCU read-side critical section
  617. * (rcu_read_lock()) is included.
  618. *
  619. * For example:
  620. *
  621. * bar = rcu_dereference_check(foo->bar, lockdep_is_held(&foo->lock));
  622. *
  623. * could be used to indicate to lockdep that foo->bar may only be dereferenced
  624. * if either rcu_read_lock() is held, or that the lock required to replace
  625. * the bar struct at foo->bar is held.
  626. *
  627. * Note that the list of conditions may also include indications of when a lock
  628. * need not be held, for example during initialisation or destruction of the
  629. * target struct:
  630. *
  631. * bar = rcu_dereference_check(foo->bar, lockdep_is_held(&foo->lock) ||
  632. * atomic_read(&foo->usage) == 0);
  633. *
  634. * Inserts memory barriers on architectures that require them
  635. * (currently only the Alpha), prevents the compiler from refetching
  636. * (and from merging fetches), and, more importantly, documents exactly
  637. * which pointers are protected by RCU and checks that the pointer is
  638. * annotated as __rcu.
  639. */
  640. #define rcu_dereference_check(p, c) \
  641. __rcu_dereference_check((p), rcu_read_lock_held() || (c), __rcu)
  642. /**
  643. * rcu_dereference_bh_check() - rcu_dereference_bh with debug checking
  644. * @p: The pointer to read, prior to dereferencing
  645. * @c: The conditions under which the dereference will take place
  646. *
  647. * This is the RCU-bh counterpart to rcu_dereference_check().
  648. */
  649. #define rcu_dereference_bh_check(p, c) \
  650. __rcu_dereference_check((p), rcu_read_lock_bh_held() || (c), __rcu)
  651. /**
  652. * rcu_dereference_sched_check() - rcu_dereference_sched with debug checking
  653. * @p: The pointer to read, prior to dereferencing
  654. * @c: The conditions under which the dereference will take place
  655. *
  656. * This is the RCU-sched counterpart to rcu_dereference_check().
  657. */
  658. #define rcu_dereference_sched_check(p, c) \
  659. __rcu_dereference_check((p), rcu_read_lock_sched_held() || (c), \
  660. __rcu)
  661. #define rcu_dereference_raw(p) rcu_dereference_check(p, 1) /*@@@ needed? @@@*/
  662. /*
  663. * The tracing infrastructure traces RCU (we want that), but unfortunately
  664. * some of the RCU checks causes tracing to lock up the system.
  665. *
  666. * The tracing version of rcu_dereference_raw() must not call
  667. * rcu_read_lock_held().
  668. */
  669. #define rcu_dereference_raw_notrace(p) __rcu_dereference_check((p), 1, __rcu)
  670. /**
  671. * rcu_access_index() - fetch RCU index with no dereferencing
  672. * @p: The index to read
  673. *
  674. * Return the value of the specified RCU-protected index, but omit the
  675. * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful
  676. * when the value of this index is accessed, but the index is not
  677. * dereferenced, for example, when testing an RCU-protected index against
  678. * -1. Although rcu_access_index() may also be used in cases where
  679. * update-side locks prevent the value of the index from changing, you
  680. * should instead use rcu_dereference_index_protected() for this use case.
  681. */
  682. #define rcu_access_index(p) __rcu_access_index((p), __rcu)
  683. /**
  684. * rcu_dereference_index_check() - rcu_dereference for indices with debug checking
  685. * @p: The pointer to read, prior to dereferencing
  686. * @c: The conditions under which the dereference will take place
  687. *
  688. * Similar to rcu_dereference_check(), but omits the sparse checking.
  689. * This allows rcu_dereference_index_check() to be used on integers,
  690. * which can then be used as array indices. Attempting to use
  691. * rcu_dereference_check() on an integer will give compiler warnings
  692. * because the sparse address-space mechanism relies on dereferencing
  693. * the RCU-protected pointer. Dereferencing integers is not something
  694. * that even gcc will put up with.
  695. *
  696. * Note that this function does not implicitly check for RCU read-side
  697. * critical sections. If this function gains lots of uses, it might
  698. * make sense to provide versions for each flavor of RCU, but it does
  699. * not make sense as of early 2010.
  700. */
  701. #define rcu_dereference_index_check(p, c) \
  702. __rcu_dereference_index_check((p), (c))
  703. /**
  704. * rcu_dereference_protected() - fetch RCU pointer when updates prevented
  705. * @p: The pointer to read, prior to dereferencing
  706. * @c: The conditions under which the dereference will take place
  707. *
  708. * Return the value of the specified RCU-protected pointer, but omit
  709. * both the smp_read_barrier_depends() and the ACCESS_ONCE(). This
  710. * is useful in cases where update-side locks prevent the value of the
  711. * pointer from changing. Please note that this primitive does -not-
  712. * prevent the compiler from repeating this reference or combining it
  713. * with other references, so it should not be used without protection
  714. * of appropriate locks.
  715. *
  716. * This function is only for update-side use. Using this function
  717. * when protected only by rcu_read_lock() will result in infrequent
  718. * but very ugly failures.
  719. */
  720. #define rcu_dereference_protected(p, c) \
  721. __rcu_dereference_protected((p), (c), __rcu)
  722. /**
  723. * rcu_dereference() - fetch RCU-protected pointer for dereferencing
  724. * @p: The pointer to read, prior to dereferencing
  725. *
  726. * This is a simple wrapper around rcu_dereference_check().
  727. */
  728. #define rcu_dereference(p) rcu_dereference_check(p, 0)
  729. /**
  730. * rcu_dereference_bh() - fetch an RCU-bh-protected pointer for dereferencing
  731. * @p: The pointer to read, prior to dereferencing
  732. *
  733. * Makes rcu_dereference_check() do the dirty work.
  734. */
  735. #define rcu_dereference_bh(p) rcu_dereference_bh_check(p, 0)
  736. /**
  737. * rcu_dereference_sched() - fetch RCU-sched-protected pointer for dereferencing
  738. * @p: The pointer to read, prior to dereferencing
  739. *
  740. * Makes rcu_dereference_check() do the dirty work.
  741. */
  742. #define rcu_dereference_sched(p) rcu_dereference_sched_check(p, 0)
  743. /**
  744. * rcu_read_lock() - mark the beginning of an RCU read-side critical section
  745. *
  746. * When synchronize_rcu() is invoked on one CPU while other CPUs
  747. * are within RCU read-side critical sections, then the
  748. * synchronize_rcu() is guaranteed to block until after all the other
  749. * CPUs exit their critical sections. Similarly, if call_rcu() is invoked
  750. * on one CPU while other CPUs are within RCU read-side critical
  751. * sections, invocation of the corresponding RCU callback is deferred
  752. * until after the all the other CPUs exit their critical sections.
  753. *
  754. * Note, however, that RCU callbacks are permitted to run concurrently
  755. * with new RCU read-side critical sections. One way that this can happen
  756. * is via the following sequence of events: (1) CPU 0 enters an RCU
  757. * read-side critical section, (2) CPU 1 invokes call_rcu() to register
  758. * an RCU callback, (3) CPU 0 exits the RCU read-side critical section,
  759. * (4) CPU 2 enters a RCU read-side critical section, (5) the RCU
  760. * callback is invoked. This is legal, because the RCU read-side critical
  761. * section that was running concurrently with the call_rcu() (and which
  762. * therefore might be referencing something that the corresponding RCU
  763. * callback would free up) has completed before the corresponding
  764. * RCU callback is invoked.
  765. *
  766. * RCU read-side critical sections may be nested. Any deferred actions
  767. * will be deferred until the outermost RCU read-side critical section
  768. * completes.
  769. *
  770. * You can avoid reading and understanding the next paragraph by
  771. * following this rule: don't put anything in an rcu_read_lock() RCU
  772. * read-side critical section that would block in a !PREEMPT kernel.
  773. * But if you want the full story, read on!
  774. *
  775. * In non-preemptible RCU implementations (TREE_RCU and TINY_RCU), it
  776. * is illegal to block while in an RCU read-side critical section. In
  777. * preemptible RCU implementations (TREE_PREEMPT_RCU and TINY_PREEMPT_RCU)
  778. * in CONFIG_PREEMPT kernel builds, RCU read-side critical sections may
  779. * be preempted, but explicit blocking is illegal. Finally, in preemptible
  780. * RCU implementations in real-time (with -rt patchset) kernel builds,
  781. * RCU read-side critical sections may be preempted and they may also
  782. * block, but only when acquiring spinlocks that are subject to priority
  783. * inheritance.
  784. */
  785. static inline void rcu_read_lock(void)
  786. {
  787. __rcu_read_lock();
  788. __acquire(RCU);
  789. rcu_lock_acquire(&rcu_lock_map);
  790. rcu_lockdep_assert(rcu_is_watching(),
  791. "rcu_read_lock() used illegally while idle");
  792. }
  793. /*
  794. * So where is rcu_write_lock()? It does not exist, as there is no
  795. * way for writers to lock out RCU readers. This is a feature, not
  796. * a bug -- this property is what provides RCU's performance benefits.
  797. * Of course, writers must coordinate with each other. The normal
  798. * spinlock primitives work well for this, but any other technique may be
  799. * used as well. RCU does not care how the writers keep out of each
  800. * others' way, as long as they do so.
  801. */
  802. /**
  803. * rcu_read_unlock() - marks the end of an RCU read-side critical section.
  804. *
  805. * See rcu_read_lock() for more information.
  806. */
  807. static inline void rcu_read_unlock(void)
  808. {
  809. rcu_lockdep_assert(rcu_is_watching(),
  810. "rcu_read_unlock() used illegally while idle");
  811. rcu_lock_release(&rcu_lock_map);
  812. __release(RCU);
  813. __rcu_read_unlock();
  814. }
  815. /**
  816. * rcu_read_lock_bh() - mark the beginning of an RCU-bh critical section
  817. *
  818. * This is equivalent of rcu_read_lock(), but to be used when updates
  819. * are being done using call_rcu_bh() or synchronize_rcu_bh(). Since
  820. * both call_rcu_bh() and synchronize_rcu_bh() consider completion of a
  821. * softirq handler to be a quiescent state, a process in RCU read-side
  822. * critical section must be protected by disabling softirqs. Read-side
  823. * critical sections in interrupt context can use just rcu_read_lock(),
  824. * though this should at least be commented to avoid confusing people
  825. * reading the code.
  826. *
  827. * Note that rcu_read_lock_bh() and the matching rcu_read_unlock_bh()
  828. * must occur in the same context, for example, it is illegal to invoke
  829. * rcu_read_unlock_bh() from one task if the matching rcu_read_lock_bh()
  830. * was invoked from some other task.
  831. */
  832. static inline void rcu_read_lock_bh(void)
  833. {
  834. local_bh_disable();
  835. __acquire(RCU_BH);
  836. rcu_lock_acquire(&rcu_bh_lock_map);
  837. rcu_lockdep_assert(rcu_is_watching(),
  838. "rcu_read_lock_bh() used illegally while idle");
  839. }
  840. /*
  841. * rcu_read_unlock_bh - marks the end of a softirq-only RCU critical section
  842. *
  843. * See rcu_read_lock_bh() for more information.
  844. */
  845. static inline void rcu_read_unlock_bh(void)
  846. {
  847. rcu_lockdep_assert(rcu_is_watching(),
  848. "rcu_read_unlock_bh() used illegally while idle");
  849. rcu_lock_release(&rcu_bh_lock_map);
  850. __release(RCU_BH);
  851. local_bh_enable();
  852. }
  853. /**
  854. * rcu_read_lock_sched() - mark the beginning of a RCU-sched critical section
  855. *
  856. * This is equivalent of rcu_read_lock(), but to be used when updates
  857. * are being done using call_rcu_sched() or synchronize_rcu_sched().
  858. * Read-side critical sections can also be introduced by anything that
  859. * disables preemption, including local_irq_disable() and friends.
  860. *
  861. * Note that rcu_read_lock_sched() and the matching rcu_read_unlock_sched()
  862. * must occur in the same context, for example, it is illegal to invoke
  863. * rcu_read_unlock_sched() from process context if the matching
  864. * rcu_read_lock_sched() was invoked from an NMI handler.
  865. */
  866. static inline void rcu_read_lock_sched(void)
  867. {
  868. preempt_disable();
  869. __acquire(RCU_SCHED);
  870. rcu_lock_acquire(&rcu_sched_lock_map);
  871. rcu_lockdep_assert(rcu_is_watching(),
  872. "rcu_read_lock_sched() used illegally while idle");
  873. }
  874. /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */
  875. static inline notrace void rcu_read_lock_sched_notrace(void)
  876. {
  877. preempt_disable_notrace();
  878. __acquire(RCU_SCHED);
  879. }
  880. /*
  881. * rcu_read_unlock_sched - marks the end of a RCU-classic critical section
  882. *
  883. * See rcu_read_lock_sched for more information.
  884. */
  885. static inline void rcu_read_unlock_sched(void)
  886. {
  887. rcu_lockdep_assert(rcu_is_watching(),
  888. "rcu_read_unlock_sched() used illegally while idle");
  889. rcu_lock_release(&rcu_sched_lock_map);
  890. __release(RCU_SCHED);
  891. preempt_enable();
  892. }
  893. /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */
  894. static inline notrace void rcu_read_unlock_sched_notrace(void)
  895. {
  896. __release(RCU_SCHED);
  897. preempt_enable_notrace();
  898. }
  899. /**
  900. * RCU_INIT_POINTER() - initialize an RCU protected pointer
  901. *
  902. * Initialize an RCU-protected pointer in special cases where readers
  903. * do not need ordering constraints on the CPU or the compiler. These
  904. * special cases are:
  905. *
  906. * 1. This use of RCU_INIT_POINTER() is NULLing out the pointer -or-
  907. * 2. The caller has taken whatever steps are required to prevent
  908. * RCU readers from concurrently accessing this pointer -or-
  909. * 3. The referenced data structure has already been exposed to
  910. * readers either at compile time or via rcu_assign_pointer() -and-
  911. * a. You have not made -any- reader-visible changes to
  912. * this structure since then -or-
  913. * b. It is OK for readers accessing this structure from its
  914. * new location to see the old state of the structure. (For
  915. * example, the changes were to statistical counters or to
  916. * other state where exact synchronization is not required.)
  917. *
  918. * Failure to follow these rules governing use of RCU_INIT_POINTER() will
  919. * result in impossible-to-diagnose memory corruption. As in the structures
  920. * will look OK in crash dumps, but any concurrent RCU readers might
  921. * see pre-initialized values of the referenced data structure. So
  922. * please be very careful how you use RCU_INIT_POINTER()!!!
  923. *
  924. * If you are creating an RCU-protected linked structure that is accessed
  925. * by a single external-to-structure RCU-protected pointer, then you may
  926. * use RCU_INIT_POINTER() to initialize the internal RCU-protected
  927. * pointers, but you must use rcu_assign_pointer() to initialize the
  928. * external-to-structure pointer -after- you have completely initialized
  929. * the reader-accessible portions of the linked structure.
  930. *
  931. * Note that unlike rcu_assign_pointer(), RCU_INIT_POINTER() provides no
  932. * ordering guarantees for either the CPU or the compiler.
  933. */
  934. #define RCU_INIT_POINTER(p, v) \
  935. do { \
  936. p = RCU_INITIALIZER(v); \
  937. } while (0)
  938. /**
  939. * RCU_POINTER_INITIALIZER() - statically initialize an RCU protected pointer
  940. *
  941. * GCC-style initialization for an RCU-protected pointer in a structure field.
  942. */
  943. #define RCU_POINTER_INITIALIZER(p, v) \
  944. .p = RCU_INITIALIZER(v)
  945. /*
  946. * Does the specified offset indicate that the corresponding rcu_head
  947. * structure can be handled by kfree_rcu()?
  948. */
  949. #define __is_kfree_rcu_offset(offset) ((offset) < 4096)
  950. /*
  951. * Helper macro for kfree_rcu() to prevent argument-expansion eyestrain.
  952. */
  953. #define __kfree_rcu(head, offset) \
  954. do { \
  955. BUILD_BUG_ON(!__is_kfree_rcu_offset(offset)); \
  956. kfree_call_rcu(head, (void (*)(struct rcu_head *))(unsigned long)(offset)); \
  957. } while (0)
  958. /**
  959. * kfree_rcu() - kfree an object after a grace period.
  960. * @ptr: pointer to kfree
  961. * @rcu_head: the name of the struct rcu_head within the type of @ptr.
  962. *
  963. * Many rcu callbacks functions just call kfree() on the base structure.
  964. * These functions are trivial, but their size adds up, and furthermore
  965. * when they are used in a kernel module, that module must invoke the
  966. * high-latency rcu_barrier() function at module-unload time.
  967. *
  968. * The kfree_rcu() function handles this issue. Rather than encoding a
  969. * function address in the embedded rcu_head structure, kfree_rcu() instead
  970. * encodes the offset of the rcu_head structure within the base structure.
  971. * Because the functions are not allowed in the low-order 4096 bytes of
  972. * kernel virtual memory, offsets up to 4095 bytes can be accommodated.
  973. * If the offset is larger than 4095 bytes, a compile-time error will
  974. * be generated in __kfree_rcu(). If this error is triggered, you can
  975. * either fall back to use of call_rcu() or rearrange the structure to
  976. * position the rcu_head structure into the first 4096 bytes.
  977. *
  978. * Note that the allowable offset might decrease in the future, for example,
  979. * to allow something like kmem_cache_free_rcu().
  980. *
  981. * The BUILD_BUG_ON check must not involve any function calls, hence the
  982. * checks are done in macros here.
  983. */
  984. #define kfree_rcu(ptr, rcu_head) \
  985. __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
  986. #if defined(CONFIG_TINY_RCU) || defined(CONFIG_RCU_NOCB_CPU_ALL)
  987. static inline int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
  988. {
  989. *delta_jiffies = ULONG_MAX;
  990. return 0;
  991. }
  992. #endif /* #if defined(CONFIG_TINY_RCU) || defined(CONFIG_RCU_NOCB_CPU_ALL) */
  993. #if defined(CONFIG_RCU_NOCB_CPU_ALL)
  994. static inline bool rcu_is_nocb_cpu(int cpu) { return true; }
  995. #elif defined(CONFIG_RCU_NOCB_CPU)
  996. bool rcu_is_nocb_cpu(int cpu);
  997. #else
  998. static inline bool rcu_is_nocb_cpu(int cpu) { return false; }
  999. #endif
  1000. /* Only for use by adaptive-ticks code. */
  1001. #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
  1002. bool rcu_sys_is_idle(void);
  1003. void rcu_sysidle_force_exit(void);
  1004. #else /* #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
  1005. static inline bool rcu_sys_is_idle(void)
  1006. {
  1007. return false;
  1008. }
  1009. static inline void rcu_sysidle_force_exit(void)
  1010. {
  1011. }
  1012. #endif /* #else #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
  1013. #endif /* __LINUX_RCUPDATE_H */