aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/kernel/traps.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/i386/kernel/traps.c')
-rw-r--r--arch/i386/kernel/traps.c231
1 files changed, 134 insertions, 97 deletions
diff --git a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c
index 4fcc6690be99..a13037fe0ee3 100644
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -28,6 +28,7 @@
28#include <linux/kprobes.h> 28#include <linux/kprobes.h>
29#include <linux/kexec.h> 29#include <linux/kexec.h>
30#include <linux/unwind.h> 30#include <linux/unwind.h>
31#include <linux/uaccess.h>
31 32
32#ifdef CONFIG_EISA 33#ifdef CONFIG_EISA
33#include <linux/ioport.h> 34#include <linux/ioport.h>
@@ -40,7 +41,6 @@
40 41
41#include <asm/processor.h> 42#include <asm/processor.h>
42#include <asm/system.h> 43#include <asm/system.h>
43#include <asm/uaccess.h>
44#include <asm/io.h> 44#include <asm/io.h>
45#include <asm/atomic.h> 45#include <asm/atomic.h>
46#include <asm/debugreg.h> 46#include <asm/debugreg.h>
@@ -51,6 +51,7 @@
51#include <asm/smp.h> 51#include <asm/smp.h>
52#include <asm/arch_hooks.h> 52#include <asm/arch_hooks.h>
53#include <asm/kdebug.h> 53#include <asm/kdebug.h>
54#include <asm/stacktrace.h>
54 55
55#include <linux/module.h> 56#include <linux/module.h>
56 57
@@ -118,26 +119,16 @@ static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
118 p < (void *)tinfo + THREAD_SIZE - 3; 119 p < (void *)tinfo + THREAD_SIZE - 3;
119} 120}
120 121
121/*
122 * Print one address/symbol entries per line.
123 */
124static inline void print_addr_and_symbol(unsigned long addr, char *log_lvl)
125{
126 printk(" [<%08lx>] ", addr);
127
128 print_symbol("%s\n", addr);
129}
130
131static inline unsigned long print_context_stack(struct thread_info *tinfo, 122static inline unsigned long print_context_stack(struct thread_info *tinfo,
132 unsigned long *stack, unsigned long ebp, 123 unsigned long *stack, unsigned long ebp,
133 char *log_lvl) 124 struct stacktrace_ops *ops, void *data)
134{ 125{
135 unsigned long addr; 126 unsigned long addr;
136 127
137#ifdef CONFIG_FRAME_POINTER 128#ifdef CONFIG_FRAME_POINTER
138 while (valid_stack_ptr(tinfo, (void *)ebp)) { 129 while (valid_stack_ptr(tinfo, (void *)ebp)) {
139 addr = *(unsigned long *)(ebp + 4); 130 addr = *(unsigned long *)(ebp + 4);
140 print_addr_and_symbol(addr, log_lvl); 131 ops->address(data, addr);
141 /* 132 /*
142 * break out of recursive entries (such as 133 * break out of recursive entries (such as
143 * end_of_stack_stop_unwind_function): 134 * end_of_stack_stop_unwind_function):
@@ -150,30 +141,37 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
150 while (valid_stack_ptr(tinfo, stack)) { 141 while (valid_stack_ptr(tinfo, stack)) {
151 addr = *stack++; 142 addr = *stack++;
152 if (__kernel_text_address(addr)) 143 if (__kernel_text_address(addr))
153 print_addr_and_symbol(addr, log_lvl); 144 ops->address(data, addr);
154 } 145 }
155#endif 146#endif
156 return ebp; 147 return ebp;
157} 148}
158 149
150struct ops_and_data {
151 struct stacktrace_ops *ops;
152 void *data;
153};
154
159static asmlinkage int 155static asmlinkage int
160show_trace_unwind(struct unwind_frame_info *info, void *log_lvl) 156dump_trace_unwind(struct unwind_frame_info *info, void *data)
161{ 157{
158 struct ops_and_data *oad = (struct ops_and_data *)data;
162 int n = 0; 159 int n = 0;
163 160
164 while (unwind(info) == 0 && UNW_PC(info)) { 161 while (unwind(info) == 0 && UNW_PC(info)) {
165 n++; 162 n++;
166 print_addr_and_symbol(UNW_PC(info), log_lvl); 163 oad->ops->address(oad->data, UNW_PC(info));
167 if (arch_unw_user_mode(info)) 164 if (arch_unw_user_mode(info))
168 break; 165 break;
169 } 166 }
170 return n; 167 return n;
171} 168}
172 169
173static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, 170void dump_trace(struct task_struct *task, struct pt_regs *regs,
174 unsigned long *stack, char *log_lvl) 171 unsigned long *stack,
172 struct stacktrace_ops *ops, void *data)
175{ 173{
176 unsigned long ebp; 174 unsigned long ebp = 0;
177 175
178 if (!task) 176 if (!task)
179 task = current; 177 task = current;
@@ -181,54 +179,116 @@ static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
181 if (call_trace >= 0) { 179 if (call_trace >= 0) {
182 int unw_ret = 0; 180 int unw_ret = 0;
183 struct unwind_frame_info info; 181 struct unwind_frame_info info;
182 struct ops_and_data oad = { .ops = ops, .data = data };
184 183
185 if (regs) { 184 if (regs) {
186 if (unwind_init_frame_info(&info, task, regs) == 0) 185 if (unwind_init_frame_info(&info, task, regs) == 0)
187 unw_ret = show_trace_unwind(&info, log_lvl); 186 unw_ret = dump_trace_unwind(&info, &oad);
188 } else if (task == current) 187 } else if (task == current)
189 unw_ret = unwind_init_running(&info, show_trace_unwind, log_lvl); 188 unw_ret = unwind_init_running(&info, dump_trace_unwind, &oad);
190 else { 189 else {
191 if (unwind_init_blocked(&info, task) == 0) 190 if (unwind_init_blocked(&info, task) == 0)
192 unw_ret = show_trace_unwind(&info, log_lvl); 191 unw_ret = dump_trace_unwind(&info, &oad);
193 } 192 }
194 if (unw_ret > 0) { 193 if (unw_ret > 0) {
195 if (call_trace == 1 && !arch_unw_user_mode(&info)) { 194 if (call_trace == 1 && !arch_unw_user_mode(&info)) {
196 print_symbol("DWARF2 unwinder stuck at %s\n", 195 ops->warning_symbol(data, "DWARF2 unwinder stuck at %s\n",
197 UNW_PC(&info)); 196 UNW_PC(&info));
198 if (UNW_SP(&info) >= PAGE_OFFSET) { 197 if (UNW_SP(&info) >= PAGE_OFFSET) {
199 printk("Leftover inexact backtrace:\n"); 198 ops->warning(data, "Leftover inexact backtrace:\n");
200 stack = (void *)UNW_SP(&info); 199 stack = (void *)UNW_SP(&info);
200 if (!stack)
201 return;
202 ebp = UNW_FP(&info);
201 } else 203 } else
202 printk("Full inexact backtrace again:\n"); 204 ops->warning(data, "Full inexact backtrace again:\n");
203 } else if (call_trace >= 1) 205 } else if (call_trace >= 1)
204 return; 206 return;
205 else 207 else
206 printk("Full inexact backtrace again:\n"); 208 ops->warning(data, "Full inexact backtrace again:\n");
207 } else 209 } else
208 printk("Inexact backtrace:\n"); 210 ops->warning(data, "Inexact backtrace:\n");
211 }
212 if (!stack) {
213 unsigned long dummy;
214 stack = &dummy;
215 if (task && task != current)
216 stack = (unsigned long *)task->thread.esp;
209 } 217 }
210 218
211 if (task == current) { 219#ifdef CONFIG_FRAME_POINTER
212 /* Grab ebp right from our regs */ 220 if (!ebp) {
213 asm ("movl %%ebp, %0" : "=r" (ebp) : ); 221 if (task == current) {
214 } else { 222 /* Grab ebp right from our regs */
215 /* ebp is the last reg pushed by switch_to */ 223 asm ("movl %%ebp, %0" : "=r" (ebp) : );
216 ebp = *(unsigned long *) task->thread.esp; 224 } else {
225 /* ebp is the last reg pushed by switch_to */
226 ebp = *(unsigned long *) task->thread.esp;
227 }
217 } 228 }
229#endif
218 230
219 while (1) { 231 while (1) {
220 struct thread_info *context; 232 struct thread_info *context;
221 context = (struct thread_info *) 233 context = (struct thread_info *)
222 ((unsigned long)stack & (~(THREAD_SIZE - 1))); 234 ((unsigned long)stack & (~(THREAD_SIZE - 1)));
223 ebp = print_context_stack(context, stack, ebp, log_lvl); 235 ebp = print_context_stack(context, stack, ebp, ops, data);
236 /* Should be after the line below, but somewhere
237 in early boot context comes out corrupted and we
238 can't reference it -AK */
239 if (ops->stack(data, "IRQ") < 0)
240 break;
224 stack = (unsigned long*)context->previous_esp; 241 stack = (unsigned long*)context->previous_esp;
225 if (!stack) 242 if (!stack)
226 break; 243 break;
227 printk("%s =======================\n", log_lvl);
228 } 244 }
229} 245}
246EXPORT_SYMBOL(dump_trace);
247
248static void
249print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
250{
251 printk(data);
252 print_symbol(msg, symbol);
253 printk("\n");
254}
255
256static void print_trace_warning(void *data, char *msg)
257{
258 printk("%s%s\n", (char *)data, msg);
259}
260
261static int print_trace_stack(void *data, char *name)
262{
263 return 0;
264}
265
266/*
267 * Print one address/symbol entries per line.
268 */
269static void print_trace_address(void *data, unsigned long addr)
270{
271 printk("%s [<%08lx>] ", (char *)data, addr);
272 print_symbol("%s\n", addr);
273}
274
275static struct stacktrace_ops print_trace_ops = {
276 .warning = print_trace_warning,
277 .warning_symbol = print_trace_warning_symbol,
278 .stack = print_trace_stack,
279 .address = print_trace_address,
280};
281
282static void
283show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
284 unsigned long * stack, char *log_lvl)
285{
286 dump_trace(task, regs, stack, &print_trace_ops, log_lvl);
287 printk("%s =======================\n", log_lvl);
288}
230 289
231void show_trace(struct task_struct *task, struct pt_regs *regs, unsigned long * stack) 290void show_trace(struct task_struct *task, struct pt_regs *regs,
291 unsigned long * stack)
232{ 292{
233 show_trace_log_lvl(task, regs, stack, ""); 293 show_trace_log_lvl(task, regs, stack, "");
234} 294}
@@ -291,8 +351,9 @@ void show_registers(struct pt_regs *regs)
291 ss = regs->xss & 0xffff; 351 ss = regs->xss & 0xffff;
292 } 352 }
293 print_modules(); 353 print_modules();
294 printk(KERN_EMERG "CPU: %d\nEIP: %04x:[<%08lx>] %s VLI\n" 354 printk(KERN_EMERG "CPU: %d\n"
295 "EFLAGS: %08lx (%s %.*s) \n", 355 KERN_EMERG "EIP: %04x:[<%08lx>] %s VLI\n"
356 KERN_EMERG "EFLAGS: %08lx (%s %.*s)\n",
296 smp_processor_id(), 0xffff & regs->xcs, regs->eip, 357 smp_processor_id(), 0xffff & regs->xcs, regs->eip,
297 print_tainted(), regs->eflags, system_utsname.release, 358 print_tainted(), regs->eflags, system_utsname.release,
298 (int)strcspn(system_utsname.version, " "), 359 (int)strcspn(system_utsname.version, " "),
@@ -348,7 +409,7 @@ static void handle_BUG(struct pt_regs *regs)
348 409
349 if (eip < PAGE_OFFSET) 410 if (eip < PAGE_OFFSET)
350 return; 411 return;
351 if (__get_user(ud2, (unsigned short __user *)eip)) 412 if (probe_kernel_address((unsigned short __user *)eip, ud2))
352 return; 413 return;
353 if (ud2 != 0x0b0f) 414 if (ud2 != 0x0b0f)
354 return; 415 return;
@@ -361,7 +422,8 @@ static void handle_BUG(struct pt_regs *regs)
361 char *file; 422 char *file;
362 char c; 423 char c;
363 424
364 if (__get_user(line, (unsigned short __user *)(eip + 2))) 425 if (probe_kernel_address((unsigned short __user *)(eip + 2),
426 line))
365 break; 427 break;
366 if (__get_user(file, (char * __user *)(eip + 4)) || 428 if (__get_user(file, (char * __user *)(eip + 4)) ||
367 (unsigned long)file < PAGE_OFFSET || __get_user(c, file)) 429 (unsigned long)file < PAGE_OFFSET || __get_user(c, file))
@@ -634,18 +696,24 @@ gp_in_kernel:
634 } 696 }
635} 697}
636 698
637static void mem_parity_error(unsigned char reason, struct pt_regs * regs) 699static __kprobes void
700mem_parity_error(unsigned char reason, struct pt_regs * regs)
638{ 701{
639 printk(KERN_EMERG "Uhhuh. NMI received. Dazed and confused, but trying " 702 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x on "
640 "to continue\n"); 703 "CPU %d.\n", reason, smp_processor_id());
641 printk(KERN_EMERG "You probably have a hardware problem with your RAM " 704 printk(KERN_EMERG "You probably have a hardware problem with your RAM "
642 "chips\n"); 705 "chips\n");
706 if (panic_on_unrecovered_nmi)
707 panic("NMI: Not continuing");
708
709 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
643 710
644 /* Clear and disable the memory parity error line. */ 711 /* Clear and disable the memory parity error line. */
645 clear_mem_error(reason); 712 clear_mem_error(reason);
646} 713}
647 714
648static void io_check_error(unsigned char reason, struct pt_regs * regs) 715static __kprobes void
716io_check_error(unsigned char reason, struct pt_regs * regs)
649{ 717{
650 unsigned long i; 718 unsigned long i;
651 719
@@ -661,7 +729,8 @@ static void io_check_error(unsigned char reason, struct pt_regs * regs)
661 outb(reason, 0x61); 729 outb(reason, 0x61);
662} 730}
663 731
664static void unknown_nmi_error(unsigned char reason, struct pt_regs * regs) 732static __kprobes void
733unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
665{ 734{
666#ifdef CONFIG_MCA 735#ifdef CONFIG_MCA
667 /* Might actually be able to figure out what the guilty party 736 /* Might actually be able to figure out what the guilty party
@@ -671,15 +740,18 @@ static void unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
671 return; 740 return;
672 } 741 }
673#endif 742#endif
674 printk("Uhhuh. NMI received for unknown reason %02x on CPU %d.\n", 743 printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x on "
675 reason, smp_processor_id()); 744 "CPU %d.\n", reason, smp_processor_id());
676 printk("Dazed and confused, but trying to continue\n"); 745 printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
677 printk("Do you have a strange power saving mode enabled?\n"); 746 if (panic_on_unrecovered_nmi)
747 panic("NMI: Not continuing");
748
749 printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
678} 750}
679 751
680static DEFINE_SPINLOCK(nmi_print_lock); 752static DEFINE_SPINLOCK(nmi_print_lock);
681 753
682void die_nmi (struct pt_regs *regs, const char *msg) 754void __kprobes die_nmi(struct pt_regs *regs, const char *msg)
683{ 755{
684 if (notify_die(DIE_NMIWATCHDOG, msg, regs, 0, 2, SIGINT) == 756 if (notify_die(DIE_NMIWATCHDOG, msg, regs, 0, 2, SIGINT) ==
685 NOTIFY_STOP) 757 NOTIFY_STOP)
@@ -711,7 +783,7 @@ void die_nmi (struct pt_regs *regs, const char *msg)
711 do_exit(SIGSEGV); 783 do_exit(SIGSEGV);
712} 784}
713 785
714static void default_do_nmi(struct pt_regs * regs) 786static __kprobes void default_do_nmi(struct pt_regs * regs)
715{ 787{
716 unsigned char reason = 0; 788 unsigned char reason = 0;
717 789
@@ -728,12 +800,12 @@ static void default_do_nmi(struct pt_regs * regs)
728 * Ok, so this is none of the documented NMI sources, 800 * Ok, so this is none of the documented NMI sources,
729 * so it must be the NMI watchdog. 801 * so it must be the NMI watchdog.
730 */ 802 */
731 if (nmi_watchdog) { 803 if (nmi_watchdog_tick(regs, reason))
732 nmi_watchdog_tick(regs);
733 return; 804 return;
734 } 805 if (!do_nmi_callback(regs, smp_processor_id()))
735#endif 806#endif
736 unknown_nmi_error(reason, regs); 807 unknown_nmi_error(reason, regs);
808
737 return; 809 return;
738 } 810 }
739 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP) 811 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
@@ -749,14 +821,7 @@ static void default_do_nmi(struct pt_regs * regs)
749 reassert_nmi(); 821 reassert_nmi();
750} 822}
751 823
752static int dummy_nmi_callback(struct pt_regs * regs, int cpu) 824fastcall __kprobes void do_nmi(struct pt_regs * regs, long error_code)
753{
754 return 0;
755}
756
757static nmi_callback_t nmi_callback = dummy_nmi_callback;
758
759fastcall void do_nmi(struct pt_regs * regs, long error_code)
760{ 825{
761 int cpu; 826 int cpu;
762 827
@@ -766,25 +831,11 @@ fastcall void do_nmi(struct pt_regs * regs, long error_code)
766 831
767 ++nmi_count(cpu); 832 ++nmi_count(cpu);
768 833
769 if (!rcu_dereference(nmi_callback)(regs, cpu)) 834 default_do_nmi(regs);
770 default_do_nmi(regs);
771 835
772 nmi_exit(); 836 nmi_exit();
773} 837}
774 838
775void set_nmi_callback(nmi_callback_t callback)
776{
777 vmalloc_sync_all();
778 rcu_assign_pointer(nmi_callback, callback);
779}
780EXPORT_SYMBOL_GPL(set_nmi_callback);
781
782void unset_nmi_callback(void)
783{
784 nmi_callback = dummy_nmi_callback;
785}
786EXPORT_SYMBOL_GPL(unset_nmi_callback);
787
788#ifdef CONFIG_KPROBES 839#ifdef CONFIG_KPROBES
789fastcall void __kprobes do_int3(struct pt_regs *regs, long error_code) 840fastcall void __kprobes do_int3(struct pt_regs *regs, long error_code)
790{ 841{
@@ -1124,20 +1175,6 @@ void __init trap_init_f00f_bug(void)
1124} 1175}
1125#endif 1176#endif
1126 1177
1127#define _set_gate(gate_addr,type,dpl,addr,seg) \
1128do { \
1129 int __d0, __d1; \
1130 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
1131 "movw %4,%%dx\n\t" \
1132 "movl %%eax,%0\n\t" \
1133 "movl %%edx,%1" \
1134 :"=m" (*((long *) (gate_addr))), \
1135 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
1136 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
1137 "3" ((char *) (addr)),"2" ((seg) << 16)); \
1138} while (0)
1139
1140
1141/* 1178/*
1142 * This needs to use 'idt_table' rather than 'idt', and 1179 * This needs to use 'idt_table' rather than 'idt', and
1143 * thus use the _nonmapped_ version of the IDT, as the 1180 * thus use the _nonmapped_ version of the IDT, as the
@@ -1146,7 +1183,7 @@ do { \
1146 */ 1183 */
1147void set_intr_gate(unsigned int n, void *addr) 1184void set_intr_gate(unsigned int n, void *addr)
1148{ 1185{
1149 _set_gate(idt_table+n,14,0,addr,__KERNEL_CS); 1186 _set_gate(n, DESCTYPE_INT, addr, __KERNEL_CS);
1150} 1187}
1151 1188
1152/* 1189/*
@@ -1154,22 +1191,22 @@ void set_intr_gate(unsigned int n, void *addr)
1154 */ 1191 */
1155static inline void set_system_intr_gate(unsigned int n, void *addr) 1192static inline void set_system_intr_gate(unsigned int n, void *addr)
1156{ 1193{
1157 _set_gate(idt_table+n, 14, 3, addr, __KERNEL_CS); 1194 _set_gate(n, DESCTYPE_INT | DESCTYPE_DPL3, addr, __KERNEL_CS);
1158} 1195}
1159 1196
1160static void __init set_trap_gate(unsigned int n, void *addr) 1197static void __init set_trap_gate(unsigned int n, void *addr)
1161{ 1198{
1162 _set_gate(idt_table+n,15,0,addr,__KERNEL_CS); 1199 _set_gate(n, DESCTYPE_TRAP, addr, __KERNEL_CS);
1163} 1200}
1164 1201
1165static void __init set_system_gate(unsigned int n, void *addr) 1202static void __init set_system_gate(unsigned int n, void *addr)
1166{ 1203{
1167 _set_gate(idt_table+n,15,3,addr,__KERNEL_CS); 1204 _set_gate(n, DESCTYPE_TRAP | DESCTYPE_DPL3, addr, __KERNEL_CS);
1168} 1205}
1169 1206
1170static void __init set_task_gate(unsigned int n, unsigned int gdt_entry) 1207static void __init set_task_gate(unsigned int n, unsigned int gdt_entry)
1171{ 1208{
1172 _set_gate(idt_table+n,5,0,0,(gdt_entry<<3)); 1209 _set_gate(n, DESCTYPE_TASK, (void *)0, (gdt_entry<<3));
1173} 1210}
1174 1211
1175 1212