0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/kvm_para.h>
0011
0012
0013
0014
0015
0016
0017 int sysctl_panic_on_rcu_stall __read_mostly;
0018 int sysctl_max_rcu_stall_to_panic __read_mostly;
0019
0020 #ifdef CONFIG_PROVE_RCU
0021 #define RCU_STALL_DELAY_DELTA (5 * HZ)
0022 #else
0023 #define RCU_STALL_DELAY_DELTA 0
0024 #endif
0025 #define RCU_STALL_MIGHT_DIV 8
0026 #define RCU_STALL_MIGHT_MIN (2 * HZ)
0027
0028 int rcu_exp_jiffies_till_stall_check(void)
0029 {
0030 int cpu_stall_timeout = READ_ONCE(rcu_exp_cpu_stall_timeout);
0031 int exp_stall_delay_delta = 0;
0032 int till_stall_check;
0033
0034
0035 if (!cpu_stall_timeout)
0036 cpu_stall_timeout = jiffies_to_msecs(rcu_jiffies_till_stall_check());
0037
0038
0039
0040
0041
0042 till_stall_check = clamp(msecs_to_jiffies(cpu_stall_timeout), 2UL, 21UL * HZ);
0043
0044 if (cpu_stall_timeout && jiffies_to_msecs(till_stall_check) != cpu_stall_timeout)
0045 WRITE_ONCE(rcu_exp_cpu_stall_timeout, jiffies_to_msecs(till_stall_check));
0046
0047 #ifdef CONFIG_PROVE_RCU
0048
0049 exp_stall_delay_delta = ((till_stall_check * 25) / 100) + 1;
0050 #endif
0051
0052 return till_stall_check + exp_stall_delay_delta;
0053 }
0054 EXPORT_SYMBOL_GPL(rcu_exp_jiffies_till_stall_check);
0055
0056
0057 int rcu_jiffies_till_stall_check(void)
0058 {
0059 int till_stall_check = READ_ONCE(rcu_cpu_stall_timeout);
0060
0061
0062
0063
0064
0065 if (till_stall_check < 3) {
0066 WRITE_ONCE(rcu_cpu_stall_timeout, 3);
0067 till_stall_check = 3;
0068 } else if (till_stall_check > 300) {
0069 WRITE_ONCE(rcu_cpu_stall_timeout, 300);
0070 till_stall_check = 300;
0071 }
0072 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
0073 }
0074 EXPORT_SYMBOL_GPL(rcu_jiffies_till_stall_check);
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 bool rcu_gp_might_be_stalled(void)
0090 {
0091 unsigned long d = rcu_jiffies_till_stall_check() / RCU_STALL_MIGHT_DIV;
0092 unsigned long j = jiffies;
0093
0094 if (d < RCU_STALL_MIGHT_MIN)
0095 d = RCU_STALL_MIGHT_MIN;
0096 smp_mb();
0097 if (!rcu_gp_in_progress())
0098 return false;
0099
0100
0101 smp_mb();
0102
0103 return !time_before(j, READ_ONCE(rcu_state.gp_start) + d);
0104 }
0105
0106
0107 void rcu_sysrq_start(void)
0108 {
0109 if (!rcu_cpu_stall_suppress)
0110 rcu_cpu_stall_suppress = 2;
0111 }
0112
0113 void rcu_sysrq_end(void)
0114 {
0115 if (rcu_cpu_stall_suppress == 2)
0116 rcu_cpu_stall_suppress = 0;
0117 }
0118
0119
0120 static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr)
0121 {
0122 rcu_cpu_stall_suppress = 1;
0123 return NOTIFY_DONE;
0124 }
0125
0126 static struct notifier_block rcu_panic_block = {
0127 .notifier_call = rcu_panic,
0128 };
0129
0130 static int __init check_cpu_stall_init(void)
0131 {
0132 atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block);
0133 return 0;
0134 }
0135 early_initcall(check_cpu_stall_init);
0136
0137
0138 static void panic_on_rcu_stall(void)
0139 {
0140 static int cpu_stall;
0141
0142 if (++cpu_stall < sysctl_max_rcu_stall_to_panic)
0143 return;
0144
0145 if (sysctl_panic_on_rcu_stall)
0146 panic("RCU Stall\n");
0147 }
0148
0149
0150
0151
0152
0153
0154 void rcu_cpu_stall_reset(void)
0155 {
0156 WRITE_ONCE(rcu_state.jiffies_stall,
0157 jiffies + rcu_jiffies_till_stall_check());
0158 }
0159
0160
0161
0162
0163
0164
0165 static void record_gp_stall_check_time(void)
0166 {
0167 unsigned long j = jiffies;
0168 unsigned long j1;
0169
0170 WRITE_ONCE(rcu_state.gp_start, j);
0171 j1 = rcu_jiffies_till_stall_check();
0172 smp_mb();
0173 WRITE_ONCE(rcu_state.jiffies_stall, j + j1);
0174 rcu_state.jiffies_resched = j + j1 / 2;
0175 rcu_state.n_force_qs_gpstart = READ_ONCE(rcu_state.n_force_qs);
0176 }
0177
0178
0179 static void zero_cpu_stall_ticks(struct rcu_data *rdp)
0180 {
0181 rdp->ticks_this_gp = 0;
0182 rdp->softirq_snap = kstat_softirqs_cpu(RCU_SOFTIRQ, smp_processor_id());
0183 WRITE_ONCE(rdp->last_fqs_resched, jiffies);
0184 }
0185
0186
0187
0188
0189
0190 static void rcu_stall_kick_kthreads(void)
0191 {
0192 unsigned long j;
0193
0194 if (!READ_ONCE(rcu_kick_kthreads))
0195 return;
0196 j = READ_ONCE(rcu_state.jiffies_kick_kthreads);
0197 if (time_after(jiffies, j) && rcu_state.gp_kthread &&
0198 (rcu_gp_in_progress() || READ_ONCE(rcu_state.gp_flags))) {
0199 WARN_ONCE(1, "Kicking %s grace-period kthread\n",
0200 rcu_state.name);
0201 rcu_ftrace_dump(DUMP_ALL);
0202 wake_up_process(rcu_state.gp_kthread);
0203 WRITE_ONCE(rcu_state.jiffies_kick_kthreads, j + HZ);
0204 }
0205 }
0206
0207
0208
0209
0210
0211
0212 static void rcu_iw_handler(struct irq_work *iwp)
0213 {
0214 struct rcu_data *rdp;
0215 struct rcu_node *rnp;
0216
0217 rdp = container_of(iwp, struct rcu_data, rcu_iw);
0218 rnp = rdp->mynode;
0219 raw_spin_lock_rcu_node(rnp);
0220 if (!WARN_ON_ONCE(!rdp->rcu_iw_pending)) {
0221 rdp->rcu_iw_gp_seq = rnp->gp_seq;
0222 rdp->rcu_iw_pending = false;
0223 }
0224 raw_spin_unlock_rcu_node(rnp);
0225 }
0226
0227
0228
0229
0230
0231 #ifdef CONFIG_PREEMPT_RCU
0232
0233
0234
0235
0236
0237 static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
0238 {
0239 unsigned long flags;
0240 struct task_struct *t;
0241
0242 raw_spin_lock_irqsave_rcu_node(rnp, flags);
0243 if (!rcu_preempt_blocked_readers_cgp(rnp)) {
0244 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0245 return;
0246 }
0247 t = list_entry(rnp->gp_tasks->prev,
0248 struct task_struct, rcu_node_entry);
0249 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
0250
0251
0252
0253
0254 touch_nmi_watchdog();
0255 sched_show_task(t);
0256 }
0257 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0258 }
0259
0260
0261 struct rcu_stall_chk_rdr {
0262 int nesting;
0263 union rcu_special rs;
0264 bool on_blkd_list;
0265 };
0266
0267
0268
0269
0270
0271 static int check_slow_task(struct task_struct *t, void *arg)
0272 {
0273 struct rcu_stall_chk_rdr *rscrp = arg;
0274
0275 if (task_curr(t))
0276 return -EBUSY;
0277 rscrp->nesting = t->rcu_read_lock_nesting;
0278 rscrp->rs = t->rcu_read_unlock_special;
0279 rscrp->on_blkd_list = !list_empty(&t->rcu_node_entry);
0280 return 0;
0281 }
0282
0283
0284
0285
0286
0287 static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
0288 __releases(rnp->lock)
0289 {
0290 int i = 0;
0291 int ndetected = 0;
0292 struct rcu_stall_chk_rdr rscr;
0293 struct task_struct *t;
0294 struct task_struct *ts[8];
0295
0296 lockdep_assert_irqs_disabled();
0297 if (!rcu_preempt_blocked_readers_cgp(rnp)) {
0298 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0299 return 0;
0300 }
0301 pr_err("\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
0302 rnp->level, rnp->grplo, rnp->grphi);
0303 t = list_entry(rnp->gp_tasks->prev,
0304 struct task_struct, rcu_node_entry);
0305 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
0306 get_task_struct(t);
0307 ts[i++] = t;
0308 if (i >= ARRAY_SIZE(ts))
0309 break;
0310 }
0311 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0312 while (i) {
0313 t = ts[--i];
0314 if (task_call_func(t, check_slow_task, &rscr))
0315 pr_cont(" P%d", t->pid);
0316 else
0317 pr_cont(" P%d/%d:%c%c%c%c",
0318 t->pid, rscr.nesting,
0319 ".b"[rscr.rs.b.blocked],
0320 ".q"[rscr.rs.b.need_qs],
0321 ".e"[rscr.rs.b.exp_hint],
0322 ".l"[rscr.on_blkd_list]);
0323 lockdep_assert_irqs_disabled();
0324 put_task_struct(t);
0325 ndetected++;
0326 }
0327 pr_cont("\n");
0328 return ndetected;
0329 }
0330
0331 #else
0332
0333
0334
0335
0336
0337 static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
0338 {
0339 }
0340
0341
0342
0343
0344
0345 static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
0346 __releases(rnp->lock)
0347 {
0348 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0349 return 0;
0350 }
0351 #endif
0352
0353
0354
0355
0356
0357
0358
0359 static void rcu_dump_cpu_stacks(void)
0360 {
0361 int cpu;
0362 unsigned long flags;
0363 struct rcu_node *rnp;
0364
0365 rcu_for_each_leaf_node(rnp) {
0366 raw_spin_lock_irqsave_rcu_node(rnp, flags);
0367 for_each_leaf_node_possible_cpu(rnp, cpu)
0368 if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
0369 if (cpu_is_offline(cpu))
0370 pr_err("Offline CPU %d blocking current GP.\n", cpu);
0371 else if (!trigger_single_cpu_backtrace(cpu))
0372 dump_cpu_task(cpu);
0373 }
0374 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0375 }
0376 }
0377
0378 static const char * const gp_state_names[] = {
0379 [RCU_GP_IDLE] = "RCU_GP_IDLE",
0380 [RCU_GP_WAIT_GPS] = "RCU_GP_WAIT_GPS",
0381 [RCU_GP_DONE_GPS] = "RCU_GP_DONE_GPS",
0382 [RCU_GP_ONOFF] = "RCU_GP_ONOFF",
0383 [RCU_GP_INIT] = "RCU_GP_INIT",
0384 [RCU_GP_WAIT_FQS] = "RCU_GP_WAIT_FQS",
0385 [RCU_GP_DOING_FQS] = "RCU_GP_DOING_FQS",
0386 [RCU_GP_CLEANUP] = "RCU_GP_CLEANUP",
0387 [RCU_GP_CLEANED] = "RCU_GP_CLEANED",
0388 };
0389
0390
0391
0392
0393 static const char *gp_state_getname(short gs)
0394 {
0395 if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
0396 return "???";
0397 return gp_state_names[gs];
0398 }
0399
0400
0401 static bool rcu_is_gp_kthread_starving(unsigned long *jp)
0402 {
0403 unsigned long j = jiffies - READ_ONCE(rcu_state.gp_activity);
0404
0405 if (jp)
0406 *jp = j;
0407 return j > 2 * HZ;
0408 }
0409
0410 static bool rcu_is_rcuc_kthread_starving(struct rcu_data *rdp, unsigned long *jp)
0411 {
0412 int cpu;
0413 struct task_struct *rcuc;
0414 unsigned long j;
0415
0416 rcuc = rdp->rcu_cpu_kthread_task;
0417 if (!rcuc)
0418 return false;
0419
0420 cpu = task_cpu(rcuc);
0421 if (cpu_is_offline(cpu) || idle_cpu(cpu))
0422 return false;
0423
0424 j = jiffies - READ_ONCE(rdp->rcuc_activity);
0425
0426 if (jp)
0427 *jp = j;
0428 return j > 2 * HZ;
0429 }
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442 static void print_cpu_stall_info(int cpu)
0443 {
0444 unsigned long delta;
0445 bool falsepositive;
0446 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
0447 char *ticks_title;
0448 unsigned long ticks_value;
0449 bool rcuc_starved;
0450 unsigned long j;
0451 char buf[32];
0452
0453
0454
0455
0456
0457 touch_nmi_watchdog();
0458
0459 ticks_value = rcu_seq_ctr(rcu_state.gp_seq - rdp->gp_seq);
0460 if (ticks_value) {
0461 ticks_title = "GPs behind";
0462 } else {
0463 ticks_title = "ticks this GP";
0464 ticks_value = rdp->ticks_this_gp;
0465 }
0466 delta = rcu_seq_ctr(rdp->mynode->gp_seq - rdp->rcu_iw_gp_seq);
0467 falsepositive = rcu_is_gp_kthread_starving(NULL) &&
0468 rcu_dynticks_in_eqs(rcu_dynticks_snap(cpu));
0469 rcuc_starved = rcu_is_rcuc_kthread_starving(rdp, &j);
0470 if (rcuc_starved)
0471 sprintf(buf, " rcuc=%ld jiffies(starved)", j);
0472 pr_err("\t%d-%c%c%c%c: (%lu %s) idle=%04x/%ld/%#lx softirq=%u/%u fqs=%ld%s%s\n",
0473 cpu,
0474 "O."[!!cpu_online(cpu)],
0475 "o."[!!(rdp->grpmask & rdp->mynode->qsmaskinit)],
0476 "N."[!!(rdp->grpmask & rdp->mynode->qsmaskinitnext)],
0477 !IS_ENABLED(CONFIG_IRQ_WORK) ? '?' :
0478 rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
0479 "!."[!delta],
0480 ticks_value, ticks_title,
0481 rcu_dynticks_snap(cpu) & 0xffff,
0482 ct_dynticks_nesting_cpu(cpu), ct_dynticks_nmi_nesting_cpu(cpu),
0483 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
0484 data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
0485 rcuc_starved ? buf : "",
0486 falsepositive ? " (false positive?)" : "");
0487 }
0488
0489
0490 static void rcu_check_gp_kthread_starvation(void)
0491 {
0492 int cpu;
0493 struct task_struct *gpk = rcu_state.gp_kthread;
0494 unsigned long j;
0495
0496 if (rcu_is_gp_kthread_starving(&j)) {
0497 cpu = gpk ? task_cpu(gpk) : -1;
0498 pr_err("%s kthread starved for %ld jiffies! g%ld f%#x %s(%d) ->state=%#x ->cpu=%d\n",
0499 rcu_state.name, j,
0500 (long)rcu_seq_current(&rcu_state.gp_seq),
0501 data_race(READ_ONCE(rcu_state.gp_flags)),
0502 gp_state_getname(rcu_state.gp_state),
0503 data_race(READ_ONCE(rcu_state.gp_state)),
0504 gpk ? data_race(READ_ONCE(gpk->__state)) : ~0, cpu);
0505 if (gpk) {
0506 pr_err("\tUnless %s kthread gets sufficient CPU time, OOM is now expected behavior.\n", rcu_state.name);
0507 pr_err("RCU grace-period kthread stack dump:\n");
0508 sched_show_task(gpk);
0509 if (cpu >= 0) {
0510 if (cpu_is_offline(cpu)) {
0511 pr_err("RCU GP kthread last ran on offline CPU %d.\n", cpu);
0512 } else {
0513 pr_err("Stack dump where RCU GP kthread last ran:\n");
0514 if (!trigger_single_cpu_backtrace(cpu))
0515 dump_cpu_task(cpu);
0516 }
0517 }
0518 wake_up_process(gpk);
0519 }
0520 }
0521 }
0522
0523
0524 static void rcu_check_gp_kthread_expired_fqs_timer(void)
0525 {
0526 struct task_struct *gpk = rcu_state.gp_kthread;
0527 short gp_state;
0528 unsigned long jiffies_fqs;
0529 int cpu;
0530
0531
0532
0533
0534
0535 gp_state = smp_load_acquire(&rcu_state.gp_state);
0536 jiffies_fqs = READ_ONCE(rcu_state.jiffies_force_qs);
0537
0538 if (gp_state == RCU_GP_WAIT_FQS &&
0539 time_after(jiffies, jiffies_fqs + RCU_STALL_MIGHT_MIN) &&
0540 gpk && !READ_ONCE(gpk->on_rq)) {
0541 cpu = task_cpu(gpk);
0542 pr_err("%s kthread timer wakeup didn't happen for %ld jiffies! g%ld f%#x %s(%d) ->state=%#x\n",
0543 rcu_state.name, (jiffies - jiffies_fqs),
0544 (long)rcu_seq_current(&rcu_state.gp_seq),
0545 data_race(rcu_state.gp_flags),
0546 gp_state_getname(RCU_GP_WAIT_FQS), RCU_GP_WAIT_FQS,
0547 data_race(READ_ONCE(gpk->__state)));
0548 pr_err("\tPossible timer handling issue on cpu=%d timer-softirq=%u\n",
0549 cpu, kstat_softirqs_cpu(TIMER_SOFTIRQ, cpu));
0550 }
0551 }
0552
0553 static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
0554 {
0555 int cpu;
0556 unsigned long flags;
0557 unsigned long gpa;
0558 unsigned long j;
0559 int ndetected = 0;
0560 struct rcu_node *rnp;
0561 long totqlen = 0;
0562
0563 lockdep_assert_irqs_disabled();
0564
0565
0566 rcu_stall_kick_kthreads();
0567 if (rcu_stall_is_suppressed())
0568 return;
0569
0570
0571
0572
0573
0574
0575 trace_rcu_stall_warning(rcu_state.name, TPS("StallDetected"));
0576 pr_err("INFO: %s detected stalls on CPUs/tasks:\n", rcu_state.name);
0577 rcu_for_each_leaf_node(rnp) {
0578 raw_spin_lock_irqsave_rcu_node(rnp, flags);
0579 if (rnp->qsmask != 0) {
0580 for_each_leaf_node_possible_cpu(rnp, cpu)
0581 if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
0582 print_cpu_stall_info(cpu);
0583 ndetected++;
0584 }
0585 }
0586 ndetected += rcu_print_task_stall(rnp, flags);
0587 lockdep_assert_irqs_disabled();
0588 }
0589
0590 for_each_possible_cpu(cpu)
0591 totqlen += rcu_get_n_cbs_cpu(cpu);
0592 pr_cont("\t(detected by %d, t=%ld jiffies, g=%ld, q=%lu ncpus=%d)\n",
0593 smp_processor_id(), (long)(jiffies - gps),
0594 (long)rcu_seq_current(&rcu_state.gp_seq), totqlen, rcu_state.n_online_cpus);
0595 if (ndetected) {
0596 rcu_dump_cpu_stacks();
0597
0598
0599 rcu_for_each_leaf_node(rnp)
0600 rcu_print_detail_task_stall_rnp(rnp);
0601 } else {
0602 if (rcu_seq_current(&rcu_state.gp_seq) != gp_seq) {
0603 pr_err("INFO: Stall ended before state dump start\n");
0604 } else {
0605 j = jiffies;
0606 gpa = data_race(READ_ONCE(rcu_state.gp_activity));
0607 pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n",
0608 rcu_state.name, j - gpa, j, gpa,
0609 data_race(READ_ONCE(jiffies_till_next_fqs)),
0610 data_race(READ_ONCE(rcu_get_root()->qsmask)));
0611 }
0612 }
0613
0614 if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
0615 WRITE_ONCE(rcu_state.jiffies_stall,
0616 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
0617
0618 rcu_check_gp_kthread_expired_fqs_timer();
0619 rcu_check_gp_kthread_starvation();
0620
0621 panic_on_rcu_stall();
0622
0623 rcu_force_quiescent_state();
0624 }
0625
0626 static void print_cpu_stall(unsigned long gps)
0627 {
0628 int cpu;
0629 unsigned long flags;
0630 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
0631 struct rcu_node *rnp = rcu_get_root();
0632 long totqlen = 0;
0633
0634 lockdep_assert_irqs_disabled();
0635
0636
0637 rcu_stall_kick_kthreads();
0638 if (rcu_stall_is_suppressed())
0639 return;
0640
0641
0642
0643
0644
0645
0646 trace_rcu_stall_warning(rcu_state.name, TPS("SelfDetected"));
0647 pr_err("INFO: %s self-detected stall on CPU\n", rcu_state.name);
0648 raw_spin_lock_irqsave_rcu_node(rdp->mynode, flags);
0649 print_cpu_stall_info(smp_processor_id());
0650 raw_spin_unlock_irqrestore_rcu_node(rdp->mynode, flags);
0651 for_each_possible_cpu(cpu)
0652 totqlen += rcu_get_n_cbs_cpu(cpu);
0653 pr_cont("\t(t=%lu jiffies g=%ld q=%lu ncpus=%d)\n",
0654 jiffies - gps,
0655 (long)rcu_seq_current(&rcu_state.gp_seq), totqlen, rcu_state.n_online_cpus);
0656
0657 rcu_check_gp_kthread_expired_fqs_timer();
0658 rcu_check_gp_kthread_starvation();
0659
0660 rcu_dump_cpu_stacks();
0661
0662 raw_spin_lock_irqsave_rcu_node(rnp, flags);
0663
0664 if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
0665 WRITE_ONCE(rcu_state.jiffies_stall,
0666 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
0667 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0668
0669 panic_on_rcu_stall();
0670
0671
0672
0673
0674
0675
0676
0677
0678 set_tsk_need_resched(current);
0679 set_preempt_need_resched();
0680 }
0681
0682 static void check_cpu_stall(struct rcu_data *rdp)
0683 {
0684 bool didstall = false;
0685 unsigned long gs1;
0686 unsigned long gs2;
0687 unsigned long gps;
0688 unsigned long j;
0689 unsigned long jn;
0690 unsigned long js;
0691 struct rcu_node *rnp;
0692
0693 lockdep_assert_irqs_disabled();
0694 if ((rcu_stall_is_suppressed() && !READ_ONCE(rcu_kick_kthreads)) ||
0695 !rcu_gp_in_progress())
0696 return;
0697 rcu_stall_kick_kthreads();
0698 j = jiffies;
0699
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718 gs1 = READ_ONCE(rcu_state.gp_seq);
0719 smp_rmb();
0720 js = READ_ONCE(rcu_state.jiffies_stall);
0721 smp_rmb();
0722 gps = READ_ONCE(rcu_state.gp_start);
0723 smp_rmb();
0724 gs2 = READ_ONCE(rcu_state.gp_seq);
0725 if (gs1 != gs2 ||
0726 ULONG_CMP_LT(j, js) ||
0727 ULONG_CMP_GE(gps, js))
0728 return;
0729 rnp = rdp->mynode;
0730 jn = jiffies + ULONG_MAX / 2;
0731 if (rcu_gp_in_progress() &&
0732 (READ_ONCE(rnp->qsmask) & rdp->grpmask) &&
0733 cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
0734
0735
0736
0737
0738
0739
0740 if (kvm_check_and_clear_guest_paused())
0741 return;
0742
0743
0744 print_cpu_stall(gps);
0745 if (READ_ONCE(rcu_cpu_stall_ftrace_dump))
0746 rcu_ftrace_dump(DUMP_ALL);
0747 didstall = true;
0748
0749 } else if (rcu_gp_in_progress() &&
0750 ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY) &&
0751 cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
0752
0753
0754
0755
0756
0757
0758 if (kvm_check_and_clear_guest_paused())
0759 return;
0760
0761
0762 print_other_cpu_stall(gs2, gps);
0763 if (READ_ONCE(rcu_cpu_stall_ftrace_dump))
0764 rcu_ftrace_dump(DUMP_ALL);
0765 didstall = true;
0766 }
0767 if (didstall && READ_ONCE(rcu_state.jiffies_stall) == jn) {
0768 jn = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
0769 WRITE_ONCE(rcu_state.jiffies_stall, jn);
0770 }
0771 }
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794 bool rcu_check_boost_fail(unsigned long gp_state, int *cpup)
0795 {
0796 bool atb = false;
0797 int cpu;
0798 unsigned long flags;
0799 struct rcu_node *rnp;
0800
0801 rcu_for_each_leaf_node(rnp) {
0802 if (!cpup) {
0803 if (data_race(READ_ONCE(rnp->qsmask))) {
0804 return false;
0805 } else {
0806 if (READ_ONCE(rnp->gp_tasks))
0807 atb = true;
0808 continue;
0809 }
0810 }
0811 *cpup = -1;
0812 raw_spin_lock_irqsave_rcu_node(rnp, flags);
0813 if (rnp->gp_tasks)
0814 atb = true;
0815 if (!rnp->qsmask) {
0816
0817 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0818 continue;
0819 }
0820
0821 for_each_leaf_node_possible_cpu(rnp, cpu) {
0822 if (rnp->qsmask & (1UL << (cpu - rnp->grplo))) {
0823 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0824 *cpup = cpu;
0825 return false;
0826 }
0827 }
0828 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0829 }
0830
0831 return atb;
0832 }
0833 EXPORT_SYMBOL_GPL(rcu_check_boost_fail);
0834
0835
0836
0837
0838 void show_rcu_gp_kthreads(void)
0839 {
0840 unsigned long cbs = 0;
0841 int cpu;
0842 unsigned long j;
0843 unsigned long ja;
0844 unsigned long jr;
0845 unsigned long js;
0846 unsigned long jw;
0847 struct rcu_data *rdp;
0848 struct rcu_node *rnp;
0849 struct task_struct *t = READ_ONCE(rcu_state.gp_kthread);
0850
0851 j = jiffies;
0852 ja = j - data_race(READ_ONCE(rcu_state.gp_activity));
0853 jr = j - data_race(READ_ONCE(rcu_state.gp_req_activity));
0854 js = j - data_race(READ_ONCE(rcu_state.gp_start));
0855 jw = j - data_race(READ_ONCE(rcu_state.gp_wake_time));
0856 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",
0857 rcu_state.name, gp_state_getname(rcu_state.gp_state),
0858 data_race(READ_ONCE(rcu_state.gp_state)),
0859 t ? data_race(READ_ONCE(t->__state)) : 0x1ffff, t ? t->rt_priority : 0xffU,
0860 js, ja, jr, jw, (long)data_race(READ_ONCE(rcu_state.gp_wake_seq)),
0861 (long)data_race(READ_ONCE(rcu_state.gp_seq)),
0862 (long)data_race(READ_ONCE(rcu_get_root()->gp_seq_needed)),
0863 data_race(READ_ONCE(rcu_state.gp_max)),
0864 data_race(READ_ONCE(rcu_state.gp_flags)));
0865 rcu_for_each_node_breadth_first(rnp) {
0866 if (ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq), READ_ONCE(rnp->gp_seq_needed)) &&
0867 !data_race(READ_ONCE(rnp->qsmask)) && !data_race(READ_ONCE(rnp->boost_tasks)) &&
0868 !data_race(READ_ONCE(rnp->exp_tasks)) && !data_race(READ_ONCE(rnp->gp_tasks)))
0869 continue;
0870 pr_info("\trcu_node %d:%d ->gp_seq %ld ->gp_seq_needed %ld ->qsmask %#lx %c%c%c%c ->n_boosts %ld\n",
0871 rnp->grplo, rnp->grphi,
0872 (long)data_race(READ_ONCE(rnp->gp_seq)),
0873 (long)data_race(READ_ONCE(rnp->gp_seq_needed)),
0874 data_race(READ_ONCE(rnp->qsmask)),
0875 ".b"[!!data_race(READ_ONCE(rnp->boost_kthread_task))],
0876 ".B"[!!data_race(READ_ONCE(rnp->boost_tasks))],
0877 ".E"[!!data_race(READ_ONCE(rnp->exp_tasks))],
0878 ".G"[!!data_race(READ_ONCE(rnp->gp_tasks))],
0879 data_race(READ_ONCE(rnp->n_boosts)));
0880 if (!rcu_is_leaf_node(rnp))
0881 continue;
0882 for_each_leaf_node_possible_cpu(rnp, cpu) {
0883 rdp = per_cpu_ptr(&rcu_data, cpu);
0884 if (READ_ONCE(rdp->gpwrap) ||
0885 ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq),
0886 READ_ONCE(rdp->gp_seq_needed)))
0887 continue;
0888 pr_info("\tcpu %d ->gp_seq_needed %ld\n",
0889 cpu, (long)data_race(READ_ONCE(rdp->gp_seq_needed)));
0890 }
0891 }
0892 for_each_possible_cpu(cpu) {
0893 rdp = per_cpu_ptr(&rcu_data, cpu);
0894 cbs += data_race(READ_ONCE(rdp->n_cbs_invoked));
0895 if (rcu_segcblist_is_offloaded(&rdp->cblist))
0896 show_rcu_nocb_state(rdp);
0897 }
0898 pr_info("RCU callbacks invoked since boot: %lu\n", cbs);
0899 show_rcu_tasks_gp_kthreads();
0900 }
0901 EXPORT_SYMBOL_GPL(show_rcu_gp_kthreads);
0902
0903
0904
0905
0906
0907 static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp,
0908 const unsigned long gpssdelay)
0909 {
0910 unsigned long flags;
0911 unsigned long j;
0912 struct rcu_node *rnp_root = rcu_get_root();
0913 static atomic_t warned = ATOMIC_INIT(0);
0914
0915 if (!IS_ENABLED(CONFIG_PROVE_RCU) || rcu_gp_in_progress() ||
0916 ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
0917 READ_ONCE(rnp_root->gp_seq_needed)) ||
0918 !smp_load_acquire(&rcu_state.gp_kthread))
0919 return;
0920 j = jiffies;
0921 if (time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
0922 time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
0923 atomic_read(&warned))
0924 return;
0925
0926 raw_spin_lock_irqsave_rcu_node(rnp, flags);
0927 j = jiffies;
0928 if (rcu_gp_in_progress() ||
0929 ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
0930 READ_ONCE(rnp_root->gp_seq_needed)) ||
0931 time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
0932 time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
0933 atomic_read(&warned)) {
0934 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0935 return;
0936 }
0937
0938
0939 if (rnp_root != rnp)
0940 raw_spin_lock_rcu_node(rnp_root);
0941 j = jiffies;
0942 if (rcu_gp_in_progress() ||
0943 ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
0944 READ_ONCE(rnp_root->gp_seq_needed)) ||
0945 time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
0946 time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
0947 atomic_xchg(&warned, 1)) {
0948 if (rnp_root != rnp)
0949
0950 raw_spin_unlock_rcu_node(rnp_root);
0951 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0952 return;
0953 }
0954 WARN_ON(1);
0955 if (rnp_root != rnp)
0956 raw_spin_unlock_rcu_node(rnp_root);
0957 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
0958 show_rcu_gp_kthreads();
0959 }
0960
0961
0962
0963
0964
0965
0966 void rcu_fwd_progress_check(unsigned long j)
0967 {
0968 unsigned long cbs;
0969 int cpu;
0970 unsigned long max_cbs = 0;
0971 int max_cpu = -1;
0972 struct rcu_data *rdp;
0973
0974 if (rcu_gp_in_progress()) {
0975 pr_info("%s: GP age %lu jiffies\n",
0976 __func__, jiffies - data_race(READ_ONCE(rcu_state.gp_start)));
0977 show_rcu_gp_kthreads();
0978 } else {
0979 pr_info("%s: Last GP end %lu jiffies ago\n",
0980 __func__, jiffies - data_race(READ_ONCE(rcu_state.gp_end)));
0981 preempt_disable();
0982 rdp = this_cpu_ptr(&rcu_data);
0983 rcu_check_gp_start_stall(rdp->mynode, rdp, j);
0984 preempt_enable();
0985 }
0986 for_each_possible_cpu(cpu) {
0987 cbs = rcu_get_n_cbs_cpu(cpu);
0988 if (!cbs)
0989 continue;
0990 if (max_cpu < 0)
0991 pr_info("%s: callbacks", __func__);
0992 pr_cont(" %d: %lu", cpu, cbs);
0993 if (cbs <= max_cbs)
0994 continue;
0995 max_cbs = cbs;
0996 max_cpu = cpu;
0997 }
0998 if (max_cpu >= 0)
0999 pr_cont("\n");
1000 }
1001 EXPORT_SYMBOL_GPL(rcu_fwd_progress_check);
1002
1003
1004 static bool sysrq_rcu;
1005 module_param(sysrq_rcu, bool, 0444);
1006
1007
1008 static void sysrq_show_rcu(int key)
1009 {
1010 show_rcu_gp_kthreads();
1011 }
1012
1013 static const struct sysrq_key_op sysrq_rcudump_op = {
1014 .handler = sysrq_show_rcu,
1015 .help_msg = "show-rcu(y)",
1016 .action_msg = "Show RCU tree",
1017 .enable_mask = SYSRQ_ENABLE_DUMP,
1018 };
1019
1020 static int __init rcu_sysrq_init(void)
1021 {
1022 if (sysrq_rcu)
1023 return register_sysrq_key('y', &sysrq_rcudump_op);
1024 return 0;
1025 }
1026 early_initcall(rcu_sysrq_init);