From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751881AbdH1Gzn (ORCPT ); Mon, 28 Aug 2017 02:55:43 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:45858 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751525AbdH1Gxd (ORCPT ); Mon, 28 Aug 2017 02:53:33 -0400 Message-Id: <20170828064959.006502252@linutronix.de> User-Agent: quilt/0.63-1 Date: Mon, 28 Aug 2017 08:47:51 +0200 From: Thomas Gleixner To: LKML Cc: Ingo Molnar , Peter Anvin , Peter Zijlstra , Andy Lutomirski , Borislav Petkov , Steven Rostedt Subject: [patch V3 36/44] x86/idt: Move debug stack init to table based References: <20170828064715.802987421@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=x86-idt--Move-debug-stack-init-to-table-based.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the debug_idt init table and make use of it. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/desc.h | 2 ++ arch/x86/kernel/idt.c | 23 +++++++++++++++++++++++ arch/x86/kernel/traps.c | 6 +----- 3 files changed, 26 insertions(+), 5 deletions(-) --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h @@ -509,8 +509,10 @@ extern void idt_setup_early_traps(void); #ifdef CONFIG_X86_64 extern void idt_setup_early_pf(void); +extern void idt_setup_debugidt_traps(void); #else static inline void idt_setup_early_pf(void) { } +static inline void idt_setup_debugidt_traps(void) { } #endif extern void idt_invalidate(void *addr); --- a/arch/x86/kernel/idt.c +++ b/arch/x86/kernel/idt.c @@ -68,6 +68,15 @@ static const __initdata struct idt_data static const __initdata struct idt_data early_pf_idts[] = { INTG(X86_TRAP_PF, page_fault), }; + +/* + * Override for the debug_idt. Same as the default, but with interrupt + * stack set to DEFAULT_STACK (0). Required for NMI trap handling. + */ +static const __initdata struct idt_data dbg_idts[] = { + INTG(X86_TRAP_DB, debug), + INTG(X86_TRAP_BP, int3), +}; #endif /* Must be page-aligned because the real IDT is used in a fixmap. */ @@ -82,6 +91,10 @@ struct desc_ptr idt_descr __ro_after_ini /* No need to be aligned, but done to keep all IDTs defined the same way. */ gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss; +/* + * Override for the debug_idt. Same as the default, but with interrupt + * stack set to DEFAULT_STACK (0). Required for NMI trap handling. + */ const struct desc_ptr debug_idt_descr = { .size = IDT_ENTRIES * 16 - 1, .address = (unsigned long) debug_idt_table, @@ -143,6 +156,16 @@ void __init idt_setup_early_pf(void) idt_setup_from_table(idt_table, early_pf_idts, ARRAY_SIZE(early_pf_idts)); } + +/** + * idt_setup_debugidt_traps - Initialize the debug idt table with debug traps + */ +void __init idt_setup_debugidt_traps(void) +{ + memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16); + + idt_setup_from_table(debug_idt_table, dbg_idts, ARRAY_SIZE(dbg_idts)); +} #endif /** --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -990,9 +990,5 @@ void __init trap_init(void) x86_init.irqs.trap_init(); -#ifdef CONFIG_X86_64 - memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16); - set_nmi_gate(X86_TRAP_DB, &debug); - set_nmi_gate(X86_TRAP_BP, &int3); -#endif + idt_setup_debugidt_traps(); }