Skip to content

Commit 261743b

Browse files
Feng Tangakpm00
authored andcommitted
panic: clean up code for console replay
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/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Feng Tang <[email protected]> Suggested-by: Petr Mladek <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Cc: John Ogness <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Lance Yang <[email protected]> Cc: "Paul E . McKenney" <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Nathan Chancellor <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent bf8be1c commit 261743b

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4555,7 +4555,7 @@
45554555
bit 2: print timer info
45564556
bit 3: print locks info if CONFIG_LOCKDEP is on
45574557
bit 4: print ftrace buffer
4558-
bit 5: print all printk messages in buffer
4558+
bit 5: replay all messages on consoles at the end of panic
45594559
bit 6: print all CPUs backtrace (if available in the arch)
45604560
bit 7: print only tasks in uninterruptible (blocked) state
45614561
*Be aware* that this option may print a _lot_ of lines,

Documentation/admin-guide/sysctl/kernel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ bit 1 print system memory info
889889
bit 2 print timer info
890890
bit 3 print locks info if ``CONFIG_LOCKDEP`` is on
891891
bit 4 print ftrace buffer
892-
bit 5 print all printk messages in buffer
892+
bit 5 replay all messages on consoles at the end of panic
893893
bit 6 print all CPUs backtrace (if available in the arch)
894894
bit 7 print only tasks in uninterruptible (blocked) state
895895
===== ============================================

kernel/panic.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ EXPORT_SYMBOL_GPL(panic_timeout);
7474
#define PANIC_PRINT_TIMER_INFO 0x00000004
7575
#define PANIC_PRINT_LOCK_INFO 0x00000008
7676
#define PANIC_PRINT_FTRACE_INFO 0x00000010
77-
#define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020
77+
#define PANIC_CONSOLE_REPLAY 0x00000020
7878
#define PANIC_PRINT_ALL_CPU_BT 0x00000040
7979
#define PANIC_PRINT_BLOCKED_TASKS 0x00000080
8080
unsigned long panic_print;
@@ -238,14 +238,14 @@ void nmi_panic(struct pt_regs *regs, const char *msg)
238238
}
239239
EXPORT_SYMBOL(nmi_panic);
240240

241-
static void panic_print_sys_info(bool console_flush)
241+
static void panic_console_replay(void)
242242
{
243-
if (console_flush) {
244-
if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
245-
console_flush_on_panic(CONSOLE_REPLAY_ALL);
246-
return;
247-
}
243+
if (panic_print & PANIC_CONSOLE_REPLAY)
244+
console_flush_on_panic(CONSOLE_REPLAY_ALL);
245+
}
248246

247+
static void panic_print_sys_info(void)
248+
{
249249
if (panic_print & PANIC_PRINT_TASK_INFO)
250250
show_state();
251251

@@ -410,7 +410,7 @@ void panic(const char *fmt, ...)
410410
*/
411411
atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
412412

413-
panic_print_sys_info(false);
413+
panic_print_sys_info();
414414

415415
kmsg_dump_desc(KMSG_DUMP_PANIC, buf);
416416

@@ -439,7 +439,7 @@ void panic(const char *fmt, ...)
439439
debug_locks_off();
440440
console_flush_on_panic(CONSOLE_FLUSH_PENDING);
441441

442-
panic_print_sys_info(true);
442+
panic_console_replay();
443443

444444
if (!panic_blink)
445445
panic_blink = no_blink;

0 commit comments

Comments
 (0)