Skip to content

Commit 0a30908

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/idt: Move debug stack init to table based
Add the debug_idt init table and make use of it. 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 433f892 commit 0a30908

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

arch/x86/include/asm/desc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,10 @@ extern void idt_setup_early_traps(void);
509509

510510
#ifdef CONFIG_X86_64
511511
extern void idt_setup_early_pf(void);
512+
extern void idt_setup_debugidt_traps(void);
512513
#else
513514
static inline void idt_setup_early_pf(void) { }
515+
static inline void idt_setup_debugidt_traps(void) { }
514516
#endif
515517

516518
extern void idt_invalidate(void *addr);

arch/x86/kernel/idt.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ static const __initdata struct idt_data early_idts[] = {
6868
static const __initdata struct idt_data early_pf_idts[] = {
6969
INTG(X86_TRAP_PF, page_fault),
7070
};
71+
72+
/*
73+
* Override for the debug_idt. Same as the default, but with interrupt
74+
* stack set to DEFAULT_STACK (0). Required for NMI trap handling.
75+
*/
76+
static const __initdata struct idt_data dbg_idts[] = {
77+
INTG(X86_TRAP_DB, debug),
78+
INTG(X86_TRAP_BP, int3),
79+
};
7180
#endif
7281

7382
/* Must be page-aligned because the real IDT is used in a fixmap. */
@@ -82,6 +91,10 @@ struct desc_ptr idt_descr __ro_after_init = {
8291
/* No need to be aligned, but done to keep all IDTs defined the same way. */
8392
gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
8493

94+
/*
95+
* Override for the debug_idt. Same as the default, but with interrupt
96+
* stack set to DEFAULT_STACK (0). Required for NMI trap handling.
97+
*/
8598
const struct desc_ptr debug_idt_descr = {
8699
.size = IDT_ENTRIES * 16 - 1,
87100
.address = (unsigned long) debug_idt_table,
@@ -143,6 +156,16 @@ void __init idt_setup_early_pf(void)
143156
idt_setup_from_table(idt_table, early_pf_idts,
144157
ARRAY_SIZE(early_pf_idts));
145158
}
159+
160+
/**
161+
* idt_setup_debugidt_traps - Initialize the debug idt table with debug traps
162+
*/
163+
void __init idt_setup_debugidt_traps(void)
164+
{
165+
memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
166+
167+
idt_setup_from_table(debug_idt_table, dbg_idts, ARRAY_SIZE(dbg_idts));
168+
}
146169
#endif
147170

148171
/**

arch/x86/kernel/traps.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,5 @@ void __init trap_init(void)
990990

991991
x86_init.irqs.trap_init();
992992

993-
#ifdef CONFIG_X86_64
994-
memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
995-
set_nmi_gate(X86_TRAP_DB, &debug);
996-
set_nmi_gate(X86_TRAP_BP, &int3);
997-
#endif
993+
idt_setup_debugidt_traps();
998994
}

0 commit comments

Comments
 (0)