xref: /linux/kernel/rcu/tree_stall.h (revision d58db3f3a00af00fce5f914c9d1a946ef7feecb6)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * RCU CPU stall warnings for normal RCU grace periods
4  *
5  * Copyright IBM Corporation, 2019
6  *
7  * Author: Paul E. McKenney <paulmck@linux.ibm.com>
8  */
9 
10 #include <linux/console.h>
11 #include <linux/kvm_para.h>
12 #include <linux/rcu_notifier.h>
13 
14 //////////////////////////////////////////////////////////////////////////////
15 //
16 // Controlling CPU stall warnings, including delay calculation.
17 
18 /* panic() on RCU Stall sysctl. */
19 int sysctl_panic_on_rcu_stall __read_mostly;
20 int sysctl_max_rcu_stall_to_panic __read_mostly;
21 
22 #ifdef CONFIG_PROVE_RCU
23 #define RCU_STALL_DELAY_DELTA		(5 * HZ)
24 #else
25 #define RCU_STALL_DELAY_DELTA		0
26 #endif
27 #define RCU_STALL_MIGHT_DIV		8
28 #define RCU_STALL_MIGHT_MIN		(2 * HZ)
29 
30 int rcu_exp_jiffies_till_stall_check(void)
31 {
32 	int cpu_stall_timeout = READ_ONCE(rcu_exp_cpu_stall_timeout);
33 	int exp_stall_delay_delta = 0;
34 	int till_stall_check;
35 
36 	// Zero says to use rcu_cpu_stall_timeout, but in milliseconds.
37 	if (!cpu_stall_timeout)
38 		cpu_stall_timeout = jiffies_to_msecs(rcu_jiffies_till_stall_check());
39 
40 	// Limit check must be consistent with the Kconfig limits for
41 	// CONFIG_RCU_EXP_CPU_STALL_TIMEOUT, so check the allowed range.
42 	// The minimum clamped value is "2UL", because at least one full
43 	// tick has to be guaranteed.
44 	till_stall_check = clamp(msecs_to_jiffies(cpu_stall_timeout), 2UL, 300UL * HZ);
45 
46 	if (cpu_stall_timeout && jiffies_to_msecs(till_stall_check) != cpu_stall_timeout)
47 		WRITE_ONCE(rcu_exp_cpu_stall_timeout, jiffies_to_msecs(till_stall_check));
48 
49 #ifdef CONFIG_PROVE_RCU
50 	/* Add extra ~25% out of till_stall_check. */
51 	exp_stall_delay_delta = ((till_stall_check * 25) / 100) + 1;
52 #endif
53 
54 	return till_stall_check + exp_stall_delay_delta;
55 }
56 EXPORT_SYMBOL_GPL(rcu_exp_jiffies_till_stall_check);
57 
58 /* Limit-check stall timeouts specified at boottime and runtime. */
59 int rcu_jiffies_till_stall_check(void)
60 {
61 	int till_stall_check = READ_ONCE(rcu_cpu_stall_timeout);
62 
63 	/*
64 	 * Limit check must be consistent with the Kconfig limits
65 	 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
66 	 */
67 	if (till_stall_check < 3) {
68 		WRITE_ONCE(rcu_cpu_stall_timeout, 3);
69 		till_stall_check = 3;
70 	} else if (till_stall_check > 300) {
71 		WRITE_ONCE(rcu_cpu_stall_timeout, 300);
72 		till_stall_check = 300;
73 	}
74 	return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
75 }
76 EXPORT_SYMBOL_GPL(rcu_jiffies_till_stall_check);
77 
78 /**
79  * rcu_gp_might_be_stalled - Is it likely that the grace period is stalled?
80  *
81  * Returns @true if the current grace period is sufficiently old that
82  * it is reasonable to assume that it might be stalled.  This can be
83  * useful when deciding whether to allocate memory to enable RCU-mediated
84  * freeing on the one hand or just invoking synchronize_rcu() on the other.
85  * The latter is preferable when the grace period is stalled.
86  *
87  * Note that sampling of the .gp_start and .gp_seq fields must be done
88  * carefully to avoid false positives at the beginnings and ends of
89  * grace periods.
90  */
91 bool rcu_gp_might_be_stalled(void)
92 {
93 	unsigned long d = rcu_jiffies_till_stall_check() / RCU_STALL_MIGHT_DIV;
94 	unsigned long j = jiffies;
95 
96 	if (d < RCU_STALL_MIGHT_MIN)
97 		d = RCU_STALL_MIGHT_MIN;
98 	smp_mb(); // jiffies before .gp_seq to avoid false positives.
99 	if (!rcu_gp_in_progress())
100 		return false;
101 	// Long delays at this point avoids false positive, but a delay
102 	// of ULONG_MAX/4 jiffies voids your no-false-positive warranty.
103 	smp_mb(); // .gp_seq before second .gp_start
104 	// And ditto here.
105 	return !time_before(j, READ_ONCE(rcu_state.gp_start) + d);
106 }
107 
108 /* Don't do RCU CPU stall warnings during long sysrq printouts. */
109 void rcu_sysrq_start(void)
110 {
111 	if (!rcu_cpu_stall_suppress)
112 		rcu_cpu_stall_suppress = 2;
113 }
114 
115 void rcu_sysrq_end(void)
116 {
117 	if (rcu_cpu_stall_suppress == 2)
118 		rcu_cpu_stall_suppress = 0;
119 }
120 
121 /* Don't print RCU CPU stall warnings during a kernel panic. */
122 static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr)
123 {
124 	rcu_cpu_stall_suppress = 1;
125 	return NOTIFY_DONE;
126 }
127 
128 static struct notifier_block rcu_panic_block = {
129 	.notifier_call = rcu_panic,
130 };
131 
132 static int __init check_cpu_stall_init(void)
133 {
134 	atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block);
135 	return 0;
136 }
137 early_initcall(check_cpu_stall_init);
138 
139 /* If so specified via sysctl, panic, yielding cleaner stall-warning output. */
140 static void panic_on_rcu_stall(void)
141 {
142 	static int cpu_stall;
143 
144 	if (++cpu_stall < sysctl_max_rcu_stall_to_panic)
145 		return;
146 
147 	if (sysctl_panic_on_rcu_stall)
148 		panic("RCU Stall\n");
149 }
150 
151 /**
152  * rcu_cpu_stall_reset - restart stall-warning timeout for current grace period
153  *
154  * To perform the reset request from the caller, disable stall detection until
155  * 3 fqs loops have passed. This is required to ensure a fresh jiffies is
156  * loaded.  It should be safe to do from the fqs loop as enough timer
157  * interrupts and context switches should have passed.
158  *
159  * The caller must disable hard irqs.
160  */
161 void rcu_cpu_stall_reset(void)
162 {
163 	WRITE_ONCE(rcu_state.nr_fqs_jiffies_stall, 3);
164 	WRITE_ONCE(rcu_state.jiffies_stall, ULONG_MAX);
165 }
166 
167 //////////////////////////////////////////////////////////////////////////////
168 //
169 // Interaction with RCU grace periods
170 
171 /* Start of new grace period, so record stall time (and forcing times). */
172 static void record_gp_stall_check_time(void)
173 {
174 	unsigned long j = jiffies;
175 	unsigned long j1;
176 
177 	WRITE_ONCE(rcu_state.gp_start, j);
178 	j1 = rcu_jiffies_till_stall_check();
179 	smp_mb(); // ->gp_start before ->jiffies_stall and caller's ->gp_seq.
180 	WRITE_ONCE(rcu_state.nr_fqs_jiffies_stall, 0);
181 	WRITE_ONCE(rcu_state.jiffies_stall, j + j1);
182 	rcu_state.jiffies_resched = j + j1 / 2;
183 	rcu_state.n_force_qs_gpstart = READ_ONCE(rcu_state.n_force_qs);
184 }
185 
186 /* Zero ->ticks_this_gp and snapshot the number of RCU softirq handlers. */
187 static void zero_cpu_stall_ticks(struct rcu_data *rdp)
188 {
189 	rdp->ticks_this_gp = 0;
190 	rdp->softirq_snap = kstat_softirqs_cpu(RCU_SOFTIRQ, smp_processor_id());
191 	WRITE_ONCE(rdp->last_fqs_resched, jiffies);
192 }
193 
194 /*
195  * If too much time has passed in the current grace period, and if
196  * so configured, go kick the relevant kthreads.
197  */
198 static void rcu_stall_kick_kthreads(void)
199 {
200 	unsigned long j;
201 
202 	if (!READ_ONCE(rcu_kick_kthreads))
203 		return;
204 	j = READ_ONCE(rcu_state.jiffies_kick_kthreads);
205 	if (time_after(jiffies, j) && rcu_state.gp_kthread &&
206 	    (rcu_gp_in_progress() || READ_ONCE(rcu_state.gp_flags))) {
207 		WARN_ONCE(1, "Kicking %s grace-period kthread\n",
208 			  rcu_state.name);
209 		rcu_ftrace_dump(DUMP_ALL);
210 		wake_up_process(rcu_state.gp_kthread);
211 		WRITE_ONCE(rcu_state.jiffies_kick_kthreads, j + HZ);
212 	}
213 }
214 
215 /*
216  * Handler for the irq_work request posted about halfway into the RCU CPU
217  * stall timeout, and used to detect excessive irq disabling.  Set state
218  * appropriately, but just complain if there is unexpected state on entry.
219  */
220 static void rcu_iw_handler(struct irq_work *iwp)
221 {
222 	struct rcu_data *rdp;
223 	struct rcu_node *rnp;
224 
225 	rdp = container_of(iwp, struct rcu_data, rcu_iw);
226 	rnp = rdp->mynode;
227 	raw_spin_lock_rcu_node(rnp);
228 	if (!WARN_ON_ONCE(!rdp->rcu_iw_pending)) {
229 		rdp->rcu_iw_gp_seq = rnp->gp_seq;
230 		rdp->rcu_iw_pending = false;
231 	}
232 	raw_spin_unlock_rcu_node(rnp);
233 }
234 
235 //////////////////////////////////////////////////////////////////////////////
236 //
237 // Printing RCU CPU stall warnings
238 
239 #ifdef CONFIG_PREEMPT_RCU
240 
241 /*
242  * Dump detailed information for all tasks blocking the current RCU
243  * grace period on the specified rcu_node structure.
244  */
245 static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
246 {
247 	unsigned long flags;
248 	struct task_struct *t;
249 
250 	raw_spin_lock_irqsave_rcu_node(rnp, flags);
251 	if (!rcu_preempt_blocked_readers_cgp(rnp)) {
252 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
253 		return;
254 	}
255 	t = list_entry(rnp->gp_tasks->prev,
256 		       struct task_struct, rcu_node_entry);
257 	list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
258 		/*
259 		 * We could be printing a lot while holding a spinlock.
260 		 * Avoid triggering hard lockup.
261 		 */
262 		touch_nmi_watchdog();
263 		sched_show_task(t);
264 	}
265 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
266 }
267 
268 // Communicate task state back to the RCU CPU stall warning request.
269 struct rcu_stall_chk_rdr {
270 	int nesting;
271 	union rcu_special rs;
272 	bool on_blkd_list;
273 };
274 
275 /*
276  * Report out the state of a not-running task that is stalling the
277  * current RCU grace period.
278  */
279 static int check_slow_task(struct task_struct *t, void *arg)
280 {
281 	struct rcu_stall_chk_rdr *rscrp = arg;
282 
283 	if (task_curr(t))
284 		return -EBUSY; // It is running, so decline to inspect it.
285 	rscrp->nesting = t->rcu_read_lock_nesting;
286 	rscrp->rs = t->rcu_read_unlock_special;
287 	rscrp->on_blkd_list = !list_empty(&t->rcu_node_entry);
288 	return 0;
289 }
290 
291 /*
292  * Scan the current list of tasks blocked within RCU read-side critical
293  * sections, printing out the tid of each of the first few of them.
294  */
295 static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
296 	__releases(rnp->lock)
297 {
298 	int i = 0;
299 	int ndetected = 0;
300 	struct rcu_stall_chk_rdr rscr;
301 	struct task_struct *t;
302 	struct task_struct *ts[8];
303 
304 	lockdep_assert_irqs_disabled();
305 	if (!rcu_preempt_blocked_readers_cgp(rnp)) {
306 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
307 		return 0;
308 	}
309 	pr_err("\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
310 	       rnp->level, rnp->grplo, rnp->grphi);
311 	t = list_entry(rnp->gp_tasks->prev,
312 		       struct task_struct, rcu_node_entry);
313 	list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
314 		get_task_struct(t);
315 		ts[i++] = t;
316 		if (i >= ARRAY_SIZE(ts))
317 			break;
318 	}
319 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
320 	while (i) {
321 		t = ts[--i];
322 		if (task_call_func(t, check_slow_task, &rscr))
323 			pr_cont(" P%d", t->pid);
324 		else
325 			pr_cont(" P%d/%d:%c%c%c%c",
326 				t->pid, rscr.nesting,
327 				".b"[rscr.rs.b.blocked],
328 				".q"[rscr.rs.b.need_qs],
329 				".e"[rscr.rs.b.exp_hint],
330 				".l"[rscr.on_blkd_list]);
331 		lockdep_assert_irqs_disabled();
332 		put_task_struct(t);
333 		ndetected++;
334 	}
335 	pr_cont("\n");
336 	return ndetected;
337 }
338 
339 #else /* #ifdef CONFIG_PREEMPT_RCU */
340 
341 /*
342  * Because preemptible RCU does not exist, we never have to check for
343  * tasks blocked within RCU read-side critical sections.
344  */
345 static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
346 {
347 }
348 
349 /*
350  * Because preemptible RCU does not exist, we never have to check for
351  * tasks blocked within RCU read-side critical sections.
352  */
353 static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
354 	__releases(rnp->lock)
355 {
356 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
357 	return 0;
358 }
359 #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
360 
361 /*
362  * Dump stacks of all tasks running on stalled CPUs.  First try using
363  * NMIs, but fall back to manual remote stack tracing on architectures
364  * that don't support NMI-based stack dumps.  The NMI-triggered stack
365  * traces are more accurate because they are printed by the target CPU.
366  */
367 static void rcu_dump_cpu_stacks(void)
368 {
369 	int cpu;
370 	unsigned long flags;
371 	struct rcu_node *rnp;
372 
373 	rcu_for_each_leaf_node(rnp) {
374 		raw_spin_lock_irqsave_rcu_node(rnp, flags);
375 		for_each_leaf_node_possible_cpu(rnp, cpu)
376 			if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
377 				if (cpu_is_offline(cpu))
378 					pr_err("Offline CPU %d blocking current GP.\n", cpu);
379 				else
380 					dump_cpu_task(cpu);
381 			}
382 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
383 	}
384 }
385 
386 static const char * const gp_state_names[] = {
387 	[RCU_GP_IDLE] = "RCU_GP_IDLE",
388 	[RCU_GP_WAIT_GPS] = "RCU_GP_WAIT_GPS",
389 	[RCU_GP_DONE_GPS] = "RCU_GP_DONE_GPS",
390 	[RCU_GP_ONOFF] = "RCU_GP_ONOFF",
391 	[RCU_GP_INIT] = "RCU_GP_INIT",
392 	[RCU_GP_WAIT_FQS] = "RCU_GP_WAIT_FQS",
393 	[RCU_GP_DOING_FQS] = "RCU_GP_DOING_FQS",
394 	[RCU_GP_CLEANUP] = "RCU_GP_CLEANUP",
395 	[RCU_GP_CLEANED] = "RCU_GP_CLEANED",
396 };
397 
398 /*
399  * Convert a ->gp_state value to a character string.
400  */
401 static const char *gp_state_getname(short gs)
402 {
403 	if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
404 		return "???";
405 	return gp_state_names[gs];
406 }
407 
408 /* Is the RCU grace-period kthread being starved of CPU time? */
409 static bool rcu_is_gp_kthread_starving(unsigned long *jp)
410 {
411 	unsigned long j = jiffies - READ_ONCE(rcu_state.gp_activity);
412 
413 	if (jp)
414 		*jp = j;
415 	return j > 2 * HZ;
416 }
417 
418 static bool rcu_is_rcuc_kthread_starving(struct rcu_data *rdp, unsigned long *jp)
419 {
420 	int cpu;
421 	struct task_struct *rcuc;
422 	unsigned long j;
423 
424 	rcuc = rdp->rcu_cpu_kthread_task;
425 	if (!rcuc)
426 		return false;
427 
428 	cpu = task_cpu(rcuc);
429 	if (cpu_is_offline(cpu) || idle_cpu(cpu))
430 		return false;
431 
432 	j = jiffies - READ_ONCE(rdp->rcuc_activity);
433 
434 	if (jp)
435 		*jp = j;
436 	return j > 2 * HZ;
437 }
438 
439 static void print_cpu_stat_info(int cpu)
440 {
441 	struct rcu_snap_record rsr, *rsrp;
442 	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
443 	struct kernel_cpustat *kcsp = &kcpustat_cpu(cpu);
444 
445 	if (!rcu_cpu_stall_cputime)
446 		return;
447 
448 	rsrp = &rdp->snap_record;
449 	if (rsrp->gp_seq != rdp->gp_seq)
450 		return;
451 
452 	rsr.cputime_irq     = kcpustat_field(kcsp, CPUTIME_IRQ, cpu);
453 	rsr.cputime_softirq = kcpustat_field(kcsp, CPUTIME_SOFTIRQ, cpu);
454 	rsr.cputime_system  = kcpustat_field(kcsp, CPUTIME_SYSTEM, cpu);
455 
456 	pr_err("\t         hardirqs   softirqs   csw/system\n");
457 	pr_err("\t number: %8ld %10d %12lld\n",
458 		kstat_cpu_irqs_sum(cpu) - rsrp->nr_hardirqs,
459 		kstat_cpu_softirqs_sum(cpu) - rsrp->nr_softirqs,
460 		nr_context_switches_cpu(cpu) - rsrp->nr_csw);
461 	pr_err("\tcputime: %8lld %10lld %12lld   ==> %d(ms)\n",
462 		div_u64(rsr.cputime_irq - rsrp->cputime_irq, NSEC_PER_MSEC),
463 		div_u64(rsr.cputime_softirq - rsrp->cputime_softirq, NSEC_PER_MSEC),
464 		div_u64(rsr.cputime_system - rsrp->cputime_system, NSEC_PER_MSEC),
465 		jiffies_to_msecs(jiffies - rsrp->jiffies));
466 }
467 
468 /*
469  * Print out diagnostic information for the specified stalled CPU.
470  *
471  * If the specified CPU is aware of the current RCU grace period, then
472  * print the number of scheduling clock interrupts the CPU has taken
473  * during the time that it has been aware.  Otherwise, print the number
474  * of RCU grace periods that this CPU is ignorant of, for example, "1"
475  * if the CPU was aware of the previous grace period.
476  *
477  * Also print out idle info.
478  */
479 static void print_cpu_stall_info(int cpu)
480 {
481 	unsigned long delta;
482 	bool falsepositive;
483 	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
484 	char *ticks_title;
485 	unsigned long ticks_value;
486 	bool rcuc_starved;
487 	unsigned long j;
488 	char buf[32];
489 
490 	/*
491 	 * We could be printing a lot while holding a spinlock.  Avoid
492 	 * triggering hard lockup.
493 	 */
494 	touch_nmi_watchdog();
495 
496 	ticks_value = rcu_seq_ctr(rcu_state.gp_seq - rdp->gp_seq);
497 	if (ticks_value) {
498 		ticks_title = "GPs behind";
499 	} else {
500 		ticks_title = "ticks this GP";
501 		ticks_value = rdp->ticks_this_gp;
502 	}
503 	delta = rcu_seq_ctr(rdp->mynode->gp_seq - rdp->rcu_iw_gp_seq);
504 	falsepositive = rcu_is_gp_kthread_starving(NULL) &&
505 			rcu_dynticks_in_eqs(ct_dynticks_cpu(cpu));
506 	rcuc_starved = rcu_is_rcuc_kthread_starving(rdp, &j);
507 	if (rcuc_starved)
508 		// Print signed value, as negative values indicate a probable bug.
509 		snprintf(buf, sizeof(buf), " rcuc=%ld jiffies(starved)", j);
510 	pr_err("\t%d-%c%c%c%c: (%lu %s) idle=%04x/%ld/%#lx softirq=%u/%u fqs=%ld%s%s\n",
511 	       cpu,
512 	       "O."[!!cpu_online(cpu)],
513 	       "o."[!!(rdp->grpmask & rdp->mynode->qsmaskinit)],
514 	       "N."[!!(rdp->grpmask & rdp->mynode->qsmaskinitnext)],
515 	       !IS_ENABLED(CONFIG_IRQ_WORK) ? '?' :
516 			rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
517 				"!."[!delta],
518 	       ticks_value, ticks_title,
519 	       ct_dynticks_cpu(cpu) & 0xffff,
520 	       ct_dynticks_nesting_cpu(cpu), ct_dynticks_nmi_nesting_cpu(cpu),
521 	       rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
522 	       data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
523 	       rcuc_starved ? buf : "",
524 	       falsepositive ? " (false positive?)" : "");
525 
526 	print_cpu_stat_info(cpu);
527 }
528 
529 /* Complain about starvation of grace-period kthread.  */
530 static void rcu_check_gp_kthread_starvation(void)
531 {
532 	int cpu;
533 	struct task_struct *gpk = rcu_state.gp_kthread;
534 	unsigned long j;
535 
536 	if (rcu_is_gp_kthread_starving(&j)) {
537 		cpu = gpk ? task_cpu(gpk) : -1;
538 		pr_err("%s kthread starved for %ld jiffies! g%ld f%#x %s(%d) ->state=%#x ->cpu=%d\n",
539 		       rcu_state.name, j,
540 		       (long)rcu_seq_current(&rcu_state.gp_seq),
541 		       data_race(READ_ONCE(rcu_state.gp_flags)),
542 		       gp_state_getname(rcu_state.gp_state),
543 		       data_race(READ_ONCE(rcu_state.gp_state)),
544 		       gpk ? data_race(READ_ONCE(gpk->__state)) : ~0, cpu);
545 		if (gpk) {
546 			struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
547 
548 			pr_err("\tUnless %s kthread gets sufficient CPU time, OOM is now expected behavior.\n", rcu_state.name);
549 			pr_err("RCU grace-period kthread stack dump:\n");
550 			sched_show_task(gpk);
551 			if (cpu_is_offline(cpu)) {
552 				pr_err("RCU GP kthread last ran on offline CPU %d.\n", cpu);
553 			} else if (!(data_race(READ_ONCE(rdp->mynode->qsmask)) & rdp->grpmask)) {
554 				pr_err("Stack dump where RCU GP kthread last ran:\n");
555 				dump_cpu_task(cpu);
556 			}
557 			wake_up_process(gpk);
558 		}
559 	}
560 }
561 
562 /* Complain about missing wakeups from expired fqs wait timer */
563 static void rcu_check_gp_kthread_expired_fqs_timer(void)
564 {
565 	struct task_struct *gpk = rcu_state.gp_kthread;
566 	short gp_state;
567 	unsigned long jiffies_fqs;
568 	int cpu;
569 
570 	/*
571 	 * Order reads of .gp_state and .jiffies_force_qs.
572 	 * Matching smp_wmb() is present in rcu_gp_fqs_loop().
573 	 */
574 	gp_state = smp_load_acquire(&rcu_state.gp_state);
575 	jiffies_fqs = READ_ONCE(rcu_state.jiffies_force_qs);
576 
577 	if (gp_state == RCU_GP_WAIT_FQS &&
578 	    time_after(jiffies, jiffies_fqs + RCU_STALL_MIGHT_MIN) &&
579 	    gpk && !READ_ONCE(gpk->on_rq)) {
580 		cpu = task_cpu(gpk);
581 		pr_err("%s kthread timer wakeup didn't happen for %ld jiffies! g%ld f%#x %s(%d) ->state=%#x\n",
582 		       rcu_state.name, (jiffies - jiffies_fqs),
583 		       (long)rcu_seq_current(&rcu_state.gp_seq),
584 		       data_race(READ_ONCE(rcu_state.gp_flags)), // Diagnostic read
585 		       gp_state_getname(RCU_GP_WAIT_FQS), RCU_GP_WAIT_FQS,
586 		       data_race(READ_ONCE(gpk->__state)));
587 		pr_err("\tPossible timer handling issue on cpu=%d timer-softirq=%u\n",
588 		       cpu, kstat_softirqs_cpu(TIMER_SOFTIRQ, cpu));
589 	}
590 }
591 
592 static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
593 {
594 	int cpu;
595 	unsigned long flags;
596 	unsigned long gpa;
597 	unsigned long j;
598 	int ndetected = 0;
599 	struct rcu_node *rnp;
600 	long totqlen = 0;
601 
602 	lockdep_assert_irqs_disabled();
603 
604 	/* Kick and suppress, if so configured. */
605 	rcu_stall_kick_kthreads();
606 	if (rcu_stall_is_suppressed())
607 		return;
608 
609 	nbcon_cpu_emergency_enter();
610 
611 	/*
612 	 * OK, time to rat on our buddy...
613 	 * See Documentation/RCU/stallwarn.rst for info on how to debug
614 	 * RCU CPU stall warnings.
615 	 */
616 	trace_rcu_stall_warning(rcu_state.name, TPS("StallDetected"));
617 	pr_err("INFO: %s detected stalls on CPUs/tasks:\n", rcu_state.name);
618 	rcu_for_each_leaf_node(rnp) {
619 		raw_spin_lock_irqsave_rcu_node(rnp, flags);
620 		if (rnp->qsmask != 0) {
621 			for_each_leaf_node_possible_cpu(rnp, cpu)
622 				if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
623 					print_cpu_stall_info(cpu);
624 					ndetected++;
625 				}
626 		}
627 		ndetected += rcu_print_task_stall(rnp, flags); // Releases rnp->lock.
628 		lockdep_assert_irqs_disabled();
629 	}
630 
631 	for_each_possible_cpu(cpu)
632 		totqlen += rcu_get_n_cbs_cpu(cpu);
633 	pr_err("\t(detected by %d, t=%ld jiffies, g=%ld, q=%lu ncpus=%d)\n",
634 	       smp_processor_id(), (long)(jiffies - gps),
635 	       (long)rcu_seq_current(&rcu_state.gp_seq), totqlen,
636 	       data_race(rcu_state.n_online_cpus)); // Diagnostic read
637 	if (ndetected) {
638 		rcu_dump_cpu_stacks();
639 
640 		/* Complain about tasks blocking the grace period. */
641 		rcu_for_each_leaf_node(rnp)
642 			rcu_print_detail_task_stall_rnp(rnp);
643 	} else {
644 		if (rcu_seq_current(&rcu_state.gp_seq) != gp_seq) {
645 			pr_err("INFO: Stall ended before state dump start\n");
646 		} else {
647 			j = jiffies;
648 			gpa = data_race(READ_ONCE(rcu_state.gp_activity));
649 			pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n",
650 			       rcu_state.name, j - gpa, j, gpa,
651 			       data_race(READ_ONCE(jiffies_till_next_fqs)),
652 			       data_race(READ_ONCE(rcu_get_root()->qsmask)));
653 		}
654 	}
655 	/* Rewrite if needed in case of slow consoles. */
656 	if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
657 		WRITE_ONCE(rcu_state.jiffies_stall,
658 			   jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
659 
660 	rcu_check_gp_kthread_expired_fqs_timer();
661 	rcu_check_gp_kthread_starvation();
662 
663 	nbcon_cpu_emergency_exit();
664 
665 	panic_on_rcu_stall();
666 
667 	rcu_force_quiescent_state();  /* Kick them all. */
668 }
669 
670 static void print_cpu_stall(unsigned long gps)
671 {
672 	int cpu;
673 	unsigned long flags;
674 	struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
675 	struct rcu_node *rnp = rcu_get_root();
676 	long totqlen = 0;
677 
678 	lockdep_assert_irqs_disabled();
679 
680 	/* Kick and suppress, if so configured. */
681 	rcu_stall_kick_kthreads();
682 	if (rcu_stall_is_suppressed())
683 		return;
684 
685 	nbcon_cpu_emergency_enter();
686 
687 	/*
688 	 * OK, time to rat on ourselves...
689 	 * See Documentation/RCU/stallwarn.rst for info on how to debug
690 	 * RCU CPU stall warnings.
691 	 */
692 	trace_rcu_stall_warning(rcu_state.name, TPS("SelfDetected"));
693 	pr_err("INFO: %s self-detected stall on CPU\n", rcu_state.name);
694 	raw_spin_lock_irqsave_rcu_node(rdp->mynode, flags);
695 	print_cpu_stall_info(smp_processor_id());
696 	raw_spin_unlock_irqrestore_rcu_node(rdp->mynode, flags);
697 	for_each_possible_cpu(cpu)
698 		totqlen += rcu_get_n_cbs_cpu(cpu);
699 	pr_err("\t(t=%lu jiffies g=%ld q=%lu ncpus=%d)\n",
700 		jiffies - gps,
701 		(long)rcu_seq_current(&rcu_state.gp_seq), totqlen,
702 		data_race(rcu_state.n_online_cpus)); // Diagnostic read
703 
704 	rcu_check_gp_kthread_expired_fqs_timer();
705 	rcu_check_gp_kthread_starvation();
706 
707 	rcu_dump_cpu_stacks();
708 
709 	raw_spin_lock_irqsave_rcu_node(rnp, flags);
710 	/* Rewrite if needed in case of slow consoles. */
711 	if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
712 		WRITE_ONCE(rcu_state.jiffies_stall,
713 			   jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
714 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
715 
716 	nbcon_cpu_emergency_exit();
717 
718 	panic_on_rcu_stall();
719 
720 	/*
721 	 * Attempt to revive the RCU machinery by forcing a context switch.
722 	 *
723 	 * A context switch would normally allow the RCU state machine to make
724 	 * progress and it could be we're stuck in kernel space without context
725 	 * switches for an entirely unreasonable amount of time.
726 	 */
727 	set_tsk_need_resched(current);
728 	set_preempt_need_resched();
729 }
730 
731 static void check_cpu_stall(struct rcu_data *rdp)
732 {
733 	bool self_detected;
734 	unsigned long gs1;
735 	unsigned long gs2;
736 	unsigned long gps;
737 	unsigned long j;
738 	unsigned long jn;
739 	unsigned long js;
740 	struct rcu_node *rnp;
741 
742 	lockdep_assert_irqs_disabled();
743 	if ((rcu_stall_is_suppressed() && !READ_ONCE(rcu_kick_kthreads)) ||
744 	    !rcu_gp_in_progress())
745 		return;
746 	rcu_stall_kick_kthreads();
747 
748 	/*
749 	 * Check if it was requested (via rcu_cpu_stall_reset()) that the FQS
750 	 * loop has to set jiffies to ensure a non-stale jiffies value. This
751 	 * is required to have good jiffies value after coming out of long
752 	 * breaks of jiffies updates. Not doing so can cause false positives.
753 	 */
754 	if (READ_ONCE(rcu_state.nr_fqs_jiffies_stall) > 0)
755 		return;
756 
757 	j = jiffies;
758 
759 	/*
760 	 * Lots of memory barriers to reject false positives.
761 	 *
762 	 * The idea is to pick up rcu_state.gp_seq, then
763 	 * rcu_state.jiffies_stall, then rcu_state.gp_start, and finally
764 	 * another copy of rcu_state.gp_seq.  These values are updated in
765 	 * the opposite order with memory barriers (or equivalent) during
766 	 * grace-period initialization and cleanup.  Now, a false positive
767 	 * can occur if we get an new value of rcu_state.gp_start and a old
768 	 * value of rcu_state.jiffies_stall.  But given the memory barriers,
769 	 * the only way that this can happen is if one grace period ends
770 	 * and another starts between these two fetches.  This is detected
771 	 * by comparing the second fetch of rcu_state.gp_seq with the
772 	 * previous fetch from rcu_state.gp_seq.
773 	 *
774 	 * Given this check, comparisons of jiffies, rcu_state.jiffies_stall,
775 	 * and rcu_state.gp_start suffice to forestall false positives.
776 	 */
777 	gs1 = READ_ONCE(rcu_state.gp_seq);
778 	smp_rmb(); /* Pick up ->gp_seq first... */
779 	js = READ_ONCE(rcu_state.jiffies_stall);
780 	smp_rmb(); /* ...then ->jiffies_stall before the rest... */
781 	gps = READ_ONCE(rcu_state.gp_start);
782 	smp_rmb(); /* ...and finally ->gp_start before ->gp_seq again. */
783 	gs2 = READ_ONCE(rcu_state.gp_seq);
784 	if (gs1 != gs2 ||
785 	    ULONG_CMP_LT(j, js) ||
786 	    ULONG_CMP_GE(gps, js))
787 		return; /* No stall or GP completed since entering function. */
788 	rnp = rdp->mynode;
789 	jn = jiffies + ULONG_MAX / 2;
790 	self_detected = READ_ONCE(rnp->qsmask) & rdp->grpmask;
791 	if (rcu_gp_in_progress() &&
792 	    (self_detected || ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY)) &&
793 	    cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
794 		/*
795 		 * If a virtual machine is stopped by the host it can look to
796 		 * the watchdog like an RCU stall. Check to see if the host
797 		 * stopped the vm.
798 		 */
799 		if (kvm_check_and_clear_guest_paused())
800 			return;
801 
802 		rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_NORM, (void *)j - gps);
803 		if (self_detected) {
804 			/* We haven't checked in, so go dump stack. */
805 			print_cpu_stall(gps);
806 		} else {
807 			/* They had a few time units to dump stack, so complain. */
808 			print_other_cpu_stall(gs2, gps);
809 		}
810 
811 		if (READ_ONCE(rcu_cpu_stall_ftrace_dump))
812 			rcu_ftrace_dump(DUMP_ALL);
813 
814 		if (READ_ONCE(rcu_state.jiffies_stall) == jn) {
815 			jn = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
816 			WRITE_ONCE(rcu_state.jiffies_stall, jn);
817 		}
818 	}
819 }
820 
821 //////////////////////////////////////////////////////////////////////////////
822 //
823 // RCU forward-progress mechanisms, including for callback invocation.
824 
825 
826 /*
827  * Check to see if a failure to end RCU priority inversion was due to
828  * a CPU not passing through a quiescent state.  When this happens, there
829  * is nothing that RCU priority boosting can do to help, so we shouldn't
830  * count this as an RCU priority boosting failure.  A return of true says
831  * RCU priority boosting is to blame, and false says otherwise.  If false
832  * is returned, the first of the CPUs to blame is stored through cpup.
833  * If there was no CPU blocking the current grace period, but also nothing
834  * in need of being boosted, *cpup is set to -1.  This can happen in case
835  * of vCPU preemption while the last CPU is reporting its quiscent state,
836  * for example.
837  *
838  * If cpup is NULL, then a lockless quick check is carried out, suitable
839  * for high-rate usage.  On the other hand, if cpup is non-NULL, each
840  * rcu_node structure's ->lock is acquired, ruling out high-rate usage.
841  */
842 bool rcu_check_boost_fail(unsigned long gp_state, int *cpup)
843 {
844 	bool atb = false;
845 	int cpu;
846 	unsigned long flags;
847 	struct rcu_node *rnp;
848 
849 	rcu_for_each_leaf_node(rnp) {
850 		if (!cpup) {
851 			if (data_race(READ_ONCE(rnp->qsmask))) {
852 				return false;
853 			} else {
854 				if (READ_ONCE(rnp->gp_tasks))
855 					atb = true;
856 				continue;
857 			}
858 		}
859 		*cpup = -1;
860 		raw_spin_lock_irqsave_rcu_node(rnp, flags);
861 		if (rnp->gp_tasks)
862 			atb = true;
863 		if (!rnp->qsmask) {
864 			// No CPUs without quiescent states for this rnp.
865 			raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
866 			continue;
867 		}
868 		// Find the first holdout CPU.
869 		for_each_leaf_node_possible_cpu(rnp, cpu) {
870 			if (rnp->qsmask & (1UL << (cpu - rnp->grplo))) {
871 				raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
872 				*cpup = cpu;
873 				return false;
874 			}
875 		}
876 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
877 	}
878 	// Can't blame CPUs, so must blame RCU priority boosting.
879 	return atb;
880 }
881 EXPORT_SYMBOL_GPL(rcu_check_boost_fail);
882 
883 /*
884  * Show the state of the grace-period kthreads.
885  */
886 void show_rcu_gp_kthreads(void)
887 {
888 	unsigned long cbs = 0;
889 	int cpu;
890 	unsigned long j;
891 	unsigned long ja;
892 	unsigned long jr;
893 	unsigned long js;
894 	unsigned long jw;
895 	struct rcu_data *rdp;
896 	struct rcu_node *rnp;
897 	struct task_struct *t = READ_ONCE(rcu_state.gp_kthread);
898 
899 	j = jiffies;
900 	ja = j - data_race(READ_ONCE(rcu_state.gp_activity));
901 	jr = j - data_race(READ_ONCE(rcu_state.gp_req_activity));
902 	js = j - data_race(READ_ONCE(rcu_state.gp_start));
903 	jw = j - data_race(READ_ONCE(rcu_state.gp_wake_time));
904 	pr_info("%s: wait state: %s(%d) ->state: %#x ->rt_priority %u delta ->gp_start %lu ->gp_activity %lu ->gp_req_activity %lu ->gp_wake_time %lu ->gp_wake_seq %ld ->gp_seq %ld ->gp_seq_needed %ld ->gp_max %lu ->gp_flags %#x\n",
905 		rcu_state.name, gp_state_getname(rcu_state.gp_state),
906 		data_race(READ_ONCE(rcu_state.gp_state)),
907 		t ? data_race(READ_ONCE(t->__state)) : 0x1ffff, t ? t->rt_priority : 0xffU,
908 		js, ja, jr, jw, (long)data_race(READ_ONCE(rcu_state.gp_wake_seq)),
909 		(long)data_race(READ_ONCE(rcu_state.gp_seq)),
910 		(long)data_race(READ_ONCE(rcu_get_root()->gp_seq_needed)),
911 		data_race(READ_ONCE(rcu_state.gp_max)),
912 		data_race(READ_ONCE(rcu_state.gp_flags)));
913 	rcu_for_each_node_breadth_first(rnp) {
914 		if (ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq), READ_ONCE(rnp->gp_seq_needed)) &&
915 		    !data_race(READ_ONCE(rnp->qsmask)) && !data_race(READ_ONCE(rnp->boost_tasks)) &&
916 		    !data_race(READ_ONCE(rnp->exp_tasks)) && !data_race(READ_ONCE(rnp->gp_tasks)))
917 			continue;
918 		pr_info("\trcu_node %d:%d ->gp_seq %ld ->gp_seq_needed %ld ->qsmask %#lx %c%c%c%c ->n_boosts %ld\n",
919 			rnp->grplo, rnp->grphi,
920 			(long)data_race(READ_ONCE(rnp->gp_seq)),
921 			(long)data_race(READ_ONCE(rnp->gp_seq_needed)),
922 			data_race(READ_ONCE(rnp->qsmask)),
923 			".b"[!!data_race(READ_ONCE(rnp->boost_kthread_task))],
924 			".B"[!!data_race(READ_ONCE(rnp->boost_tasks))],
925 			".E"[!!data_race(READ_ONCE(rnp->exp_tasks))],
926 			".G"[!!data_race(READ_ONCE(rnp->gp_tasks))],
927 			data_race(READ_ONCE(rnp->n_boosts)));
928 		if (!rcu_is_leaf_node(rnp))
929 			continue;
930 		for_each_leaf_node_possible_cpu(rnp, cpu) {
931 			rdp = per_cpu_ptr(&rcu_data, cpu);
932 			if (READ_ONCE(rdp->gpwrap) ||
933 			    ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq),
934 					 READ_ONCE(rdp->gp_seq_needed)))
935 				continue;
936 			pr_info("\tcpu %d ->gp_seq_needed %ld\n",
937 				cpu, (long)data_race(READ_ONCE(rdp->gp_seq_needed)));
938 		}
939 	}
940 	for_each_possible_cpu(cpu) {
941 		rdp = per_cpu_ptr(&rcu_data, cpu);
942 		cbs += data_race(READ_ONCE(rdp->n_cbs_invoked));
943 		if (rcu_segcblist_is_offloaded(&rdp->cblist))
944 			show_rcu_nocb_state(rdp);
945 	}
946 	pr_info("RCU callbacks invoked since boot: %lu\n", cbs);
947 	show_rcu_tasks_gp_kthreads();
948 }
949 EXPORT_SYMBOL_GPL(show_rcu_gp_kthreads);
950 
951 /*
952  * This function checks for grace-period requests that fail to motivate
953  * RCU to come out of its idle mode.
954  */
955 static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp,
956 				     const unsigned long gpssdelay)
957 {
958 	unsigned long flags;
959 	unsigned long j;
960 	struct rcu_node *rnp_root = rcu_get_root();
961 	static atomic_t warned = ATOMIC_INIT(0);
962 
963 	if (!IS_ENABLED(CONFIG_PROVE_RCU) || rcu_gp_in_progress() ||
964 	    ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
965 			 READ_ONCE(rnp_root->gp_seq_needed)) ||
966 	    !smp_load_acquire(&rcu_state.gp_kthread)) // Get stable kthread.
967 		return;
968 	j = jiffies; /* Expensive access, and in common case don't get here. */
969 	if (time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
970 	    time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
971 	    atomic_read(&warned))
972 		return;
973 
974 	raw_spin_lock_irqsave_rcu_node(rnp, flags);
975 	j = jiffies;
976 	if (rcu_gp_in_progress() ||
977 	    ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
978 			 READ_ONCE(rnp_root->gp_seq_needed)) ||
979 	    time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
980 	    time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
981 	    atomic_read(&warned)) {
982 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
983 		return;
984 	}
985 	/* Hold onto the leaf lock to make others see warned==1. */
986 
987 	if (rnp_root != rnp)
988 		raw_spin_lock_rcu_node(rnp_root); /* irqs already disabled. */
989 	j = jiffies;
990 	if (rcu_gp_in_progress() ||
991 	    ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
992 			 READ_ONCE(rnp_root->gp_seq_needed)) ||
993 	    time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
994 	    time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
995 	    atomic_xchg(&warned, 1)) {
996 		if (rnp_root != rnp)
997 			/* irqs remain disabled. */
998 			raw_spin_unlock_rcu_node(rnp_root);
999 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
1000 		return;
1001 	}
1002 	WARN_ON(1);
1003 	if (rnp_root != rnp)
1004 		raw_spin_unlock_rcu_node(rnp_root);
1005 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
1006 	show_rcu_gp_kthreads();
1007 }
1008 
1009 /*
1010  * Do a forward-progress check for rcutorture.  This is normally invoked
1011  * due to an OOM event.  The argument "j" gives the time period during
1012  * which rcutorture would like progress to have been made.
1013  */
1014 void rcu_fwd_progress_check(unsigned long j)
1015 {
1016 	unsigned long cbs;
1017 	int cpu;
1018 	unsigned long max_cbs = 0;
1019 	int max_cpu = -1;
1020 	struct rcu_data *rdp;
1021 
1022 	if (rcu_gp_in_progress()) {
1023 		pr_info("%s: GP age %lu jiffies\n",
1024 			__func__, jiffies - data_race(READ_ONCE(rcu_state.gp_start)));
1025 		show_rcu_gp_kthreads();
1026 	} else {
1027 		pr_info("%s: Last GP end %lu jiffies ago\n",
1028 			__func__, jiffies - data_race(READ_ONCE(rcu_state.gp_end)));
1029 		preempt_disable();
1030 		rdp = this_cpu_ptr(&rcu_data);
1031 		rcu_check_gp_start_stall(rdp->mynode, rdp, j);
1032 		preempt_enable();
1033 	}
1034 	for_each_possible_cpu(cpu) {
1035 		cbs = rcu_get_n_cbs_cpu(cpu);
1036 		if (!cbs)
1037 			continue;
1038 		if (max_cpu < 0)
1039 			pr_info("%s: callbacks", __func__);
1040 		pr_cont(" %d: %lu", cpu, cbs);
1041 		if (cbs <= max_cbs)
1042 			continue;
1043 		max_cbs = cbs;
1044 		max_cpu = cpu;
1045 	}
1046 	if (max_cpu >= 0)
1047 		pr_cont("\n");
1048 }
1049 EXPORT_SYMBOL_GPL(rcu_fwd_progress_check);
1050 
1051 /* Commandeer a sysrq key to dump RCU's tree. */
1052 static bool sysrq_rcu;
1053 module_param(sysrq_rcu, bool, 0444);
1054 
1055 /* Dump grace-period-request information due to commandeered sysrq. */
1056 static void sysrq_show_rcu(u8 key)
1057 {
1058 	show_rcu_gp_kthreads();
1059 }
1060 
1061 static const struct sysrq_key_op sysrq_rcudump_op = {
1062 	.handler = sysrq_show_rcu,
1063 	.help_msg = "show-rcu(y)",
1064 	.action_msg = "Show RCU tree",
1065 	.enable_mask = SYSRQ_ENABLE_DUMP,
1066 };
1067 
1068 static int __init rcu_sysrq_init(void)
1069 {
1070 	if (sysrq_rcu)
1071 		return register_sysrq_key('y', &sysrq_rcudump_op);
1072 	return 0;
1073 }
1074 early_initcall(rcu_sysrq_init);
1075 
1076 #ifdef CONFIG_RCU_CPU_STALL_NOTIFIER
1077 
1078 //////////////////////////////////////////////////////////////////////////////
1079 //
1080 // RCU CPU stall-warning notifiers
1081 
1082 static ATOMIC_NOTIFIER_HEAD(rcu_cpu_stall_notifier_list);
1083 
1084 /**
1085  * rcu_stall_chain_notifier_register - Add an RCU CPU stall notifier
1086  * @n: Entry to add.
1087  *
1088  * Adds an RCU CPU stall notifier to an atomic notifier chain.
1089  * The @action passed to a notifier will be @RCU_STALL_NOTIFY_NORM or
1090  * friends.  The @data will be the duration of the stalled grace period,
1091  * in jiffies, coerced to a void* pointer.
1092  *
1093  * Returns 0 on success, %-EEXIST on error.
1094  */
1095 int rcu_stall_chain_notifier_register(struct notifier_block *n)
1096 {
1097 	int rcsn = rcu_cpu_stall_notifiers;
1098 
1099 	WARN(1, "Adding %pS() to RCU stall notifier list (%s).\n", n->notifier_call,
1100 	     rcsn ? "possibly suppressing RCU CPU stall warnings" : "failed, so all is well");
1101 	if (rcsn)
1102 		return atomic_notifier_chain_register(&rcu_cpu_stall_notifier_list, n);
1103 	return -EEXIST;
1104 }
1105 EXPORT_SYMBOL_GPL(rcu_stall_chain_notifier_register);
1106 
1107 /**
1108  * rcu_stall_chain_notifier_unregister - Remove an RCU CPU stall notifier
1109  * @n: Entry to add.
1110  *
1111  * Removes an RCU CPU stall notifier from an atomic notifier chain.
1112  *
1113  * Returns zero on success, %-ENOENT on failure.
1114  */
1115 int rcu_stall_chain_notifier_unregister(struct notifier_block *n)
1116 {
1117 	return atomic_notifier_chain_unregister(&rcu_cpu_stall_notifier_list, n);
1118 }
1119 EXPORT_SYMBOL_GPL(rcu_stall_chain_notifier_unregister);
1120 
1121 /*
1122  * rcu_stall_notifier_call_chain - Call functions in an RCU CPU stall notifier chain
1123  * @val: Value passed unmodified to notifier function
1124  * @v: Pointer passed unmodified to notifier function
1125  *
1126  * Calls each function in the RCU CPU stall notifier chain in turn, which
1127  * is an atomic call chain.  See atomic_notifier_call_chain() for more
1128  * information.
1129  *
1130  * This is for use within RCU, hence the omission of the extra asterisk
1131  * to indicate a non-kerneldoc format header comment.
1132  */
1133 int rcu_stall_notifier_call_chain(unsigned long val, void *v)
1134 {
1135 	return atomic_notifier_call_chain(&rcu_cpu_stall_notifier_list, val, v);
1136 }
1137 
1138 #endif // #ifdef CONFIG_RCU_CPU_STALL_NOTIFIER
1139