blob: f6dfd9334b67e54aa0a9eda6cfac7f1094cf80d9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/mm.h>
2#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#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 Petkov4d067d82013-05-09 12:02:29 +020011#ifdef CONFIG_X86_32
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#define DOUBLEFAULT_STACKSIZE (1024)
14static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
16
Chuck Ebbert3dab3072007-08-10 22:31:11 +020017#define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19static void doublefault_fn(void)
20{
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010021 struct desc_ptr gdt_desc = {0, 0};
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 unsigned long gdt, tss;
23
Konrad Rzeszutek Wilk357d1222013-04-05 16:42:23 -040024 native_store_gdt(&gdt_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 gdt = gdt_desc.address;
26
Chuck Ebbert3dab3072007-08-10 22:31:11 +020027 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 if (ptr_ok(gdt)) {
30 gdt += GDT_ENTRY_TSS << 3;
Akinobu Mita254e0a62009-07-19 00:08:54 +090031 tss = get_desc_base((struct desc_struct *)gdt);
Chuck Ebbert3dab3072007-08-10 22:31:11 +020032 printk(KERN_EMERG "double fault, tss at %08lx\n", tss);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34 if (ptr_ok(tss)) {
Glauber de Oliveira Costaca241c72008-01-30 13:31:31 +010035 struct x86_hw_tss *t = (struct x86_hw_tss *)tss;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
H. Peter Anvinfaca6222008-01-30 13:31:02 +010037 printk(KERN_EMERG "eip = %08lx, esp = %08lx\n",
38 t->ip, t->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Chuck Ebbert3dab3072007-08-10 22:31:11 +020040 printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n",
H. Peter Anvinfaca6222008-01-30 13:31:02 +010041 t->ax, t->bx, t->cx, t->dx);
Chuck Ebbert3dab3072007-08-10 22:31:11 +020042 printk(KERN_EMERG "esi = %08lx, edi = %08lx\n",
H. Peter Anvinfaca6222008-01-30 13:31:02 +010043 t->si, t->di);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 }
45 }
46
Chuck Ebbertcaad3c22006-06-25 05:46:53 -070047 for (;;)
48 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
51struct tss_struct doublefault_tss __cacheline_aligned = {
Rusty Russella75c54f2007-05-02 19:27:13 +020052 .x86_tss = {
H. Peter Anvinfaca6222008-01-30 13:31:02 +010053 .sp0 = STACK_START,
Rusty Russella75c54f2007-05-02 19:27:13 +020054 .ss0 = __KERNEL_DS,
55 .ldt = 0,
56 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
H. Peter Anvinfaca6222008-01-30 13:31:02 +010058 .ip = (unsigned long) doublefault_fn,
Rusty Russella75c54f2007-05-02 19:27:13 +020059 /* 0x2 bit is always set */
H. Peter Anvinfaca6222008-01-30 13:31:02 +010060 .flags = X86_EFLAGS_SF | 0x2,
61 .sp = STACK_START,
Rusty Russella75c54f2007-05-02 19:27:13 +020062 .es = __USER_DS,
63 .cs = __KERNEL_CS,
64 .ss = __KERNEL_DS,
65 .ds = __USER_DS,
Chuck Ebbert3dab3072007-08-10 22:31:11 +020066 .fs = __KERNEL_PERCPU,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Vegard Nossumaf5c2bd2008-10-03 17:54:25 +020068 .__cr3 = __pa_nodebug(swapper_pg_dir),
Rusty Russella75c54f2007-05-02 19:27:13 +020069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
Borislav Petkov4d067d82013-05-09 12:02:29 +020071
72/* dummy for do_double_fault() call */
73void df_debug(struct pt_regs *regs, long error_code) {}
74
75#else /* !CONFIG_X86_32 */
76
77void 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