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