x86/boot: support to handle exception in early boot
cover x86/boot: support to handle exception in early boot
The boot code becomes a little complicated, and hits some bugs, e.g. Commit 3a63f70bf4c3a ("x86/boot: Early parse RSDP and save it in boot_params") broke kexec boot on EFI systems.
There is few hint when bug happens. Catching the exception and printing message can give a immediate help, instead of adding more debug_putstr() to narraw down the problem.
Although no functional dependency, but in order to show message, the early console should be ready. I have sent a separate series:
https://www.mail-archive.com/[email protected]/msg1992923.html
https://www.mail-archive.com/[email protected]/msg1992919.html
Pingfan Liu (2):
x86/idt: split out idt routines
x86/boot: set up idt for very early boot stage
arch/x86/boot/compressed/head_64.S | 11 +++++++ arch/x86/boot/compressed/misc.c | 61 ++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/idt.h | 64 ++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/idt.c | 58 +--------------------------------- 4 files changed, 137 insertions(+), 57 deletions(-) create mode 100644 arch/x86/include/asm/idt.h
Signature · 1 line
2.7.4
PATCH 1/2 x86/idt: split out idt routines
Some idt routines can be reused in early boot stage. Splitting them out.
--- arch/x86/include/asm/idt.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/idt.c | 58 +---------------------------------------- 2 files changed, 65 insertions(+), 57 deletions(-) create mode 100644 arch/x86/include/asm/idt.h
arch/x86/include/asm/idt.h new file +64 -0
@@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_IDT_H +#define _ASM_X86_IDT_H + +#include <asm/desc_defs.h> + +struct idt_data { +unsigned int vector; +unsigned int segment; +struct idt_bits bits; +const void *addr; +}; + +#define DPL0 0x0 +#define DPL3 0x3 + +#define DEFAULT_STACK 0 + +#define G (_vector, _addr, _ist, _type, _dpl, _segment) \ + { \ + .vector = _vector, \ + .bits.ist = _ist, \ + .bits.type = _type, \ + .bits.dpl = _dpl, \ + .bits.p = 1, \ + .addr = _addr, \ + .segment = _segment, \ + } + +/* Interrupt gate */ +#define INTG (_vector, _addr) \ + G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL0, __KERNEL_CS) + +/* System interrupt gate */ +#define SYSG (_vector, _addr) \ + G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL3, __KERNEL_CS) + +/* Interrupt gate with interrupt stack */ +#define ISTG (_vector, _addr, _ist) \ + G(_vector, _addr, _ist, GATE_INTERRUPT, DPL0, __KERNEL_CS) + +/* System interrupt gate with interrupt stack */ +#define SISTG (_vector, _addr, _ist) \ + G(_vector, _addr, _ist, GATE_INTERRUPT, DPL3, __KERNEL_CS) + +/* Task gate */ +#define TSKG (_vector, _gdt) \ + G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3) + +static inline void idt_init_desc (gate_desc *gate,const struct idt_data *d) +{ +unsigned long addr = (unsigned long ) d->addr; + + gate->offset_low = (u16 ) addr; + gate->segment = (u16 ) d->segment; + gate->bits = d->bits; + gate->offset_middle = (u16) (addr >>16 ); +#ifdef CONFIG_X86_64 + gate->offset_high = (u32) (addr >>32 ); + gate->reserved =0 ; +#endif +} + +#endif
arch/x86/kernel/idt.c +1 -57
70 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 2/2 x86/boot: set up idt for very early boot stage
In reply to Pingfan LiuThe boot code becomes a little complicated, and hits some bugs, e.g. Commit 3a63f70bf4c3a ("x86/boot: Early parse RSDP and save it in boot_params") broke kexec boot on EFI systems.
There is few hint when bug happens. Catching the exception and printing message can give a immediate help, instead of adding more debug_putstr() to narraw down the problem.
At present, page fault exception handler is added. And the printed out message looks like:
early boot page fault:
ENTRY(startup_64) is at: 000000047f67d200
nip: 000000047fdeedd3
fault address: fffffffeef6fde30
--- arch/x86/boot/compressed/head_64.S | 11 +++++++ arch/x86/boot/compressed/misc.c | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
arch/x86/boot/compressed/head_64.S +11 -0
@@ -527,6 +527,10 @@ relocated: shrq $3, %rcx rep stosq + pushq %rsi /* Save the real mode argument */ + leaq startup_64(%rip), %rdi + call setup_early_boot_idt + popq %rsi /* * Do the extraction, and jump to the new kernel.. */
@@ -659,6 +663,13 @@ no_longmode: #include "../../kernel/verify_cpu.S" + .code64 +.align 8 +ENTRY(boot_page_fault) + mov 8(%rsp), %rdi + call do_boot_page_fault + iretq + .data gdt64: .word gdt_end - gdt
arch/x86/boot/compressed/misc.c +61 -0
70 lines not on this page · raw message
Signature · 1 line
2.7.4