]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | #include <linux/mm.h> |
3 | #include <linux/sched.h> | |
b17b0153 | 4 | #include <linux/sched/debug.h> |
1da177e4 LT |
5 | #include <linux/init_task.h> |
6 | #include <linux/fs.h> | |
7 | ||
7c0f6ba6 | 8 | #include <linux/uaccess.h> |
1da177e4 LT |
9 | #include <asm/pgtable.h> |
10 | #include <asm/processor.h> | |
11 | #include <asm/desc.h> | |
12 | ||
4d067d8e BP |
13 | #ifdef CONFIG_X86_32 |
14 | ||
1da177e4 LT |
15 | #define DOUBLEFAULT_STACKSIZE (1024) |
16 | static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE]; | |
17 | #define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE) | |
18 | ||
3dab307e | 19 | #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM) |
1da177e4 LT |
20 | |
21 | static void doublefault_fn(void) | |
22 | { | |
6b68f01b | 23 | struct desc_ptr gdt_desc = {0, 0}; |
1da177e4 LT |
24 | unsigned long gdt, tss; |
25 | ||
357d1226 | 26 | native_store_gdt(&gdt_desc); |
1da177e4 LT |
27 | gdt = gdt_desc.address; |
28 | ||
3dab307e | 29 | printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size); |
1da177e4 LT |
30 | |
31 | if (ptr_ok(gdt)) { | |
32 | gdt += GDT_ENTRY_TSS << 3; | |
254e0a6b | 33 | tss = get_desc_base((struct desc_struct *)gdt); |
3dab307e | 34 | printk(KERN_EMERG "double fault, tss at %08lx\n", tss); |
1da177e4 LT |
35 | |
36 | if (ptr_ok(tss)) { | |
ca241c75 | 37 | struct x86_hw_tss *t = (struct x86_hw_tss *)tss; |
1da177e4 | 38 | |
faca6227 PA |
39 | printk(KERN_EMERG "eip = %08lx, esp = %08lx\n", |
40 | t->ip, t->sp); | |
1da177e4 | 41 | |
3dab307e | 42 | printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n", |
faca6227 | 43 | t->ax, t->bx, t->cx, t->dx); |
3dab307e | 44 | printk(KERN_EMERG "esi = %08lx, edi = %08lx\n", |
faca6227 | 45 | t->si, t->di); |
1da177e4 LT |
46 | } |
47 | } | |
48 | ||
caad3c2a CE |
49 | for (;;) |
50 | cpu_relax(); | |
1da177e4 LT |
51 | } |
52 | ||
7fb983b4 AL |
53 | struct x86_hw_tss doublefault_tss __cacheline_aligned = { |
54 | .sp0 = STACK_START, | |
55 | .ss0 = __KERNEL_DS, | |
56 | .ldt = 0, | |
57 | .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, | |
58 | ||
59 | .ip = (unsigned long) doublefault_fn, | |
60 | /* 0x2 bit is always set */ | |
61 | .flags = X86_EFLAGS_SF | 0x2, | |
62 | .sp = STACK_START, | |
63 | .es = __USER_DS, | |
64 | .cs = __KERNEL_CS, | |
65 | .ss = __KERNEL_DS, | |
66 | .ds = __USER_DS, | |
67 | .fs = __KERNEL_PERCPU, | |
5890f300 AL |
68 | #ifndef CONFIG_X86_32_LAZY_GS |
69 | .gs = __KERNEL_STACK_CANARY, | |
70 | #endif | |
7fb983b4 AL |
71 | |
72 | .__cr3 = __pa_nodebug(swapper_pg_dir), | |
1da177e4 | 73 | }; |
4d067d8e BP |
74 | |
75 | /* dummy for do_double_fault() call */ | |
76 | void df_debug(struct pt_regs *regs, long error_code) {} | |
77 | ||
78 | #else /* !CONFIG_X86_32 */ | |
79 | ||
80 | void df_debug(struct pt_regs *regs, long error_code) | |
81 | { | |
82 | pr_emerg("PANIC: double fault, error_code: 0x%lx\n", error_code); | |
83 | show_regs(regs); | |
84 | panic("Machine halted."); | |
85 | } | |
86 | #endif |