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