2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
5 #include <linux/sched/debug.h>
6 #include <linux/kallsyms.h>
7 #include <linux/kprobes.h>
8 #include <linux/uaccess.h>
9 #include <linux/hardirq.h>
10 #include <linux/kdebug.h>
11 #include <linux/export.h>
12 #include <linux/ptrace.h>
13 #include <linux/kexec.h>
14 #include <linux/sysfs.h>
15 #include <linux/bug.h>
16 #include <linux/nmi.h>
18 #include <asm/stacktrace.h>
20 const char *stack_type_name(enum stack_type type)
22 if (type == STACK_TYPE_IRQ)
25 if (type == STACK_TYPE_SOFTIRQ)
31 static bool in_hardirq_stack(unsigned long *stack, struct stack_info *info)
33 unsigned long *begin = (unsigned long *)this_cpu_read(hardirq_stack);
34 unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
37 * This is a software stack, so 'end' can be a valid stack pointer.
38 * It just means the stack is empty.
40 if (stack < begin || stack > end)
43 info->type = STACK_TYPE_IRQ;
48 * See irq_32.c -- the next stack pointer is stored at the beginning of
51 info->next_sp = (unsigned long *)*begin;
56 static bool in_softirq_stack(unsigned long *stack, struct stack_info *info)
58 unsigned long *begin = (unsigned long *)this_cpu_read(softirq_stack);
59 unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
62 * This is a software stack, so 'end' can be a valid stack pointer.
63 * It just means the stack is empty.
65 if (stack < begin || stack > end)
68 info->type = STACK_TYPE_SOFTIRQ;
73 * The next stack pointer is stored at the beginning of the stack.
76 info->next_sp = (unsigned long *)*begin;
81 int get_stack_info(unsigned long *stack, struct task_struct *task,
82 struct stack_info *info, unsigned long *visit_mask)
87 task = task ? : current;
89 if (in_task_stack(stack, task, info))
95 if (in_hardirq_stack(stack, info))
98 if (in_softirq_stack(stack, info))
105 * Make sure we don't iterate through any given stack more than once.
106 * If it comes up a second time then there's something wrong going on:
107 * just break out and report an unknown stack type.
110 if (*visit_mask & (1UL << info->type)) {
111 printk_deferred_once(KERN_WARNING "WARNING: stack recursion on stack type %d\n", info->type);
114 *visit_mask |= 1UL << info->type;
120 info->type = STACK_TYPE_UNKNOWN;
124 void show_regs(struct pt_regs *regs)
128 show_regs_print_info(KERN_EMERG);
129 __show_regs(regs, !user_mode(regs));
132 * When in-kernel, we also print out the stack and code at the
133 * time of the fault..
135 if (!user_mode(regs)) {
136 unsigned int code_prologue = code_bytes * 43 / 64;
137 unsigned int code_len = code_bytes;
141 show_trace_log_lvl(current, regs, NULL, KERN_EMERG);
145 ip = (u8 *)regs->ip - code_prologue;
146 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
147 /* try starting at IP */
149 code_len = code_len - code_prologue + 1;
151 for (i = 0; i < code_len; i++, ip++) {
152 if (ip < (u8 *)PAGE_OFFSET ||
153 probe_kernel_address(ip, c)) {
154 pr_cont(" Bad EIP value.");
157 if (ip == (u8 *)regs->ip)
158 pr_cont(" <%02x>", c);