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