Skip to contentSkip to conversation

generalize panic_print's dump function to be

RFC PATCH In review Feng Tang 2 participants 9 messages May 7, 2025 – May 9, 2025 Hung task detector

lore
Share & tools
lore

Feng Tang

author
#0 lore raw

cover generalize panic_print's dump function to be

When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.

panic case already has panic_print_sys_info() for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.

So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.

Locally these have been used in our bug chasing for stablility issues and was helpful.

Please help to review, thanks!

- Feng

Feng Tang (3):
kernel/panic: generalize panic_print's function to show sys info kernel/hung_task: add option to dump system info when hung task
detected
kernel/watchdog: add option to dump system info when system is locked
up

 include/linux/panic.h | 12 ++++++++++++
 kernel/hung_task.c    | 29 +++++++++++++++-------------
 kernel/panic.c        | 44 +++++++++++++++++++++----------------------
 kernel/watchdog.c     | 11 +++++++++++
 4 files changed, 61 insertions(+), 35 deletions(-)
Signature · 1 line
2.39.5 (Apple Git-154)
author
#1 lore raw

RFC PATCH 1/3 kernel/panic: generalize panic_print's function to show sys info

panic_print was introduced to help debugging kernel panic by dumping different kinds of system information like tasks' call stack, memory, ftrace buffer etc. Acutually this function could help debugging cases like task-hung, soft/hard lockup too, where user may need the snapshot of system info at that time.

Extract sys_show_info() function out to be used by other kernel parts for debugging.

---
 include/linux/panic.h | 12 ++++++++++++
 kernel/panic.c        | 44 +++++++++++++++++++++----------------------
 2 files changed, 34 insertions(+), 22 deletions(-)
include/linux/panic.h +12 -0
index 2494d51707ef..a6b538936a67 100644
@@ -16,6 +16,18 @@ extern void oops_enter(void);
 extern void oops_exit(void);
 extern bool oops_may_print(void);
 
+/* Currently SYS_PRINT_ALL_PRINTK_MSG is only used for panic case */
+#define SYS_PRINT_TASK_INFO		0x00000001
+#define SYS_PRINT_MEM_INFO		0x00000002
+#define SYS_PRINT_TIMER_INFO		0x00000004
+#define SYS_PRINT_LOCK_INFO		0x00000008
+#define SYS_PRINT_FTRACE_INFO		0x00000010
+#define SYS_PRINT_ALL_PRINTK_MSG	0x00000020
+#define SYS_PRINT_ALL_CPU_BT		0x00000040
+#define SYS_PRINT_BLOCKED_TASKS		0x00000080
+
+extern void sys_show_info(unsigned long info_mask);
+
 extern bool panic_triggering_all_cpu_backtrace;
 extern int panic_timeout;
 extern unsigned long panic_print;
kernel/panic.c +22 -22

74 lines not on this page · raw message

Signature · 1 line
2.39.5 (Apple Git-154)
author
#2 lore raw

RFC PATCH 2/3 kernel/hung_task: add option to dump system info when hung task detected

In reply to Feng Tang
Kernel panic code utilizes sys_show_info() to dump needed system

information to help debugging. Similarly, add this debug option for task hung case, and 'hungtask_print' is the knob to control what information should be printed out.

Also clean up the code about dumping locks and triggering backtrace for all CPUs. One todo may be to merge this 'hungtask_print' with some sysctl knobs in hung_task.c.

---
 kernel/hung_task.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
kernel/hung_task.c +16 -13
index dc898ec93463..8229637be2c7 100644
@@ -58,12 +58,20 @@ static unsigned long __read_mostly sysctl_hung_task_check_interval_secs;
 static int __read_mostly sysctl_hung_task_warnings = 10;
 
 static int __read_mostly did_panic;
-static bool hung_task_show_lock;
 static bool hung_task_call_panic;
-static bool hung_task_show_all_bt;
 
 static struct task_struct *watchdog_task;
 
