1 // SPDX-License-Identifier: GPL-2.0
3 * Provide a default dump_stack() function for architectures
4 * which don't implement their own.
7 #include <linux/kernel.h>
8 #include <linux/export.h>
9 #include <linux/sched.h>
10 #include <linux/sched/debug.h>
11 #include <linux/smp.h>
12 #include <linux/atomic.h>
13 #include <linux/kexec.h>
14 #include <linux/utsname.h>
15 #include <linux/stop_machine.h>
17 static char dump_stack_arch_desc_str[128];
20 * dump_stack_set_arch_desc - set arch-specific str to show with task dumps
21 * @fmt: printf-style format string
22 * @...: arguments for the format string
24 * The configured string will be printed right after utsname during task
25 * dumps. Usually used to add arch-specific system identifiers. If an
26 * arch wants to make use of such an ID string, it should initialize this
27 * as soon as possible during boot.
29 void __init dump_stack_set_arch_desc(const char *fmt, ...)
34 vsnprintf(dump_stack_arch_desc_str, sizeof(dump_stack_arch_desc_str),
40 * dump_stack_print_info - print generic debug info for dump_stack()
43 * Arch-specific dump_stack() implementations can use this function to
44 * print out the same debug information as the generic dump_stack().
46 void dump_stack_print_info(const char *log_lvl)
48 printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s\n",
49 log_lvl, raw_smp_processor_id(), current->pid, current->comm,
50 kexec_crash_loaded() ? "Kdump: loaded " : "",
52 init_utsname()->release,
53 (int)strcspn(init_utsname()->version, " "),
54 init_utsname()->version);
56 if (dump_stack_arch_desc_str[0] != '\0')
57 printk("%sHardware name: %s\n",
58 log_lvl, dump_stack_arch_desc_str);
60 print_worker_info(log_lvl, current);
61 print_stop_info(log_lvl, current);
65 * show_regs_print_info - print generic debug info for show_regs()
68 * show_regs() implementations can use this function to print out generic
71 void show_regs_print_info(const char *log_lvl)
73 dump_stack_print_info(log_lvl);
76 static void __dump_stack(void)
78 dump_stack_print_info(KERN_DEFAULT);
79 show_stack(NULL, NULL, KERN_DEFAULT);
83 * dump_stack - dump the current task information and its stack trace
85 * Architectures can override this implementation by implementing its own.
87 asmlinkage __visible void dump_stack(void)
92 * Permit this cpu to perform nested stack dumps while serialising
95 printk_cpu_lock_irqsave(flags);
97 printk_cpu_unlock_irqrestore(flags);
99 EXPORT_SYMBOL(dump_stack);