0001
0002
0003
0004
0005
0006
0007 #include <linux/kernel.h>
0008 #include <linux/buildid.h>
0009 #include <linux/export.h>
0010 #include <linux/sched.h>
0011 #include <linux/sched/debug.h>
0012 #include <linux/smp.h>
0013 #include <linux/atomic.h>
0014 #include <linux/kexec.h>
0015 #include <linux/utsname.h>
0016 #include <linux/stop_machine.h>
0017
0018 static char dump_stack_arch_desc_str[128];
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 void __init dump_stack_set_arch_desc(const char *fmt, ...)
0031 {
0032 va_list args;
0033
0034 va_start(args, fmt);
0035 vsnprintf(dump_stack_arch_desc_str, sizeof(dump_stack_arch_desc_str),
0036 fmt, args);
0037 va_end(args);
0038 }
0039
0040 #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
0041 #define BUILD_ID_FMT " %20phN"
0042 #define BUILD_ID_VAL vmlinux_build_id
0043 #else
0044 #define BUILD_ID_FMT "%s"
0045 #define BUILD_ID_VAL ""
0046 #endif
0047
0048
0049
0050
0051
0052
0053
0054
0055 void dump_stack_print_info(const char *log_lvl)
0056 {
0057 printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s" BUILD_ID_FMT "\n",
0058 log_lvl, raw_smp_processor_id(), current->pid, current->comm,
0059 kexec_crash_loaded() ? "Kdump: loaded " : "",
0060 print_tainted(),
0061 init_utsname()->release,
0062 (int)strcspn(init_utsname()->version, " "),
0063 init_utsname()->version, BUILD_ID_VAL);
0064
0065 if (dump_stack_arch_desc_str[0] != '\0')
0066 printk("%sHardware name: %s\n",
0067 log_lvl, dump_stack_arch_desc_str);
0068
0069 print_worker_info(log_lvl, current);
0070 print_stop_info(log_lvl, current);
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080 void show_regs_print_info(const char *log_lvl)
0081 {
0082 dump_stack_print_info(log_lvl);
0083 }
0084
0085 static void __dump_stack(const char *log_lvl)
0086 {
0087 dump_stack_print_info(log_lvl);
0088 show_stack(NULL, NULL, log_lvl);
0089 }
0090
0091
0092
0093
0094
0095
0096
0097 asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
0098 {
0099 unsigned long flags;
0100
0101
0102
0103
0104
0105 printk_cpu_sync_get_irqsave(flags);
0106 __dump_stack(log_lvl);
0107 printk_cpu_sync_put_irqrestore(flags);
0108 }
0109 EXPORT_SYMBOL(dump_stack_lvl);
0110
0111 asmlinkage __visible void dump_stack(void)
0112 {
0113 dump_stack_lvl(KERN_DEFAULT);
0114 }
0115 EXPORT_SYMBOL(dump_stack);