Skip to content

Commit e36df28

Browse files
daveyoungpmladek
authored andcommitted
printk: move dump stack related code to lib/dump_stack.c
dump_stack related stuff should belong to lib/dump_stack.c thus move them there. Also conditionally compile lib/dump_stack.c since dump_stack code does not make sense if printk is disabled. Link: http://lkml.kernel.org/r/[email protected] To: Steven Rostedt <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Andi Kleen <[email protected]> Signed-off-by: Dave Young <[email protected]> Suggested-by: Steven Rostedt <[email protected]> Suggested-by: Sergey Senozhatsky <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Petr Mladek <[email protected]>
1 parent 097114a commit e36df28

File tree

4 files changed

+67
-63
lines changed

4 files changed

+67
-63
lines changed

include/linux/printk.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ void __init setup_log_buf(int early);
201201
__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
202202
void dump_stack_print_info(const char *log_lvl);
203203
void show_regs_print_info(const char *log_lvl);
204+
extern asmlinkage void dump_stack(void) __cold;
204205
extern void printk_safe_init(void);
205206
extern void printk_safe_flush(void);
206207
extern void printk_safe_flush_on_panic(void);
@@ -264,6 +265,10 @@ static inline void show_regs_print_info(const char *log_lvl)
264265
{
265266
}
266267

268+
static inline asmlinkage void dump_stack(void)
269+
{
270+
}
271+
267272
static inline void printk_safe_init(void)
268273
{
269274
}
@@ -279,8 +284,6 @@ static inline void printk_safe_flush_on_panic(void)
279284

280285
extern int kptr_restrict;
281286

282-
extern asmlinkage void dump_stack(void) __cold;
283-
284287
#ifndef pr_fmt
285288
#define pr_fmt(fmt) fmt
286289
#endif

kernel/printk/printk.c

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@
4242
#include <linux/rculist.h>
4343
#include <linux/poll.h>
4444
#include <linux/irq_work.h>
45-
#include <linux/utsname.h>
4645
#include <linux/ctype.h>
4746
#include <linux/uio.h>
4847
#include <linux/sched/clock.h>
4948
#include <linux/sched/debug.h>
5049
#include <linux/sched/task_stack.h>
51-
#include <linux/kexec.h>
5250

5351
#include <linux/uaccess.h>
5452
#include <asm/sections.h>
@@ -3257,62 +3255,4 @@ void kmsg_dump_rewind(struct kmsg_dumper *dumper)
32573255
}
32583256
EXPORT_SYMBOL_GPL(kmsg_dump_rewind);
32593257

3260-
static char dump_stack_arch_desc_str[128];
3261-
3262-
/**
3263-
* dump_stack_set_arch_desc - set arch-specific str to show with task dumps
3264-
* @fmt: printf-style format string
3265-
* @...: arguments for the format string
3266-
*
3267-
* The configured string will be printed right after utsname during task
3268-
* dumps. Usually used to add arch-specific system identifiers. If an
3269-
* arch wants to make use of such an ID string, it should initialize this
3270-
* as soon as possible during boot.
3271-
*/
3272-
void __init dump_stack_set_arch_desc(const char *fmt, ...)
3273-
{
3274-
va_list args;
3275-
3276-
va_start(args, fmt);
3277-
vsnprintf(dump_stack_arch_desc_str, sizeof(dump_stack_arch_desc_str),
3278-
fmt, args);
3279-
va_end(args);
3280-
}
3281-
3282-
/**
3283-
* dump_stack_print_info - print generic debug info for dump_stack()
3284-
* @log_lvl: log level
3285-
*
3286-
* Arch-specific dump_stack() implementations can use this function to
3287-
* print out the same debug information as the generic dump_stack().
3288-
*/
3289-
void dump_stack_print_info(const char *log_lvl)
3290-
{
3291-
printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s\n",
3292-
log_lvl, raw_smp_processor_id(), current->pid, current->comm,
3293-
kexec_crash_loaded() ? "Kdump: loaded " : "",
3294-
print_tainted(),
3295-
init_utsname()->release,
3296-
(int)strcspn(init_utsname()->version, " "),
3297-
init_utsname()->version);
3298-
3299-
if (dump_stack_arch_desc_str[0] != '\0')
3300-
printk("%sHardware name: %s\n",
3301-
log_lvl, dump_stack_arch_desc_str);
3302-
3303-
print_worker_info(log_lvl, current);
3304-
}
3305-
3306-
/**
3307-
* show_regs_print_info - print generic debug info for show_regs()
3308-
* @log_lvl: log level
3309-
*
3310-
* show_regs() implementations can use this function to print out generic
3311-
* debug information.
3312-
*/
3313-
void show_regs_print_info(const char *log_lvl)
3314-
{
3315-
dump_stack_print_info(log_lvl);
3316-
}
3317-
33183258
#endif