+/*
+ * A bitmask to control what kinds of system info to be printed when a
+ * hung task is detected, it could be task, memory, lock etc. Refer panic.h
+ * for details of bit definition.
+ */
+unsigned long hungtask_print;
+core_param(hungtask_print, hungtask_print, ulong, 0644);
+
+static unsigned long cur_hungtask_print;
+
 #ifdef CONFIG_SMP
 /*
  * Should we dump all CPUs backtraces in a hung task event?
@@ -163,11 +171,12 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
 	 */
 	sysctl_hung_task_detect_count++;
 
+	cur_hungtask_print = hungtask_print;
 	trace_sched_process_hang(t);
 
 	if (sysctl_hung_task_panic) {
 		console_verbose();
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
 		hung_task_call_panic = true;
 	}
 
@@ -190,10 +199,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
 			" disables this message.\n");
 		sched_show_task(t);
 		debug_show_blocker(t);
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
 
 		if (sysctl_hung_task_all_cpu_backtrace)
-			hung_task_show_all_bt = true;
+			cur_hungtask_print |= SYS_PRINT_ALL_CPU_BT;
 		if (!sysctl_hung_task_warnings)
 			pr_info("Future hung task reports are suppressed, see sysctl kernel.hung_task_warnings\n");
 	}
@@ -242,7 +251,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
 	if (test_taint(TAINT_DIE) || did_panic)
 		return;
 
-	hung_task_show_lock = false;
+	cur_hungtask_print = 0;
 	rcu_read_lock();
 	for_each_process_thread(g, t) {
 		unsigned int state;
@@ -266,14 +275,8 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
 	}
  unlock:
 	rcu_read_unlock();
-	if (hung_task_show_lock)
-		debug_show_all_locks();
-
-	if (hung_task_show_all_bt) {
-		hung_task_show_all_bt = false;
-		trigger_all_cpu_backtrace();
-	}
 
+	sys_show_info(cur_hungtask_print);
 	if (hung_task_call_panic)
 		panic("hung_task: blocked tasks");
 }
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer
#3 lore raw

Re: [PATCH RFC 2/3] kernel/hung_task: add option to dump system info when hung task detected

Hi Feng,

Thanks for the patch series!

Quoted 25 lines · Feng Tang
Kernel panic code utilizes sys_show_info() to dump needed system

information to help debugging. Similarly, add this debug option for task hung case, and 'hungtask_print' is the knob to control what information should be printed out.

Also clean up the code about dumping locks and triggering backtrace for all CPUs. One todo may be to merge this 'hungtask_print' with some sysctl knobs in hung_task.c.

---
  kernel/hung_task.c | 29 ++++++++++++++++-------------
  1 file changed, 16 insertions(+), 13 deletions(-)
kernel/hung_task.c +0 -2
index dc898ec93463..8229637be2c7 100644
@@ -58,12 +58,20 @@ static unsigned long __read_mostly sysctl_hung_task_check_interval_secs;
  static int __read_mostly sysctl_hung_task_warnings = 10;
 
  static int __read_mostly did_panic;
-static bool hung_task_show_lock;
  static bool hung_task_call_panic;
-static bool hung_task_show_all_bt;

kernel/hung_task.c static unsigned long __read_mostly sysctl_hung_task_check_interval_secs; · line 71

Quoted 10 lines
kernel/hung_task.c +7 -0
 
  static struct task_struct *watchdog_task;
 
+/*
+ * A bitmask to control what kinds of system info to be printed when a
+ * hung task is detected, it could be task, memory, lock etc. Refer panic.h
+ * for details of bit definition.
+ */
+unsigned long hungtask_print;
+core_param(hungtask_print, hungtask_print, ulong, 0644);

how about lockup_debug_print_mask?

It could be useful for debugging, but there are a few concerns:

1) SYS_PRINT_* vs. hung_task_* priority conflict
- If SYS_PRINT_ALL_CPU_BT is set on the command line but hung_task_all_cpu_backtrace is disabled, which one wins?
- Or should SYS_PRINT_ALL_CPU_BT force-enable hung_task_all_cpu_backtrace?

2) Duplicate prints
With SYS_PRINT_BLOCKED_TASKS enabled, processes in D state will be printed twice, right?

Also, we really should document how those command-line parameters work ;)

Thansk,
Lance

Quoted 58 lines
kernel/hung_task.c +9 -11
+
+static unsigned long cur_hungtask_print;
+
  #ifdef CONFIG_SMP
  /*
   * Should we dump all CPUs backtraces in a hung task event?
@@ -163,11 +171,12 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
  	 */
  	sysctl_hung_task_detect_count++;
 
+	cur_hungtask_print = hungtask_print;
  	trace_sched_process_hang(t);
 
  	if (sysctl_hung_task_panic) {
  		console_verbose();
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
  		hung_task_call_panic = true;
  	}
 
@@ -190,10 +199,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
  			" disables this message.\n");
  		sched_show_task(t);
  		debug_show_blocker(t);
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
 
  		if (sysctl_hung_task_all_cpu_backtrace)
-			hung_task_show_all_bt = true;
+			cur_hungtask_print |= SYS_PRINT_ALL_CPU_BT;
  		if (!sysctl_hung_task_warnings)
  			pr_info("Future hung task reports are suppressed, see sysctl kernel.hung_task_warnings\n");
  	}
@@ -242,7 +251,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
  	if (test_taint(TAINT_DIE) || did_panic)
  		return;
 
-	hung_task_show_lock = false;
+	cur_hungtask_print = 0;
  	rcu_read_lock();
  	for_each_process_thread(g, t) {
  		unsigned int state;
@@ -266,14 +275,8 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
  	}
   unlock:
  	rcu_read_unlock();
-	if (hung_task_show_lock)
-		debug_show_all_locks();
-
-	if (hung_task_show_all_bt) {
-		hung_task_show_all_bt = false;
-		trigger_all_cpu_backtrace();
-	}
 
+	sys_show_info(cur_hungtask_print);
  	if (hung_task_call_panic)
  		panic("hung_task: blocked tasks");
  }
author
#4 lore raw

Re: [PATCH RFC 2/3] kernel/hung_task: add option to dump system info when hung task detected

Hi Lance,

Many thanks for the review!

Quoted 31 lines · Lance Yang

Hi Feng,

Thanks for the patch series!

Quoted 26 lines · Feng Tang
Kernel panic code utilizes sys_show_info() to dump needed system

information to help debugging. Similarly, add this debug option for task hung case, and 'hungtask_print' is the knob to control what information should be printed out.

Also clean up the code about dumping locks and triggering backtrace for all CPUs. One todo may be to merge this 'hungtask_print' with some sysctl knobs in hung_task.c.

---
  kernel/hung_task.c | 29 ++++++++++++++++-------------
  1 file changed, 16 insertions(+), 13 deletions(-)
kernel/hung_task.c +1 -2
index dc898ec93463..8229637be2c7 100644
@@ -58,12 +58,20 @@ static unsigned long __read_mostly sysctl_hung_task_check_interval_secs;
  static int __read_mostly sysctl_hung_task_warnings = 10;
  static int __read_mostly did_panic;
-static bool hung_task_show_lock;
  static bool hung_task_call_panic;
-static bool hung_task_show_all_bt;
  static struct task_struct *watchdog_task;
+/*
Quoted 8 lines

kernel/hung_task.c static unsigned long __read_mostly sysctl_hung_task_check_interval_secs; · line 71

Quoted 6 lines
kernel/hung_task.c +6 -0
+ * A bitmask to control what kinds of system info to be printed when a
+ * hung task is detected, it could be task, memory, lock etc. Refer panic.h
+ * for details of bit definition.
+ */
+unsigned long hungtask_print;
+core_param(hungtask_print, hungtask_print, ulong, 0644);

