]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/i386/kernel/traps.c
x86: Fix alternatives and kprobes to remap write-protected kernel text
[mirror_ubuntu-bionic-kernel.git] / arch / i386 / kernel / traps.c
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/i386/traps.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * Pentium III FXSR, SSE support
7 * Gareth Hughes <gareth@valinux.com>, May 2000
8 */
9
10/*
11 * 'Traps.c' handles hardware traps and faults after we have saved some
12 * state in 'asm.s'.
13 */
1da177e4
LT
14#include <linux/sched.h>
15#include <linux/kernel.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/timer.h>
19#include <linux/mm.h>
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24#include <linux/highmem.h>
25#include <linux/kallsyms.h>
26#include <linux/ptrace.h>
27#include <linux/utsname.h>
28#include <linux/kprobes.h>
6e274d14 29#include <linux/kexec.h>
176a2718 30#include <linux/unwind.h>
1e2af92e 31#include <linux/uaccess.h>
a36df98a 32#include <linux/nmi.h>
91768d6c 33#include <linux/bug.h>
1da177e4
LT
34
35#ifdef CONFIG_EISA
36#include <linux/ioport.h>
37#include <linux/eisa.h>
38#endif
39
40#ifdef CONFIG_MCA
41#include <linux/mca.h>
42#endif
43
c0d12172
DJ
44#if defined(CONFIG_EDAC)
45#include <linux/edac.h>
46#endif
47
1da177e4
LT
48#include <asm/processor.h>
49#include <asm/system.h>
1da177e4
LT
50#include <asm/io.h>
51#include <asm/atomic.h>
52#include <asm/debugreg.h>
53#include <asm/desc.h>
54#include <asm/i387.h>
55#include <asm/nmi.h>
176a2718 56#include <asm/unwind.h>
1da177e4
LT
57#include <asm/smp.h>
58#include <asm/arch_hooks.h>
1eeb66a1 59#include <linux/kdebug.h>
2b14a78c 60#include <asm/stacktrace.h>
1da177e4 61
1da177e4
LT
62#include <linux/module.h>
63
64#include "mach_traps.h"
65
29cbc78b
AK
66int panic_on_unrecovered_nmi;
67
1da177e4
LT
68asmlinkage int system_call(void);
69
1da177e4
LT
70/* Do we ignore FPU interrupts ? */
71char ignore_fpu_irq = 0;
72
73/*
74 * The IDT has to be page-aligned to simplify the Pentium
75 * F0 0F bug workaround.. We have a special link segment
76 * for this.
77 */
78struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, };
79
80asmlinkage void divide_error(void);
81asmlinkage void debug(void);
82asmlinkage void nmi(void);
83asmlinkage void int3(void);
84asmlinkage void overflow(void);
85asmlinkage void bounds(void);
86asmlinkage void invalid_op(void);
87asmlinkage void device_not_available(void);
88asmlinkage void coprocessor_segment_overrun(void);
89asmlinkage void invalid_TSS(void);
90asmlinkage void segment_not_present(void);
91asmlinkage void stack_segment(void);
92asmlinkage void general_protection(void);
93asmlinkage void page_fault(void);
94asmlinkage void coprocessor_error(void);
95asmlinkage void simd_coprocessor_error(void);
96asmlinkage void alignment_check(void);
97asmlinkage void spurious_interrupt_bug(void);
98asmlinkage void machine_check(void);
99
0741f4d2 100int kstack_depth_to_print = 24;
86c41837 101static unsigned int code_bytes = 64;
e041c683 102
1da177e4
LT
103static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
104{
105 return p > (void *)tinfo &&
106 p < (void *)tinfo + THREAD_SIZE - 3;
107}
108
109static inline unsigned long print_context_stack(struct thread_info *tinfo,
7aa89746 110 unsigned long *stack, unsigned long ebp,
2b14a78c 111 struct stacktrace_ops *ops, void *data)
1da177e4
LT
112{
113 unsigned long addr;
114
115#ifdef CONFIG_FRAME_POINTER
116 while (valid_stack_ptr(tinfo, (void *)ebp)) {
808dbbb6 117 unsigned long new_ebp;
1da177e4 118 addr = *(unsigned long *)(ebp + 4);
2b14a78c 119 ops->address(data, addr);
b88d4f1d
IM
120 /*
121 * break out of recursive entries (such as
808dbbb6
LT
122 * end_of_stack_stop_unwind_function). Also,
123 * we can never allow a frame pointer to
124 * move downwards!
b88d4f1d 125 */
808dbbb6
LT
126 new_ebp = *(unsigned long *)ebp;
127 if (new_ebp <= ebp)
b88d4f1d 128 break;
808dbbb6 129 ebp = new_ebp;
1da177e4
LT
130 }
131#else
132 while (valid_stack_ptr(tinfo, stack)) {
133 addr = *stack++;
7aa89746 134 if (__kernel_text_address(addr))
2b14a78c 135 ops->address(data, addr);
1da177e4
LT
136 }
137#endif
138 return ebp;
139}
140
b615ebda
AK
141#define MSG(msg) ops->warning(data, msg)
142
2b14a78c
AK
143void dump_trace(struct task_struct *task, struct pt_regs *regs,
144 unsigned long *stack,
145 struct stacktrace_ops *ops, void *data)
1da177e4 146{
a32cf397 147 unsigned long ebp = 0;
1da177e4
LT
148
149 if (!task)
150 task = current;
151
a32cf397 152 if (!stack) {
2b14a78c
AK
153 unsigned long dummy;
154 stack = &dummy;
028a690a 155 if (task != current)
2b14a78c 156 stack = (unsigned long *)task->thread.esp;
176a2718
JB
157 }
158
a32cf397
AK
159#ifdef CONFIG_FRAME_POINTER
160 if (!ebp) {
161 if (task == current) {
162 /* Grab ebp right from our regs */
163 asm ("movl %%ebp, %0" : "=r" (ebp) : );
164 } else {
165 /* ebp is the last reg pushed by switch_to */
166 ebp = *(unsigned long *) task->thread.esp;
167 }
1da177e4 168 }
a32cf397 169#endif
1da177e4
LT
170
171 while (1) {
172 struct thread_info *context;
173 context = (struct thread_info *)
174 ((unsigned long)stack & (~(THREAD_SIZE - 1)));
2b14a78c
AK
175 ebp = print_context_stack(context, stack, ebp, ops, data);
176 /* Should be after the line below, but somewhere
177 in early boot context comes out corrupted and we
178 can't reference it -AK */
179 if (ops->stack(data, "IRQ") < 0)
180 break;
1da177e4
LT
181 stack = (unsigned long*)context->previous_esp;
182 if (!stack)
183 break;
a36df98a 184 touch_nmi_watchdog();
1da177e4
LT
185 }
186}
2b14a78c
AK
187EXPORT_SYMBOL(dump_trace);
188
189static void
190print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
191{
192 printk(data);
193 print_symbol(msg, symbol);
194 printk("\n");
195}
196
197static void print_trace_warning(void *data, char *msg)
198{
199 printk("%s%s\n", (char *)data, msg);
200}
201
202static int print_trace_stack(void *data, char *name)
203{
204 return 0;
205}
206
207/*
208 * Print one address/symbol entries per line.
209 */
210static void print_trace_address(void *data, unsigned long addr)
211{
212 printk("%s [<%08lx>] ", (char *)data, addr);
213 print_symbol("%s\n", addr);
601e6255 214 touch_nmi_watchdog();
2b14a78c
AK
215}
216
217static struct stacktrace_ops print_trace_ops = {
218 .warning = print_trace_warning,
219 .warning_symbol = print_trace_warning_symbol,
220 .stack = print_trace_stack,
221 .address = print_trace_address,
222};
223
224static void
225show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
226 unsigned long * stack, char *log_lvl)
227{
228 dump_trace(task, regs, stack, &print_trace_ops, log_lvl);
229 printk("%s =======================\n", log_lvl);
230}
1da177e4 231
2b14a78c
AK
232void show_trace(struct task_struct *task, struct pt_regs *regs,
233 unsigned long * stack)
7aa89746 234{
176a2718 235 show_trace_log_lvl(task, regs, stack, "");
7aa89746
CE
236}
237
176a2718
JB
238static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
239 unsigned long *esp, char *log_lvl)
1da177e4
LT
240{
241 unsigned long *stack;
242 int i;
243
244 if (esp == NULL) {
245 if (task)
246 esp = (unsigned long*)task->thread.esp;
247 else
248 esp = (unsigned long *)&esp;
249 }
250
251 stack = esp;
252 for(i = 0; i < kstack_depth_to_print; i++) {
253 if (kstack_end(stack))
254 break;
75874d5c
CE
255 if (i && ((i % 8) == 0))
256 printk("\n%s ", log_lvl);
1da177e4
LT
257 printk("%08lx ", *stack++);
258 }
75874d5c 259 printk("\n%sCall Trace:\n", log_lvl);
176a2718 260 show_trace_log_lvl(task, regs, esp, log_lvl);
7aa89746
CE
261}
262
263void show_stack(struct task_struct *task, unsigned long *esp)
264{
75874d5c 265 printk(" ");
176a2718 266 show_stack_log_lvl(task, NULL, esp, "");
1da177e4
LT
267}
268
269/*
270 * The architecture-independent dump_stack generator
271 */
272void dump_stack(void)
273{
274 unsigned long stack;
275
176a2718 276 show_trace(current, NULL, &stack);
1da177e4
LT
277}
278
279EXPORT_SYMBOL(dump_stack);
280
281void show_registers(struct pt_regs *regs)
282{
283 int i;
284 int in_kernel = 1;
285 unsigned long esp;
464d1a78 286 unsigned short ss, gs;
1da177e4
LT
287
288 esp = (unsigned long) (&regs->esp);
0998e422 289 savesegment(ss, ss);
464d1a78 290 savesegment(gs, gs);
db753bdf 291 if (user_mode_vm(regs)) {
1da177e4
LT
292 in_kernel = 0;
293 esp = regs->esp;
294 ss = regs->xss & 0xffff;
295 }
296 print_modules();
f354b3a9
DJ
297 printk(KERN_EMERG "CPU: %d\n"
298 KERN_EMERG "EIP: %04x:[<%08lx>] %s VLI\n"
299 KERN_EMERG "EFLAGS: %08lx (%s %.*s)\n",
1da177e4 300 smp_processor_id(), 0xffff & regs->xcs, regs->eip,
96b644bd
SH
301 print_tainted(), regs->eflags, init_utsname()->release,
302 (int)strcspn(init_utsname()->version, " "),
303 init_utsname()->version);
9c107805
DJ
304 print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip);
305 printk(KERN_EMERG "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
1da177e4 306 regs->eax, regs->ebx, regs->ecx, regs->edx);
9c107805 307 printk(KERN_EMERG "esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
1da177e4 308 regs->esi, regs->edi, regs->ebp, esp);
464d1a78
JF
309 printk(KERN_EMERG "ds: %04x es: %04x fs: %04x gs: %04x ss: %04x\n",
310 regs->xds & 0xffff, regs->xes & 0xffff, regs->xfs & 0xffff, gs, ss);
7e04a118
CE
311 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)",
312 TASK_COMM_LEN, current->comm, current->pid,
c9f4f06d 313 current_thread_info(), current, task_thread_info(current));
1da177e4
LT
314 /*
315 * When in-kernel, we also print out the stack and code at the
316 * time of the fault..
317 */
318 if (in_kernel) {
11a4180c 319 u8 *eip;
86c41837
CE
320 unsigned int code_prologue = code_bytes * 43 / 64;
321 unsigned int code_len = code_bytes;
99325326 322 unsigned char c;
1da177e4 323
9c107805 324 printk("\n" KERN_EMERG "Stack: ");
176a2718 325 show_stack_log_lvl(NULL, regs, (unsigned long *)esp, KERN_EMERG);
1da177e4 326
9c107805 327 printk(KERN_EMERG "Code: ");
1da177e4 328
86c41837 329 eip = (u8 *)regs->eip - code_prologue;
11a4180c
AK
330 if (eip < (u8 *)PAGE_OFFSET ||
331 probe_kernel_address(eip, c)) {
99325326 332 /* try starting at EIP */
11a4180c 333 eip = (u8 *)regs->eip;
86c41837 334 code_len = code_len - code_prologue + 1;
99325326 335 }
86c41837 336 for (i = 0; i < code_len; i++, eip++) {
11a4180c
AK
337 if (eip < (u8 *)PAGE_OFFSET ||
338 probe_kernel_address(eip, c)) {
1da177e4
LT
339 printk(" Bad EIP value.");
340 break;
341 }
11a4180c 342 if (eip == (u8 *)regs->eip)
1da177e4
LT
343 printk("<%02x> ", c);
344 else
345 printk("%02x ", c);
346 }
347 }
348 printk("\n");
349}
350
91768d6c 351int is_valid_bugaddr(unsigned long eip)
1da177e4
LT
352{
353 unsigned short ud2;
1da177e4
LT
354
355 if (eip < PAGE_OFFSET)
91768d6c 356 return 0;
11a4180c 357 if (probe_kernel_address((unsigned short *)eip, ud2))
91768d6c 358 return 0;
1da177e4 359
91768d6c 360 return ud2 == 0x0b0f;
1da177e4
LT
361}
362
91768d6c
JF
363/*
364 * This is gone through when something in the kernel has done something bad and
365 * is about to be terminated.
366 */
1da177e4
LT
367void die(const char * str, struct pt_regs * regs, long err)
368{
369 static struct {
370 spinlock_t lock;
371 u32 lock_owner;
372 int lock_owner_depth;
373 } die = {
6cfd76a2 374 .lock = __SPIN_LOCK_UNLOCKED(die.lock),
1da177e4
LT
375 .lock_owner = -1,
376 .lock_owner_depth = 0
377 };
378 static int die_counter;
e43d674f 379 unsigned long flags;
1da177e4 380
dd287796
AM
381 oops_enter();
382
39c715b7 383 if (die.lock_owner != raw_smp_processor_id()) {
1da177e4 384 console_verbose();
e43d674f 385 spin_lock_irqsave(&die.lock, flags);
1da177e4
LT
386 die.lock_owner = smp_processor_id();
387 die.lock_owner_depth = 0;
388 bust_spinlocks(1);
389 }
e43d674f
JB
390 else
391 local_save_flags(flags);
1da177e4
LT
392
393 if (++die.lock_owner_depth < 3) {
394 int nl = 0;
7bee5c0f
RD
395 unsigned long esp;
396 unsigned short ss;
397
608e2619 398 report_bug(regs->eip, regs);
91768d6c 399
9c107805 400 printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
1da177e4 401#ifdef CONFIG_PREEMPT
9c107805 402 printk(KERN_EMERG "PREEMPT ");
1da177e4
LT
403 nl = 1;
404#endif
405#ifdef CONFIG_SMP
9c107805
DJ
406 if (!nl)
407 printk(KERN_EMERG);
1da177e4
LT
408 printk("SMP ");
409 nl = 1;
410#endif
411#ifdef CONFIG_DEBUG_PAGEALLOC
9c107805
DJ
412 if (!nl)
413 printk(KERN_EMERG);
1da177e4
LT
414 printk("DEBUG_PAGEALLOC");
415 nl = 1;
416#endif
417 if (nl)
418 printk("\n");
20c0d2d4
JB
419 if (notify_die(DIE_OOPS, str, regs, err,
420 current->thread.trap_no, SIGSEGV) !=
7bee5c0f 421 NOTIFY_STOP) {
20c0d2d4 422 show_registers(regs);
7bee5c0f
RD
423 /* Executive summary in case the oops scrolled away */
424 esp = (unsigned long) (&regs->esp);
425 savesegment(ss, ss);
426 if (user_mode(regs)) {
427 esp = regs->esp;
428 ss = regs->xss & 0xffff;
429 }
430 printk(KERN_EMERG "EIP: [<%08lx>] ", regs->eip);
431 print_symbol("%s", regs->eip);
432 printk(" SS:ESP %04x:%08lx\n", ss, esp);
433 }
20c0d2d4
JB
434 else
435 regs = NULL;
1da177e4 436 } else
9c107805 437 printk(KERN_EMERG "Recursive die() failure, output suppressed\n");
1da177e4
LT
438
439 bust_spinlocks(0);
440 die.lock_owner = -1;
bcdcd8e7 441 add_taint(TAINT_DIE);
e43d674f 442 spin_unlock_irqrestore(&die.lock, flags);
6e274d14 443
20c0d2d4
JB
444 if (!regs)
445 return;
446
6e274d14
AN
447 if (kexec_should_crash(current))
448 crash_kexec(regs);
449
1da177e4
LT
450 if (in_interrupt())
451 panic("Fatal exception in interrupt");
452
cea6a4ba 453 if (panic_on_oops)
012c437d 454 panic("Fatal exception");
cea6a4ba 455
dd287796 456 oops_exit();
1da177e4
LT
457 do_exit(SIGSEGV);
458}
459
460static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
461{
717b594a 462 if (!user_mode_vm(regs))
1da177e4
LT
463 die(str, regs, err);
464}
465
3d97ae5b
PP
466static void __kprobes do_trap(int trapnr, int signr, char *str, int vm86,
467 struct pt_regs * regs, long error_code,
468 siginfo_t *info)
1da177e4 469{
4f339ecb 470 struct task_struct *tsk = current;
4f339ecb 471
1da177e4
LT
472 if (regs->eflags & VM_MASK) {
473 if (vm86)
474 goto vm86_trap;
475 goto trap_signal;
476 }
477
717b594a 478 if (!user_mode(regs))
1da177e4
LT
479 goto kernel_trap;
480
481 trap_signal: {
d1895183
AK
482 /*
483 * We want error_code and trap_no set for userspace faults and
484 * kernelspace faults which result in die(), but not
485 * kernelspace faults which are fixed up. die() gives the
486 * process no chance to handle the signal and notice the
487 * kernel fault information, so that won't result in polluting
488 * the information about previously queued, but not yet
489 * delivered, faults. See also do_general_protection below.
490 */
491 tsk->thread.error_code = error_code;
492 tsk->thread.trap_no = trapnr;
493
1da177e4
LT
494 if (info)
495 force_sig_info(signr, info, tsk);
496 else
497 force_sig(signr, tsk);
498 return;
499 }
500
501 kernel_trap: {
d1895183
AK
502 if (!fixup_exception(regs)) {
503 tsk->thread.error_code = error_code;
504 tsk->thread.trap_no = trapnr;
1da177e4 505 die(str, regs, error_code);
d1895183 506 }
1da177e4
LT
507 return;
508 }
509
510 vm86_trap: {
511 int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr);
512 if (ret) goto trap_signal;
513 return;
514 }
515}
516
517#define DO_ERROR(trapnr, signr, str, name) \
518fastcall void do_##name(struct pt_regs * regs, long error_code) \
519{ \
520 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
521 == NOTIFY_STOP) \
522 return; \
523 do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \
524}
525
a10d9a71 526#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr, irq) \
1da177e4
LT
527fastcall void do_##name(struct pt_regs * regs, long error_code) \
528{ \
529 siginfo_t info; \
a10d9a71
PZ
530 if (irq) \
531 local_irq_enable(); \
1da177e4
LT
532 info.si_signo = signr; \
533 info.si_errno = 0; \
534 info.si_code = sicode; \
535 info.si_addr = (void __user *)siaddr; \
536 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
537 == NOTIFY_STOP) \
538 return; \
539 do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
540}
541
542#define DO_VM86_ERROR(trapnr, signr, str, name) \
543fastcall void do_##name(struct pt_regs * regs, long error_code) \
544{ \
545 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
546 == NOTIFY_STOP) \
547 return; \
548 do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \
549}
550
551#define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
552fastcall void do_##name(struct pt_regs * regs, long error_code) \
553{ \
554 siginfo_t info; \
555 info.si_signo = signr; \
556 info.si_errno = 0; \
557 info.si_code = sicode; \
558 info.si_addr = (void __user *)siaddr; \
559 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
560 == NOTIFY_STOP) \
561 return; \
562 do_trap(trapnr, signr, str, 1, regs, error_code, &info); \
563}
564
565DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip)
566#ifndef CONFIG_KPROBES
567DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
568#endif
569DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
570DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds)
a10d9a71 571DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip, 0)
1da177e4
LT
572DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
573DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
574DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
575DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
a10d9a71
PZ
576DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
577DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0, 1)
1da177e4 578
3d97ae5b
PP
579fastcall void __kprobes do_general_protection(struct pt_regs * regs,
580 long error_code)
1da177e4
LT
581{
582 int cpu = get_cpu();
583 struct tss_struct *tss = &per_cpu(init_tss, cpu);
584 struct thread_struct *thread = &current->thread;
585
586 /*
587 * Perform the lazy TSS's I/O bitmap copy. If the TSS has an
588 * invalid offset set (the LAZY one) and the faulting thread has
589 * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS
590 * and we set the offset field correctly. Then we let the CPU to
591 * restart the faulting instruction.
592 */
a75c54f9 593 if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY &&
1da177e4
LT
594 thread->io_bitmap_ptr) {
595 memcpy(tss->io_bitmap, thread->io_bitmap_ptr,
596 thread->io_bitmap_max);
597 /*
598 * If the previously set map was extending to higher ports
599 * than the current one, pad extra space with 0xff (no access).
600 */
601 if (thread->io_bitmap_max < tss->io_bitmap_max)
602 memset((char *) tss->io_bitmap +
603 thread->io_bitmap_max, 0xff,
604 tss->io_bitmap_max - thread->io_bitmap_max);
605 tss->io_bitmap_max = thread->io_bitmap_max;
a75c54f9 606 tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET;
d5cd4aad 607 tss->io_bitmap_owner = thread;
1da177e4
LT
608 put_cpu();
609 return;
610 }
611 put_cpu();
612
613 if (regs->eflags & VM_MASK)
614 goto gp_in_vm86;
615
717b594a 616 if (!user_mode(regs))
1da177e4
LT
617 goto gp_in_kernel;
618
619 current->thread.error_code = error_code;
620 current->thread.trap_no = 13;
abd4f750
MAS
621 if (show_unhandled_signals && unhandled_signal(current, SIGSEGV) &&
622 printk_ratelimit())
623 printk(KERN_INFO
624 "%s[%d] general protection eip:%lx esp:%lx error:%lx\n",
625 current->comm, current->pid,
626 regs->eip, regs->esp, error_code);
627
1da177e4
LT
628 force_sig(SIGSEGV, current);
629 return;
630
631gp_in_vm86:
632 local_irq_enable();
633 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
634 return;
635
636gp_in_kernel:
637 if (!fixup_exception(regs)) {
d1895183
AK
638 current->thread.error_code = error_code;
639 current->thread.trap_no = 13;
1da177e4
LT
640 if (notify_die(DIE_GPF, "general protection fault", regs,
641 error_code, 13, SIGSEGV) == NOTIFY_STOP)
642 return;
643 die("general protection fault", regs, error_code);
644 }
645}
646