]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86/kernel/dumpstack_64.c
x86/bugs/AMD: Add support to disable RDS on Fam[15,16,17]h if requested
[mirror_ubuntu-artful-kernel.git] / arch / x86 / kernel / dumpstack_64.c
1 /*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
4 */
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>
17
18 #include <asm/stacktrace.h>
19
20 static char *exception_stack_names[N_EXCEPTION_STACKS] = {
21 [ DOUBLEFAULT_STACK-1 ] = "#DF",
22 [ NMI_STACK-1 ] = "NMI",
23 [ DEBUG_STACK-1 ] = "#DB",
24 [ MCE_STACK-1 ] = "#MC",
25 };
26
27 static unsigned long exception_stack_sizes[N_EXCEPTION_STACKS] = {
28 [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STKSZ,
29 [DEBUG_STACK - 1] = DEBUG_STKSZ
30 };
31
32 const char *stack_type_name(enum stack_type type)
33 {
34 BUILD_BUG_ON(N_EXCEPTION_STACKS != 4);
35
36 if (type == STACK_TYPE_IRQ)
37 return "IRQ";
38
39 if (type == STACK_TYPE_ENTRY) {
40 /*
41 * On 64-bit, we have a generic entry stack that we
42 * use for all the kernel entry points, including
43 * SYSENTER.
44 */
45 return "ENTRY_TRAMPOLINE";
46 }
47
48 if (type >= STACK_TYPE_EXCEPTION && type <= STACK_TYPE_EXCEPTION_LAST)
49 return exception_stack_names[type - STACK_TYPE_EXCEPTION];
50
51 return NULL;
52 }
53
54 static bool in_exception_stack(unsigned long *stack, struct stack_info *info)
55 {
56 unsigned long *begin, *end;
57 struct pt_regs *regs;
58 unsigned k;
59
60 BUILD_BUG_ON(N_EXCEPTION_STACKS != 4);
61
62 for (k = 0; k < N_EXCEPTION_STACKS; k++) {
63 end = (unsigned long *)raw_cpu_ptr(&orig_ist)->ist[k];
64 begin = end - (exception_stack_sizes[k] / sizeof(long));
65 regs = (struct pt_regs *)end - 1;
66
67 if (stack < begin || stack >= end)
68 continue;
69
70 info->type = STACK_TYPE_EXCEPTION + k;
71 info->begin = begin;
72 info->end = end;
73 info->next_sp = (unsigned long *)regs->sp;
74
75 return true;
76 }
77
78 return false;
79 }
80
81 static bool in_irq_stack(unsigned long *stack, struct stack_info *info)
82 {
83 unsigned long *end = (unsigned long *)this_cpu_read(irq_stack_ptr);
84 unsigned long *begin = end - (IRQ_STACK_SIZE / sizeof(long));
85
86 /*
87 * This is a software stack, so 'end' can be a valid stack pointer.
88 * It just means the stack is empty.
89 */
90 if (stack < begin || stack > end)
91 return false;
92
93 info->type = STACK_TYPE_IRQ;
94 info->begin = begin;
95 info->end = end;
96
97 /*
98 * The next stack pointer is the first thing pushed by the entry code
99 * after switching to the irq stack.
100 */
101 info->next_sp = (unsigned long *)*(end - 1);
102
103 return true;
104 }
105
106 int get_stack_info(unsigned long *stack, struct task_struct *task,
107 struct stack_info *info, unsigned long *visit_mask)
108 {
109 if (!stack)
110 goto unknown;
111
112 task = task ? : current;
113
114 if (in_task_stack(stack, task, info))
115 goto recursion_check;
116
117 if (task != current)
118 goto unknown;
119
120 if (in_exception_stack(stack, info))
121 goto recursion_check;
122
123 if (in_irq_stack(stack, info))
124 goto recursion_check;
125
126 if (in_entry_stack(stack, info))
127 goto recursion_check;
128
129 goto unknown;
130
131 recursion_check:
132 /*
133 * Make sure we don't iterate through any given stack more than once.
134 * If it comes up a second time then there's something wrong going on:
135 * just break out and report an unknown stack type.
136 */
137 if (visit_mask) {
138 if (*visit_mask & (1UL << info->type)) {
139 printk_deferred_once(KERN_WARNING "WARNING: stack recursion on stack type %d\n", info->type);
140 goto unknown;
141 }
142 *visit_mask |= 1UL << info->type;
143 }
144
145 return 0;
146
147 unknown:
148 info->type = STACK_TYPE_UNKNOWN;
149 return -EINVAL;
150 }
151
152 void show_regs(struct pt_regs *regs)
153 {
154 int i;
155
156 show_regs_print_info(KERN_DEFAULT);
157 __show_regs(regs, 1);
158
159 /*
160 * When in-kernel, we also print out the stack and code at the
161 * time of the fault..
162 */
163 if (!user_mode(regs)) {
164 unsigned int code_prologue = code_bytes * 43 / 64;
165 unsigned int code_len = code_bytes;
166 unsigned char c;
167 u8 *ip;
168
169 show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT);
170
171 printk(KERN_DEFAULT "Code: ");
172
173 ip = (u8 *)regs->ip - code_prologue;
174 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
175 /* try starting at IP */
176 ip = (u8 *)regs->ip;
177 code_len = code_len - code_prologue + 1;
178 }
179 for (i = 0; i < code_len; i++, ip++) {
180 if (ip < (u8 *)PAGE_OFFSET ||
181 probe_kernel_address(ip, c)) {
182 pr_cont(" Bad RIP value.");
183 break;
184 }
185 if (ip == (u8 *)regs->ip)
186 pr_cont("<%02x> ", c);
187 else
188 pr_cont("%02x ", c);
189 }
190 }
191 pr_cont("\n");
192 }