how about lockup_debug_print_mask?

The 3/3 patch has a 'lockup_print' as it is for soft/hard lockup :). The name follows the existing 'panic_print', and indeed it's actually a bitmask, how about 'hung_print_mask'?

Quoted 7 lines

It could be useful for debugging, but there are a few concerns:

1) SYS_PRINT_* vs. hung_task_* priority conflict
- If SYS_PRINT_ALL_CPU_BT is set on the command line but hung_task_all_cpu_backtrace is disabled, which one wins?
- Or should SYS_PRINT_ALL_CPU_BT force-enable hung_task_all_cpu_backtrace?

With this patch, the 'hungtask_print' and hung_task_all_cpu_backtrace will be ORed, so yes, if user sets SYS_PRINT_ALL_CPU_BT explicitly, the all-cpu-backtrace will be printed.

While the default value for hungtask_print is 0, and no system info will be dumped by default.

Long term wise, I'm not sure if sysctl_hung_task_all_cpu_backtracemay could be removed as its function can be covered by this print_mask knob.

Quoted 3 lines

2) Duplicate prints
With SYS_PRINT_BLOCKED_TASKS enabled, processes in D state will be printed twice, right?

Good point. As sys_show_info() is a general API helper, the user may chose not to set SYS_PRINT_BLOCKED_TASKS when debugging task hung.

In one recent bug we debugged with this patch, when the first "task hung" was shown, there were already dozens of tasks were in D state, which just hadn't hit the 120 seconds limit yet, and dumping them all helped in that case.

Quoted 1 line

Also, we really should document how those command-line parameters work ;)

Exactly! It currently just said 'refer panic.h' in code comment, maybe I should copy those definitions here as comments. How do you think?

Thanks,
Feng

Quoted 55 lines

Thansk,
Lance

Quoted 52 lines
kernel/hung_task.c +9 -11
+
+static unsigned long cur_hungtask_print;
+
  #ifdef CONFIG_SMP
  /*
   * Should we dump all CPUs backtraces in a hung task event?
@@ -163,11 +171,12 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
  	 */
  	sysctl_hung_task_detect_count++;
+	cur_hungtask_print = hungtask_print;
  	trace_sched_process_hang(t);
  	if (sysctl_hung_task_panic) {
  		console_verbose();
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
  		hung_task_call_panic = true;
  	}
@@ -190,10 +199,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
  			" disables this message.\n");
  		sched_show_task(t);
  		debug_show_blocker(t);
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
  		if (sysctl_hung_task_all_cpu_backtrace)
-			hung_task_show_all_bt = true;
+			cur_hungtask_print |= SYS_PRINT_ALL_CPU_BT;
  		if (!sysctl_hung_task_warnings)
  			pr_info("Future hung task reports are suppressed, see sysctl kernel.hung_task_warnings\n");
  	}
@@ -242,7 +251,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
  	if (test_taint(TAINT_DIE) || did_panic)
  		return;
-	hung_task_show_lock = false;
+	cur_hungtask_print = 0;
  	rcu_read_lock();
  	for_each_process_thread(g, t) {
  		unsigned int state;
@@ -266,14 +275,8 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
  	}
   unlock:
  	rcu_read_unlock();
-	if (hung_task_show_lock)
-		debug_show_all_locks();
-
-	if (hung_task_show_all_bt) {
-		hung_task_show_all_bt = false;
-		trigger_all_cpu_backtrace();
-	}
+	sys_show_info(cur_hungtask_print);
  	if (hung_task_call_panic)
  		panic("hung_task: blocked tasks");
  }
maintainer
#5 lore raw

Re: [PATCH RFC 2/3] kernel/hung_task: add option to dump system info when hung task detected

Quoted 44 lines · Feng Tang

Hi Lance,

Many thanks for the review!

Quoted 39 lines · Lance Yang

Hi Feng,

Thanks for the patch series!

Quoted 22 lines · Feng Tang
Kernel panic code utilizes sys_show_info() to dump needed system

