From 0bf23f3d6cadb2f0961d0ea370371cf35480bcb5 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Sun, 26 Apr 2015 14:48:08 +0200 Subject: x86/fpu: Factor out FPU bug checks into fpu/bugs.c Create separate fpu/bugs.c code so that if we read generic FPU code we don't have to wade through all the bugcheck related code first. Reviewed-by: Borislav Petkov Cc: Andy Lutomirski Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Ingo Molnar --- arch/x86/kernel/fpu/bugs.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 arch/x86/kernel/fpu/bugs.c (limited to 'arch/x86/kernel/fpu/bugs.c') diff --git a/arch/x86/kernel/fpu/bugs.c b/arch/x86/kernel/fpu/bugs.c new file mode 100644 index 000000000000..400a3d713fb2 --- /dev/null +++ b/arch/x86/kernel/fpu/bugs.c @@ -0,0 +1,64 @@ +/* + * x86 FPU bug checks: + */ +#include + +/* + * Boot time CPU/FPU FDIV bug detection code: + */ + +static double __initdata x = 4195835.0; +static double __initdata y = 3145727.0; + +/* + * This used to check for exceptions.. + * However, it turns out that to support that, + * the XMM trap handlers basically had to + * be buggy. So let's have a correct XMM trap + * handler, and forget about printing out + * some status at boot. + * + * We should really only care about bugs here + * anyway. Not features. + */ +static void __init check_fpu(void) +{ + s32 fdiv_bug; + + kernel_fpu_begin(); + + /* + * trap_init() enabled FXSR and company _before_ testing for FP + * problems here. + * + * Test for the divl bug: http://en.wikipedia.org/wiki/Fdiv_bug + */ + __asm__("fninit\n\t" + "fldl %1\n\t" + "fdivl %2\n\t" + "fmull %2\n\t" + "fldl %1\n\t" + "fsubp %%st,%%st(1)\n\t" + "fistpl %0\n\t" + "fwait\n\t" + "fninit" + : "=m" (*&fdiv_bug) + : "m" (*&x), "m" (*&y)); + + kernel_fpu_end(); + + if (fdiv_bug) { + set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV); + pr_warn("Hmm, FPU with FDIV bug\n"); + } +} + +void fpu__init_check_bugs(void) +{ + /* + * kernel_fpu_begin/end() in check_fpu() relies on the patched + * alternative instructions. + */ + if (cpu_has_fpu) + check_fpu(); +} -- cgit v1.2.3-59-g8ed1b From 71eb3c6d155c54fb74d2f95166162296a8f9af12 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Tue, 5 May 2015 10:54:04 +0200 Subject: x86/fpu: Make check_fpu() init ordering independent check_fpu() currently relies on being called early in the init sequence, when CR0::TS has not been set up yet. Save/restore CR0::TS across this function, to make it invariant to init ordering. This way we'll be able to move the generic FPU setup routines earlier in the init sequence. Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Ingo Molnar --- arch/x86/kernel/fpu/bugs.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'arch/x86/kernel/fpu/bugs.c') diff --git a/arch/x86/kernel/fpu/bugs.c b/arch/x86/kernel/fpu/bugs.c index 400a3d713fb2..449b5f3f4925 100644 --- a/arch/x86/kernel/fpu/bugs.c +++ b/arch/x86/kernel/fpu/bugs.c @@ -23,8 +23,13 @@ static double __initdata y = 3145727.0; */ static void __init check_fpu(void) { + u32 cr0_saved; s32 fdiv_bug; + /* We might have CR0::TS set already, clear it: */ + cr0_saved = read_cr0(); + write_cr0(cr0_saved & ~X86_CR0_TS); + kernel_fpu_begin(); /* @@ -47,6 +52,8 @@ static void __init check_fpu(void) kernel_fpu_end(); + write_cr0(cr0_saved); + if (fdiv_bug) { set_cpu_bug(&boot_cpu_data, X86_BUG_FDIV); pr_warn("Hmm, FPU with FDIV bug\n"); -- cgit v1.2.3-59-g8ed1b From 32231879f66162352fc6f3041c5c2b1d965879b2 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Mon, 4 May 2015 09:52:42 +0200 Subject: x86/fpu/init: Propagate __init annotations Now that all the FPU init function call dependencies are cleaned up we can propagate __init annotations deeper. This shrinks the runtime size of the kernel a bit, and also addresses a few section warnings. Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Ingo Molnar --- arch/x86/kernel/fpu/bugs.c | 2 +- arch/x86/kernel/fpu/init.c | 12 ++++++------ arch/x86/kernel/fpu/xstate.c | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'arch/x86/kernel/fpu/bugs.c') diff --git a/arch/x86/kernel/fpu/bugs.c b/arch/x86/kernel/fpu/bugs.c index 449b5f3f4925..dd9ca9b60ff3 100644 --- a/arch/x86/kernel/fpu/bugs.c +++ b/arch/x86/kernel/fpu/bugs.c @@ -60,7 +60,7 @@ static void __init check_fpu(void) } } -void fpu__init_check_bugs(void) +void __init fpu__init_check_bugs(void) { /* * kernel_fpu_begin/end() in check_fpu() relies on the patched diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index 889025217407..a9e506a99a83 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -90,7 +90,7 @@ static void fpu__init_system_early_generic(struct cpuinfo_x86 *c) */ unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu; -static void fpu__init_system_mxcsr(void) +static void __init fpu__init_system_mxcsr(void) { unsigned int mask = 0; @@ -115,7 +115,7 @@ static void fpu__init_system_mxcsr(void) /* * Once per bootup FPU initialization sequences that will run on most x86 CPUs: */ -static void fpu__init_system_generic(void) +static void __init fpu__init_system_generic(void) { /* * Set up the legacy init FPU context. (xstate init might overwrite this @@ -141,7 +141,7 @@ EXPORT_SYMBOL_GPL(xstate_size); * We set this up first, and later it will be overwritten by * fpu__init_system_xstate() if the CPU knows about xstates. */ -static void fpu__init_system_xstate_size_legacy(void) +static void __init fpu__init_system_xstate_size_legacy(void) { /* * Note that xstate_size might be overwriten later during @@ -212,7 +212,7 @@ __setup("eagerfpu=", eager_fpu_setup); /* * Pick the FPU context switching strategy: */ -static void fpu__init_system_ctx_switch(void) +static void __init fpu__init_system_ctx_switch(void) { WARN_ON(current->thread.fpu.fpstate_active); current_thread_info()->status = 0; @@ -234,14 +234,14 @@ static void fpu__init_system_ctx_switch(void) if (eagerfpu == ENABLE) setup_force_cpu_cap(X86_FEATURE_EAGER_FPU); - printk_once(KERN_INFO "x86/fpu: Using '%s' FPU context switches.\n", eagerfpu == ENABLE ? "eager" : "lazy"); + printk(KERN_INFO "x86/fpu: Using '%s' FPU context switches.\n", eagerfpu == ENABLE ? "eager" : "lazy"); } /* * Called on the boot CPU once per system bootup, to set up the initial * FPU state that is later cloned into all processes: */ -void fpu__init_system(struct cpuinfo_x86 *c) +void __init fpu__init_system(struct cpuinfo_x86 *c) { fpu__init_system_early_generic(c); diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 9e77332f00e4..201f08feb259 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -191,7 +191,7 @@ static void __init setup_xstate_features(void) } } -static void print_xstate_feature(u64 xstate_mask) +static void __init print_xstate_feature(u64 xstate_mask) { const char *feature_name; @@ -202,7 +202,7 @@ static void print_xstate_feature(u64 xstate_mask) /* * Print out all the supported xstate features: */ -static void print_xstate_features(void) +static void __init print_xstate_features(void) { print_xstate_feature(XSTATE_FP); print_xstate_feature(XSTATE_SSE); @@ -219,7 +219,7 @@ static void print_xstate_features(void) * xsave area. This supports both standard format and compacted format * of the xsave aread. */ -static void setup_xstate_comp(void) +static void __init setup_xstate_comp(void) { unsigned int xstate_comp_sizes[sizeof(xfeatures_mask)*8]; int i; @@ -260,7 +260,7 @@ static void setup_xstate_comp(void) /* * setup the xstate image representing the init state */ -static void setup_init_fpu_buf(void) +static void __init setup_init_fpu_buf(void) { if (!cpu_has_xsave) return; @@ -314,7 +314,7 @@ static void __init init_xstate_size(void) * * ( Not marked __init because of false positive section warnings. ) */ -void fpu__init_system_xstate(void) +void __init fpu__init_system_xstate(void) { unsigned int eax, ebx, ecx, edx; -- cgit v1.2.3-59-g8ed1b