Skip to content

Commit 088e9d2

Browse files
Daniel Bristot de Oliveirapaulmck
authored andcommitted
rcu: sysctl: Panic on RCU Stall
It is not always easy to determine the cause of an RCU stall just by analysing the RCU stall messages, mainly when the problem is caused by the indirect starvation of rcu threads. For example, when preempt_rcu is not awakened due to the starvation of a timer softirq. We have been hard coding panic() in the RCU stall functions for some time while testing the kernel-rt. But this is not possible in some scenarios, like when supporting customers. This patch implements the sysctl kernel.panic_on_rcu_stall. If set to 1, the system will panic() when an RCU stall takes place, enabling the capture of a vmcore. The vmcore provides a way to analyze all kernel/tasks states, helping out to point to the culprit and the solution for the stall. The kernel.panic_on_rcu_stall sysctl is disabled by default. Changes from v1: - Fixed a typo in the git log - The if(sysctl_panic_on_rcu_stall) panic() is in a static function - Fixed the CONFIG_TINY_RCU compilation issue - The var sysctl_panic_on_rcu_stall is now __read_mostly Cc: Jonathan Corbet <corbet@lwn.net> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Josh Triplett <josh@joshtriplett.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Lai Jiangshan <jiangshanlai@gmail.com> Acked-by: Christian Borntraeger <borntraeger@de.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Reviewed-by: Arnaldo Carvalho de Melo <acme@kernel.org> Tested-by: "Luis Claudio R. Goncalves" <lgoncalv@redhat.com> Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent aab0573 commit 088e9d2

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎Documentation/sysctl/kernel.txt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ show up in /proc/sys/kernel:
5858
- panic_on_stackoverflow
5959
- panic_on_unrecovered_nmi
6060
- panic_on_warn
61+
- panic_on_rcu_stall
6162
- perf_cpu_time_max_percent
6263
- perf_event_paranoid
6364
- perf_event_max_stack
@@ -618,6 +619,17 @@ a kernel rebuild when attempting to kdump at the location of a WARN().
618619

619620
==============================================================
620621

622+
panic_on_rcu_stall:
623+
624+
When set to 1, calls panic() after RCU stall detection messages. This
625+
is useful to define the root cause of RCU stalls using a vmcore.
626+
627+
0: do not panic() when RCU stall takes place, default behavior.
628+
629+
1: panic() after printing RCU stall messages.
630+
631+
==============================================================
632+
621633
perf_cpu_time_max_percent:
622634

623635
Hints to the kernel how much CPU time it should be allowed to

‎include/linux/kernel.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ extern int panic_on_oops;
451451
extern int panic_on_unrecovered_nmi;
452452
extern int panic_on_io_nmi;
453453
extern int panic_on_warn;
454+
extern int sysctl_panic_on_rcu_stall;
454455
extern int sysctl_panic_on_stackoverflow;
455456

456457
extern bool crash_kexec_post_notifiers;

‎kernel/rcu/tree.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
125125
/* Number of rcu_nodes at specified level. */
126126
static int num_rcu_lvl[] = NUM_RCU_LVL_INIT;
127127
int rcu_num_nodes __read_mostly = NUM_RCU_NODES; /* Total # rcu_nodes in use. */
128+
/* panic() on RCU Stall sysctl. */
129+
int sysctl_panic_on_rcu_stall __read_mostly;
128130

129131
/*
130132
* The rcu_scheduler_active variable transitions from zero to one just
@@ -1312,6 +1314,12 @@ static void rcu_stall_kick_kthreads(struct rcu_state *rsp)
13121314
}
13131315
}
13141316

1317+
static inline void panic_on_rcu_stall(void)
1318+
{
1319+
if (sysctl_panic_on_rcu_stall)
1320+
panic("RCU Stall\n");
1321+
}
1322+
13151323
static void print_other_cpu_stall(struct rcu_state *rsp, unsigned long gpnum)
13161324
{
13171325
int cpu;
@@ -1391,6 +1399,8 @@ static void print_other_cpu_stall(struct rcu_state *rsp, unsigned long gpnum)
13911399

13921400
rcu_check_gp_kthread_starvation(rsp);
13931401

1402+
panic_on_rcu_stall();
1403+
13941404
force_quiescent_state(rsp); /* Kick them all. */
13951405
}
13961406

@@ -1431,6 +1441,8 @@ static void print_cpu_stall(struct rcu_state *rsp)
14311441
jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
14321442
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
14331443

1444+
panic_on_rcu_stall();
1445+
14341446
/*
14351447
* Attempt to revive the RCU machinery by forcing a context switch.
14361448
*

‎kernel/sysctl.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,17 @@ static struct ctl_table kern_table[] = {
12041204
.extra1 = &one,
12051205
.extra2 = &one,
12061206
},
1207+
#endif
1208+
#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1209+
{
1210+
.procname = "panic_on_rcu_stall",
1211+
.data = &sysctl_panic_on_rcu_stall,
1212+
.maxlen = sizeof(sysctl_panic_on_rcu_stall),
1213+
.mode = 0644,
1214+
.proc_handler = proc_dointvec_minmax,
1215+
.extra1 = &zero,
1216+
.extra2 = &one,
1217+
},
12071218
#endif
12081219
{ }
12091220
};

0 commit comments

Comments
 (0)