information to help debugging. Similarly, add this debug option for task hung case, and 'hungtask_print' is the knob to control what information should be printed out.

Also clean up the code about dumping locks and triggering backtrace for all CPUs. One todo may be to merge this 'hungtask_print' with some sysctl knobs in hung_task.c.

---
   kernel/hung_task.c | 29 ++++++++++++++++-------------
   1 file changed, 16 insertions(+), 13 deletions(-)
kernel/hung_task.c +0 -1
index dc898ec93463..8229637be2c7 100644
@@ -58,12 +58,20 @@ static unsigned long __read_mostly sysctl_hung_task_check_interval_secs;
   static int __read_mostly sysctl_hung_task_warnings = 10;
   static int __read_mostly did_panic;
-static bool hung_task_show_lock;

kernel/hung_task.c static unsigned long __read_mostly sysctl_hung_task_check_interval_secs; · line 68

Quoted 10 lines
kernel/hung_task.c +7 -1
   static bool hung_task_call_panic;
-static bool hung_task_show_all_bt;
   static struct task_struct *watchdog_task;
+/*
+ * A bitmask to control what kinds of system info to be printed when a
+ * hung task is detected, it could be task, memory, lock etc. Refer panic.h
+ * for details of bit definition.
+ */
+unsigned long hungtask_print;
+core_param(hungtask_print, hungtask_print, ulong, 0644);

how about lockup_debug_print_mask?

Oops, typo: hungtask_* (not lockup_*)

Quoted 4 lines

The 3/3 patch has a 'lockup_print' as it is for soft/hard lockup :). The name follows the existing 'panic_print', and indeed it's actually a bitmask, how about 'hung_print_mask'?

Yep, we should be following ’panic_print‘ pattern like 'hungtask_print', but I‘d rather go with 'hungtask_print_mask' ;)

Quoted 13 lines
Quoted 8 lines

It could be useful for debugging, but there are a few concerns:

1) SYS_PRINT_* vs. hung_task_* priority conflict
- If SYS_PRINT_ALL_CPU_BT is set on the command line but hung_task_all_cpu_backtrace is disabled, which one wins?
- Or should SYS_PRINT_ALL_CPU_BT force-enable hung_task_all_cpu_backtrace?

With this patch, the 'hungtask_print' and hung_task_all_cpu_backtrace will be ORed, so yes, if user sets SYS_PRINT_ALL_CPU_BT explicitly, the all-cpu-backtrace will be printed.

Quoted 5 lines

While the default value for hungtask_print is 0, and no system info will be dumped by default.

Long term wise, I'm not sure if sysctl_hung_task_all_cpu_backtracemay could be removed as its function can be covered by this print_mask knob.

Afraid we cannot remove that knob — it would break user-space. Note that hungtask_print_mask should act as an extension (to provide more details when investigating hangs), and it must still follow hung-task detector's rules, IIUC.

Hmm... SYS_PRINT_ALL_CPU_BT is a bit tricky here. Maybe we can directly enable hung_task_all_cpu_backtrace when SYS_PRINT_ALL_CPU_BT is set in hungtask_print_mask, while still allowing manual disabling to dump backtraces for all CPUs via hung_task_all_cpu_backtrace. This way, we keep its original semantics ;)

Quoted 11 lines
Quoted 4 lines

2) Duplicate prints
With SYS_PRINT_BLOCKED_TASKS enabled, processes in D state will be printed twice, right?

Good point. As sys_show_info() is a general API helper, the user may chose not to set SYS_PRINT_BLOCKED_TASKS when debugging task hung.

In one recent bug we debugged with this patch, when the first "task hung" was shown, there were already dozens of tasks were in D state, which just hadn't hit the 120 seconds limit yet, and dumping them all helped in that case.

Makes sense to me. Right, SYS_PRINT_BLOCKED_TASKS doesn’t duplicate prints, and catches all D-state tasks - even the ones not yet timed out.

