~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/dump_stack.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Provide a default dump_stack() function for architectures
  4  * which don't implement their own.
  5  */
  6 
  7 #include <linux/kernel.h>
  8 #include <linux/buildid.h>
  9 #include <linux/export.h>
 10 #include <linux/sched.h>
 11 #include <linux/sched/debug.h>
 12 #include <linux/smp.h>
 13 #include <linux/atomic.h>
 14 #include <linux/kexec.h>
 15 #include <linux/utsname.h>
 16 #include <linux/stop_machine.h>
 17 
 18 static char dump_stack_arch_desc_str[128];
 19 
 20 /**
 21  * dump_stack_set_arch_desc - set arch-specific str to show with task dumps
 22  * @fmt: printf-style format string
 23  * @...: arguments for the format string
 24  *
 25  * The configured string will be printed right after utsname during task
 26  * dumps.  Usually used to add arch-specific system identifiers.  If an
 27  * arch wants to make use of such an ID string, it should initialize this
 28  * as soon as possible during boot.
 29  */
 30 void __init dump_stack_set_arch_desc(const char *fmt, ...)
 31 {
 32         va_list args;
 33 
 34         va_start(args, fmt);
 35         vsnprintf(dump_stack_arch_desc_str, sizeof(dump_stack_arch_desc_str),
 36                   fmt, args);
 37         va_end(args);
 38 }
 39 
 40 #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID)
 41 #define BUILD_ID_FMT " %20phN"
 42 #define BUILD_ID_VAL vmlinux_build_id
 43 #else
 44 #define BUILD_ID_FMT "%s"
 45 #define BUILD_ID_VAL ""
 46 #endif
 47 
 48 /**
 49  * dump_stack_print_info - print generic debug info for dump_stack()
 50  * @log_lvl: log level
 51  *
 52  * Arch-specific dump_stack() implementations can use this function to
 53  * print out the same debug information as the generic dump_stack().
 54  */
 55 void dump_stack_print_info(const char *log_lvl)
 56 {
 57         printk("%sCPU: %d UID: %u PID: %d Comm: %.20s %s%s %s %.*s" BUILD_ID_FMT "\n",
 58                log_lvl, raw_smp_processor_id(),
 59                __kuid_val(current_real_cred()->euid),
 60                current->pid, current->comm,
 61                kexec_crash_loaded() ? "Kdump: loaded " : "",
 62                print_tainted(),
 63                init_utsname()->release,
 64                (int)strcspn(init_utsname()->version, " "),
 65                init_utsname()->version, BUILD_ID_VAL);
 66 
 67         if (get_taint())
 68                 printk("%s%s\n", log_lvl, print_tainted_verbose());
 69 
 70         if (dump_stack_arch_desc_str[0] != '\0')
 71                 printk("%sHardware name: %s\n",
 72                        log_lvl, dump_stack_arch_desc_str);
 73 
 74         print_worker_info(log_lvl, current);
 75         print_stop_info(log_lvl, current);
 76 }
 77 
 78 /**
 79  * show_regs_print_info - print generic debug info for show_regs()
 80  * @log_lvl: log level
 81  *
 82  * show_regs() implementations can use this function to print out generic
 83  * debug information.
 84  */
 85 void show_regs_print_info(const char *log_lvl)
 86 {
 87         dump_stack_print_info(log_lvl);
 88 }
 89 
 90 static void __dump_stack(const char *log_lvl)
 91 {
 92         dump_stack_print_info(log_lvl);
 93         show_stack(NULL, NULL, log_lvl);
 94 }
 95 
 96 /**
 97  * dump_stack_lvl - dump the current task information and its stack trace
 98  * @log_lvl: log level
 99  *
100  * Architectures can override this implementation by implementing its own.
101  */
102 asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
103 {
104         bool in_panic = this_cpu_in_panic();
105         unsigned long flags;
106 
107         /*
108          * Permit this cpu to perform nested stack dumps while serialising
109          * against other CPUs, unless this CPU is in panic.
110          *
111          * When in panic, non-panic CPUs are not permitted to store new
112          * printk messages so there is no need to synchronize the output.
113          * This avoids potential deadlock in panic() if another CPU is
114          * holding and unable to release the printk_cpu_sync.
115          */
116         if (!in_panic)
117                 printk_cpu_sync_get_irqsave(flags);
118 
119         __dump_stack(log_lvl);
120 
121         if (!in_panic)
122                 printk_cpu_sync_put_irqrestore(flags);
123 }
124 EXPORT_SYMBOL(dump_stack_lvl);
125 
126 asmlinkage __visible void dump_stack(void)
127 {
128         dump_stack_lvl(KERN_DEFAULT);
129 }
130 EXPORT_SYMBOL(dump_stack);
131 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php