Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 287651
b: refs/heads/master
c: 15d8791
h: refs/heads/master
i:
  287649: 390cdfc
  287647: aa22db5
v: v3
  • Loading branch information
Linus Torvalds committed Feb 16, 2012
1 parent df9eb9c commit 19c0235
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c38e23456278e967f094b08247ffc3711b1029b2
refs/heads/master: 15d8791cae75dca27bfda8ecfe87dca9379d6bb0
42 changes: 42 additions & 0 deletions trunk/arch/x86/include/asm/i387.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,48 @@ static inline void irq_ts_restore(int TS_state)
stts();
}

/*
* The question "does this thread have fpu access?"
* is slightly racy, since preemption could come in
* and revoke it immediately after the test.
*
* However, even in that very unlikely scenario,
* we can just assume we have FPU access - typically
* to save the FP state - we'll just take a #NM
* fault and get the FPU access back.
*
* The actual user_fpu_begin/end() functions
* need to be preemption-safe, though.
*
* NOTE! user_fpu_end() must be used only after you
* have saved the FP state, and user_fpu_begin() must
* be used only immediately before restoring it.
* These functions do not do any save/restore on
* their own.
*/
static inline int user_has_fpu(void)
{
return current_thread_info()->status & TS_USEDFPU;
}

static inline void user_fpu_end(void)
{
preempt_disable();
current_thread_info()->status &= ~TS_USEDFPU;
stts();
preempt_enable();
}

static inline void user_fpu_begin(void)
{
preempt_disable();
if (!user_has_fpu()) {
clts();
current_thread_info()->status |= TS_USEDFPU;
}
preempt_enable();
}

/*
* These disable preemption on their own and are safe
*/
Expand Down
1 change: 0 additions & 1 deletion trunk/arch/x86/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ EXPORT_SYMBOL_GPL(math_state_restore);
dotraplinkage void __kprobes
do_device_not_available(struct pt_regs *regs, long error_code)
{
WARN_ON_ONCE(!user_mode_vm(regs));
#ifdef CONFIG_MATH_EMULATION
if (read_cr0() & X86_CR0_EM) {
struct math_emu_info info = { };
Expand Down
10 changes: 3 additions & 7 deletions trunk/arch/x86/kernel/xsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,15 @@ int save_i387_xstate(void __user *buf)
if (!used_math())
return 0;

if (task_thread_info(tsk)->status & TS_USEDFPU) {
if (user_has_fpu()) {
if (use_xsave())
err = xsave_user(buf);
else
err = fxsave_user(buf);

if (err)
return err;
task_thread_info(tsk)->status &= ~TS_USEDFPU;
stts();
user_fpu_end();
} else {
sanitize_i387_state(tsk);
if (__copy_to_user(buf, &tsk->thread.fpu.state->fxsave,
Expand Down Expand Up @@ -292,10 +291,7 @@ int restore_i387_xstate(void __user *buf)
return err;
}

if (!(task_thread_info(current)->status & TS_USEDFPU)) {
clts();
task_thread_info(current)->status |= TS_USEDFPU;
}
user_fpu_begin();
if (use_xsave())
err = restore_user_xstate(buf);
else
Expand Down

0 comments on commit 19c0235

Please sign in to comment.