Quoted 5 lines
Quoted 2 lines

Also, we really should document how those command-line parameters work ;)

Exactly! It currently just said 'refer panic.h' in code comment, maybe I should copy those definitions here as comments. How do you think?

Yes. Both comments and kernel-doc are needed ;)

Thanks,
Lance

Quoted 59 lines

Thanks,
Feng

Quoted 55 lines

Thansk,
Lance

Quoted 52 lines
kernel/hung_task.c +9 -11
+
+static unsigned long cur_hungtask_print;
+
   #ifdef CONFIG_SMP
   /*
    * Should we dump all CPUs backtraces in a hung task event?
@@ -163,11 +171,12 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
   	 */
   	sysctl_hung_task_detect_count++;
+	cur_hungtask_print = hungtask_print;
   	trace_sched_process_hang(t);
   	if (sysctl_hung_task_panic) {
   		console_verbose();
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
   		hung_task_call_panic = true;
   	}
@@ -190,10 +199,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
   			" disables this message.\n");
   		sched_show_task(t);
   		debug_show_blocker(t);
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
   		if (sysctl_hung_task_all_cpu_backtrace)
-			hung_task_show_all_bt = true;
+			cur_hungtask_print |= SYS_PRINT_ALL_CPU_BT;
   		if (!sysctl_hung_task_warnings)
   			pr_info("Future hung task reports are suppressed, see sysctl kernel.hung_task_warnings\n");
   	}
@@ -242,7 +251,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
   	if (test_taint(TAINT_DIE) || did_panic)
   		return;
-	hung_task_show_lock = false;
+	cur_hungtask_print = 0;
   	rcu_read_lock();
   	for_each_process_thread(g, t) {
   		unsigned int state;
@@ -266,14 +275,8 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
   	}
    unlock:
   	rcu_read_unlock();
-	if (hung_task_show_lock)
-		debug_show_all_locks();
-
-	if (hung_task_show_all_bt) {
-		hung_task_show_all_bt = false;
-		trigger_all_cpu_backtrace();
-	}
+	sys_show_info(cur_hungtask_print);
   	if (hung_task_call_panic)
   		panic("hung_task: blocked tasks");
   }
author
#6 lore raw

Re: [PATCH RFC 2/3] kernel/hung_task: add option to dump system info when hung task detected

Quoted 51 lines · Lance Yang
Quoted 44 lines · Feng Tang

Hi Lance,

Many thanks for the review!

Quoted 39 lines · Lance Yang

Hi Feng,

Thanks for the patch series!

Quoted 22 lines · Feng Tang
Kernel panic code utilizes sys_show_info() to dump needed system

information to help debugging. Similarly, add this debug option for task hung case, and 'hungtask_print' is the knob to control what information should be printed out.

Also clean up the code about dumping locks and triggering backtrace for all CPUs. One todo may be to merge this 'hungtask_print' with some sysctl knobs in hung_task.c.

---
   kernel/hung_task.c | 29 ++++++++++++++++-------------
   1 file changed, 16 insertions(+), 13 deletions(-)
kernel/hung_task.c +0 -1
index dc898ec93463..8229637be2c7 100644
@@ -58,12 +58,20 @@ static unsigned long __read_mostly sysctl_hung_task_check_interval_secs;
   static int __read_mostly sysctl_hung_task_warnings = 10;
   static int __read_mostly did_panic;
-static bool hung_task_show_lock;

kernel/hung_task.c static unsigned long __read_mostly sysctl_hung_task_check_interval_secs; · line 68

Quoted 10 lines
kernel/hung_task.c +7 -1
   static bool hung_task_call_panic;
-static bool hung_task_show_all_bt;
   static struct task_struct *watchdog_task;
+/*
+ * A bitmask to control what kinds of system info to be printed when a
+ * hung task is detected, it could be task, memory, lock etc. Refer panic.h
+ * for details of bit definition.
+ */
+unsigned long hungtask_print;
+core_param(hungtask_print, hungtask_print, ulong, 0644);

