Skip to content

Commit 7a05d45

Browse files
amlutoZhengShunQian
authored andcommitted
x86/fpu: Fix math emulation in eager fpu mode
commit 4ecd16e upstream. Systems without an FPU are generally old and therefore use lazy FPU switching. Unsurprisingly, math emulation in eager FPU mode is a bit buggy. Fix it. There were two bugs involving kernel code trying to use the FPU registers in eager mode even if they didn't exist and one BUG_ON() that was incorrect. Signed-off-by: Andy Lutomirski <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Quentin Casasnovas <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Sai Praneeth Prakhya <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: yu-cheng yu <[email protected]> Link: http://lkml.kernel.org/r/b4b8d112436bd6fab866e1b4011131507e8d7fbe.1453675014.git.luto@kernel.org Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c12b9a3 commit 7a05d45

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

arch/x86/include/asm/fpu/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
596596
* If the task has used the math, pre-load the FPU on xsave processors
597597
* or if the past 5 consecutive context-switches used math.
598598
*/
599-
fpu.preload = new_fpu->fpstate_active &&
599+
fpu.preload = static_cpu_has(X86_FEATURE_FPU) &&
600+
new_fpu->fpstate_active &&
600601
(use_eager_fpu() || new_fpu->counter > 5);
601602

602603
if (old_fpu->fpregs_active) {

arch/x86/kernel/fpu/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void fpu__clear(struct fpu *fpu)
437437
{
438438
WARN_ON_FPU(fpu != &current->thread.fpu); /* Almost certainly an anomaly */
439439

440-
if (!use_eager_fpu()) {
440+
if (!use_eager_fpu() || !static_cpu_has(X86_FEATURE_FPU)) {
441441
/* FPU state will be reallocated lazily at the first use. */
442442
fpu__drop(fpu);
443443
} else {

arch/x86/kernel/traps.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ dotraplinkage void
751751
do_device_not_available(struct pt_regs *regs, long error_code)
752752
{
753753
RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");
754-
BUG_ON(use_eager_fpu());
755754

756755
#ifdef CONFIG_MATH_EMULATION
757756
if (read_cr0() & X86_CR0_EM) {

0 commit comments

Comments
 (0)