[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250507104322.30700-2-feng.tang@linux.alibaba.com>
Date: Wed, 7 May 2025 18:43:20 +0800
From: Feng Tang <feng.tang@...ux.alibaba.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
Petr Mladek <pmladek@...e.com>,
Steven Rostedt <rostedt@...dmis.org>,
Lance Yang <ioworker0@...il.com>,
linux-kernel@...r.kernel.org
Cc: Feng Tang <feng.tang@...ux.alibaba.com>
Subject: [PATCH RFC 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.
Signed-off-by: Feng Tang <feng.tang@...ux.alibaba.com>
---
include/linux/panic.h | 12 ++++++++++++
kernel/panic.c | 44 +++++++++++++++++++++----------------------
2 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/include/linux/panic.h b/include/linux/panic.h
index 2494d51707ef..a6b538936a67 100644
--- a/include/linux/panic.h
+++ b/include/linux/panic.h
@@ -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;
diff --git a/kernel/panic.c b/kernel/panic.c
index a3889f38153d..4fd9499f6505 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -69,14 +69,6 @@ bool panic_triggering_all_cpu_backtrace;
int panic_timeout = CONFIG_PANIC_TIMEOUT;
EXPORT_SYMBOL_GPL(panic_timeout);
-#define PANIC_PRINT_TASK_INFO 0x00000001
-#define PANIC_PRINT_MEM_INFO 0x00000002
-#define PANIC_PRINT_TIMER_INFO 0x00000004
-#define PANIC_PRINT_LOCK_INFO 0x00000008
-#define PANIC_PRINT_FTRACE_INFO 0x00000010
-#define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020
-#define PANIC_PRINT_ALL_CPU_BT 0x00000040
-#define PANIC_PRINT_BLOCKED_TASKS 0x00000080
unsigned long panic_print;
ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
@@ -208,31 +200,39 @@ void nmi_panic(struct pt_regs *regs, const char *msg)
}
EXPORT_SYMBOL(nmi_panic);
-static void panic_print_sys_info(bool console_flush)
+void sys_show_info(unsigned long info_mask)
{
- if (console_flush) {
- if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
- console_flush_on_panic(CONSOLE_REPLAY_ALL);
- return;
- }
-
- if (panic_print & PANIC_PRINT_TASK_INFO)
+ if (info_mask & SYS_PRINT_TASK_INFO)
show_state();
- if (panic_print & PANIC_PRINT_MEM_INFO)
+ if (info_mask & SYS_PRINT_MEM_INFO)
show_mem();
- if (panic_print & PANIC_PRINT_TIMER_INFO)
+ if (info_mask & SYS_PRINT_TIMER_INFO)
sysrq_timer_list_show();
- if (panic_print & PANIC_PRINT_LOCK_INFO)
+ if (info_mask & SYS_PRINT_LOCK_INFO)
debug_show_all_locks();
- if (panic_print & PANIC_PRINT_FTRACE_INFO)
+ if (info_mask & SYS_PRINT_FTRACE_INFO)
ftrace_dump(DUMP_ALL);
- if (panic_print & PANIC_PRINT_BLOCKED_TASKS)
+ if (info_mask & SYS_PRINT_BLOCKED_TASKS)
show_state_filter(TASK_UNINTERRUPTIBLE);
+
+ if (info_mask & SYS_PRINT_ALL_CPU_BT)
+ trigger_all_cpu_backtrace();
+}
+
+static void panic_print_sys_info(bool console_flush)
+{
+ if (console_flush) {
+ if (panic_print & SYS_PRINT_ALL_PRINTK_MSG)
+ console_flush_on_panic(CONSOLE_REPLAY_ALL);
+ return;
+ }
+
+ sys_show_info(panic_print);
}
void check_panic_on_warn(const char *origin)
@@ -255,7 +255,7 @@ void check_panic_on_warn(const char *origin)
*/
static void panic_other_cpus_shutdown(bool crash_kexec)
{
- if (panic_print & PANIC_PRINT_ALL_CPU_BT) {
+ if (panic_print & SYS_PRINT_ALL_CPU_BT) {
/* Temporary allow non-panic CPUs to write their backtraces. */
panic_triggering_all_cpu_backtrace = true;
trigger_all_cpu_backtrace();
--
2.39.5 (Apple Git-154)
Powered by blists - more mailing lists