x86/idt: Move regular trap init to tables
authorThomas Gleixner <tglx@linutronix.de>
Mon, 28 Aug 2017 06:47:53 +0000 (08:47 +0200)
committerIngo Molnar <mingo@kernel.org>
Tue, 29 Aug 2017 10:07:27 +0000 (12:07 +0200)
Initialize the regular traps with a table.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/20170828064959.182128165@linutronix.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/include/asm/desc.h
arch/x86/kernel/idt.c
arch/x86/kernel/traps.c

index e6245277706776b800ad001d9f360da83d205488..0a5735ef06cb5d806d8f47ae8a5292b11d7e4663 100644 (file)
@@ -506,6 +506,7 @@ static inline void load_current_idt(void)
 
 extern void idt_setup_early_handler(void);
 extern void idt_setup_early_traps(void);
+extern void idt_setup_traps(void);
 
 #ifdef CONFIG_X86_64
 extern void idt_setup_early_pf(void);
index a6326fd6698a171db2bad502f8c7de5e4688a378..14d9eb29763cc38ab853a5fd884ff0ffb94e1bde 100644 (file)
@@ -60,6 +60,49 @@ static const __initdata struct idt_data early_idts[] = {
 #endif
 };
 
+/*
+ * The default IDT entries which are set up in trap_init() before
+ * cpu_init() is invoked. Interrupt stacks cannot be used at that point and
+ * the traps which use them are reinitialized with IST after cpu_init() has
+ * set up TSS.
+ */
+static const __initdata struct idt_data def_idts[] = {
+       INTG(X86_TRAP_DE,               divide_error),
+       INTG(X86_TRAP_NMI,              nmi),
+       INTG(X86_TRAP_BR,               bounds),
+       INTG(X86_TRAP_UD,               invalid_op),
+       INTG(X86_TRAP_NM,               device_not_available),
+       INTG(X86_TRAP_OLD_MF,           coprocessor_segment_overrun),
+       INTG(X86_TRAP_TS,               invalid_TSS),
+       INTG(X86_TRAP_NP,               segment_not_present),
+       INTG(X86_TRAP_SS,               stack_segment),
+       INTG(X86_TRAP_GP,               general_protection),
+       INTG(X86_TRAP_SPURIOUS,         spurious_interrupt_bug),
+       INTG(X86_TRAP_MF,               coprocessor_error),
+       INTG(X86_TRAP_AC,               alignment_check),
+       INTG(X86_TRAP_XF,               simd_coprocessor_error),
+
+#ifdef CONFIG_X86_32
+       TSKG(X86_TRAP_DF,               GDT_ENTRY_DOUBLEFAULT_TSS),
+#else
+       INTG(X86_TRAP_DF,               double_fault),
+#endif
+       INTG(X86_TRAP_DB,               debug),
+       INTG(X86_TRAP_NMI,              nmi),
+       INTG(X86_TRAP_BP,               int3),
+
+#ifdef CONFIG_X86_MCE
+       INTG(X86_TRAP_MC,               &machine_check),
+#endif
+
+       SYSG(X86_TRAP_OF,               overflow),
+#if defined(CONFIG_IA32_EMULATION)
+       SYSG(IA32_SYSCALL_VECTOR,       entry_INT80_compat),
+#elif defined(CONFIG_X86_32)
+       SYSG(IA32_SYSCALL_VECTOR,       entry_INT80_32),
+#endif
+};
+
 #ifdef CONFIG_X86_64
 /*
  * Early traps running on the DEFAULT_STACK because the other interrupt
@@ -154,6 +197,14 @@ void __init idt_setup_early_traps(void)
        load_idt(&idt_descr);
 }
 
+/**
+ * idt_setup_traps - Initialize the idt table with default traps
+ */
+void __init idt_setup_traps(void)
+{
+       idt_setup_from_table(idt_table, def_idts, ARRAY_SIZE(def_idts));
+}
+
 #ifdef CONFIG_X86_64
 /**
  * idt_setup_early_pf - Initialize the idt table with early pagefault handler
index 293f5bddd761331ba7f8d7f5bab3ff465a6b2511..34ea3651362ef8383fb456f24125ec4881f42668 100644 (file)
@@ -925,46 +925,7 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
 
 void __init trap_init(void)
 {
-       int i;
-
-       set_intr_gate(X86_TRAP_DE, divide_error);
-       set_intr_gate_ist(X86_TRAP_NMI, &nmi, NMI_STACK);
-       /* int4 can be called from all */
-       set_system_intr_gate(X86_TRAP_OF, &overflow);
-       set_intr_gate(X86_TRAP_BR, bounds);
-       set_intr_gate(X86_TRAP_UD, invalid_op);
-       set_intr_gate(X86_TRAP_NM, device_not_available);
-#ifdef CONFIG_X86_32
-       set_task_gate(X86_TRAP_DF, GDT_ENTRY_DOUBLEFAULT_TSS);
-#else
-       set_intr_gate_ist(X86_TRAP_DF, &double_fault, DOUBLEFAULT_STACK);
-#endif
-       set_intr_gate(X86_TRAP_OLD_MF, coprocessor_segment_overrun);
-       set_intr_gate(X86_TRAP_TS, invalid_TSS);
-       set_intr_gate(X86_TRAP_NP, segment_not_present);
-       set_intr_gate(X86_TRAP_SS, stack_segment);
-       set_intr_gate(X86_TRAP_GP, general_protection);
-       set_intr_gate(X86_TRAP_SPURIOUS, spurious_interrupt_bug);
-       set_intr_gate(X86_TRAP_MF, coprocessor_error);
-       set_intr_gate(X86_TRAP_AC, alignment_check);
-#ifdef CONFIG_X86_MCE
-       set_intr_gate_ist(X86_TRAP_MC, &machine_check, MCE_STACK);
-#endif
-       set_intr_gate(X86_TRAP_XF, simd_coprocessor_error);
-
-       /* Reserve all the builtin and the syscall vector: */
-       for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
-               set_bit(i, used_vectors);
-
-#ifdef CONFIG_IA32_EMULATION
-       set_system_intr_gate(IA32_SYSCALL_VECTOR, entry_INT80_compat);
-       set_bit(IA32_SYSCALL_VECTOR, used_vectors);
-#endif
-
-#ifdef CONFIG_X86_32
-       set_system_intr_gate(IA32_SYSCALL_VECTOR, entry_INT80_32);
-       set_bit(IA32_SYSCALL_VECTOR, used_vectors);
-#endif
+       idt_setup_traps();
 
        /*
         * Set the IDT descriptor to a fixed read-only location, so that the