Skip to content

Commit b76e89e

Browse files
Feng Tangakpm00
authored andcommitted
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. Actually this function could also be used to help debugging other cases like task-hung, soft/hard lockup, etc. where user may need the snapshot of system info at that time. Extract system info dump function related code from panic.c to separate file sys_info.[ch], for wider usage by other kernel parts for debugging. Also modify the macro names about singulars/plurals. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Feng Tang <[email protected]> Suggested-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 261743b commit b76e89e

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

include/linux/sys_info.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_SYS_INFO_H
3+
#define _LINUX_SYS_INFO_H
4+
5+
/*
6+
* SYS_INFO_PANIC_CONSOLE_REPLAY is for panic case only, as it needs special
7+
* handling which only fits panic case.
8+
*/
9+
#define SYS_INFO_TASKS 0x00000001
10+
#define SYS_INFO_MEM 0x00000002
11+
#define SYS_INFO_TIMERS 0x00000004
12+
#define SYS_INFO_LOCKS 0x00000008
13+
#define SYS_INFO_FTRACE 0x00000010
14+
#define SYS_INFO_PANIC_CONSOLE_REPLAY 0x00000020
15+
#define SYS_INFO_ALL_CPU_BT 0x00000040
16+
#define SYS_INFO_BLOCKED_TASKS 0x00000080
17+
18+
void sys_info(unsigned long si_mask);
19+
20+
#endif /* _LINUX_SYS_INFO_H */

kernel/panic.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/sysfs.h>
3737
#include <linux/context_tracking.h>
3838
#include <linux/seq_buf.h>
39+
#include <linux/sys_info.h>
3940
#include <trace/events/error_report.h>
4041
#include <asm/sections.h>
4142

@@ -69,14 +70,6 @@ bool panic_triggering_all_cpu_backtrace;
6970
int panic_timeout = CONFIG_PANIC_TIMEOUT;
7071
EXPORT_SYMBOL_GPL(panic_timeout);
7172

72-
#define PANIC_PRINT_TASK_INFO 0x00000001
73-
#define PANIC_PRINT_MEM_INFO 0x00000002
74-
#define PANIC_PRINT_TIMER_INFO 0x00000004
75-
#define PANIC_PRINT_LOCK_INFO 0x00000008
76-
#define PANIC_PRINT_FTRACE_INFO 0x00000010
77-
#define PANIC_CONSOLE_REPLAY 0x00000020
78-
#define PANIC_PRINT_ALL_CPU_BT 0x00000040
79-
#define PANIC_PRINT_BLOCKED_TASKS 0x00000080
8073
unsigned long panic_print;
8174

8275
ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
@@ -240,31 +233,10 @@ EXPORT_SYMBOL(nmi_panic);
240233

241234
static void panic_console_replay(void)
242235
{
243-
if (panic_print & PANIC_CONSOLE_REPLAY)
236+
if (panic_print & SYS_INFO_PANIC_CONSOLE_REPLAY)
244237
console_flush_on_panic(CONSOLE_REPLAY_ALL);
245238
}
246239

247-
static void panic_print_sys_info(void)
248-
{
249-
if (panic_print & PANIC_PRINT_TASK_INFO)
250-
show_state();
251-
252-
if (panic_print & PANIC_PRINT_MEM_INFO)
253-
show_mem();
254-
255-
if (panic_print & PANIC_PRINT_TIMER_INFO)
256-
sysrq_timer_list_show();
257-
258-
if (panic_print & PANIC_PRINT_LOCK_INFO)
259-
debug_show_all_locks();
260-
261-
if (panic_print & PANIC_PRINT_FTRACE_INFO)
262-
ftrace_dump(DUMP_ALL);
263-
264-
if (panic_print & PANIC_PRINT_BLOCKED_TASKS)
265-
show_state_filter(TASK_UNINTERRUPTIBLE);
266-
}
267-
268240
void check_panic_on_warn(const char *origin)
269241
{
270242
unsigned int limit;
@@ -285,7 +257,7 @@ void check_panic_on_warn(const char *origin)
285257
*/
286258
static void panic_other_cpus_shutdown(bool crash_kexec)
287259
{
288-
if (panic_print & PANIC_PRINT_ALL_CPU_BT) {
260+
if (panic_print & SYS_INFO_ALL_CPU_BT) {
289261
/* Temporary allow non-panic CPUs to write their backtraces. */
290262
panic_triggering_all_cpu_backtrace = true;
291263
trigger_all_cpu_backtrace();
@@ -410,7 +382,7 @@ void panic(const char *fmt, ...)
410382
*/
411383
atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
412384

413-
panic_print_sys_info();
385+
sys_info(panic_print);
414386

415387
kmsg_dump_desc(KMSG_DUMP_PANIC, buf);
416388

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
4040
is_single_threaded.o plist.o decompress.o kobject_uevent.o \
4141
earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
4242
nmi_backtrace.o win_minmax.o memcat_p.o \
43-
buildid.o objpool.o iomem_copy.o
43+
buildid.o objpool.o iomem_copy.o sys_info.o
4444

4545
lib-$(CONFIG_UNION_FIND) += union_find.o
4646
lib-$(CONFIG_PRINTK) += dump_stack.o

lib/sys_info.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
#include <linux/sched/debug.h>
3+
#include <linux/console.h>
4+
#include <linux/kernel.h>
5+
#include <linux/ftrace.h>
6+
#include <linux/nmi.h>
7+
8+
#include <linux/sys_info.h>
9+
10+
void sys_info(unsigned long si_mask)
11+
{
12+
if (si_mask & SYS_INFO_TASKS)
13+
show_state();
14+
15+
if (si_mask & SYS_INFO_MEM)
16+
show_mem();
17+
18+
if (si_mask & SYS_INFO_TIMERS)
19+
sysrq_timer_list_show();
20+
21+
if (si_mask & SYS_INFO_LOCKS)
22+
debug_show_all_locks();
23+
24+
if (si_mask & SYS_INFO_FTRACE)
25+
ftrace_dump(DUMP_ALL);
26+
27+
if (si_mask & SYS_INFO_ALL_CPU_BT)
28+
trigger_all_cpu_backtrace();
29+
30+
if (si_mask & SYS_INFO_BLOCKED_TASKS)
31+
show_state_filter(TASK_UNINTERRUPTIBLE);
32+
}

0 commit comments

Comments
 (0)