From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753159AbdH2LXZ (ORCPT ); Tue, 29 Aug 2017 07:23:25 -0400 Received: from terminus.zytor.com ([65.50.211.136]:37123 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752295AbdH2LXY (ORCPT ); Tue, 29 Aug 2017 07:23:24 -0400 Date: Tue, 29 Aug 2017 04:17:39 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: bp@alien8.de, mingo@kernel.org, peterz@infradead.org, jpoimboe@redhat.com, hpa@zytor.com, brgerst@gmail.com, tglx@linutronix.de, dvlasenk@redhat.com, linux-kernel@vger.kernel.org, luto@kernel.org, rostedt@goodmis.org, torvalds@linux-foundation.org Reply-To: linux-kernel@vger.kernel.org, luto@kernel.org, bp@alien8.de, mingo@kernel.org, brgerst@gmail.com, tglx@linutronix.de, jpoimboe@redhat.com, hpa@zytor.com, peterz@infradead.org, dvlasenk@redhat.com, rostedt@goodmis.org, torvalds@linux-foundation.org In-Reply-To: <20170828064958.849877032@linutronix.de> References: <20170828064958.849877032@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/apic] x86/idt: Prepare for table based init Git-Commit-ID: 3318e9744244a415ee9481ca7e54234caf5e12c5 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 3318e9744244a415ee9481ca7e54234caf5e12c5 Gitweb: http://git.kernel.org/tip/3318e9744244a415ee9481ca7e54234caf5e12c5 Author: Thomas Gleixner AuthorDate: Mon, 28 Aug 2017 08:47:49 +0200 Committer: Ingo Molnar CommitDate: Tue, 29 Aug 2017 12:07:27 +0200 x86/idt: Prepare for table based init The IDT setup code is handled in several places. All of them use variants of set_intr_gate() inlines. This can be done with a table based initialization, which allows to reduce the inline zoo and puts all IDT related code and information into a single place. Add the infrastructure. Signed-off-by: Thomas Gleixner Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Steven Rostedt Link: http://lkml.kernel.org/r/20170828064958.849877032@linutronix.de Signed-off-by: Ingo Molnar --- arch/x86/kernel/idt.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/arch/x86/kernel/idt.c b/arch/x86/kernel/idt.c index 70ca248..ae6fc12 100644 --- a/arch/x86/kernel/idt.c +++ b/arch/x86/kernel/idt.c @@ -5,8 +5,49 @@ */ #include +#include +#include #include +struct idt_data { + unsigned int vector; + unsigned int segment; + struct idt_bits bits; + const void *addr; +}; + +#define DPL0 0x0 +#define DPL3 0x3 + +#define DEFAULT_STACK 0 + +#define G(_vector, _addr, _ist, _type, _dpl, _segment) \ + { \ + .vector = _vector, \ + .bits.ist = _ist, \ + .bits.type = _type, \ + .bits.dpl = _dpl, \ + .bits.p = 1, \ + .addr = _addr, \ + .segment = _segment, \ + } + +/* Interrupt gate */ +#define INTG(_vector, _addr) \ + G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL0, __KERNEL_CS) + +/* System interrupt gate */ +#define SYSG(_vector, _addr) \ + G(_vector, _addr, DEFAULT_STACK, GATE_INTERRUPT, DPL3, __KERNEL_CS) + +/* Interrupt gate with interrupt stack */ +#define ISTG(_vector, _addr, _ist) \ + G(_vector, _addr, _ist, GATE_INTERRUPT, DPL0, __KERNEL_CS) + +/* Task gate */ +#define TSKG(_vector, _gdt) \ + G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3) + /* Must be page-aligned because the real IDT is used in a fixmap. */ gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss; @@ -25,6 +66,32 @@ const struct desc_ptr debug_idt_descr = { }; #endif +static inline void idt_init_desc(gate_desc *gate, const struct idt_data *d) +{ + unsigned long addr = (unsigned long) d->addr; + + gate->offset_low = (u16) addr; + gate->segment = (u16) d->segment; + gate->bits = d->bits; + gate->offset_middle = (u16) (addr >> 16); +#ifdef CONFIG_X86_64 + gate->offset_high = (u32) (addr >> 32); + gate->reserved = 0; +#endif +} + +static __init void +idt_setup_from_table(gate_desc *idt, const struct idt_data *t, int size) +{ + gate_desc desc; + + for (; size > 0; t++, size--) { + idt_init_desc(&desc, t); + set_bit(t->vector, used_vectors); + write_idt_entry(idt, t->vector, &desc); + } +} + /** * idt_setup_early_handler - Initializes the idt table with early handlers */