x86: Merge fpu and simd exception handlers (v2)
cover x86: Merge fpu and simd exception handlers (v2)
This patch series merges the fpu and simd exception handlers into one function. The only difference is where the status bits are read from. This also applies a fix for multiple simd exceptions that was already done for fpu.
v2:
Changed the cache flush denied handler to simply redirect to general protection fault.
Squashed patch to remove die_if_kernel() into patch #1.
[PATCH 1/4] x86-32: Rework cache flush denied handler [PATCH 2/4] x86: Merge simd_math_error() into math_error() [PATCH 3/4] x86: Merge kernel_math_error() into math_error() [PATCH 4/4] x86-32: Don't set ignore_fpu_irq in simd exception
arch/x86/Kconfig.cpu | 4 + arch/x86/include/asm/traps.h | 2 +- arch/x86/kernel/entry_32.S | 19 +++++ arch/x86/kernel/irqinit.c | 2 +- arch/x86/kernel/traps.c | 173 ++++++++++++------------------------------ 5 files changed, 73 insertions(+), 127 deletions(-)
PATCH 1/4 x86-32: Rework cache flush denied handler
The cache flush denied error is an erratum on some AMD 486 clones. If an invd instruction is executed in userspace, the processor calls exception 19 (13 hex) instead of #GP (13 decimal). On cpus where XMM is not supported, redirect exception 19 to do_general_protection(). Also, remove die_if_kernel(), since this was the last user.
--- arch/x86/Kconfig.cpu | 4 ++++ arch/x86/kernel/entry_32.S | 19 +++++++++++++++++++ arch/x86/kernel/traps.c | 31 +++---------------------------- 3 files changed, 26 insertions(+), 28 deletions(-)
arch/x86/Kconfig.cpu +4 -0
@@ -338,6 +338,10 @@ config X86_F00F_BUG def_bool y depends on M586MMX || M586TSC || M586 || M486 || M386 +config X86_INVD_BUG + def_bool y + depends on M486 || M386 + config X86_WP_WORKS_OK def_bool y depends on !M386
arch/x86/kernel/entry_32.S +19 -0
@@ -53,6 +53,7 @@ #include <asm/processor-flags.h> #include <asm/ftrace.h> #include <asm/irq_vectors.h> +#include <asm/cpufeature.h> /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ #include <linux/elf-em.h>
@@ -905,7 +906,25 @@ ENTRY(simd_coprocessor_error) RING0_INT_FRAME pushl $0 CFI_ADJUST_CFA_OFFSET 4 +#ifdef CONFIG_X86_INVD_BUG + /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ +661: pushl $do_general_protection +662: +.section .altinstructions,"a" + .balign 4 + .long 661b + .long 663f + .byte X86_FEATURE_XMM + .byte 662b-661b + .byte 664f-663f +.previous +.section .altinstr_replacement,"ax" +663: pushl $do_simd_coprocessor_error +664: +.previous +#else pushl $do_simd_coprocessor_error +#endif CFI_ADJUST_CFA_OFFSET 4 jmp error_code CFI_ENDPROC
arch/x86/kernel/traps.c +3 -28
@@ -108,15 +108,6 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)dec_preempt_count (); } -#ifdef CONFIG_X86_32 -static inline void -die_if_kernel (const char *str,struct pt_regs *regs,long err) -{ -if (!user_mode_vm (regs)) -die (str, regs, err); -} -#endif -static void __kprobes do_trap (int trapnr,int signr,char *str,struct pt_regs *regs,long error_code,siginfo_t *info)
@@ -726,30 +717,14 @@ do_simd_coprocessor_error(struct pt_regs *regs, long error_code)conditional_sti (regs);#ifdef CONFIG_X86_32 -if (cpu_has_xmm) { -/* Handle SIMD FPU exceptions on PIII+ processors. */ - ignore_fpu_irq =1 ; -simd_math_error ((void __user *)regs->ip); -return ; - } -/* -* Handle strange cache flush from user space exception -* in all other cases. This is undocumented behaviour. -*/ -if (regs->flags &X86_VM_MASK ) { -handle_vm86_fault ((struct kernel_vm86_regs *)regs, error_code); -return ; - } - current->thread.trap_no =19 ; - current->thread.error_code = error_code; -die_if_kernel ("cache flush denied" , regs, error_code); -force_sig (SIGSEGV , current); + ignore_fpu_irq =1 ;#else if (!user_mode (regs) &&kernel_math_error (regs,"kernel simd math error" ,19 ))return ; -simd_math_error ((void __user *)regs->ip);#endif + +simd_math_error ((void __user *)regs->ip); }dotraplinkage void
Signature · 1 line
1.6.6.1
[tip:x86/fpu] x86-32: Rework cache flush denied handler
Commit-ID: 40d2e76315da38993129090dc5d56377e573c312 Gitweb: http://git.kernel.org/tip/40d2e76315da38993129090dc5d56377e573c312 Author: Brian Gerst <[email protected]> AuthorDate: Sun, 21 Mar 2010 09:00:43 -0400 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 3 May 2010 13:39:26 -0700
x86-32: Rework cache flush denied handler
The cache flush denied error is an erratum on some AMD 486 clones. If an invd instruction is executed in userspace, the processor calls exception 19 (13 hex) instead of #GP (13 decimal). On cpus where XMM is not supported, redirect exception 19 to do_general_protection(). Also, remove die_if_kernel(), since this was the last user.
LKML-Reference: <[email protected]>
--- arch/x86/Kconfig.cpu | 4 ++++ arch/x86/kernel/entry_32.S | 19 +++++++++++++++++++ arch/x86/kernel/traps.c | 31 +++---------------------------- 3 files changed, 26 insertions(+), 28 deletions(-)
arch/x86/Kconfig.cpu +4 -0
@@ -338,6 +338,10 @@ config X86_F00F_BUG def_bool y depends on M586MMX || M586TSC || M586 || M486 || M386 +config X86_INVD_BUG + def_bool y + depends on M486 || M386 + config X86_WP_WORKS_OK def_bool y depends on !M386
arch/x86/kernel/entry_32.S +19 -0
@@ -53,6 +53,7 @@ #include <asm/processor-flags.h> #include <asm/ftrace.h> #include <asm/irq_vectors.h> +#include <asm/cpufeature.h> /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ #include <linux/elf-em.h>
@@ -905,7 +906,25 @@ ENTRY(simd_coprocessor_error) RING0_INT_FRAME pushl $0 CFI_ADJUST_CFA_OFFSET 4 +#ifdef CONFIG_X86_INVD_BUG + /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ +661: pushl $do_general_protection +662: +.section .altinstructions,"a" + .balign 4 + .long 661b + .long 663f + .byte X86_FEATURE_XMM + .byte 662b-661b + .byte 664f-663f +.previous +.section .altinstr_replacement,"ax" +663: pushl $do_simd_coprocessor_error +664: +.previous +#else pushl $do_simd_coprocessor_error +#endif CFI_ADJUST_CFA_OFFSET 4 jmp error_code CFI_ENDPROC
arch/x86/kernel/traps.c +3 -28
@@ -108,15 +108,6 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)dec_preempt_count (); } -#ifdef CONFIG_X86_32 -static inline void -die_if_kernel (const char *str,struct pt_regs *regs,long err) -{ -if (!user_mode_vm (regs)) -die (str, regs, err); -} -#endif -static void __kprobes do_trap (int trapnr,int signr,char *str,struct pt_regs *regs,long error_code,siginfo_t *info)
@@ -729,30 +720,14 @@ do_simd_coprocessor_error(struct pt_regs *regs, long error_code)conditional_sti (regs);#ifdef CONFIG_X86_32 -if (cpu_has_xmm) { -/* Handle SIMD FPU exceptions on PIII+ processors. */ - ignore_fpu_irq =1 ; -simd_math_error ((void __user *)regs->ip); -return ; - } -/* -* Handle strange cache flush from user space exception -* in all other cases. This is undocumented behaviour. -*/ -if (regs->flags &X86_VM_MASK ) { -handle_vm86_fault ((struct kernel_vm86_regs *)regs, error_code); -return ; - } - current->thread.trap_no =19 ; - current->thread.error_code = error_code; -die_if_kernel ("cache flush denied" , regs, error_code); -force_sig (SIGSEGV , current); + ignore_fpu_irq =1 ;#else if (!user_mode (regs) &&kernel_math_error (regs,"kernel simd math error" ,19 ))return ; -simd_math_error ((void __user *)regs->ip);#endif + +simd_math_error ((void __user *)regs->ip); }dotraplinkage void
PATCH 2/4 x86: Merge simd_math_error() into math_error()
In reply to Brian GerstThe only difference between FPU and SIMD exceptions is where the status bits are read from (cwd/swd vs. mxcsr). This also fixes the discrepency introduced by commit adf77bac, which fixed FPU but not SIMD.
--- arch/x86/include/asm/traps.h | 2 +- arch/x86/kernel/irqinit.c | 2 +- arch/x86/kernel/traps.c | 100 +++++++++++++---------------------------- 3 files changed, 34 insertions(+), 70 deletions(-)
arch/x86/include/asm/traps.h +1 -1
@@ -79,7 +79,7 @@ static inline int get_si_code(unsigned long condition)extern int panic_on_unrecovered_nmi; -void math_error (void __user *); +void math_error (struct pt_regs *,int ,int );void math_emulate (struct math_emu_info *);#ifndef CONFIG_X86_32 asmlinkage void smp_thermal_interrupt(void);
arch/x86/kernel/irqinit.c +1 -1
@@ -61,7 +61,7 @@ static irqreturn_t math_error_irq(int cpl, void *dev_id)outb (0 ,0xF0 );if (ignore_fpu_irq || !boot_cpu_data.hard_math)return IRQ_NONE ; -math_error ((void __user *)get_irq_regs ()->ip); +math_error (get_irq_regs (),0 ,16 );return IRQ_HANDLED ; }
arch/x86/kernel/traps.c +32 -68
130 lines not on this page · raw message
Signature · 1 line
1.6.6.1
[tip:x86/fpu] x86: Merge simd_math_error() into math_error()
Commit-ID: 9b6dba9e0798325dab427b9d60c61630ccc39b28 Gitweb: http://git.kernel.org/tip/9b6dba9e0798325dab427b9d60c61630ccc39b28 Author: Brian Gerst <[email protected]> AuthorDate: Sun, 21 Mar 2010 09:00:44 -0400 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 3 May 2010 13:39:29 -0700
x86: Merge simd_math_error() into math_error()
The only difference between FPU and SIMD exceptions is where the status bits are read from (cwd/swd vs. mxcsr). This also fixes the discrepency introduced by commit adf77bac, which fixed FPU but not SIMD.
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/traps.h | 2 +- arch/x86/kernel/irqinit.c | 2 +- arch/x86/kernel/traps.c | 100 +++++++++++++---------------------------- 3 files changed, 34 insertions(+), 70 deletions(-)
arch/x86/include/asm/traps.h +1 -1
@@ -79,7 +79,7 @@ static inline int get_si_code(unsigned long condition)extern int panic_on_unrecovered_nmi; -void math_error (void __user *); +void math_error (struct pt_regs *,int ,int );void math_emulate (struct math_emu_info *);#ifndef CONFIG_X86_32 asmlinkage void smp_thermal_interrupt(void);
arch/x86/kernel/irqinit.c +1 -1
@@ -60,7 +60,7 @@ static irqreturn_t math_error_irq(int cpl, void *dev_id)outb (0 ,0xF0 );if (ignore_fpu_irq || !boot_cpu_data.hard_math)return IRQ_NONE ; -math_error ((void __user *)get_irq_regs ()->ip); +math_error (get_irq_regs (),0 ,16 );return IRQ_HANDLED ; }
arch/x86/kernel/traps.c +32 -68
130 lines not on this page · raw message
PATCH 3/4 x86: Merge kernel_math_error() into math_error()
In reply to Brian GerstClean up the kernel exception handling and make it more similar to the other traps.
--- arch/x86/kernel/traps.c | 44 ++++++++++++++++---------------------------- 1 files changed, 16 insertions(+), 28 deletions(-)
arch/x86/kernel/traps.c +16 -28
@@ -573,20 +573,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)return ; } -#ifdef CONFIG_X86_64 -static int kernel_math_error (struct pt_regs *regs,const char *str,int trapnr) -{ -if (fixup_exception (regs)) -return 1 ; - -notify_die (DIE_GPF , str, regs,0 , trapnr,SIGFPE ); -/* Illegal floating point operation in the kernel */ - current->thread.trap_no = trapnr; -die (str, regs,0 ); -return 0 ; -} -#endif -/* * Note that we play around with the 'TS' bit in an attempt to get * the correct behaviour even in the presence of the asynchronous
@@ -594,14 +580,28 @@ static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)*/ void math_error (struct pt_regs *regs,int error_code,int trapnr) { -struct task_struct *task; +struct task_struct *task = current;siginfo_t info;unsigned short err; +char *str = (trapnr ==16 ) ?"fpu exception" :"simd exception" ; + +if (notify_die (DIE_TRAP , str, regs, error_code, trapnr,SIGFPE ) ==NOTIFY_STOP ) +return ; +conditional_sti (regs); + +if (!user_mode_vm (regs)) + { +if (!fixup_exception (regs)) { + task->thread.error_code = error_code; + task->thread.trap_no = trapnr; +die (str, regs, error_code); + } +return ; + }/* * Save the info for the exception handler and clear the error. */ - task = current;save_init_fpu (task); task->thread.trap_no = trapnr; task->thread.error_code = error_code;
@@ -662,14 +662,8 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr) dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) { -conditional_sti (regs); -#ifdef CONFIG_X86_32 ignore_fpu_irq =1 ; -#else -if (!user_mode (regs) && -kernel_math_error (regs,"kernel x87 math error" ,16 )) -return ;#endif math_error (regs, error_code,16 );
@@ -678,14 +672,8 @@ dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) dotraplinkage voiddo_simd_coprocessor_error (struct pt_regs *regs,long error_code) { -conditional_sti (regs); -#ifdef CONFIG_X86_32 ignore_fpu_irq =1 ; -#else -if (!user_mode (regs) && -kernel_math_error (regs,"kernel simd math error" ,19 )) -return ;#endif math_error (regs, error_code,19 );
Signature · 1 line
1.6.6.1
[tip:x86/fpu] x86: Merge kernel_math_error() into math_error()
Commit-ID: e2e75c915de045f0785387dc32f55e92fab0614c Gitweb: http://git.kernel.org/tip/e2e75c915de045f0785387dc32f55e92fab0614c Author: Brian Gerst <[email protected]> AuthorDate: Sun, 21 Mar 2010 09:00:45 -0400 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 3 May 2010 13:39:31 -0700
x86: Merge kernel_math_error() into math_error()
Clean up the kernel exception handling and make it more similar to the other traps.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/traps.c | 44 ++++++++++++++++---------------------------- 1 files changed, 16 insertions(+), 28 deletions(-)
arch/x86/kernel/traps.c +16 -28
@@ -576,20 +576,6 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)return ; } -#ifdef CONFIG_X86_64 -static int kernel_math_error (struct pt_regs *regs,const char *str,int trapnr) -{ -if (fixup_exception (regs)) -return 1 ; - -notify_die (DIE_GPF , str, regs,0 , trapnr,SIGFPE ); -/* Illegal floating point operation in the kernel */ - current->thread.trap_no = trapnr; -die (str, regs,0 ); -return 0 ; -} -#endif -/* * Note that we play around with the 'TS' bit in an attempt to get * the correct behaviour even in the presence of the asynchronous
@@ -597,14 +583,28 @@ static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)*/ void math_error (struct pt_regs *regs,int error_code,int trapnr) { -struct task_struct *task; +struct task_struct *task = current;siginfo_t info;unsigned short err; +char *str = (trapnr ==16 ) ?"fpu exception" :"simd exception" ; + +if (notify_die (DIE_TRAP , str, regs, error_code, trapnr,SIGFPE ) ==NOTIFY_STOP ) +return ; +conditional_sti (regs); + +if (!user_mode_vm (regs)) + { +if (!fixup_exception (regs)) { + task->thread.error_code = error_code; + task->thread.trap_no = trapnr; +die (str, regs, error_code); + } +return ; + }/* * Save the info for the exception handler and clear the error. */ - task = current;save_init_fpu (task); task->thread.trap_no = trapnr; task->thread.error_code = error_code;
@@ -665,14 +665,8 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr) dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) { -conditional_sti (regs); -#ifdef CONFIG_X86_32 ignore_fpu_irq =1 ; -#else -if (!user_mode (regs) && -kernel_math_error (regs,"kernel x87 math error" ,16 )) -return ;#endif math_error (regs, error_code,16 );
@@ -681,14 +675,8 @@ dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) dotraplinkage voiddo_simd_coprocessor_error (struct pt_regs *regs,long error_code) { -conditional_sti (regs); -#ifdef CONFIG_X86_32 ignore_fpu_irq =1 ; -#else -if (!user_mode (regs) && -kernel_math_error (regs,"kernel simd math error" ,19 )) -return ;#endif math_error (regs, error_code,19 );
PATCH 4/4 x86-32: Don't set ignore_fpu_irq in simd exception
In reply to Brian GerstAny processor that supports simd will have an internal fpu, and the irq13 handler will not be enabled.
--- arch/x86/kernel/traps.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
arch/x86/kernel/traps.c +0 -4
@@ -672,10 +672,6 @@ dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) dotraplinkage voiddo_simd_coprocessor_error (struct pt_regs *regs,long error_code) { -#ifdef CONFIG_X86_32 - ignore_fpu_irq =1 ; -#endif -math_error (regs, error_code,19 ); }
Signature · 1 line
1.6.6.1
[tip:x86/fpu] x86-32: Don't set ignore_fpu_irq in simd exception
Commit-ID: 250825008f1f94887bc039e9227a8adfb5ba366e Gitweb: http://git.kernel.org/tip/250825008f1f94887bc039e9227a8adfb5ba366e Author: Brian Gerst <[email protected]> AuthorDate: Sun, 21 Mar 2010 09:00:46 -0400 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 3 May 2010 13:39:32 -0700
x86-32: Don't set ignore_fpu_irq in simd exception
Any processor that supports simd will have an internal fpu, and the irq13 handler will not be enabled.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/traps.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
arch/x86/kernel/traps.c +0 -4
@@ -675,10 +675,6 @@ dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) dotraplinkage voiddo_simd_coprocessor_error (struct pt_regs *regs,long error_code) { -#ifdef CONFIG_X86_32 - ignore_fpu_irq =1 ; -#endif -math_error (regs, error_code,19 ); }