lib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ KCOV_INSTRUMENT_debugobjects.o := n
1818
KCOV_INSTRUMENT_dynamic_debug.o := n
1919

2020
lib-y := ctype.o string.o vsprintf.o cmdline.o \
21-
rbtree.o radix-tree.o dump_stack.o timerqueue.o\
21+
rbtree.o radix-tree.o timerqueue.o\
2222
idr.o int_sqrt.o extable.o \
2323
sha1.o chacha20.o irq_regs.o argv_split.o \
2424
flex_proportions.o ratelimit.o show_mem.o \
2525
is_single_threaded.o plist.o decompress.o kobject_uevent.o \
2626
earlycpio.o seq_buf.o siphash.o \
2727
nmi_backtrace.o nodemask.o win_minmax.o
2828

29+
lib-$(CONFIG_PRINTK) += dump_stack.o
2930
lib-$(CONFIG_MMU) += ioremap.o
3031
lib-$(CONFIG_SMP) += cpumask.o
3132
lib-$(CONFIG_DMA_DIRECT_OPS) += dma-direct.o

lib/dump_stack.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,66 @@
1010
#include <linux/sched/debug.h>
1111
#include <linux/smp.h>
1212
#include <linux/atomic.h>
13+
#include <linux/kexec.h>
14+
#include <linux/utsname.h>
15+
16+
static char dump_stack_arch_desc_str[128];
17+
18+
/**
19+
* dump_stack_set_arch_desc - set arch-specific str to show with task dumps
20+
* @fmt: printf-style format string
21+
* @...: arguments for the format string
22+
*
23+
* The configured string will be printed right after utsname during task
24+
* dumps. Usually used to add arch-specific system identifiers. If an
25+
* arch wants to make use of such an ID string, it should initialize this
26+
* as soon as possible during boot.
27+
*/
28+
void __init dump_stack_set_arch_desc(const char *fmt, ...)
29+
{
30+
va_list args;
31+
32+
va_start(args, fmt);
33+
vsnprintf(dump_stack_arch_desc_str, sizeof(dump_stack_arch_desc_str),
34+
fmt, args);
35+
va_end(args);
36+
}
37+
38+
/**
39+
* dump_stack_print_info - print generic debug info for dump_stack()
40+
* @log_lvl: log level
41+
*
42+
* Arch-specific dump_stack() implementations can use this function to
43+
* print out the same debug information as the generic dump_stack().
44+
*/
45+
void dump_stack_print_info(const char *log_lvl)
46+
{
47+
printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s\n",
48+
log_lvl, raw_smp_processor_id(), current->pid, current->comm,
49+
kexec_crash_loaded() ? "Kdump: loaded " : "",
50+
print_tainted(),
51+
init_utsname()->release,
52+
(int)strcspn(init_utsname()->version, " "),
53+
init_utsname()->version);
54+
55+
if (dump_stack_arch_desc_str[0] != '\0')
56+
printk("%sHardware name: %s\n",
57+
log_lvl, dump_stack_arch_desc_str);
58+
59+
print_worker_info(log_lvl, current);
60+
}
61+
62+
/**
63+
* show_regs_print_info - print generic debug info for show_regs()
64+
* @log_lvl: log level
65+
*
66+
* show_regs() implementations can use this function to print out generic
67+
* debug information.
68+
*/
69+
void show_regs_print_info(const char *log_lvl)
70+
{
71+
dump_stack_print_info(log_lvl);
72+
}
1373

1474
static void __dump_stack(void)
1575
{

0 commit comments

Comments
 (0)