Skip to content

Commit

Permalink
x86-64, fpu: Disable preemption when using TS_USEDFPU
Browse files Browse the repository at this point in the history
Consolidates code and fixes the below race for 64-bit.

commit 9fa2f37bfeb798728241cc4a19578ce6e4258f25
Author: torvalds <torvalds>
Date:   Tue Sep 2 07:37:25 2003 +0000

    Be a lot more careful about TS_USEDFPU and preemption

    We had some races where we testecd (or set) TS_USEDFPU together
    with sequences that depended on the setting (like clearing or
    setting the TS flag in %cr0) and we could be preempted in between,
    which screws up the FPU state, since preemption will itself change
    USEDFPU and the TS flag.

    This makes it a lot more explicit: the "internal" low-level FPU
    functions ("__xxxx_fpu()") all require preemption to be disabled,
    and the exported "real" functions will make sure that is the case.

    One case - in __switch_to() - was switched to the non-preempt-safe
    internal version, since the scheduler itself has already disabled
    preemption.

    BKrev: 3f5448b5WRiQuyzAlbajs3qoQjSobw

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
LKML-Reference: <1283563039-3466-6-git-send-email-brgerst@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
  • Loading branch information
Brian Gerst authored and H. Peter Anvin committed Sep 9, 2010
1 parent bfd946c commit a4d4fbc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
15 changes: 0 additions & 15 deletions arch/x86/include/asm/i387.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,6 @@ static inline void irq_ts_restore(int TS_state)
stts();
}

#ifdef CONFIG_X86_64

static inline void save_init_fpu(struct task_struct *tsk)
{
__save_init_fpu(tsk);
stts();
}

#define unlazy_fpu __unlazy_fpu
#define clear_fpu __clear_fpu

#else /* CONFIG_X86_32 */

/*
* These disable preemption on their own and are safe
*/
Expand All @@ -425,8 +412,6 @@ static inline void clear_fpu(struct task_struct *tsk)
preempt_enable();
}

#endif /* CONFIG_X86_64 */

/*
* i387 state interaction
*/
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/process_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
load_TLS(next, cpu);

/* Must be after DS reload */
unlazy_fpu(prev_p);
__unlazy_fpu(prev_p);

/* Make sure cpu is ready for new context */
if (preload_fpu)
Expand Down

0 comments on commit a4d4fbc

Please sign in to comment.