x86/fpu changes for v2.6.35
Linus,
Please pull the latest x86-fpu-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git x86-fpu-for-linus
Thanks,
Ingo
------------------>
Avi Kivity (2):
x86: Eliminate TS_XSAVE
x86: Introduce 'struct fpu' and related API
Brian Gerst (4):
x86-32: Rework cache flush denied handler
x86: Merge simd_math_error() into math_error()
x86: Merge kernel_math_error() into math_error()
x86-32: Don't set ignore_fpu_irq in simd exception
H. Peter Anvin (4):
x86, fpu: Unbreak FPU emulation
x86, fpu: Use the proper asm constraint in use_xsave()
x86: Add new static_cpu_has() function using alternatives x86, fpu: Use static_cpu_has() to implement use_xsave()
arch/x86/Kconfig.cpu | 4 + arch/x86/include/asm/cpufeature.h | 57 ++++++++++++ arch/x86/include/asm/i387.h | 129 ++++++++++++++++++++------- arch/x86/include/asm/processor.h | 6 +- arch/x86/include/asm/thread_info.h | 1 - arch/x86/include/asm/traps.h | 2 +- arch/x86/include/asm/xsave.h | 7 +- arch/x86/kernel/cpu/common.c | 5 +- arch/x86/kernel/entry_32.S | 19 ++++ arch/x86/kernel/i387.c | 107 +++++++++++----------- arch/x86/kernel/irqinit.c | 2 +- arch/x86/kernel/process.c | 21 ++--- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- arch/x86/kernel/traps.c | 173 ++++++++++-------------------------- arch/x86/kernel/xsave.c | 8 +- arch/x86/math-emu/fpu_aux.c | 6 +- arch/x86/math-emu/fpu_entry.c | 4 +- arch/x86/math-emu/fpu_system.h | 2 +- 19 files changed, 308 insertions(+), 249 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/include/asm/cpufeature.h +57 -0
69 lines not on this page · raw message
arch/x86/include/asm/i387.h +95 -34
246 lines not on this page · raw message
arch/x86/include/asm/processor.h +5 -1
@@ -380,6 +380,10 @@ union thread_xstate {struct xsave_struct xsave; }; +struct fpu { +union thread_xstate *state; +}; +#ifdef CONFIG_X86_64 DECLARE_PER_CPU(struct orig_ist, orig_ist);
@@ -457,7 +461,7 @@ struct thread_struct {unsigned long trap_no;unsigned long error_code;/* floating point and extended processor state */ -union thread_xstate *xstate; +struct fpu fpu;#ifdef CONFIG_X86_32 /* Virtual 86 mode info */ struct vm86_struct __user *vm86_info;
arch/x86/include/asm/thread_info.h +0 -1
@@ -244,7 +244,6 @@ static inline struct thread_info *current_thread_info(void)#define TS_POLLING 0x0004/* true if in idle loop and not sleeping */ #define TS_RESTORE_SIGMASK 0x0008/* restore signal mask in do_signal() */ -#define TS_XSAVE 0x0010/* Use xsave/xrstor */ #define tsk_is_polling (t) (task_thread_info(t)->status & TS_POLLING)
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/include/asm/xsave.h +4 -3
@@ -37,8 +37,9 @@ extern int check_for_xstate(struct i387_fxsave_struct __user *buf,void __user *fpstate, struct _fpx_sw_bytes *sw); -static inline int xrstor_checking (struct xsave_struct *fx) +static inline int fpu_xrstor_checking (struct fpu *fpu) { +struct xsave_struct *fx = &fpu->state->xsave;int err; asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t"
@@ -110,12 +111,12 @@ static inline void xrstor_state(struct xsave_struct *fx, u64 mask) : "memory"); } -static inline void xsave (struct task_struct *tsk) +static inline void fpu_xsave (struct fpu *fpu) {/* This, however, we can work around by forcing the compiler to select an addressing mode that doesn't require extended registers. */ __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27" - : :"D" (&(tsk->thread.xstate->xsave)), + : :"D" (&(fpu->state->xsave)),"a" (-1 ),"d" (-1 ) :"memory" ); }#endif
arch/x86/kernel/cpu/common.c +1 -4
@@ -1243,10 +1243,7 @@ void __cpuinit cpu_init(void)/* * Force FPU initialization: */ -if (cpu_has_xsave) -current_thread_info ()->status =TS_XSAVE ; -else -current_thread_info ()->status =0 ; +current_thread_info ()->status =0 ;clear_used_math ();mxcsr_feature_mask_init ();
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/i387.c +52 -55
251 lines not on this page · raw message
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/process.c +9 -12
@@ -32,25 +32,22 @@ struct kmem_cache *task_xstate_cachep;int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src) { +int ret; + *dst = *src; -if (src->thread.xstate) { - dst->thread.xstate =kmem_cache_alloc (task_xstate_cachep, -GFP_KERNEL ); -if (!dst->thread.xstate) -return -ENOMEM ; -WARN_ON ((unsigned long )dst->thread.xstate &15 ); -memcpy (dst->thread.xstate, src->thread.xstate, xstate_size); +if (fpu_allocated (&src->thread.fpu)) { +memset (&dst->thread.fpu,0 ,sizeof (dst->thread.fpu)); + ret =fpu_alloc (&dst->thread.fpu); +if (ret) +return ret; +fpu_copy (&dst->thread.fpu, &src->thread.fpu); }return 0 ; }void free_thread_xstate (struct task_struct *tsk) { -if (tsk->thread.xstate) { -kmem_cache_free (task_xstate_cachep, tsk->thread.xstate); - tsk->thread.xstate =NULL ; - } - +fpu_free (&tsk->thread.fpu);WARN (tsk->thread.ds_ctx,"leaking DS context\n" ); }
arch/x86/kernel/process_32.c +1 -1
@@ -317,7 +317,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)/* we're going to use this soon, after a few expensive things */ if (preload_fpu) -prefetch (next->xstate); +prefetch (next->fpu.state);/* * Reload esp0.
arch/x86/kernel/process_64.c +1 -1
@@ -396,7 +396,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)/* we're going to use this soon, after a few expensive things */ if (preload_fpu) -prefetch (next->xstate); +prefetch (next->fpu.state);/* * Reload esp0, LDT and the page table pointer:
arch/x86/kernel/traps.c +48 -125
215 lines not on this page · raw message
arch/x86/kernel/xsave.c +4 -4
@@ -99,7 +99,7 @@ int save_i387_xstate(void __user *buf)if (err)return err; -if (task_thread_info (tsk)->status &TS_XSAVE ) +if (use_xsave ()) err =xsave_user (buf);else err =fxsave_user (buf);
@@ -109,14 +109,14 @@ int save_i387_xstate(void __user *buf)task_thread_info (tsk)->status &= ~TS_USEDFPU ;stts (); }else { -if (__copy_to_user (buf, &tsk->thread.xstate->fxsave, +if (__copy_to_user (buf, &tsk->thread.fpu.state->fxsave, xstate_size))return -1 ; }clear_used_math ();/* trigger finit */ -if (task_thread_info (tsk)->status &TS_XSAVE ) { +if (use_xsave ()) {struct _fpstate __user *fx = buf;struct _xstate __user *x = buf;u64 xstate_bv;
@@ -225,7 +225,7 @@ int restore_i387_xstate(void __user *buf)clts ();task_thread_info (current)->status |=TS_USEDFPU ; } -if (task_thread_info (tsk)->status &TS_XSAVE ) +if (use_xsave ()) err =restore_user_xstate (buf);else err = fxrstor_checking((__force struct i387_fxsave_struct *)
arch/x86/math-emu/fpu_aux.c +3 -3
@@ -30,10 +30,10 @@ static void fclex(void) }/* Needs to be externally visible */ -void finit_task (struct task_struct *tsk) +void finit_soft_fpu (struct i387_soft_struct *soft) { -struct i387_soft_struct *soft = &tsk->thread.xstate->soft;struct address *oaddr, *iaddr; +memset (soft,0 ,sizeof (*soft)); soft->cwd =0x037f ; soft->swd =0 ; soft->ftop =0 ;/* We don't keep top in the status word internally. */
@@ -52,7 +52,7 @@ void finit_task(struct task_struct *tsk)void finit (void ) { -finit_task (current); +finit_soft_fpu (¤t->thread.fpu.state->soft); }/*
arch/x86/math-emu/fpu_entry.c +2 -2
@@ -681,7 +681,7 @@ int fpregs_soft_set(struct task_struct *target, unsigned int pos, unsigned int count, const void *kbuf, const void __user *ubuf) { - struct i387_soft_struct *s387 = &target->thread.xstate->soft; + struct i387_soft_struct *s387 = &target->thread.fpu.state->soft;void *space = s387->st_space;int ret;int offset, other, i, tags, regnr, tag, newtop;
@@ -733,7 +733,7 @@ int fpregs_soft_get(struct task_struct *target, unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf) { - struct i387_soft_struct *s387 = &target->thread.xstate->soft; + struct i387_soft_struct *s387 = &target->thread.fpu.state->soft;const void *space = s387->st_space;int ret;int offset = (S387 ->ftop &7 ) *10 , other =80 - offset;
arch/x86/math-emu/fpu_system.h +1 -1
@@ -31,7 +31,7 @@#define SEG_EXPAND_DOWN (s) (((s).b & ((1 << 11) | (1 << 10))) \ == (1 << 10)) -#define I387 (current->thread.xstate) +#define I387 (current->thread.fpu.state)#define FPU_info (I387->soft.info)#define FPU_CS (*(unsigned short *) &(FPU_info->regs->cs))