Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/mm.h> |
| 2 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <linux/init_task.h> |
| 4 | #include <linux/fs.h> |
| 5 | |
| 6 | #include <asm/uaccess.h> |
| 7 | #include <asm/pgtable.h> |
| 8 | #include <asm/processor.h> |
| 9 | #include <asm/desc.h> |
| 10 | |
Borislav Petkov | 4d067d8 | 2013-05-09 12:02:29 +0200 | [diff] [blame] | 11 | #ifdef CONFIG_X86_32 |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #define DOUBLEFAULT_STACKSIZE (1024) |
| 14 | static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE]; |
| 15 | #define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE) |
| 16 | |
Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 17 | #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | static void doublefault_fn(void) |
| 20 | { |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 21 | struct desc_ptr gdt_desc = {0, 0}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | unsigned long gdt, tss; |
| 23 | |
Konrad Rzeszutek Wilk | 357d122 | 2013-04-05 16:42:23 -0400 | [diff] [blame] | 24 | native_store_gdt(&gdt_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | gdt = gdt_desc.address; |
| 26 | |
Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 27 | printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | if (ptr_ok(gdt)) { |
| 30 | gdt += GDT_ENTRY_TSS << 3; |
Akinobu Mita | 254e0a6 | 2009-07-19 00:08:54 +0900 | [diff] [blame] | 31 | tss = get_desc_base((struct desc_struct *)gdt); |
Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 32 | printk(KERN_EMERG "double fault, tss at %08lx\n", tss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | if (ptr_ok(tss)) { |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 35 | struct x86_hw_tss *t = (struct x86_hw_tss *)tss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 37 | printk(KERN_EMERG "eip = %08lx, esp = %08lx\n", |
| 38 | t->ip, t->sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 40 | printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n", |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 41 | t->ax, t->bx, t->cx, t->dx); |
Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 42 | printk(KERN_EMERG "esi = %08lx, edi = %08lx\n", |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 43 | t->si, t->di); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Chuck Ebbert | caad3c2 | 2006-06-25 05:46:53 -0700 | [diff] [blame] | 47 | for (;;) |
| 48 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | struct tss_struct doublefault_tss __cacheline_aligned = { |
Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 52 | .x86_tss = { |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 53 | .sp0 = STACK_START, |
Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 54 | .ss0 = __KERNEL_DS, |
| 55 | .ldt = 0, |
| 56 | .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 58 | .ip = (unsigned long) doublefault_fn, |
Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 59 | /* 0x2 bit is always set */ |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 60 | .flags = X86_EFLAGS_SF | 0x2, |
| 61 | .sp = STACK_START, |
Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 62 | .es = __USER_DS, |
| 63 | .cs = __KERNEL_CS, |
| 64 | .ss = __KERNEL_DS, |
| 65 | .ds = __USER_DS, |
Chuck Ebbert | 3dab307 | 2007-08-10 22:31:11 +0200 | [diff] [blame] | 66 | .fs = __KERNEL_PERCPU, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Vegard Nossum | af5c2bd | 2008-10-03 17:54:25 +0200 | [diff] [blame] | 68 | .__cr3 = __pa_nodebug(swapper_pg_dir), |
Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 69 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
Borislav Petkov | 4d067d8 | 2013-05-09 12:02:29 +0200 | [diff] [blame] | 71 | |
| 72 | /* dummy for do_double_fault() call */ |
| 73 | void df_debug(struct pt_regs *regs, long error_code) {} |
| 74 | |
| 75 | #else /* !CONFIG_X86_32 */ |
| 76 | |
| 77 | void df_debug(struct pt_regs *regs, long error_code) |
| 78 | { |
| 79 | pr_emerg("PANIC: double fault, error_code: 0x%lx\n", error_code); |
| 80 | show_regs(regs); |
| 81 | panic("Machine halted."); |
| 82 | } |
| 83 | #endif |