how about lockup_debug_print_mask?

Oops, typo: hungtask_* (not lockup_*)

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

The 3/3 patch has a 'lockup_print' as it is for soft/hard lockup :). The name follows the existing 'panic_print', and indeed it's actually a bitmask, how about 'hung_print_mask'?

Yep, we should be following ’panic_print‘ pattern like 'hungtask_print', but I‘d rather go with 'hungtask_print_mask' ;)

OK, will change to it.

Quoted 17 lines
Quoted 17 lines
Quoted 9 lines

It could be useful for debugging, but there are a few concerns:

1) SYS_PRINT_* vs. hung_task_* priority conflict
- If SYS_PRINT_ALL_CPU_BT is set on the command line but hung_task_all_cpu_backtrace is disabled, which one wins?
- Or should SYS_PRINT_ALL_CPU_BT force-enable hung_task_all_cpu_backtrace?

With this patch, the 'hungtask_print' and hung_task_all_cpu_backtrace will be ORed, so yes, if user sets SYS_PRINT_ALL_CPU_BT explicitly, the all-cpu-backtrace will be printed.

While the default value for hungtask_print is 0, and no system info will be dumped by default.

Quoted 7 lines
Quoted 2 lines

Long term wise, I'm not sure if sysctl_hung_task_all_cpu_backtracemay could be removed as its function can be covered by this print_mask knob.

Afraid we cannot remove that knob — it would break user-space. Note that hungtask_print_mask should act as an extension (to provide more details when investigating hangs), and it must still follow hung-task detector's rules, IIUC.

Right.

Quoted 5 lines

Hmm... SYS_PRINT_ALL_CPU_BT is a bit tricky here. Maybe we can directly enable hung_task_all_cpu_backtrace when SYS_PRINT_ALL_CPU_BT is set in hungtask_print_mask, while still allowing manual disabling to dump backtraces for all CPUs via hung_task_all_cpu_backtrace. This way, we keep its original semantics ;)

Sounds goot to me, thanks for the suggestion!

Quoted 17 lines
Quoted 11 lines
Quoted 4 lines

2) Duplicate prints
With SYS_PRINT_BLOCKED_TASKS enabled, processes in D state will be printed twice, right?

Good point. As sys_show_info() is a general API helper, the user may chose not to set SYS_PRINT_BLOCKED_TASKS when debugging task hung.

In one recent bug we debugged with this patch, when the first "task hung" was shown, there were already dozens of tasks were in D state, which just hadn't hit the 120 seconds limit yet, and dumping them all helped in that case.

Makes sense to me. Right, SYS_PRINT_BLOCKED_TASKS doesn’t duplicate prints, and
catches all D-state tasks - even the ones not yet timed out.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Also, we really should document how those command-line parameters work ;)

Exactly! It currently just said 'refer panic.h' in code comment, maybe I should copy those definitions here as comments. How do you think?

Yes. Both comments and kernel-doc are needed ;)

Sure. Seems kernel-parameters.txt is the good place for core parameters.

Thanks,
Feng

Quoted 63 lines

Thanks,
Lance

Quoted 59 lines

Thanks,
Feng

Quoted 55 lines

Thansk,
Lance

Quoted 52 lines
kernel/hung_task.c +9 -11
+
+static unsigned long cur_hungtask_print;
+
   #ifdef CONFIG_SMP
   /*
    * Should we dump all CPUs backtraces in a hung task event?
@@ -163,11 +171,12 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
   	 */
   	sysctl_hung_task_detect_count++;
+	cur_hungtask_print = hungtask_print;
   	trace_sched_process_hang(t);
   	if (sysctl_hung_task_panic) {
   		console_verbose();
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
   		hung_task_call_panic = true;
   	}
@@ -190,10 +199,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
   			" disables this message.\n");
   		sched_show_task(t);
   		debug_show_blocker(t);
