Skip to content

Commit

Permalink
x86/fpu: Rename init_fpu() to fpu__unlazy_stopped() and add debugging…
Browse files Browse the repository at this point in the history
… check

This function name is a misnomer now that we've split out all the
other users from it. Rename it accordingly: it's used to save
the FPU state of (ptrace-)stopped child tasks.

Add debugging check to double check this intended usage: that this
function is only called for non-current, stopped child tasks.

Reviewed-by: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed May 19, 2015
1 parent bda2837 commit 67e97fc
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions arch/x86/kernel/i387.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,27 +283,30 @@ EXPORT_SYMBOL_GPL(fpstate_alloc_init);
* value at reset if we support XMM instructions and then
* remember the current task has used the FPU.
*/
static int init_fpu(struct task_struct *tsk)
static int fpu__unlazy_stopped(struct task_struct *child)
{
int ret;

if (tsk_used_math(tsk)) {
if (cpu_has_fpu && tsk == current)
fpu__save(tsk);
task_disable_lazy_fpu_restore(tsk);
if (WARN_ON_ONCE(child == current))
return -EINVAL;

if (tsk_used_math(child)) {
if (cpu_has_fpu && child == current)
fpu__save(child);
task_disable_lazy_fpu_restore(child);
return 0;
}

/*
* Memory allocation at the first usage of the FPU and other state.
*/
ret = fpu_alloc(&tsk->thread.fpu);
ret = fpu_alloc(&child->thread.fpu);
if (ret)
return ret;

fpu_finit(&tsk->thread.fpu);
fpu_finit(&child->thread.fpu);

set_stopped_child_used_math(tsk);
set_stopped_child_used_math(child);
return 0;
}

Expand Down Expand Up @@ -331,7 +334,7 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
if (!cpu_has_fxsr)
return -ENODEV;

ret = init_fpu(target);
ret = fpu__unlazy_stopped(target);
if (ret)
return ret;

Expand All @@ -350,7 +353,7 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
if (!cpu_has_fxsr)
return -ENODEV;

ret = init_fpu(target);
ret = fpu__unlazy_stopped(target);
if (ret)
return ret;

Expand Down Expand Up @@ -384,7 +387,7 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
if (!cpu_has_xsave)
return -ENODEV;

ret = init_fpu(target);
ret = fpu__unlazy_stopped(target);
if (ret)
return ret;

Expand Down Expand Up @@ -414,7 +417,7 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
if (!cpu_has_xsave)
return -ENODEV;

ret = init_fpu(target);
ret = fpu__unlazy_stopped(target);
if (ret)
return ret;

Expand Down Expand Up @@ -577,7 +580,7 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
struct user_i387_ia32_struct env;
int ret;

ret = init_fpu(target);
ret = fpu__unlazy_stopped(target);
if (ret)
return ret;

Expand Down Expand Up @@ -608,7 +611,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
struct user_i387_ia32_struct env;
int ret;

ret = init_fpu(target);
ret = fpu__unlazy_stopped(target);
if (ret)
return ret;

Expand Down

0 comments on commit 67e97fc

Please sign in to comment.