Skip to content

Commit 433f892

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/idt: Switch early trap init to IDT tables
Add the initialization table for the early trap setup and replace the early trap init code. Signed-off-by: Thomas Gleixner <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 3318e97 commit 433f892

File tree

3 files changed

+55
-29
lines changed

3 files changed

+55
-29
lines changed

arch/x86/kernel/idt.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ struct idt_data {
4848
#define TSKG(_vector, _gdt) \
4949
G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3)
5050

51+
/*
52+
* Early traps running on the DEFAULT_STACK because the other interrupt
53+
* stacks work only after cpu_init().
54+
*/
55+
static const __initdata struct idt_data early_idts[] = {
56+
INTG(X86_TRAP_DB, debug),
57+
SYSG(X86_TRAP_BP, int3),
58+
#ifdef CONFIG_X86_32
59+
INTG(X86_TRAP_PF, page_fault),
60+
#endif
61+
};
62+
63+
#ifdef CONFIG_X86_64
64+
/*
65+
* Early traps running on the DEFAULT_STACK because the other interrupt
66+
* stacks work only after cpu_init().
67+
*/
68+
static const __initdata struct idt_data early_pf_idts[] = {
69+
INTG(X86_TRAP_PF, page_fault),
70+
};
71+
#endif
72+
5173
/* Must be page-aligned because the real IDT is used in a fixmap. */
5274
gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss;
5375

@@ -92,6 +114,37 @@ idt_setup_from_table(gate_desc *idt, const struct idt_data *t, int size)
92114
}
93115
}
94116

117+
/**
118+
* idt_setup_early_traps - Initialize the idt table with early traps
119+
*
120+
* On X8664 these traps do not use interrupt stacks as they can't work
121+
* before cpu_init() is invoked and sets up TSS. The IST variants are
122+
* installed after that.
123+
*/
124+
void __init idt_setup_early_traps(void)
125+
{
126+
idt_setup_from_table(idt_table, early_idts, ARRAY_SIZE(early_idts));
127+
load_idt(&idt_descr);
128+
}
129+
130+
#ifdef CONFIG_X86_64
131+
/**
132+
* idt_setup_early_pf - Initialize the idt table with early pagefault handler
133+
*
134+
* On X8664 this does not use interrupt stacks as they can't work before
135+
* cpu_init() is invoked and sets up TSS. The IST variant is installed
136+
* after that.
137+
*
138+
* FIXME: Why is 32bit and 64bit installing the PF handler at different
139+
* places in the early setup code?
140+
*/
141+
void __init idt_setup_early_pf(void)
142+
{
143+
idt_setup_from_table(idt_table, early_pf_idts,
144+
ARRAY_SIZE(early_pf_idts));
145+
}
146+
#endif
147+
95148
/**
96149
* idt_setup_early_handler - Initializes the idt table with early handlers
97150
*/

arch/x86/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ void __init setup_arch(char **cmdline_p)
891891
*/
892892
olpc_ofw_detect();
893893

894-
early_trap_init();
894+
idt_setup_early_traps();
895895
early_cpu_init();
896896
early_ioremap_init();
897897

@@ -1162,7 +1162,7 @@ void __init setup_arch(char **cmdline_p)
11621162

11631163
init_mem_mapping();
11641164

1165-
early_trap_pf_init();
1165+
idt_setup_early_pf();
11661166

11671167
/*
11681168
* Update mmu_cr4_features (and, indirectly, trampoline_cr4_features)

arch/x86/kernel/traps.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -923,33 +923,6 @@ dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
923923
}
924924
#endif
925925

926-
/* Set of traps needed for early debugging. */
927-
void __init early_trap_init(void)
928-
{
929-
/*
930-
* Don't use IST to set DEBUG_STACK as it doesn't work until TSS
931-
* is ready in cpu_init() <-- trap_init(). Before trap_init(),
932-
* CPU runs at ring 0 so it is impossible to hit an invalid
933-
* stack. Using the original stack works well enough at this
934-
* early stage. DEBUG_STACK will be equipped after cpu_init() in
935-
* trap_init().
936-
*/
937-
set_intr_gate(X86_TRAP_DB, debug);
938-
/* int3 can be called from all */
939-
set_system_intr_gate(X86_TRAP_BP, &int3);
940-
#ifdef CONFIG_X86_32
941-
set_intr_gate(X86_TRAP_PF, page_fault);
942-
#endif
943-
load_idt(&idt_descr);
944-
}
945-
946-
void __init early_trap_pf_init(void)
947-
{
948-
#ifdef CONFIG_X86_64
949-
set_intr_gate(X86_TRAP_PF, page_fault);
950-
#endif
951-
}
952-
953926
void __init trap_init(void)
954927
{
955928
int i;

0 commit comments

Comments
 (0)