update.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. * Authors: Dipankar Sarma <dipankar@in.ibm.com>
  21. * Manfred Spraul <manfred@colorfullife.com>
  22. *
  23. * Based on the original work by Paul McKenney <paulmck@us.ibm.com>
  24. * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
  25. * Papers:
  26. * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
  27. * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
  28. *
  29. * For detailed explanation of Read-Copy Update mechanism see -
  30. * http://lse.sourceforge.net/locking/rcupdate.html
  31. *
  32. */
  33. #include <linux/types.h>
  34. #include <linux/kernel.h>
  35. #include <linux/init.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/smp.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/sched.h>
  40. #include <linux/atomic.h>
  41. #include <linux/bitops.h>
  42. #include <linux/percpu.h>
  43. #include <linux/notifier.h>
  44. #include <linux/cpu.h>
  45. #include <linux/mutex.h>
  46. #include <linux/export.h>
  47. #include <linux/hardirq.h>
  48. #include <linux/delay.h>
  49. #include <linux/module.h>
  50. #include <linux/kthread.h>
  51. #define CREATE_TRACE_POINTS
  52. #include "rcu.h"
  53. MODULE_ALIAS("rcupdate");
  54. #ifdef MODULE_PARAM_PREFIX
  55. #undef MODULE_PARAM_PREFIX
  56. #endif
  57. #define MODULE_PARAM_PREFIX "rcupdate."
  58. module_param(rcu_expedited, int, 0);
  59. #ifdef CONFIG_PREEMPT_RCU
  60. /*
  61. * Preemptible RCU implementation for rcu_read_lock().
  62. * Just increment ->rcu_read_lock_nesting, shared state will be updated
  63. * if we block.
  64. */
  65. void __rcu_read_lock(void)
  66. {
  67. current->rcu_read_lock_nesting++;
  68. barrier(); /* critical section after entry code. */
  69. }
  70. EXPORT_SYMBOL_GPL(__rcu_read_lock);
  71. /*
  72. * Preemptible RCU implementation for rcu_read_unlock().
  73. * Decrement ->rcu_read_lock_nesting. If the result is zero (outermost
  74. * rcu_read_unlock()) and ->rcu_read_unlock_special is non-zero, then
  75. * invoke rcu_read_unlock_special() to clean up after a context switch
  76. * in an RCU read-side critical section and other special cases.
  77. */
  78. void __rcu_read_unlock(void)
  79. {
  80. struct task_struct *t = current;
  81. if (t->rcu_read_lock_nesting != 1) {
  82. --t->rcu_read_lock_nesting;
  83. } else {
  84. barrier(); /* critical section before exit code. */
  85. t->rcu_read_lock_nesting = INT_MIN;
  86. barrier(); /* assign before ->rcu_read_unlock_special load */
  87. if (unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
  88. rcu_read_unlock_special(t);
  89. barrier(); /* ->rcu_read_unlock_special load before assign */
  90. t->rcu_read_lock_nesting = 0;
  91. }
  92. #ifdef CONFIG_PROVE_LOCKING
  93. {
  94. int rrln = ACCESS_ONCE(t->rcu_read_lock_nesting);
  95. WARN_ON_ONCE(rrln < 0 && rrln > INT_MIN / 2);
  96. }
  97. #endif /* #ifdef CONFIG_PROVE_LOCKING */
  98. }
  99. EXPORT_SYMBOL_GPL(__rcu_read_unlock);
  100. #endif /* #ifdef CONFIG_PREEMPT_RCU */
  101. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  102. static struct lock_class_key rcu_lock_key;
  103. struct lockdep_map rcu_lock_map =
  104. STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key);
  105. EXPORT_SYMBOL_GPL(rcu_lock_map);
  106. static struct lock_class_key rcu_bh_lock_key;
  107. struct lockdep_map rcu_bh_lock_map =
  108. STATIC_LOCKDEP_MAP_INIT("rcu_read_lock_bh", &rcu_bh_lock_key);
  109. EXPORT_SYMBOL_GPL(rcu_bh_lock_map);
  110. static struct lock_class_key rcu_sched_lock_key;
  111. struct lockdep_map rcu_sched_lock_map =
  112. STATIC_LOCKDEP_MAP_INIT("rcu_read_lock_sched", &rcu_sched_lock_key);
  113. EXPORT_SYMBOL_GPL(rcu_sched_lock_map);
  114. static struct lock_class_key rcu_callback_key;
  115. struct lockdep_map rcu_callback_map =
  116. STATIC_LOCKDEP_MAP_INIT("rcu_callback", &rcu_callback_key);
  117. EXPORT_SYMBOL_GPL(rcu_callback_map);
  118. int notrace debug_lockdep_rcu_enabled(void)
  119. {
  120. return rcu_scheduler_active && debug_locks &&
  121. current->lockdep_recursion == 0;
  122. }
  123. EXPORT_SYMBOL_GPL(debug_lockdep_rcu_enabled);
  124. /**
  125. * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
  126. *
  127. * Check for bottom half being disabled, which covers both the
  128. * CONFIG_PROVE_RCU and not cases. Note that if someone uses
  129. * rcu_read_lock_bh(), but then later enables BH, lockdep (if enabled)
  130. * will show the situation. This is useful for debug checks in functions
  131. * that require that they be called within an RCU read-side critical
  132. * section.
  133. *
  134. * Check debug_lockdep_rcu_enabled() to prevent false positives during boot.
  135. *
  136. * Note that rcu_read_lock() is disallowed if the CPU is either idle or
  137. * offline from an RCU perspective, so check for those as well.
  138. */
  139. int rcu_read_lock_bh_held(void)
  140. {
  141. if (!debug_lockdep_rcu_enabled())
  142. return 1;
  143. if (!rcu_is_watching())
  144. return 0;
  145. if (!rcu_lockdep_current_cpu_online())
  146. return 0;
  147. return in_softirq() || irqs_disabled();
  148. }
  149. EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
  150. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  151. struct rcu_synchronize {
  152. struct rcu_head head;
  153. struct completion completion;
  154. };
  155. /*
  156. * Awaken the corresponding synchronize_rcu() instance now that a
  157. * grace period has elapsed.
  158. */
  159. static void wakeme_after_rcu(struct rcu_head *head)
  160. {
  161. struct rcu_synchronize *rcu;
  162. rcu = container_of(head, struct rcu_synchronize, head);
  163. complete(&rcu->completion);
  164. }
  165. void wait_rcu_gp(call_rcu_func_t crf)
  166. {
  167. struct rcu_synchronize rcu;
  168. init_rcu_head_on_stack(&rcu.head);
  169. init_completion(&rcu.completion);
  170. /* Will wake me after RCU finished. */
  171. crf(&rcu.head, wakeme_after_rcu);
  172. /* Wait for it. */
  173. wait_for_completion(&rcu.completion);
  174. destroy_rcu_head_on_stack(&rcu.head);
  175. }
  176. EXPORT_SYMBOL_GPL(wait_rcu_gp);
  177. #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
  178. void init_rcu_head(struct rcu_head *head)
  179. {
  180. debug_object_init(head, &rcuhead_debug_descr);
  181. }
  182. void destroy_rcu_head(struct rcu_head *head)
  183. {
  184. debug_object_free(head, &rcuhead_debug_descr);
  185. }
  186. /*
  187. * fixup_activate is called when:
  188. * - an active object is activated
  189. * - an unknown object is activated (might be a statically initialized object)
  190. * Activation is performed internally by call_rcu().
  191. */
  192. static int rcuhead_fixup_activate(void *addr, enum debug_obj_state state)
  193. {
  194. struct rcu_head *head = addr;
  195. switch (state) {
  196. case ODEBUG_STATE_NOTAVAILABLE:
  197. /*
  198. * This is not really a fixup. We just make sure that it is
  199. * tracked in the object tracker.
  200. */
  201. debug_object_init(head, &rcuhead_debug_descr);
  202. debug_object_activate(head, &rcuhead_debug_descr);
  203. return 0;
  204. default:
  205. return 1;
  206. }
  207. }
  208. /**
  209. * init_rcu_head_on_stack() - initialize on-stack rcu_head for debugobjects
  210. * @head: pointer to rcu_head structure to be initialized
  211. *
  212. * This function informs debugobjects of a new rcu_head structure that
  213. * has been allocated as an auto variable on the stack. This function
  214. * is not required for rcu_head structures that are statically defined or
  215. * that are dynamically allocated on the heap. This function has no
  216. * effect for !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
  217. */
  218. void init_rcu_head_on_stack(struct rcu_head *head)
  219. {
  220. debug_object_init_on_stack(head, &rcuhead_debug_descr);
  221. }
  222. EXPORT_SYMBOL_GPL(init_rcu_head_on_stack);
  223. /**
  224. * destroy_rcu_head_on_stack() - destroy on-stack rcu_head for debugobjects
  225. * @head: pointer to rcu_head structure to be initialized
  226. *
  227. * This function informs debugobjects that an on-stack rcu_head structure
  228. * is about to go out of scope. As with init_rcu_head_on_stack(), this
  229. * function is not required for rcu_head structures that are statically
  230. * defined or that are dynamically allocated on the heap. Also as with
  231. * init_rcu_head_on_stack(), this function has no effect for
  232. * !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
  233. */
  234. void destroy_rcu_head_on_stack(struct rcu_head *head)
  235. {
  236. debug_object_free(head, &rcuhead_debug_descr);
  237. }
  238. EXPORT_SYMBOL_GPL(destroy_rcu_head_on_stack);
  239. struct debug_obj_descr rcuhead_debug_descr = {
  240. .name = "rcu_head",
  241. .fixup_activate = rcuhead_fixup_activate,
  242. };
  243. EXPORT_SYMBOL_GPL(rcuhead_debug_descr);
  244. #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
  245. #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU) || defined(CONFIG_RCU_TRACE)
  246. void do_trace_rcu_torture_read(const char *rcutorturename, struct rcu_head *rhp,
  247. unsigned long secs,
  248. unsigned long c_old, unsigned long c)
  249. {
  250. trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c);
  251. }
  252. EXPORT_SYMBOL_GPL(do_trace_rcu_torture_read);
  253. #else
  254. #define do_trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c) \
  255. do { } while (0)
  256. #endif
  257. #ifdef CONFIG_RCU_STALL_COMMON
  258. #ifdef CONFIG_PROVE_RCU
  259. #define RCU_STALL_DELAY_DELTA (5 * HZ)
  260. #else
  261. #define RCU_STALL_DELAY_DELTA 0
  262. #endif
  263. int rcu_cpu_stall_suppress __read_mostly; /* 1 = suppress stall warnings. */
  264. static int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;
  265. module_param(rcu_cpu_stall_suppress, int, 0644);
  266. module_param(rcu_cpu_stall_timeout, int, 0644);
  267. int rcu_jiffies_till_stall_check(void)
  268. {
  269. int till_stall_check = ACCESS_ONCE(rcu_cpu_stall_timeout);
  270. /*
  271. * Limit check must be consistent with the Kconfig limits
  272. * for CONFIG_RCU_CPU_STALL_TIMEOUT.
  273. */
  274. if (till_stall_check < 3) {
  275. ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
  276. till_stall_check = 3;
  277. } else if (till_stall_check > 300) {
  278. ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
  279. till_stall_check = 300;
  280. }
  281. return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
  282. }
  283. void rcu_sysrq_start(void)
  284. {
  285. if (!rcu_cpu_stall_suppress)
  286. rcu_cpu_stall_suppress = 2;
  287. }
  288. void rcu_sysrq_end(void)
  289. {
  290. if (rcu_cpu_stall_suppress == 2)
  291. rcu_cpu_stall_suppress = 0;
  292. }
  293. static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr)
  294. {
  295. rcu_cpu_stall_suppress = 1;
  296. return NOTIFY_DONE;
  297. }
  298. static struct notifier_block rcu_panic_block = {
  299. .notifier_call = rcu_panic,
  300. };
  301. static int __init check_cpu_stall_init(void)
  302. {
  303. atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block);
  304. return 0;
  305. }
  306. early_initcall(check_cpu_stall_init);
  307. #endif /* #ifdef CONFIG_RCU_STALL_COMMON */
  308. #ifdef CONFIG_TASKS_RCU
  309. /*
  310. * Simple variant of RCU whose quiescent states are voluntary context switch,
  311. * user-space execution, and idle. As such, grace periods can take one good
  312. * long time. There are no read-side primitives similar to rcu_read_lock()
  313. * and rcu_read_unlock() because this implementation is intended to get
  314. * the system into a safe state for some of the manipulations involved in
  315. * tracing and the like. Finally, this implementation does not support
  316. * high call_rcu_tasks() rates from multiple CPUs. If this is required,
  317. * per-CPU callback lists will be needed.
  318. */
  319. /* Global list of callbacks and associated lock. */
  320. static struct rcu_head *rcu_tasks_cbs_head;
  321. static struct rcu_head **rcu_tasks_cbs_tail = &rcu_tasks_cbs_head;
  322. static DEFINE_RAW_SPINLOCK(rcu_tasks_cbs_lock);
  323. /* Track exiting tasks in order to allow them to be waited for. */
  324. DEFINE_SRCU(tasks_rcu_exit_srcu);
  325. /* Control stall timeouts. Disable with <= 0, otherwise jiffies till stall. */
  326. static int rcu_task_stall_timeout __read_mostly = HZ * 60 * 10;
  327. module_param(rcu_task_stall_timeout, int, 0644);
  328. /* Post an RCU-tasks callback. */
  329. void call_rcu_tasks(struct rcu_head *rhp, void (*func)(struct rcu_head *rhp))
  330. {
  331. unsigned long flags;
  332. rhp->next = NULL;
  333. rhp->func = func;
  334. raw_spin_lock_irqsave(&rcu_tasks_cbs_lock, flags);
  335. *rcu_tasks_cbs_tail = rhp;
  336. rcu_tasks_cbs_tail = &rhp->next;
  337. raw_spin_unlock_irqrestore(&rcu_tasks_cbs_lock, flags);
  338. }
  339. EXPORT_SYMBOL_GPL(call_rcu_tasks);
  340. /**
  341. * synchronize_rcu_tasks - wait until an rcu-tasks grace period has elapsed.
  342. *
  343. * Control will return to the caller some time after a full rcu-tasks
  344. * grace period has elapsed, in other words after all currently
  345. * executing rcu-tasks read-side critical sections have elapsed. These
  346. * read-side critical sections are delimited by calls to schedule(),
  347. * cond_resched_rcu_qs(), idle execution, userspace execution, calls
  348. * to synchronize_rcu_tasks(), and (in theory, anyway) cond_resched().
  349. *
  350. * This is a very specialized primitive, intended only for a few uses in
  351. * tracing and other situations requiring manipulation of function
  352. * preambles and profiling hooks. The synchronize_rcu_tasks() function
  353. * is not (yet) intended for heavy use from multiple CPUs.
  354. *
  355. * Note that this guarantee implies further memory-ordering guarantees.
  356. * On systems with more than one CPU, when synchronize_rcu_tasks() returns,
  357. * each CPU is guaranteed to have executed a full memory barrier since the
  358. * end of its last RCU-tasks read-side critical section whose beginning
  359. * preceded the call to synchronize_rcu_tasks(). In addition, each CPU
  360. * having an RCU-tasks read-side critical section that extends beyond
  361. * the return from synchronize_rcu_tasks() is guaranteed to have executed
  362. * a full memory barrier after the beginning of synchronize_rcu_tasks()
  363. * and before the beginning of that RCU-tasks read-side critical section.
  364. * Note that these guarantees include CPUs that are offline, idle, or
  365. * executing in user mode, as well as CPUs that are executing in the kernel.
  366. *
  367. * Furthermore, if CPU A invoked synchronize_rcu_tasks(), which returned
  368. * to its caller on CPU B, then both CPU A and CPU B are guaranteed
  369. * to have executed a full memory barrier during the execution of
  370. * synchronize_rcu_tasks() -- even if CPU A and CPU B are the same CPU
  371. * (but again only if the system has more than one CPU).
  372. */
  373. void synchronize_rcu_tasks(void)
  374. {
  375. /* Complain if the scheduler has not started. */
  376. rcu_lockdep_assert(!rcu_scheduler_active,
  377. "synchronize_rcu_tasks called too soon");
  378. /* Wait for the grace period. */
  379. wait_rcu_gp(call_rcu_tasks);
  380. }
  381. EXPORT_SYMBOL_GPL(synchronize_rcu_tasks);
  382. /**
  383. * rcu_barrier_tasks - Wait for in-flight call_rcu_tasks() callbacks.
  384. *
  385. * Although the current implementation is guaranteed to wait, it is not
  386. * obligated to, for example, if there are no pending callbacks.
  387. */
  388. void rcu_barrier_tasks(void)
  389. {
  390. /* There is only one callback queue, so this is easy. ;-) */
  391. synchronize_rcu_tasks();
  392. }
  393. EXPORT_SYMBOL_GPL(rcu_barrier_tasks);
  394. /* See if tasks are still holding out, complain if so. */
  395. static void check_holdout_task(struct task_struct *t,
  396. bool needreport, bool *firstreport)
  397. {
  398. if (!ACCESS_ONCE(t->rcu_tasks_holdout) ||
  399. t->rcu_tasks_nvcsw != ACCESS_ONCE(t->nvcsw) ||
  400. !ACCESS_ONCE(t->on_rq)) {
  401. ACCESS_ONCE(t->rcu_tasks_holdout) = false;
  402. list_del_rcu(&t->rcu_tasks_holdout_list);
  403. put_task_struct(t);
  404. return;
  405. }
  406. if (!needreport)
  407. return;
  408. if (*firstreport) {
  409. pr_err("INFO: rcu_tasks detected stalls on tasks:\n");
  410. *firstreport = false;
  411. }
  412. sched_show_task(t);
  413. }
  414. /* RCU-tasks kthread that detects grace periods and invokes callbacks. */
  415. static int __noreturn rcu_tasks_kthread(void *arg)
  416. {
  417. unsigned long flags;
  418. struct task_struct *g, *t;
  419. unsigned long lastreport;
  420. struct rcu_head *list;
  421. struct rcu_head *next;
  422. LIST_HEAD(rcu_tasks_holdouts);
  423. /* FIXME: Add housekeeping affinity. */
  424. /*
  425. * Each pass through the following loop makes one check for
  426. * newly arrived callbacks, and, if there are some, waits for
  427. * one RCU-tasks grace period and then invokes the callbacks.
  428. * This loop is terminated by the system going down. ;-)
  429. */
  430. for (;;) {
  431. /* Pick up any new callbacks. */
  432. raw_spin_lock_irqsave(&rcu_tasks_cbs_lock, flags);
  433. list = rcu_tasks_cbs_head;
  434. rcu_tasks_cbs_head = NULL;
  435. rcu_tasks_cbs_tail = &rcu_tasks_cbs_head;
  436. raw_spin_unlock_irqrestore(&rcu_tasks_cbs_lock, flags);
  437. /* If there were none, wait a bit and start over. */
  438. if (!list) {
  439. schedule_timeout_interruptible(HZ);
  440. WARN_ON(signal_pending(current));
  441. continue;
  442. }
  443. /*
  444. * Wait for all pre-existing t->on_rq and t->nvcsw
  445. * transitions to complete. Invoking synchronize_sched()
  446. * suffices because all these transitions occur with
  447. * interrupts disabled. Without this synchronize_sched(),
  448. * a read-side critical section that started before the
  449. * grace period might be incorrectly seen as having started
  450. * after the grace period.
  451. *
  452. * This synchronize_sched() also dispenses with the
  453. * need for a memory barrier on the first store to
  454. * ->rcu_tasks_holdout, as it forces the store to happen
  455. * after the beginning of the grace period.
  456. */
  457. synchronize_sched();
  458. /*
  459. * There were callbacks, so we need to wait for an
  460. * RCU-tasks grace period. Start off by scanning
  461. * the task list for tasks that are not already
  462. * voluntarily blocked. Mark these tasks and make
  463. * a list of them in rcu_tasks_holdouts.
  464. */
  465. rcu_read_lock();
  466. for_each_process_thread(g, t) {
  467. if (t != current && ACCESS_ONCE(t->on_rq) &&
  468. !is_idle_task(t)) {
  469. get_task_struct(t);
  470. t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
  471. ACCESS_ONCE(t->rcu_tasks_holdout) = true;
  472. list_add(&t->rcu_tasks_holdout_list,
  473. &rcu_tasks_holdouts);
  474. }
  475. }
  476. rcu_read_unlock();
  477. /*
  478. * Wait for tasks that are in the process of exiting.
  479. * This does only part of the job, ensuring that all
  480. * tasks that were previously exiting reach the point
  481. * where they have disabled preemption, allowing the
  482. * later synchronize_sched() to finish the job.
  483. */
  484. synchronize_srcu(&tasks_rcu_exit_srcu);
  485. /*
  486. * Each pass through the following loop scans the list
  487. * of holdout tasks, removing any that are no longer
  488. * holdouts. When the list is empty, we are done.
  489. */
  490. lastreport = jiffies;
  491. while (!list_empty(&rcu_tasks_holdouts)) {
  492. bool firstreport;
  493. bool needreport;
  494. int rtst;
  495. schedule_timeout_interruptible(HZ);
  496. rtst = ACCESS_ONCE(rcu_task_stall_timeout);
  497. needreport = rtst > 0 &&
  498. time_after(jiffies, lastreport + rtst);
  499. if (needreport)
  500. lastreport = jiffies;
  501. firstreport = true;
  502. WARN_ON(signal_pending(current));
  503. rcu_read_lock();
  504. list_for_each_entry_rcu(t, &rcu_tasks_holdouts,
  505. rcu_tasks_holdout_list)
  506. check_holdout_task(t, needreport, &firstreport);
  507. rcu_read_unlock();
  508. }
  509. /*
  510. * Because ->on_rq and ->nvcsw are not guaranteed
  511. * to have a full memory barriers prior to them in the
  512. * schedule() path, memory reordering on other CPUs could
  513. * cause their RCU-tasks read-side critical sections to
  514. * extend past the end of the grace period. However,
  515. * because these ->nvcsw updates are carried out with
  516. * interrupts disabled, we can use synchronize_sched()
  517. * to force the needed ordering on all such CPUs.
  518. *
  519. * This synchronize_sched() also confines all
  520. * ->rcu_tasks_holdout accesses to be within the grace
  521. * period, avoiding the need for memory barriers for
  522. * ->rcu_tasks_holdout accesses.
  523. *
  524. * In addition, this synchronize_sched() waits for exiting
  525. * tasks to complete their final preempt_disable() region
  526. * of execution, cleaning up after the synchronize_srcu()
  527. * above.
  528. */
  529. synchronize_sched();
  530. /* Invoke the callbacks. */
  531. while (list) {
  532. next = list->next;
  533. local_bh_disable();
  534. list->func(list);
  535. local_bh_enable();
  536. list = next;
  537. cond_resched();
  538. }
  539. }
  540. }
  541. /* Spawn rcu_tasks_kthread() at boot time. */
  542. static int __init rcu_spawn_tasks_kthread(void)
  543. {
  544. struct task_struct __maybe_unused *t;
  545. t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
  546. BUG_ON(IS_ERR(t));
  547. return 0;
  548. }
  549. early_initcall(rcu_spawn_tasks_kthread);
  550. #endif /* #ifdef CONFIG_TASKS_RCU */