]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
panic: clean up code for console replay
authorFeng Tang <feng.tang@linux.alibaba.com>
Thu, 3 Jul 2025 02:10:00 +0000 (10:10 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 20 Jul 2025 02:08:24 +0000 (19:08 -0700)
Patch series "generalize panic_print's dump function to be used by other
kernel parts", v3.

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 extracts the function out to a new file 'lib/sys_info.c',
and makes it available for other cases which also need to dump system info
for debugging.

Also as suggested by Petr Mladek, add 'panic_sys_info=' interface to take
human readable string like "tasks,mem,locks,timers,ftrace,....", and
eventually obsolete the current 'panic_print' bitmap interface.

In RFC and V1 version, hung_task and SW/HW watchdog modules are enabled
with the new sys_info dump interface.  In v2, they are kept out for better
review of current change, and will be posted later.

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

Many thanks to Petr Mladek for great suggestions on both the code and
architectures!

This patch (of 5):

Currently the panic_print_sys_info() was called twice with different
parameters to handle console replay case, which is kind of confusing.

Add panic_console_replay() explicitly and rename
'PANIC_PRINT_ALL_PRINTK_MSG' to 'PANIC_CONSOLE_REPLAY', to make the code
straightforward.  The related kernel document is also updated.

Link: https://lkml.kernel.org/r/20250703021004.42328-1-feng.tang@linux.alibaba.com
Link: https://lkml.kernel.org/r/20250703021004.42328-2-feng.tang@linux.alibaba.com
Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
Suggested-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: "Paul E . McKenney" <paulmck@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/admin-guide/kernel-parameters.txt
Documentation/admin-guide/sysctl/kernel.rst
kernel/panic.c

index ac4a239b9388c38adb21f3466741d1037ab445a7..3780b7e6bfd5a674d44fce0f948494cd6b220e3b 100644 (file)
                        bit 2: print timer info
                        bit 3: print locks info if CONFIG_LOCKDEP is on
                        bit 4: print ftrace buffer
-                       bit 5: print all printk messages in buffer
+                       bit 5: replay all messages on consoles at the end of panic
                        bit 6: print all CPUs backtrace (if available in the arch)
                        bit 7: print only tasks in uninterruptible (blocked) state
                        *Be aware* that this option may print a _lot_ of lines,
index dd49a89a62d3542fa1a599f318dff26589e1d57b..0d08b7a2db2da9298b9353e61e4278065ca27bd9 100644 (file)
@@ -889,7 +889,7 @@ bit 1  print system memory info
 bit 2  print timer info
 bit 3  print locks info if ``CONFIG_LOCKDEP`` is on
 bit 4  print ftrace buffer
-bit 5  print all printk messages in buffer
+bit 5  replay all messages on consoles at the end of panic
 bit 6  print all CPUs backtrace (if available in the arch)
 bit 7  print only tasks in uninterruptible (blocked) state
 =====  ============================================
index b0b9a8bf4560d5d0139dd74ee9a037bdfeb12c54..9b6c5dc28a653d3750fe314d78a7c3db153a1b47 100644 (file)
@@ -74,7 +74,7 @@ EXPORT_SYMBOL_GPL(panic_timeout);
 #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_CONSOLE_REPLAY           0x00000020
 #define PANIC_PRINT_ALL_CPU_BT         0x00000040
 #define PANIC_PRINT_BLOCKED_TASKS      0x00000080
 unsigned long panic_print;
@@ -238,14 +238,14 @@ void nmi_panic(struct pt_regs *regs, const char *msg)
 }
 EXPORT_SYMBOL(nmi_panic);
 
-static void panic_print_sys_info(bool console_flush)
+static void panic_console_replay(void)
 {
-       if (console_flush) {
-               if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
-                       console_flush_on_panic(CONSOLE_REPLAY_ALL);
-               return;
-       }
+       if (panic_print & PANIC_CONSOLE_REPLAY)
+               console_flush_on_panic(CONSOLE_REPLAY_ALL);
+}
 
+static void panic_print_sys_info(void)
+{
        if (panic_print & PANIC_PRINT_TASK_INFO)
                show_state();
 
@@ -410,7 +410,7 @@ void panic(const char *fmt, ...)
         */
        atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
 
-       panic_print_sys_info(false);
+       panic_print_sys_info();
 
        kmsg_dump_desc(KMSG_DUMP_PANIC, buf);
 
@@ -439,7 +439,7 @@ void panic(const char *fmt, ...)
        debug_locks_off();
        console_flush_on_panic(CONSOLE_FLUSH_PENDING);
 
-       panic_print_sys_info(true);
+       panic_console_replay();
 
        if (!panic_blink)
                panic_blink = no_blink;