1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/sched.h>
4 #include <linux/sched/debug.h>
5 #include <linux/init_task.h>
8 #include <linux/uaccess.h>
9 #include <asm/pgtable.h>
10 #include <asm/processor.h>
15 #define DOUBLEFAULT_STACKSIZE (1024)
16 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17 #define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
19 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21 static void doublefault_fn(void)
23 struct desc_ptr gdt_desc = {0, 0};
24 unsigned long gdt, tss;
26 native_store_gdt(&gdt_desc);
27 gdt = gdt_desc.address;
29 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
32 gdt += GDT_ENTRY_TSS << 3;
33 tss = get_desc_base((struct desc_struct *)gdt);
34 printk(KERN_EMERG "double fault, tss at %08lx\n", tss);
37 struct x86_hw_tss *t = (struct x86_hw_tss *)tss;
39 printk(KERN_EMERG "eip = %08lx, esp = %08lx\n",
42 printk(KERN_EMERG "eax = %08lx, ebx = %08lx, ecx = %08lx, edx = %08lx\n",
43 t->ax, t->bx, t->cx, t->dx);
44 printk(KERN_EMERG "esi = %08lx, edi = %08lx\n",
53 struct x86_hw_tss doublefault_tss __cacheline_aligned = {
57 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,
59 .ip = (unsigned long) doublefault_fn,
60 /* 0x2 bit is always set */
61 .flags = X86_EFLAGS_SF | 0x2,
67 .fs = __KERNEL_PERCPU,
68 #ifndef CONFIG_X86_32_LAZY_GS
69 .gs = __KERNEL_STACK_CANARY,
72 .__cr3 = __pa_nodebug(swapper_pg_dir),
75 /* dummy for do_double_fault() call */
76 void df_debug(struct pt_regs *regs, long error_code) {}
78 #else /* !CONFIG_X86_32 */
80 void df_debug(struct pt_regs *regs, long error_code)
82 pr_emerg("PANIC: double fault, error_code: 0x%lx\n", error_code);
84 panic("Machine halted.");