-		hung_task_show_lock = true;
+		cur_hungtask_print |= SYS_PRINT_LOCK_INFO;
   		if (sysctl_hung_task_all_cpu_backtrace)
-			hung_task_show_all_bt = true;
+			cur_hungtask_print |= SYS_PRINT_ALL_CPU_BT;
   		if (!sysctl_hung_task_warnings)
   			pr_info("Future hung task reports are suppressed, see sysctl kernel.hung_task_warnings\n");
   	}
@@ -242,7 +251,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
   	if (test_taint(TAINT_DIE) || did_panic)
   		return;
-	hung_task_show_lock = false;
+	cur_hungtask_print = 0;
   	rcu_read_lock();
   	for_each_process_thread(g, t) {
   		unsigned int state;
@@ -266,14 +275,8 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
   	}
    unlock:
   	rcu_read_unlock();
-	if (hung_task_show_lock)
-		debug_show_all_locks();
-
-	if (hung_task_show_all_bt) {
-		hung_task_show_all_bt = false;
-		trigger_all_cpu_backtrace();
-	}
+	sys_show_info(cur_hungtask_print);
   	if (hung_task_call_panic)
   		panic("hung_task: blocked tasks");
   }
author
#7 lore raw

RFC PATCH 3/3 kernel/watchdog: add option to dump system info when system is locked up

In reply to Feng Tang
Kernel panic code utilizes sys_show_info() to dump needed system

information to help debugging. Similarly, add this debug option for software/hardware lockup cases, and 'lockup_print' is the knob to control what information should be printed out.

---
 kernel/watchdog.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/watchdog.c +11 -0
index 9fa2af9dbf2c..60afcb0247ab 100644
@@ -52,6 +52,14 @@ static int __read_mostly watchdog_hardlockup_available;
 struct cpumask watchdog_cpumask __read_mostly;
 unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);
 
+/*
+ * A bitmask to control what kinds of system info to be printed when a
+ * software/hardware lockup is detected, it could be task, memory, lock etc.
+ * Refer panic.h for details of bit definition.
+ */
+unsigned long lockup_print;
+core_param(lockup_print, lockup_print, ulong, 0644);
+
 #ifdef CONFIG_HARDLOCKUP_DETECTOR
 
 # ifdef CONFIG_SMP
@@ -212,6 +220,7 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs)
 				clear_bit_unlock(0, &hard_lockup_nmi_warn);
 		}
 
+		sys_show_info(lockup_print);
 		if (hardlockup_panic)
 			nmi_panic(regs, "Hard LOCKUP");
 
@@ -774,6 +783,8 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
 		}
 
 		add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK);
+
+		sys_show_info(lockup_print);
 		if (softlockup_panic)
 			panic("softlockup: hung tasks");
 	}
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer
#8 lore raw
In reply to Feng Tang

Cc Masami and Waiman

Quoted 32 lines · Feng Tang

When working on kernel stability issues, panic, task-hung and software/hardware lockup are frequently met. And to debug them, user may need lots of system information at that time, like task call stacks, lock info, memory info etc.

panic case already has panic_print_sys_info() for this purpose, and has a 'panic_print' bitmask to control what kinds of information is needed, which is also helpful to debug other task-hung and lockup cases.

So this patchset extract the function out, and make it usable for other cases which also need system info for debugging.

Locally these have been used in our bug chasing for stablility issues and was helpful.

Please help to review, thanks!

- Feng

Feng Tang (3):
kernel/panic: generalize panic_print's function to show sys info kernel/hung_task: add option to dump system info when hung task
detected
kernel/watchdog: add option to dump system info when system is locked
up

  include/linux/panic.h | 12 ++++++++++++
  kernel/hung_task.c    | 29 +++++++++++++++-------------
  kernel/panic.c        | 44 +++++++++++++++++++++----------------------
  kernel/watchdog.c     | 11 +++++++++++
  4 files changed, 61 insertions(+), 35 deletions(-)