Skip to content

Commit b70543a

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/idt: Move regular trap init to tables
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>
1 parent 90f6225 commit b70543a

File tree

3 files changed

+53
-40
lines changed

3 files changed

+53
-40
lines changed

arch/x86/include/asm/desc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ static inline void load_current_idt(void)
506506

507507
extern void idt_setup_early_handler(void);
508508
extern void idt_setup_early_traps(void);
509+
extern void idt_setup_traps(void);
509510

510511
#ifdef CONFIG_X86_64
511512
extern void idt_setup_early_pf(void);

arch/x86/kernel/idt.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,49 @@ static const __initdata struct idt_data early_idts[] = {
6060
#endif
6161
};
6262

63+
/*
64+
* The default IDT entries which are set up in trap_init() before
65+
* cpu_init() is invoked. Interrupt stacks cannot be used at that point and
66+
* the traps which use them are reinitialized with IST after cpu_init() has
67+
* set up TSS.
68+
*/
69+
static const __initdata struct idt_data def_idts[] = {
70+
INTG(X86_TRAP_DE, divide_error),
71+
INTG(X86_TRAP_NMI, nmi),
72+
INTG(X86_TRAP_BR, bounds),
73+
INTG(X86_TRAP_UD, invalid_op),
74+
INTG(X86_TRAP_NM, device_not_available),
75+
INTG(X86_TRAP_OLD_MF, coprocessor_segment_overrun),
76+
INTG(X86_TRAP_TS, invalid_TSS),
77+
INTG(X86_TRAP_NP, segment_not_present),
78+
INTG(X86_TRAP_SS, stack_segment),
79+
INTG(X86_TRAP_GP, general_protection),
80+
INTG(X86_TRAP_SPURIOUS, spurious_interrupt_bug),
81+
INTG(X86_TRAP_MF, coprocessor_error),
82+
INTG(X86_TRAP_AC, alignment_check),
83+
INTG(X86_TRAP_XF, simd_coprocessor_error),
84+
85+
#ifdef CONFIG_X86_32
86+
TSKG(X86_TRAP_DF, GDT_ENTRY_DOUBLEFAULT_TSS),
87+
#else
88+
INTG(X86_TRAP_DF, double_fault),
89+
#endif
90+
INTG(X86_TRAP_DB, debug),
91+
INTG(X86_TRAP_NMI, nmi),
92+
INTG(X86_TRAP_BP, int3),
93+
94+
#ifdef CONFIG_X86_MCE
95+
INTG(X86_TRAP_MC, &machine_check),
96+
#endif
97+
98+
SYSG(X86_TRAP_OF, overflow),
99+
#if defined(CONFIG_IA32_EMULATION)
100+
SYSG(IA32_SYSCALL_VECTOR, entry_INT80_compat),
101+
#elif defined(CONFIG_X86_32)
102+
SYSG(IA32_SYSCALL_VECTOR, entry_INT80_32),
103+
#endif
104+
};
105+
63106
#ifdef CONFIG_X86_64
64107
/*
65108
* Early traps running on the DEFAULT_STACK because the other interrupt
@@ -154,6 +197,14 @@ void __init idt_setup_early_traps(void)
154197
load_idt(&idt_descr);
155198
}
156199

200+
/**
201+
* idt_setup_traps - Initialize the idt table with default traps
202+
*/
203+
void __init idt_setup_traps(void)
204+
{
205+
idt_setup_from_table(idt_table, def_idts, ARRAY_SIZE(def_idts));
206+
}
207+
157208
#ifdef CONFIG_X86_64
158209
/**
159210
* idt_setup_early_pf - Initialize the idt table with early pagefault handler

arch/x86/kernel/traps.c

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -925,46 +925,7 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
925925

926926
void __init trap_init(void)
927927
{
928-
int i;
929-
930-
set_intr_gate(X86_TRAP_DE, divide_error);
931-
set_intr_gate_ist(X86_TRAP_NMI, &nmi, NMI_STACK);
932-
/* int4 can be called from all */
933-
set_system_intr_gate(X86_TRAP_OF, &overflow);
934-
set_intr_gate(X86_TRAP_BR, bounds);
935-
set_intr_gate(X86_TRAP_UD, invalid_op);
936-
set_intr_gate(X86_TRAP_NM, device_not_available);
937-
#ifdef CONFIG_X86_32
938-
set_task_gate(X86_TRAP_DF, GDT_ENTRY_DOUBLEFAULT_TSS);
939-
#else
940-
set_intr_gate_ist(X86_TRAP_DF, &double_fault, DOUBLEFAULT_STACK);
941-
#endif
942-
set_intr_gate(X86_TRAP_OLD_MF, coprocessor_segment_overrun);
943-
set_intr_gate(X86_TRAP_TS, invalid_TSS);
944-
set_intr_gate(X86_TRAP_NP, segment_not_present);
945-
set_intr_gate(X86_TRAP_SS, stack_segment);
946-
set_intr_gate(X86_TRAP_GP, general_protection);
947-
set_intr_gate(X86_TRAP_SPURIOUS, spurious_interrupt_bug);
948-
set_intr_gate(X86_TRAP_MF, coprocessor_error);
949-
set_intr_gate(X86_TRAP_AC, alignment_check);
950-
#ifdef CONFIG_X86_MCE
951-
set_intr_gate_ist(X86_TRAP_MC, &machine_check, MCE_STACK);
952-
#endif
953-
set_intr_gate(X86_TRAP_XF, simd_coprocessor_error);
954-
955-
/* Reserve all the builtin and the syscall vector: */
956-
for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
957-
set_bit(i, used_vectors);
958-
959-
#ifdef CONFIG_IA32_EMULATION
960-
set_system_intr_gate(IA32_SYSCALL_VECTOR, entry_INT80_compat);
961-
set_bit(IA32_SYSCALL_VECTOR, used_vectors);
962-
#endif
963-
964-
#ifdef CONFIG_X86_32
965-
set_system_intr_gate(IA32_SYSCALL_VECTOR, entry_INT80_32);
966-
set_bit(IA32_SYSCALL_VECTOR, used_vectors);
967-
#endif
928+
idt_setup_traps();
968929

969930
/*
970931
* Set the IDT descriptor to a fixed read-only location, so that the

0 commit comments

Comments
 (0)