x86/fpu changes for v3.11
Subsystems (3)
Linus,
Please pull the latest x86-fpu-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-fpu-for-linus
HEAD: 5f8c4218148822fde6eebbeefc34bd0a6061e031 x86, fpu: Use static_cpu_has_safe before alternatives
There are two bigger changes in this tree:
- Add an [early-use-]safe static_cpu_has() variant and other robustness improvements, including the new CONFIG_X86_DEBUG_STATIC_CPU_HAS=y debugging facility, motivated by recent obscure FPU code bugs, by Borislav Petkov
- Reimplement FPU detection code in C and drop the old asm code, by H. Peter Anvin.
Thanks,
Ingo
------------------>
Borislav Petkov (4):
x86, cpu: Add a synthetic, always true, cpu feature
x86: Sanity-check static_cpu_has usage
x86: Add a static_cpu_has_safe variant
x86, fpu: Use static_cpu_has_safe before alternatives
H. Peter Anvin (1):
x86: Get rid of ->hard_math and all the FPU asm fu
arch/x86/Kconfig.debug | 10 +++ arch/x86/include/asm/cpufeature.h | 118 ++++++++++++++++++++++++++++++++++-- arch/x86/include/asm/fpu-internal.h | 4 +- arch/x86/include/asm/processor.h | 3 +- arch/x86/kernel/asm-offsets_32.c | 1 - arch/x86/kernel/cpu/bugs.c | 21 +------ arch/x86/kernel/cpu/common.c | 19 +++++- arch/x86/kernel/cpu/cyrix.c | 2 +- arch/x86/kernel/cpu/proc.c | 4 +- arch/x86/kernel/head_32.S | 21 ------- arch/x86/kernel/i387.c | 59 ++++++++++++++---- arch/x86/kernel/xsave.c | 5 +- arch/x86/lguest/boot.c | 2 +- arch/x86/xen/enlighten.c | 2 +- 14 files changed, 201 insertions(+), 70 deletions(-)
arch/x86/Kconfig.debug +10 -0
@@ -304,4 +304,14 @@ config DEBUG_NMI_SELFTEST If unsure, say N. +config X86_DEBUG_STATIC_CPU_HAS + bool "Debug alternatives" + depends on DEBUG_KERNEL + ---help--- + This option causes additional code to be generated which + fails if static_cpu_has() is used before alternatives have + run. + + If unsure, say N. + endmenu
arch/x86/include/asm/cpufeature.h +114 -4
154 lines not on this page · raw message
arch/x86/include/asm/fpu-internal.h +1 -3
@@ -62,10 +62,8 @@ extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set,#define xstateregs_active fpregs_active#ifdef CONFIG_MATH_EMULATION -# define HAVE_HWFP (boot_cpu_data.hard_math)extern void finit_soft_fpu (struct i387_soft_struct *soft);#else -# define HAVE_HWFP 1static inline void finit_soft_fpu (struct i387_soft_struct *soft) {}#endif
@@ -345,7 +343,7 @@ static inline void __thread_fpu_end(struct task_struct *tsk)static inline void __thread_fpu_begin (struct task_struct *tsk) { -if (!use_eager_fpu ()) +if (!static_cpu_has_safe (X86_FEATURE_EAGER_FPU ))clts ();__thread_set_has_fpu (tsk); }
arch/x86/include/asm/processor.h +2 -1
@@ -89,9 +89,9 @@ struct cpuinfo_x86 {char wp_works_ok;/* It doesn't on 386's */ /* Problems on some 486Dx4's and old 386's: */ -char hard_math;char rfu;char pad0; +char pad1;#else /* Number of 4K pages in DTLB/ITLB combined(in pages): */ int x86_tlbsize;
@@ -164,6 +164,7 @@ extern const struct seq_operations cpuinfo_op;#define cache_line_size () (boot_cpu_data.x86_cache_alignment)extern void cpu_detect (struct cpuinfo_x86 *c); +extern void __cpuinit fpu_detect (struct cpuinfo_x86 *c);extern void early_cpu_init (void );extern void identify_boot_cpu (void );
arch/x86/kernel/asm-offsets_32.c +0 -1
@@ -28,7 +28,6 @@ void foo(void)OFFSET (CPUINFO_x86_vendor, cpuinfo_x86, x86_vendor);OFFSET (CPUINFO_x86_model, cpuinfo_x86, x86_model);OFFSET (CPUINFO_x86_mask, cpuinfo_x86, x86_mask); -OFFSET (CPUINFO_hard_math, cpuinfo_x86, hard_math);OFFSET (CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level);OFFSET (CPUINFO_x86_capability, cpuinfo_x86, x86_capability);OFFSET (CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
arch/x86/kernel/cpu/bugs.c +2 -19
@@ -17,15 +17,6 @@#include <asm/paravirt.h> #include <asm/alternative.h> -static int __init no_387 (char *s) -{ - boot_cpu_data.hard_math =0 ; -write_cr0 (X86_CR0_TS |X86_CR0_EM |X86_CR0_MP |read_cr0 ()); -return 1 ; -} - -__setup ("no387" , no_387); -static double __initdata x =4195835.0 ;static double __initdata y =3145727.0 ;
@@ -44,15 +35,6 @@ static void __init check_fpu(void) {s32 fdiv_bug; -if (!boot_cpu_data.hard_math) { -#ifndef CONFIG_MATH_EMULATION -pr_emerg ("No coprocessor found and no math emulation present\n" ); -pr_emerg ("Giving up\n" ); -for (;;) ; -#endif -return ; - } -kernel_fpu_begin ();/*
@@ -107,5 +89,6 @@ void __init check_bugs(void)* kernel_fpu_begin/end() in check_fpu() relies on the patched * alternative instructions. */ -check_fpu (); +if (cpu_has_fpu) +check_fpu (); }
arch/x86/kernel/cpu/common.c +17 -2
@@ -711,10 +711,9 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)return ;cpu_detect (c); -get_cpu_vendor (c); -get_cpu_cap (c); +fpu_detect (c);if (this_cpu->c_early_init) this_cpu->c_early_init (c);
@@ -724,6 +723,8 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)if (this_cpu->c_bsp_init) this_cpu->c_bsp_init (c); + +setup_force_cpu_cap (X86_FEATURE_ALWAYS ); }void __init early_cpu_init (void )
@@ -1363,3 +1364,17 @@ void __cpuinit cpu_init(void) fpu_init(); }#endif + +#ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS +void warn_pre_alternatives (void ) +{ +WARN (1 ,"You're using static_cpu_has before alternatives have run!\n" ); +} +EXPORT_SYMBOL_GPL (warn_pre_alternatives); +#endif + +inline bool __static_cpu_has_safe (u16 bit) +{ +return boot_cpu_has (bit); +} +EXPORT_SYMBOL_GPL (__static_cpu_has_safe);
arch/x86/kernel/cpu/cyrix.c +1 -1
@@ -333,7 +333,7 @@ static void __cpuinit init_cyrix(struct cpuinfo_x86 *c)switch (dir0_lsn) {case 0xd :/* either a 486SLC or DLC w/o DEVID */ dir0_msn =0 ; - p = Cx486_name[(c->hard_math) ?1 :0 ]; + p = Cx486_name[(cpu_has_fpu ?1 :0 )];break ;case 0xe :/* a 486S A step */
arch/x86/kernel/cpu/proc.c +2 -2
@@ -37,8 +37,8 @@ static void show_cpuinfo_misc(struct seq_file *m, struct cpuinfo_x86 *c)static_cpu_has_bug (X86_BUG_FDIV ) ?"yes" :"no" ,static_cpu_has_bug (X86_BUG_F00F ) ?"yes" :"no" ,static_cpu_has_bug (X86_BUG_COMA ) ?"yes" :"no" , - c->hard_math ?"yes" :"no" , - c->hard_math ?"yes" :"no" , +static_cpu_has (X86_FEATURE_FPU ) ?"yes" :"no" , +static_cpu_has (X86_FEATURE_FPU ) ?"yes" :"no" , c->cpuid_level, c->wp_works_ok ? "yes" : "no"); }
arch/x86/kernel/head_32.S +0 -21
@@ -444,7 +444,6 @@ is486: orl %ecx,%eax movl %eax,%cr0 - call check_x87 lgdt early_gdt_descr lidt idt_descr ljmp $(__KERNEL_CS),$1f
@@ -467,26 +466,6 @@ is486: pushl $0 # fake return address for unwinder jmp *(initial_code) -/* - * We depend on ET to be correct. This checks for 287/387. - */ -check_x87: - movb $0,X86_HARD_MATH - clts - fninit - fstsw %ax - cmpb $0,%al - je 1f - movl %cr0,%eax /* no coprocessor: have to set bits */ - xorl $4,%eax /* set EM */ - movl %eax,%cr0 - ret - ALIGN -1: movb $1,X86_HARD_MATH - .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */ - ret - - #include "verify_cpu.S" /*
arch/x86/kernel/i387.c +48 -11
112 lines not on this page · raw message
arch/x86/kernel/xsave.c +2 -3
@@ -243,7 +243,7 @@ int save_xstate_sig(void __user *buf, void __user *buf_fx, int size)if (!access_ok (VERIFY_WRITE , buf, size))return -EACCES ; -if (!HAVE_HWFP ) +if (!static_cpu_has (X86_FEATURE_FPU ))return fpregs_soft_get (current,NULL ,0 ,sizeof (struct user_i387_ia32_struct ),NULL , (struct _fpstate_ia32 __user *) buf) ?-1 :1 ;
@@ -350,11 +350,10 @@ int __restore_xstate_sig(void __user *buf, void __user *buf_fx, int size)if (!used_math () &&init_fpu (tsk))return -1 ; -if (!HAVE_HWFP ) { +if (!static_cpu_has (X86_FEATURE_FPU ))return fpregs_soft_set (current,NULL ,0 ,sizeof (struct user_i387_ia32_struct ),NULL , buf) !=0 ; - }if (use_xsave ()) {struct _fpx_sw_bytes fx_sw_user;
arch/x86/lguest/boot.c +1 -1
@@ -1410,7 +1410,7 @@ __init void lguest_init(void) new_cpu_data.x86_capability[0 ] =cpuid_edx (1 );/* Math is always hard! */ - new_cpu_data.hard_math =1 ; +set_cpu_cap (&new_cpu_data,X86_FEATURE_FPU );/* We don't have features. We have puppies! Puppies! */ #ifdef CONFIG_X86_MCE
arch/x86/xen/enlighten.c +1 -1
@@ -1557,7 +1557,7 @@ asmlinkage void __init xen_start_kernel(void)#ifdef CONFIG_X86_32 /* set up basic CPUID stuff */ cpu_detect (&new_cpu_data); - new_cpu_data.hard_math =1 ; +set_cpu_cap (&new_cpu_data,X86_FEATURE_FPU ); new_cpu_data.wp_works_ok =1 ; new_cpu_data.x86_capability[0 ] =cpuid_edx (1 );#endif