Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Provide a default dump_stack() function for architectures
0004  * which don't implement their own.
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  * dump_stack_set_arch_desc - set arch-specific str to show with task dumps
0022  * @fmt: printf-style format string
0023  * @...: arguments for the format string
0024  *
0025  * The configured string will be printed right after utsname during task
0026  * dumps.  Usually used to add arch-specific system identifiers.  If an
0027  * arch wants to make use of such an ID string, it should initialize this
0028  * as soon as possible during boot.
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  * dump_stack_print_info - print generic debug info for dump_stack()
0050  * @log_lvl: log level
0051  *
0052  * Arch-specific dump_stack() implementations can use this function to
0053  * print out the same debug information as the generic dump_stack().
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  * show_regs_print_info - print generic debug info for show_regs()
0075  * @log_lvl: log level
0076  *
0077  * show_regs() implementations can use this function to print out generic
0078  * debug information.
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  * dump_stack_lvl - dump the current task information and its stack trace
0093  * @log_lvl: log level
0094  *
0095  * Architectures can override this implementation by implementing its own.
0096  */
0097 asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
0098 {
0099     unsigned long flags;
0100 
0101     /*
0102      * Permit this cpu to perform nested stack dumps while serialising
0103      * against other CPUs
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);