x86/idt: Cleanups and consolidation
cover x86/idt: Cleanups and consolidation
IDT functionality is spread out to places which results in way too many globals.
This series cleans that up, fixes comments and a few other oddities which I noticed while working on that code.
Thanks,
tglx
--- include/asm/desc.h | 47 -------------------- kernel/cpu/common.c | 17 ------- kernel/idt.c | 120 +++++++++++++++++++++++++++++++++++++--------------- kernel/traps.c | 11 ---- 4 files changed, 88 insertions(+), 107 deletions(-)
PATCH 1/5 x86/idt: Mark init only functions __init
Since 8175cfbbbfcb ("x86/idt: Remove update_intr_gate()") set_intr_gate() and idt_setup_from_table() are only called from __init functions. Mark them as well.
--- arch/x86/kernel/idt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/idt.c +2 -2
@@ -217,7 +217,7 @@ static inline void idt_init_desc(gate_de#endif } -static void +static __init void idt_setup_from_table (gate_desc *idt,const struct idt_data *t,int size,bool sys) {gate_desc desc;
@@ -230,7 +230,7 @@ idt_setup_from_table(gate_desc *idt, con } } -static void set_intr_gate (unsigned int n,const void *addr) +static __init void set_intr_gate (unsigned int n,const void *addr) {struct idt_data data;
[tip: x86/entry] x86/idt: Mark init only functions __init
The following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: f841aea13b3ba6d7ad19b1d0744593e2d2448d2f Gitweb: https://git.kernel.org/tip/f841aea13b3ba6d7ad19b1d0744593e2d2448d2f Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 28 May 2020 16:53:16 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sat, 30 May 2020 11:50:11 +02:00
x86/idt: Mark init only functions __init
Since 8175cfbbbfcb ("x86/idt: Remove update_intr_gate()") set_intr_gate() and idt_setup_from_table() are only called from __init functions. Mark them as well.
--- arch/x86/kernel/idt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/idt.c +2 -2
@@ -197,7 +197,7 @@ static inline void idt_init_desc(gate_desc *gate, const struct idt_data *d)#endif } -static void +static __init void idt_setup_from_table (gate_desc *idt,const struct idt_data *t,int size,bool sys) {gate_desc desc;
@@ -210,7 +210,7 @@ idt_setup_from_table(gate_desc *idt, const struct idt_data *t, int size, bool sy } } -static void set_intr_gate (unsigned int n,const void *addr) +static __init void set_intr_gate (unsigned int n,const void *addr) {struct idt_data data;
PATCH 2/5 x86/idt: Add comments about early #PF handling
In reply to Thomas GleixnerThe difference between 32 and 64 bit vs. early #PF handling is not documented. Replace the FIXME at idt_setup_early_pf() with proper comments.
--- arch/x86/kernel/idt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/x86/kernel/idt.c +8 -2
@@ -61,7 +61,11 @@ static bool idt_setup_done __initdata;static const __initconst struct idt_data early_idts[] = {INTG (X86_TRAP_DB , asm_exc_debug),SYSG (X86_TRAP_BP , asm_exc_int3), + #ifdef CONFIG_X86_32 +/* +* Not possible on 64-bit. See idt_setup_early_pf() for details. +*/ INTG (X86_TRAP_PF , asm_exc_page_fault), #endif };
@@ -276,8 +280,10 @@ void __init idt_setup_traps(void)* cpu_init() is invoked and sets up TSS. The IST variant is installed * after that. * -* FIXME: Why is 32bit and 64bit installing the PF handler at different -* places in the early setup code? +* Note, that X86_64 cannot install the real #PF handler in +* idt_setup_early_traps() because the memory intialization needs the #PF +* handler from the early_idt_handler_array to initialize the early page +* tables. */ void __init idt_setup_early_pf (void ) {
Peter Zijlstra
maintainerRe: [patch 2/5] x86/idt: Add comments about early #PF handling
Quoted 23 lines · Thomas Gleixner
The difference between 32 and 64 bit vs. early #PF handling is not documented. Replace the FIXME at
idt_setup_early_pf()with proper comments.Signed-off-by Thomas Gleixner <[email protected]>--- arch/x86/kernel/idt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)arch/x86/kernel/idt.c +4
-0@@ -61,7 +61,11 @@ static bool idt_setup_done __initdata;static const __initconst struct idt_data early_idts[] = {INTG (X86_TRAP_DB , asm_exc_debug),SYSG (X86_TRAP_BP , asm_exc_int3), + #ifdef CONFIG_X86_32 +/* +* Not possible on 64-bit. See idt_setup_early_pf() for details. +*/ INTG (X86_TRAP_PF , asm_exc_page_fault), #endif };
arch/x86/kernel/idt.c void __init idt_setup_traps(void) · line 286
Quoted 9 lines
arch/x86/kernel/idt.c +4
-2@@ -276,8 +280,10 @@ void __init idt_setup_traps(void)* cpu_init() is invoked and sets up TSS. The IST variant is installed * after that. * -* FIXME: Why is 32bit and 64bit installing the PF handler at different -* places in the early setup code? +* Note, that X86_64 cannot install the real #PF handler in +* idt_setup_early_traps() because the memory intialization needs the #PF +* handler from the early_idt_handler_array to initialize the early page +* tables.
+ "See early_make_pgtables()" ?
I had to frob around in head_64.S to find wth that early handler actually did.
Quoted 4 lines
arch/x86/kernel/idt.c +0
-0*/ void __init idt_setup_early_pf (void ) {
Re: [patch 2/5] x86/idt: Add comments about early #PF handling
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Thomas Gleixner
The difference between 32 and 64 bit vs. early #PF handling is not documented. Replace the FIXME at
idt_setup_early_pf()with proper comments.
+ * Note, thatX86_64cannot install the real #PF handler in
+ *idt_setup_early_traps()because the memory intialization needs the #PF
+ * handler from theearly_idt_handler_arrayto initialize the early page
+ * tables.
Quoted 4 lines
+ "See
early_make_pgtables()" ?I had to frob around in
head_64.Sto find wth that early handler actually did.
True.
[tip: x86/entry] x86/idt: Add comments about early #PF handling
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 66d2e706c0cecd09b1f3de4844574d30e5469c28 Gitweb: https://git.kernel.org/tip/66d2e706c0cecd09b1f3de4844574d30e5469c28 Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 28 May 2020 16:53:17 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sat, 30 May 2020 11:50:11 +02:00
x86/idt: Add comments about early #PF handling
The difference between 32 and 64 bit vs. early #PF handling is not documented. Replace the FIXME at idt_setup_early_pf() with proper comments.
--- arch/x86/kernel/idt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/x86/kernel/idt.c +8 -2
@@ -61,7 +61,11 @@ static bool idt_setup_done __initdata;static const __initconst struct idt_data early_idts[] = {INTG (X86_TRAP_DB , asm_exc_debug),SYSG (X86_TRAP_BP , asm_exc_int3), + #ifdef CONFIG_X86_32 +/* +* Not possible on 64-bit. See idt_setup_early_pf() for details. +*/ INTG (X86_TRAP_PF , asm_exc_page_fault), #endif };
@@ -256,8 +260,10 @@ void __init idt_setup_traps(void)* cpu_init() is invoked and sets up TSS. The IST variant is installed * after that. * -* FIXME: Why is 32bit and 64bit installing the PF handler at different -* places in the early setup code? +* Note, that X86_64 cannot install the real #PF handler in +* idt_setup_early_traps() because the memory intialization needs the #PF +* handler from the early_idt_handler_array to initialize the early page +* tables. */ void __init idt_setup_early_pf (void ) {
PATCH 3/5 x86/idt: Use proper constants for table sizes
In reply to Thomas GleixnerUse the actual struct size to calculate the IDT table sizes instead of two different hardcoded values.
--- arch/x86/kernel/idt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/kernel/idt.c +7 -4
@@ -51,6 +51,8 @@ struct idt_data {#define TSKG (_vector, _gdt) \ G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3) +#define IDT_TABLE_SIZE (IDT_ENTRIES * sizeof(gate_desc)) +#define IDT_DEBUG_TABLE_SIZE (16 * sizeof(gate_desc))static bool idt_setup_done__initdata ;
@@ -176,7 +178,7 @@ static const __initconst struct idt_data gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss;struct desc_ptr idt_descr__ro_after_init = { - .size = (IDT_ENTRIES *2 *sizeof (unsigned long )) -1 , + .size =IDT_TABLE_SIZE -1 , .address = (unsigned long ) idt_table, };
@@ -202,7 +204,7 @@ static const __initconst struct idt_data* stack set to DEFAULT_STACK (0). Required for NMI trap handling. */ const struct desc_ptr debug_idt_descr = { - .size =IDT_ENTRIES *16 -1 , + .size =IDT_DEBUG_TABLE_SIZE -1 , .address = (unsigned long ) debug_idt_table, };#endif
@@ -304,9 +306,10 @@ void __init idt_setup_ist_traps(void)*/ void __init idt_setup_debugidt_traps (void ) { -memcpy (&debug_idt_table, &idt_table,IDT_ENTRIES *16 ); +memcpy (&debug_idt_table, &idt_table,IDT_DEBUG_TABLE_SIZE ); -idt_setup_from_table (debug_idt_table, dbg_idts,ARRAY_SIZE (dbg_idts), false); +idt_setup_from_table (debug_idt_table, dbg_idts,ARRAY_SIZE (dbg_idts), + false); }#endif
[tip: x86/entry] x86/idt: Use proper constants for table size
The following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: ab46346736ed50ed90f4bfb854f4bec61fecee9e Gitweb: https://git.kernel.org/tip/ab46346736ed50ed90f4bfb854f4bec61fecee9e Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 28 May 2020 16:53:18 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sat, 30 May 2020 11:50:12 +02:00
x86/idt: Use proper constants for table size
Use the actual struct size to calculate the IDT table size instead of hardcoded values.
--- arch/x86/kernel/idt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/idt.c +2 -1
@@ -51,6 +51,7 @@ struct idt_data {#define TSKG (_vector, _gdt) \ G(_vector, NULL, DEFAULT_STACK, GATE_TASK, DPL0, _gdt << 3) +#define IDT_TABLE_SIZE (IDT_ENTRIES * sizeof(gate_desc))static bool idt_setup_done__initdata ;
@@ -168,7 +169,7 @@ static const __initconst struct idt_data early_pf_idts[] = { gate_desc idt_table[IDT_ENTRIES] __page_aligned_bss;struct desc_ptr idt_descr__ro_after_init = { - .size = (IDT_ENTRIES *2 *sizeof (unsigned long )) -1 , + .size =IDT_TABLE_SIZE -1 , .address = (unsigned long ) idt_table, };
PATCH 4/5 x86/idt: Cleanup trap_init()
In reply to Thomas GleixnerNo point in having all the IDT cruft in trap_init(). Move it into the IDT code, get rid of the extra global function and fixup the comments.
--- arch/x86/include/asm/desc.h | 2 -- arch/x86/kernel/idt.c | 26 +++++++++++++++++++------- arch/x86/kernel/traps.c | 11 ----------- 3 files changed, 19 insertions(+), 20 deletions(-)
arch/x86/include/asm/desc.h +0 -2
@@ -438,11 +438,9 @@ extern void idt_setup_apic_and_irq_gates#ifdef CONFIG_X86_64 extern void idt_setup_early_pf (void );extern void idt_setup_ist_traps (void ); -extern void idt_setup_debugidt_traps (void );#else static inline void idt_setup_early_pf (void ) { }static inline void idt_setup_ist_traps (void ) { } -static inline void idt_setup_debugidt_traps (void ) { }#endif extern void idt_invalidate (void *addr);
arch/x86/kernel/idt.c +19 -7
@@ -4,6 +4,7 @@*/ #include <linux/interrupt.h> +#include <asm/cpu_entry_area.h> #include <asm/traps.h> #include <asm/proto.h> #include <asm/desc.h>
@@ -299,20 +300,27 @@ void __init idt_setup_early_pf(void)void __init idt_setup_ist_traps (void ) {idt_setup_from_table (idt_table, ist_idts,ARRAY_SIZE (ist_idts), true); -} -/** -* idt_setup_debugidt_traps - Initialize the debug idt table with debug traps -*/ -void __init idt_setup_debugidt_traps (void ) -{ +/* All traps set up: Initialize the debug IDT table. */ memcpy (&debug_idt_table, &idt_table,IDT_DEBUG_TABLE_SIZE ); -idt_setup_from_table (debug_idt_table, dbg_idts,ARRAY_SIZE (dbg_idts), false); }#endif +static void idt_map_in_cea (void ) +{ +/* +* Set the IDT descriptor to a fixed read-only location in the cpu +* entry area, so that the "sidt" instruction will not leak the +* location of the kernel, and to defend the IDT against arbitrary +* memory write vulnerabilities. +*/ +cea_set_pte (CPU_ENTRY_AREA_RO_IDT_VADDR ,__pa_symbol (idt_table), +PAGE_KERNEL_RO ); + idt_descr.address =CPU_ENTRY_AREA_RO_IDT ; +} +/** * idt_setup_apic_and_irq_gates - Setup APIC/SMP and normal interrupt gates */
@@ -339,6 +347,10 @@ void __init idt_setup_apic_and_irq_gates set_intr_gate(i, entry); }#endif +/* Map IDT into CPU entry area and reload it. */ +idt_map_in_cea (); +load_current_idt (); + idt_setup_done = true; }
arch/x86/kernel/traps.c +0 -11
@@ -1077,20 +1077,9 @@ void __init trap_init(void)idt_setup_traps ();/* -* Set the IDT descriptor to a fixed read-only location, so that the -* "sidt" instruction will not leak the location of the kernel, and -* to defend the IDT against arbitrary memory write vulnerabilities. -* It will be reloaded in cpu_init() */ -cea_set_pte (CPU_ENTRY_AREA_RO_IDT_VADDR ,__pa_symbol (idt_table), -PAGE_KERNEL_RO ); - idt_descr.address =CPU_ENTRY_AREA_RO_IDT ; - -/* * Should be a barrier for any external CPU state: */ cpu_init ();idt_setup_ist_traps (); - -idt_setup_debugidt_traps (); }
[tip: x86/entry] x86/idt: Cleanup trap_init()
The following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 88dbb6cfb9be0eaaa95c15a4b6d7f49044a2e1b7 Gitweb: https://git.kernel.org/tip/88dbb6cfb9be0eaaa95c15a4b6d7f49044a2e1b7 Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 28 May 2020 16:53:19 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sat, 30 May 2020 11:50:12 +02:00
x86/idt: Cleanup trap_init()
No point in having all the IDT cruft in trap_init(). Move it into the IDT code and fixup the comments.
--- arch/x86/kernel/idt.c | 18 ++++++++++++++++++ arch/x86/kernel/traps.c | 9 --------- 2 files changed, 18 insertions(+), 9 deletions(-)
arch/x86/kernel/idt.c +18 -0
@@ -4,6 +4,7 @@*/ #include <linux/interrupt.h> +#include <asm/cpu_entry_area.h> #include <asm/traps.h> #include <asm/proto.h> #include <asm/desc.h>
@@ -281,6 +282,19 @@ void __init idt_setup_ist_traps(void) }#endif +static void __init idt_map_in_cea (void ) +{ +/* +* Set the IDT descriptor to a fixed read-only location in the cpu +* entry area, so that the "sidt" instruction will not leak the +* location of the kernel, and to defend the IDT against arbitrary +* memory write vulnerabilities. +*/ +cea_set_pte (CPU_ENTRY_AREA_RO_IDT_VADDR ,__pa_symbol (idt_table), +PAGE_KERNEL_RO ); + idt_descr.address =CPU_ENTRY_AREA_RO_IDT ; +} +/** * idt_setup_apic_and_irq_gates - Setup APIC/SMP and normal interrupt gates */
@@ -307,6 +321,10 @@ void __init idt_setup_apic_and_irq_gates(void) set_intr_gate(i, entry); }#endif +/* Map IDT into CPU entry area and reload it. */ +idt_map_in_cea (); +load_idt (&idt_descr); + idt_setup_done = true; }
arch/x86/kernel/traps.c +0 -9
@@ -1056,15 +1056,6 @@ void __init trap_init(void)idt_setup_traps ();/* -* Set the IDT descriptor to a fixed read-only location, so that the -* "sidt" instruction will not leak the location of the kernel, and -* to defend the IDT against arbitrary memory write vulnerabilities. -* It will be reloaded in cpu_init() */ -cea_set_pte (CPU_ENTRY_AREA_RO_IDT_VADDR ,__pa_symbol (idt_table), -PAGE_KERNEL_RO ); - idt_descr.address =CPU_ENTRY_AREA_RO_IDT ; - -/* * Should be a barrier for any external CPU state: */ cpu_init ();
PATCH 5/5 x86/idt: Consolidate idt functionality
In reply to Thomas Gleixner - Move load_current_idt() out of line and replace the hideous comment with a lockdep assert.
- Move debug IDT cruft into the IDT code and simplify it. This makes debug_idt_ctr static and removes one function call.
- Move the idt descriptor table definition to spare the extra #ifdef sections and make it static.
--- arch/x86/include/asm/desc.h | 45 ------------------------- arch/x86/kernel/cpu/common.c | 17 --------- arch/x86/kernel/idt.c | 75 ++++++++++++++++++++++++++++++------------- 3 files changed, 55 insertions(+), 82 deletions(-)
arch/x86/include/asm/desc.h +1 -44
@@ -40,11 +40,6 @@ static inline void fill_ldt(struct desc_ desc->l =0 ; } -extern struct desc_ptr idt_descr; -extern gate_desc idt_table[]; -extern const struct desc_ptr debug_idt_descr; -extern gate_desc debug_idt_table[]; -struct gdt_page {struct desc_struct gdt[GDT_ENTRIES ]; } __attribute__((aligned (PAGE_SIZE )));
@@ -390,45 +385,7 @@ void alloc_intr_gate(unsigned int n, conextern unsigned long system_vectors[]; -#ifdef CONFIG_X86_64 -DECLARE_PER_CPU (u32, debug_idt_ctr); -static __always_inline bool is_debug_idt_enabled(void) -{ -if (this_cpu_read (debug_idt_ctr)) -return true; - -return false; -} - -static __always_inline void load_debug_idt(void) -{ -load_idt ((const struct desc_ptr *)&debug_idt_descr); -} -#else -static inline bool is_debug_idt_enabled (void ) -{ -return false; -} - -static inline void load_debug_idt (void ) -{ -} -#endif - -/* -* The load_current_idt() must be called with interrupts disabled -* to avoid races. That way the IDT will always be set back to the expected -* descriptor. It's also called when a CPU is being initialized, and -* that doesn't need to disable interrupts, as nothing should be -* bothering the CPU then. -*/ -static __always_inline void load_current_idt(void) -{ -if (is_debug_idt_enabled ()) -load_debug_idt (); -else -load_idt ((const struct desc_ptr *)&idt_descr); -} +void load_current_idt (void );extern void idt_setup_early_handler (void );extern void idt_setup_early_traps (void );
arch/x86/kernel/cpu/common.c +0 -17
@@ -1689,23 +1689,6 @@ void syscall_init(void) X86_EFLAGS_IOPL|X86_EFLAGS_AC|X86_EFLAGS_NT); } -DEFINE_PER_CPU (int, debug_stack_usage); -DEFINE_PER_CPU (u32, debug_idt_ctr); - -noinstr void debug_stack_set_zero(void) -{ -this_cpu_inc (debug_idt_ctr); -load_current_idt (); -} - -noinstr void debug_stack_reset(void) -{ -if (WARN_ON (!this_cpu_read (debug_idt_ctr))) -return ; -if (this_cpu_dec_return (debug_idt_ctr) ==0 ) -load_current_idt (); -} -#else /* CONFIG_X86_64 */ DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
arch/x86/kernel/idt.c +54 -21
109 lines not on this page · raw message
Peter Zijlstra
maintainerRe: [patch 5/5] x86/idt: Consolidate idt functionality
Quoted 14 lines · Thomas Gleixner
arch/x86/include/asm/desc.h +0
-14-#ifdef CONFIG_X86_64 -DECLARE_PER_CPU (u32, debug_idt_ctr); -static __always_inline bool is_debug_idt_enabled(void) -{ -if (this_cpu_read (debug_idt_ctr)) -return true; - -return false; -} - -static __always_inline void load_debug_idt(void) -{ -load_idt ((const struct desc_ptr *)&debug_idt_descr); -}
arch/x86/include/asm/desc.h void alloc_intr_gate(unsigned int n, con · line 416
Quoted 10 lines
arch/x86/include/asm/desc.h +0
-10-#else -static inline bool is_debug_idt_enabled (void ) -{ -return false; -} - -static inline void load_debug_idt (void ) -{ -} -#endif
I have a patch that does this too; except it doesn't put it back. I like that one better :-)
kbuild test robot
build botRe: [patch 5/5] x86/idt: Consolidate idt functionality
In reply to Thomas GleixnerI love your patch! Yet something to improve:
Hi Thomas,
I love your patch! Yet something to improve:
[auto build test ERROR on tip/auto-latest]
[cannot apply to linus/master tip/x86/core linux/master v5.7-rc7 next-20200528] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Thomas-Gleixner/x86-idt-Cleanups-and-consolidation/20200528-230255 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 4e052965f46b6fd9641d79bf10208eac2631475f config: i386-randconfig-m021-20200528 (attached as .config) compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
arch/x86/mm/fault.c: In function 'is_f00f_bug':
>> arch/x86/mm/fault.c:567:19: error: 'idt_descr' undeclared (first use in this function); did you mean 'ldt_desc'? 567 | nr = (address - idt_descr.address) >> 3; | ^~~~~~~~~ | ldt_desc
arch/x86/mm/fault.c:567:19: note: each undeclared identifier is reported only once for each function it appears in
vim +567 arch/x86/mm/fault.c
35f3266ffbee7f arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 557
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 558 static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 559 {
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 560 #ifdef CONFIG_X86_F00F_BUG
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 561 unsigned long nr;
2d4a71676f4d89 arch/x86/mm/fault.c Ingo Molnar 2009-02-20 562
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 563 /*
2d4a71676f4d89 arch/x86/mm/fault.c Ingo Molnar 2009-02-20 564 * Pentium F0 0F C7 C8 bug workaround:
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 565 */
e2604b49e8a882 arch/x86/mm/fault.c Borislav Petkov 2013-03-20 566 if (boot_cpu_has_bug(X86_BUG_F00F)) {
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 @567 nr = (address - idt_descr.address) >> 3;
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 568
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 569 if (nr == 6) {
a99471a459d4c8 arch/x86/mm/fault.c Thomas Gleixner 2020-02-25 570 handle_invalid_op(regs);
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 571 return 1;
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 572 }
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 573 }
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 574 #endif
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 575 return 0;
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 576 }
29caf2f98cdb26 arch/x86/mm/fault_64.c Harvey Harrison 2008-01-30 577 :::::: The code at line 567 was first introduced by commit
:::::: 29caf2f98cdb266dffb50dfd412f951e8d46f719 x86: add is_f00f_bug helper to fault_32|64.c
:::::: TO: Harvey Harrison <[email protected]> :::::: CC: Ingo Molnar <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[tip: x86/entry] x86/idt: Consolidate idt functionality
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 5980d208e5ef28455e9e8b08f6250b443a2f0893 Gitweb: https://git.kernel.org/tip/5980d208e5ef28455e9e8b08f6250b443a2f0893 Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 28 May 2020 16:53:20 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sat, 30 May 2020 11:50:13 +02:00
x86/idt: Consolidate idt functionality
- Move load_current_idt() out of line and replace the hideous comment with a lockdep assert. This allows to make idt_table and idt_descr static.
- Mark idt_table read only after the IDT initialization is complete.
- Shuffle code around to consolidate the #ifdef sections into one.
- Adapt the F00F bug code.
--- arch/x86/include/asm/desc.h | 17 +--------- arch/x86/kernel/idt.c | 63 +++++++++++++++++++++--------------- arch/x86/mm/fault.c | 16 ++------- 3 files changed, 44 insertions(+), 52 deletions(-)
arch/x86/include/asm/desc.h +2 -15
@@ -40,9 +40,6 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in desc->l =0 ; } -extern struct desc_ptr idt_descr; -extern gate_desc idt_table[]; -struct gdt_page {struct desc_struct gdt[GDT_ENTRIES ]; } __attribute__((aligned (PAGE_SIZE )));
@@ -388,22 +385,12 @@ void alloc_intr_gate(unsigned int n, const void *addr);extern unsigned long system_vectors[]; -/* -* The load_current_idt() must be called with interrupts disabled -* to avoid races. That way the IDT will always be set back to the expected -* descriptor. It's also called when a CPU is being initialized, and -* that doesn't need to disable interrupts, as nothing should be -* bothering the CPU then. -*/ -static __always_inline void load_current_idt(void) -{ -load_idt ((const struct desc_ptr *)&idt_descr); -} - +extern void load_current_idt (void );extern void idt_setup_early_handler (void );extern void idt_setup_early_traps (void );extern void idt_setup_traps (void );extern void idt_setup_apic_and_irq_gates (void ); +extern bool idt_is_f00f_address (unsigned long address);#ifdef CONFIG_X86_64 extern void idt_setup_early_pf (void );
arch/x86/kernel/idt.c +38 -25
93 lines not on this page · raw message
arch/x86/mm/fault.c +4 -12
@@ -555,21 +555,13 @@ static int is_errata100(struct pt_regs *regs, unsigned long address)return 0 ; } +/* Pentium F0 0F C7 C8 bug workaround: */ static int is_f00f_bug (struct pt_regs *regs,unsigned long address) {#ifdef CONFIG_X86_F00F_BUG -unsigned long nr; - -/* -* Pentium F0 0F C7 C8 bug workaround: -*/ -if (boot_cpu_has_bug (X86_BUG_F00F )) { - nr = (address - idt_descr.address) >>3 ; - -if (nr ==6 ) { -handle_invalid_op (regs); -return 1 ; - } +if (boot_cpu_has_bug (X86_BUG_F00F ) &&idt_is_f00f_address (address)) { +handle_invalid_op (regs); +return 1 ; }#endif return 0 ;
[tip: x86/entry] x86/idt: Consolidate idt functionality
In reply to Thomas GleixnerThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: 5f98f9eee4d41e012f6a768cec1bd6a143572c09 Gitweb: https://git.kernel.org/tip/5f98f9eee4d41e012f6a768cec1bd6a143572c09 Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 28 May 2020 16:53:20 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 01 Jun 2020 14:40:14 +02:00
x86/idt: Consolidate idt functionality
- Move load_current_idt() out of line and replace the hideous comment with a lockdep assert. This allows to make idt_table and idt_descr static.
- Mark idt_table read only after the IDT initialization is complete.
- Shuffle code around to consolidate the #ifdef sections into one.
- Adapt the F00F bug code.
--- arch/x86/include/asm/desc.h | 17 +--------- arch/x86/kernel/idt.c | 63 +++++++++++++++++++++--------------- arch/x86/mm/fault.c | 16 ++------- 3 files changed, 44 insertions(+), 52 deletions(-)
arch/x86/include/asm/desc.h +2 -15
@@ -40,9 +40,6 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in desc->l =0 ; } -extern struct desc_ptr idt_descr; -extern gate_desc idt_table[]; -struct gdt_page {struct desc_struct gdt[GDT_ENTRIES ]; } __attribute__((aligned (PAGE_SIZE )));
@@ -388,22 +385,12 @@ void alloc_intr_gate(unsigned int n, const void *addr);extern unsigned long system_vectors[]; -/* -* The load_current_idt() must be called with interrupts disabled -* to avoid races. That way the IDT will always be set back to the expected -* descriptor. It's also called when a CPU is being initialized, and -* that doesn't need to disable interrupts, as nothing should be -* bothering the CPU then. -*/ -static __always_inline void load_current_idt(void) -{ -load_idt ((const struct desc_ptr *)&idt_descr); -} - +extern void load_current_idt (void );extern void idt_setup_early_handler (void );extern void idt_setup_early_traps (void );extern void idt_setup_traps (void );extern void idt_setup_apic_and_irq_gates (void ); +extern bool idt_is_f00f_address (unsigned long address);#ifdef CONFIG_X86_64 extern void idt_setup_early_pf (void );
arch/x86/kernel/idt.c +38 -25
93 lines not on this page · raw message
arch/x86/mm/fault.c +4 -12
@@ -555,21 +555,13 @@ static int is_errata100(struct pt_regs *regs, unsigned long address)return 0 ; } +/* Pentium F0 0F C7 C8 bug workaround: */ static int is_f00f_bug (struct pt_regs *regs,unsigned long address) {#ifdef CONFIG_X86_F00F_BUG -unsigned long nr; - -/* -* Pentium F0 0F C7 C8 bug workaround: -*/ -if (boot_cpu_has_bug (X86_BUG_F00F )) { - nr = (address - idt_descr.address) >>3 ; - -if (nr ==6 ) { -handle_invalid_op (regs); -return 1 ; - } +if (boot_cpu_has_bug (X86_BUG_F00F ) &&idt_is_f00f_address (address)) { +handle_invalid_op (regs); +return 1 ; }#endif return 0 ;