update.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Read-Copy Update mechanism for mutual exclusion
  4. *
  5. * Copyright IBM Corporation, 2001
  6. *
  7. * Authors: Dipankar Sarma <dipankar@in.ibm.com>
  8. * Manfred Spraul <manfred@colorfullife.com>
  9. *
  10. * Based on the original work by Paul McKenney <paulmck@linux.ibm.com>
  11. * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
  12. * Papers:
  13. * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
  14. * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
  15. *
  16. * For detailed explanation of Read-Copy Update mechanism see -
  17. * http://lse.sourceforge.net/locking/rcupdate.html
  18. *
  19. */
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/smp.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/sched/signal.h>
  27. #include <linux/sched/debug.h>
  28. #include <linux/torture.h>
  29. #include <linux/atomic.h>
  30. #include <linux/bitops.h>
  31. #include <linux/percpu.h>
  32. #include <linux/notifier.h>
  33. #include <linux/cpu.h>
  34. #include <linux/mutex.h>
  35. #include <linux/export.h>
  36. #include <linux/hardirq.h>
  37. #include <linux/delay.h>
  38. #include <linux/moduleparam.h>
  39. #include <linux/kthread.h>
  40. #include <linux/tick.h>
  41. #include <linux/rcupdate_wait.h>
  42. #include <linux/sched/isolation.h>
  43. #include <linux/kprobes.h>
  44. #include <linux/slab.h>
  45. #include <linux/irq_work.h>
  46. #include <linux/rcupdate_trace.h>
  47. #define CREATE_TRACE_POINTS
  48. #include "rcu.h"
  49. #ifdef MODULE_PARAM_PREFIX
  50. #undef MODULE_PARAM_PREFIX
  51. #endif
  52. #define MODULE_PARAM_PREFIX "rcupdate."
  53. #ifndef CONFIG_TINY_RCU
  54. module_param(rcu_expedited, int, 0444);
  55. module_param(rcu_normal, int, 0444);
  56. static int rcu_normal_after_boot = IS_ENABLED(CONFIG_PREEMPT_RT);
  57. #if !defined(CONFIG_PREEMPT_RT) || defined(CONFIG_NO_HZ_FULL)
  58. module_param(rcu_normal_after_boot, int, 0444);
  59. #endif
  60. #endif /* #ifndef CONFIG_TINY_RCU */
  61. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  62. /**
  63. * rcu_read_lock_held_common() - might we be in RCU-sched read-side critical section?
  64. * @ret: Best guess answer if lockdep cannot be relied on
  65. *
  66. * Returns true if lockdep must be ignored, in which case ``*ret`` contains
  67. * the best guess described below. Otherwise returns false, in which
  68. * case ``*ret`` tells the caller nothing and the caller should instead
  69. * consult lockdep.
  70. *
  71. * If CONFIG_DEBUG_LOCK_ALLOC is selected, set ``*ret`` to nonzero iff in an
  72. * RCU-sched read-side critical section. In absence of
  73. * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side
  74. * critical section unless it can prove otherwise. Note that disabling
  75. * of preemption (including disabling irqs) counts as an RCU-sched
  76. * read-side critical section. This is useful for debug checks in functions
  77. * that required that they be called within an RCU-sched read-side
  78. * critical section.
  79. *
  80. * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
  81. * and while lockdep is disabled.
  82. *
  83. * Note that if the CPU is in the idle loop from an RCU point of view (ie:
  84. * that we are in the section between ct_idle_enter() and ct_idle_exit())
  85. * then rcu_read_lock_held() sets ``*ret`` to false even if the CPU did an
  86. * rcu_read_lock(). The reason for this is that RCU ignores CPUs that are
  87. * in such a section, considering these as in extended quiescent state,
  88. * so such a CPU is effectively never in an RCU read-side critical section
  89. * regardless of what RCU primitives it invokes. This state of affairs is
  90. * required --- we need to keep an RCU-free window in idle where the CPU may
  91. * possibly enter into low power mode. This way we can notice an extended
  92. * quiescent state to other CPUs that started a grace period. Otherwise
  93. * we would delay any grace period as long as we run in the idle task.
  94. *
  95. * Similarly, we avoid claiming an RCU read lock held if the current
  96. * CPU is offline.
  97. */
  98. static bool rcu_read_lock_held_common(bool *ret)
  99. {
  100. if (!debug_lockdep_rcu_enabled()) {
  101. *ret = true;
  102. return true;
  103. }
  104. if (!rcu_is_watching()) {
  105. *ret = false;
  106. return true;
  107. }
  108. if (!rcu_lockdep_current_cpu_online()) {
  109. *ret = false;
  110. return true;
  111. }
  112. return false;
  113. }
  114. int rcu_read_lock_sched_held(void)
  115. {
  116. bool ret;
  117. if (rcu_read_lock_held_common(&ret))
  118. return ret;
  119. return lock_is_held(&rcu_sched_lock_map) || !preemptible();
  120. }
  121. EXPORT_SYMBOL(rcu_read_lock_sched_held);
  122. #endif
  123. #ifndef CONFIG_TINY_RCU
  124. /*
  125. * Should expedited grace-period primitives always fall back to their
  126. * non-expedited counterparts? Intended for use within RCU. Note
  127. * that if the user specifies both rcu_expedited and rcu_normal, then
  128. * rcu_normal wins. (Except during the time period during boot from
  129. * when the first task is spawned until the rcu_set_runtime_mode()
  130. * core_initcall() is invoked, at which point everything is expedited.)
  131. */
  132. bool rcu_gp_is_normal(void)
  133. {
  134. return READ_ONCE(rcu_normal) &&
  135. rcu_scheduler_active != RCU_SCHEDULER_INIT;
  136. }
  137. EXPORT_SYMBOL_GPL(rcu_gp_is_normal);
  138. static atomic_t rcu_async_hurry_nesting = ATOMIC_INIT(1);
  139. /*
  140. * Should call_rcu() callbacks be processed with urgency or are
  141. * they OK being executed with arbitrary delays?
  142. */
  143. bool rcu_async_should_hurry(void)
  144. {
  145. return !IS_ENABLED(CONFIG_RCU_LAZY) ||
  146. atomic_read(&rcu_async_hurry_nesting);
  147. }
  148. EXPORT_SYMBOL_GPL(rcu_async_should_hurry);
  149. /**
  150. * rcu_async_hurry - Make future async RCU callbacks not lazy.
  151. *
  152. * After a call to this function, future calls to call_rcu()
  153. * will be processed in a timely fashion.
  154. */
  155. void rcu_async_hurry(void)
  156. {
  157. if (IS_ENABLED(CONFIG_RCU_LAZY))
  158. atomic_inc(&rcu_async_hurry_nesting);
  159. }
  160. EXPORT_SYMBOL_GPL(rcu_async_hurry);
  161. /**
  162. * rcu_async_relax - Make future async RCU callbacks lazy.
  163. *
  164. * After a call to this function, future calls to call_rcu()
  165. * will be processed in a lazy fashion.
  166. */
  167. void rcu_async_relax(void)
  168. {
  169. if (IS_ENABLED(CONFIG_RCU_LAZY))
  170. atomic_dec(&rcu_async_hurry_nesting);
  171. }
  172. EXPORT_SYMBOL_GPL(rcu_async_relax);
  173. static atomic_t rcu_expedited_nesting = ATOMIC_INIT(1);
  174. /*
  175. * Should normal grace-period primitives be expedited? Intended for
  176. * use within RCU. Note that this function takes the rcu_expedited
  177. * sysfs/boot variable and rcu_scheduler_active into account as well
  178. * as the rcu_expedite_gp() nesting. So looping on rcu_unexpedite_gp()
  179. * until rcu_gp_is_expedited() returns false is a -really- bad idea.
  180. */
  181. bool rcu_gp_is_expedited(void)
  182. {
  183. return rcu_expedited || atomic_read(&rcu_expedited_nesting);
  184. }
  185. EXPORT_SYMBOL_GPL(rcu_gp_is_expedited);
  186. /**
  187. * rcu_expedite_gp - Expedite future RCU grace periods
  188. *
  189. * After a call to this function, future calls to synchronize_rcu() and
  190. * friends act as the corresponding synchronize_rcu_expedited() function
  191. * had instead been called.
  192. */
  193. void rcu_expedite_gp(void)
  194. {
  195. atomic_inc(&rcu_expedited_nesting);
  196. }
  197. EXPORT_SYMBOL_GPL(rcu_expedite_gp);
  198. /**
  199. * rcu_unexpedite_gp - Cancel prior rcu_expedite_gp() invocation
  200. *
  201. * Undo a prior call to rcu_expedite_gp(). If all prior calls to
  202. * rcu_expedite_gp() are undone by a subsequent call to rcu_unexpedite_gp(),
  203. * and if the rcu_expedited sysfs/boot parameter is not set, then all
  204. * subsequent calls to synchronize_rcu() and friends will return to
  205. * their normal non-expedited behavior.
  206. */
  207. void rcu_unexpedite_gp(void)
  208. {
  209. atomic_dec(&rcu_expedited_nesting);
  210. }
  211. EXPORT_SYMBOL_GPL(rcu_unexpedite_gp);
  212. static bool rcu_boot_ended __read_mostly;
  213. /*
  214. * Inform RCU of the end of the in-kernel boot sequence.
  215. */
  216. void rcu_end_inkernel_boot(void)
  217. {
  218. rcu_unexpedite_gp();
  219. rcu_async_relax();
  220. if (rcu_normal_after_boot)
  221. WRITE_ONCE(rcu_normal, 1);
  222. rcu_boot_ended = true;
  223. }
  224. /*
  225. * Let rcutorture know when it is OK to turn it up to eleven.
  226. */
  227. bool rcu_inkernel_boot_has_ended(void)
  228. {
  229. return rcu_boot_ended;
  230. }
  231. EXPORT_SYMBOL_GPL(rcu_inkernel_boot_has_ended);
  232. #endif /* #ifndef CONFIG_TINY_RCU */
  233. /*
  234. * Test each non-SRCU synchronous grace-period wait API. This is
  235. * useful just after a change in mode for these primitives, and
  236. * during early boot.
  237. */
  238. void rcu_test_sync_prims(void)
  239. {
  240. if (!IS_ENABLED(CONFIG_PROVE_RCU))
  241. return;
  242. pr_info("Running RCU synchronous self tests\n");
  243. synchronize_rcu();
  244. synchronize_rcu_expedited();
  245. }
  246. #if !defined(CONFIG_TINY_RCU)
  247. /*
  248. * Switch to run-time mode once RCU has fully initialized.
  249. */
  250. static int __init rcu_set_runtime_mode(void)
  251. {
  252. rcu_test_sync_prims();
  253. rcu_scheduler_active = RCU_SCHEDULER_RUNNING;
  254. kfree_rcu_scheduler_running();
  255. rcu_test_sync_prims();
  256. return 0;
  257. }
  258. core_initcall(rcu_set_runtime_mode);
  259. #endif /* #if !defined(CONFIG_TINY_RCU) */
  260. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  261. static struct lock_class_key rcu_lock_key;
  262. struct lockdep_map rcu_lock_map = {
  263. .name = "rcu_read_lock",
  264. .key = &rcu_lock_key,
  265. .wait_type_outer = LD_WAIT_FREE,
  266. .wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT implies PREEMPT_RCU */
  267. };
  268. EXPORT_SYMBOL_GPL(rcu_lock_map);
  269. static struct lock_class_key rcu_bh_lock_key;
  270. struct lockdep_map rcu_bh_lock_map = {
  271. .name = "rcu_read_lock_bh",
  272. .key = &rcu_bh_lock_key,
  273. .wait_type_outer = LD_WAIT_FREE,
  274. .wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. */
  275. };
  276. EXPORT_SYMBOL_GPL(rcu_bh_lock_map);
  277. static struct lock_class_key rcu_sched_lock_key;
  278. struct lockdep_map rcu_sched_lock_map = {
  279. .name = "rcu_read_lock_sched",
  280. .key = &rcu_sched_lock_key,
  281. .wait_type_outer = LD_WAIT_FREE,
  282. .wait_type_inner = LD_WAIT_SPIN,
  283. };
  284. EXPORT_SYMBOL_GPL(rcu_sched_lock_map);
  285. // Tell lockdep when RCU callbacks are being invoked.
  286. static struct lock_class_key rcu_callback_key;
  287. struct lockdep_map rcu_callback_map =
  288. STATIC_LOCKDEP_MAP_INIT("rcu_callback", &rcu_callback_key);
  289. EXPORT_SYMBOL_GPL(rcu_callback_map);
  290. noinstr int notrace debug_lockdep_rcu_enabled(void)
  291. {
  292. return rcu_scheduler_active != RCU_SCHEDULER_INACTIVE && READ_ONCE(debug_locks) &&
  293. current->lockdep_recursion == 0;
  294. }
  295. EXPORT_SYMBOL_GPL(debug_lockdep_rcu_enabled);
  296. /**
  297. * rcu_read_lock_held() - might we be in RCU read-side critical section?
  298. *
  299. * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU
  300. * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC,
  301. * this assumes we are in an RCU read-side critical section unless it can
  302. * prove otherwise. This is useful for debug checks in functions that
  303. * require that they be called within an RCU read-side critical section.
  304. *
  305. * Checks debug_lockdep_rcu_enabled() to prevent false positives during boot
  306. * and while lockdep is disabled.
  307. *
  308. * Note that rcu_read_lock() and the matching rcu_read_unlock() must
  309. * occur in the same context, for example, it is illegal to invoke
  310. * rcu_read_unlock() in process context if the matching rcu_read_lock()
  311. * was invoked from within an irq handler.
  312. *
  313. * Note that rcu_read_lock() is disallowed if the CPU is either idle or
  314. * offline from an RCU perspective, so check for those as well.
  315. */
  316. int rcu_read_lock_held(void)
  317. {
  318. bool ret;
  319. if (rcu_read_lock_held_common(&ret))
  320. return ret;
  321. return lock_is_held(&rcu_lock_map);
  322. }
  323. EXPORT_SYMBOL_GPL(rcu_read_lock_held);
  324. /**
  325. * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
  326. *
  327. * Check for bottom half being disabled, which covers both the
  328. * CONFIG_PROVE_RCU and not cases. Note that if someone uses
  329. * rcu_read_lock_bh(), but then later enables BH, lockdep (if enabled)
  330. * will show the situation. This is useful for debug checks in functions
  331. * that require that they be called within an RCU read-side critical
  332. * section.
  333. *
  334. * Check debug_lockdep_rcu_enabled() to prevent false positives during boot.
  335. *
  336. * Note that rcu_read_lock_bh() is disallowed if the CPU is either idle or
  337. * offline from an RCU perspective, so check for those as well.
  338. */
  339. int rcu_read_lock_bh_held(void)
  340. {
  341. bool ret;
  342. if (rcu_read_lock_held_common(&ret))
  343. return ret;
  344. return in_softirq() || irqs_disabled();
  345. }
  346. EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
  347. int rcu_read_lock_any_held(void)
  348. {
  349. bool ret;
  350. if (rcu_read_lock_held_common(&ret))
  351. return ret;
  352. if (lock_is_held(&rcu_lock_map) ||
  353. lock_is_held(&rcu_bh_lock_map) ||
  354. lock_is_held(&rcu_sched_lock_map))
  355. return 1;
  356. return !preemptible();
  357. }
  358. EXPORT_SYMBOL_GPL(rcu_read_lock_any_held);
  359. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  360. /**
  361. * wakeme_after_rcu() - Callback function to awaken a task after grace period
  362. * @head: Pointer to rcu_head member within rcu_synchronize structure
  363. *
  364. * Awaken the corresponding task now that a grace period has elapsed.
  365. */
  366. void wakeme_after_rcu(struct rcu_head *head)
  367. {
  368. struct rcu_synchronize *rcu;
  369. rcu = container_of(head, struct rcu_synchronize, head);
  370. complete(&rcu->completion);
  371. }
  372. EXPORT_SYMBOL_GPL(wakeme_after_rcu);
  373. void __wait_rcu_gp(bool checktiny, unsigned int state, int n, call_rcu_func_t *crcu_array,
  374. struct rcu_synchronize *rs_array)
  375. {
  376. int i;
  377. int j;
  378. /* Initialize and register callbacks for each crcu_array element. */
  379. for (i = 0; i < n; i++) {
  380. if (checktiny &&
  381. (crcu_array[i] == call_rcu)) {
  382. might_sleep();
  383. continue;
  384. }
  385. for (j = 0; j < i; j++)
  386. if (crcu_array[j] == crcu_array[i])
  387. break;
  388. if (j == i) {
  389. init_rcu_head_on_stack(&rs_array[i].head);
  390. init_completion(&rs_array[i].completion);
  391. (crcu_array[i])(&rs_array[i].head, wakeme_after_rcu);
  392. }
  393. }
  394. /* Wait for all callbacks to be invoked. */
  395. for (i = 0; i < n; i++) {
  396. if (checktiny &&
  397. (crcu_array[i] == call_rcu))
  398. continue;
  399. for (j = 0; j < i; j++)
  400. if (crcu_array[j] == crcu_array[i])
  401. break;
  402. if (j == i) {
  403. wait_for_completion_state(&rs_array[i].completion, state);
  404. destroy_rcu_head_on_stack(&rs_array[i].head);
  405. }
  406. }
  407. }
  408. EXPORT_SYMBOL_GPL(__wait_rcu_gp);
  409. void finish_rcuwait(struct rcuwait *w)
  410. {
  411. rcu_assign_pointer(w->task, NULL);
  412. __set_current_state(TASK_RUNNING);
  413. }
  414. EXPORT_SYMBOL_GPL(finish_rcuwait);
  415. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  416. void init_rcu_head(struct rcu_head *head)
  417. {
  418. debug_object_init(head, &rcuhead_debug_descr);
  419. }
  420. EXPORT_SYMBOL_GPL(init_rcu_head);
  421. void destroy_rcu_head(struct rcu_head *head)
  422. {
  423. debug_object_free(head, &rcuhead_debug_descr);
  424. }
  425. EXPORT_SYMBOL_GPL(destroy_rcu_head);
  426. static bool rcuhead_is_static_object(void *addr)
  427. {
  428. return true;
  429. }
  430. /**
  431. * init_rcu_head_on_stack() - initialize on-stack rcu_head for debugobjects
  432. * @head: pointer to rcu_head structure to be initialized
  433. *
  434. * This function informs debugobjects of a new rcu_head structure that
  435. * has been allocated as an auto variable on the stack. This function
  436. * is not required for rcu_head structures that are statically defined or
  437. * that are dynamically allocated on the heap. This function has no
  438. * effect for !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
  439. */
  440. void init_rcu_head_on_stack(struct rcu_head *head)
  441. {
  442. debug_object_init_on_stack(head, &rcuhead_debug_descr);
  443. }
  444. EXPORT_SYMBOL_GPL(init_rcu_head_on_stack);
  445. /**
  446. * destroy_rcu_head_on_stack() - destroy on-stack rcu_head for debugobjects
  447. * @head: pointer to rcu_head structure to be initialized
  448. *
  449. * This function informs debugobjects that an on-stack rcu_head structure
  450. * is about to go out of scope. As with init_rcu_head_on_stack(), this
  451. * function is not required for rcu_head structures that are statically
  452. * defined or that are dynamically allocated on the heap. Also as with
  453. * init_rcu_head_on_stack(), this function has no effect for
  454. * !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
  455. */
  456. void destroy_rcu_head_on_stack(struct rcu_head *head)
  457. {
  458. debug_object_free(head, &rcuhead_debug_descr);
  459. }
  460. EXPORT_SYMBOL_GPL(destroy_rcu_head_on_stack);
  461. const struct debug_obj_descr rcuhead_debug_descr = {
  462. .name = "rcu_head",
  463. .is_static_object = rcuhead_is_static_object,
  464. };
  465. EXPORT_SYMBOL_GPL(rcuhead_debug_descr);
  466. #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  467. #if defined(CONFIG_TREE_RCU) || defined(CONFIG_RCU_TRACE)
  468. void do_trace_rcu_torture_read(const char *rcutorturename, struct rcu_head *rhp,
  469. unsigned long secs,
  470. unsigned long c_old, unsigned long c)
  471. {
  472. trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c);
  473. }
  474. EXPORT_SYMBOL_GPL(do_trace_rcu_torture_read);
  475. #else
  476. #define do_trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c) \
  477. do { } while (0)
  478. #endif
  479. #if IS_ENABLED(CONFIG_RCU_TORTURE_TEST) || IS_MODULE(CONFIG_RCU_TORTURE_TEST) || IS_ENABLED(CONFIG_LOCK_TORTURE_TEST) || IS_MODULE(CONFIG_LOCK_TORTURE_TEST)
  480. /* Get rcutorture access to sched_setaffinity(). */
  481. long torture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
  482. {
  483. int ret;
  484. ret = sched_setaffinity(pid, in_mask);
  485. WARN_ONCE(ret, "%s: sched_setaffinity(%d) returned %d\n", __func__, pid, ret);
  486. return ret;
  487. }
  488. EXPORT_SYMBOL_GPL(torture_sched_setaffinity);
  489. #endif
  490. int rcu_cpu_stall_notifiers __read_mostly; // !0 = provide stall notifiers (rarely useful)
  491. EXPORT_SYMBOL_GPL(rcu_cpu_stall_notifiers);
  492. #ifdef CONFIG_RCU_STALL_COMMON
  493. int rcu_cpu_stall_ftrace_dump __read_mostly;
  494. module_param(rcu_cpu_stall_ftrace_dump, int, 0644);
  495. #ifdef CONFIG_RCU_CPU_STALL_NOTIFIER
  496. module_param(rcu_cpu_stall_notifiers, int, 0444);
  497. #endif // #ifdef CONFIG_RCU_CPU_STALL_NOTIFIER
  498. int rcu_cpu_stall_suppress __read_mostly; // !0 = suppress stall warnings.
  499. EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress);
  500. module_param(rcu_cpu_stall_suppress, int, 0644);
  501. int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;
  502. module_param(rcu_cpu_stall_timeout, int, 0644);
  503. int rcu_exp_cpu_stall_timeout __read_mostly = CONFIG_RCU_EXP_CPU_STALL_TIMEOUT;
  504. module_param(rcu_exp_cpu_stall_timeout, int, 0644);
  505. int rcu_cpu_stall_cputime __read_mostly = IS_ENABLED(CONFIG_RCU_CPU_STALL_CPUTIME);
  506. module_param(rcu_cpu_stall_cputime, int, 0644);
  507. bool rcu_exp_stall_task_details __read_mostly;
  508. module_param(rcu_exp_stall_task_details, bool, 0644);
  509. #endif /* #ifdef CONFIG_RCU_STALL_COMMON */
  510. // Suppress boot-time RCU CPU stall warnings and rcutorture writer stall
  511. // warnings. Also used by rcutorture even if stall warnings are excluded.
  512. int rcu_cpu_stall_suppress_at_boot __read_mostly; // !0 = suppress boot stalls.
  513. EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress_at_boot);
  514. module_param(rcu_cpu_stall_suppress_at_boot, int, 0444);
  515. /**
  516. * get_completed_synchronize_rcu - Return a pre-completed polled state cookie
  517. *
  518. * Returns a value that will always be treated by functions like
  519. * poll_state_synchronize_rcu() as a cookie whose grace period has already
  520. * completed.
  521. */
  522. unsigned long get_completed_synchronize_rcu(void)
  523. {
  524. return RCU_GET_STATE_COMPLETED;
  525. }
  526. EXPORT_SYMBOL_GPL(get_completed_synchronize_rcu);
  527. #ifdef CONFIG_PROVE_RCU
  528. /*
  529. * Early boot self test parameters.
  530. */
  531. static bool rcu_self_test;
  532. module_param(rcu_self_test, bool, 0444);
  533. static int rcu_self_test_counter;
  534. static void test_callback(struct rcu_head *r)
  535. {
  536. rcu_self_test_counter++;
  537. pr_info("RCU test callback executed %d\n", rcu_self_test_counter);
  538. }
  539. DEFINE_STATIC_SRCU(early_srcu);
  540. static unsigned long early_srcu_cookie;
  541. struct early_boot_kfree_rcu {
  542. struct rcu_head rh;
  543. };
  544. static void early_boot_test_call_rcu(void)
  545. {
  546. static struct rcu_head head;
  547. int idx;
  548. static struct rcu_head shead;
  549. struct early_boot_kfree_rcu *rhp;
  550. idx = srcu_down_read(&early_srcu);
  551. srcu_up_read(&early_srcu, idx);
  552. call_rcu(&head, test_callback);
  553. early_srcu_cookie = start_poll_synchronize_srcu(&early_srcu);
  554. call_srcu(&early_srcu, &shead, test_callback);
  555. rhp = kmalloc(sizeof(*rhp), GFP_KERNEL);
  556. if (!WARN_ON_ONCE(!rhp))
  557. kfree_rcu(rhp, rh);
  558. }
  559. void rcu_early_boot_tests(void)
  560. {
  561. pr_info("Running RCU self tests\n");
  562. if (rcu_self_test)
  563. early_boot_test_call_rcu();
  564. rcu_test_sync_prims();
  565. }
  566. static int rcu_verify_early_boot_tests(void)
  567. {
  568. int ret = 0;
  569. int early_boot_test_counter = 0;
  570. if (rcu_self_test) {
  571. early_boot_test_counter++;
  572. rcu_barrier();
  573. early_boot_test_counter++;
  574. srcu_barrier(&early_srcu);
  575. WARN_ON_ONCE(!poll_state_synchronize_srcu(&early_srcu, early_srcu_cookie));
  576. cleanup_srcu_struct(&early_srcu);
  577. }
  578. if (rcu_self_test_counter != early_boot_test_counter) {
  579. WARN_ON(1);
  580. ret = -1;
  581. }
  582. return ret;
  583. }
  584. late_initcall(rcu_verify_early_boot_tests);
  585. #else
  586. void rcu_early_boot_tests(void) {}
  587. #endif /* CONFIG_PROVE_RCU */
  588. #include "tasks.h"
  589. #ifndef CONFIG_TINY_RCU
  590. /*
  591. * Print any significant non-default boot-time settings.
  592. */
  593. void __init rcupdate_announce_bootup_oddness(void)
  594. {
  595. if (rcu_normal)
  596. pr_info("\tNo expedited grace period (rcu_normal).\n");
  597. else if (rcu_normal_after_boot)
  598. pr_info("\tNo expedited grace period (rcu_normal_after_boot).\n");
  599. else if (rcu_expedited)
  600. pr_info("\tAll grace periods are expedited (rcu_expedited).\n");
  601. if (rcu_cpu_stall_suppress)
  602. pr_info("\tRCU CPU stall warnings suppressed (rcu_cpu_stall_suppress).\n");
  603. if (rcu_cpu_stall_timeout != CONFIG_RCU_CPU_STALL_TIMEOUT)
  604. pr_info("\tRCU CPU stall warnings timeout set to %d (rcu_cpu_stall_timeout).\n", rcu_cpu_stall_timeout);
  605. rcu_tasks_bootup_oddness();
  606. }
  607. #endif /* #ifndef CONFIG_TINY_RCU */