Skip to content

Commit

Permalink
x86/fpu: Don't abuse FPU in kernel threads if use_eager_fpu()
Browse files Browse the repository at this point in the history
AFAICS, there is no reason why kernel threads should have FPU context
even if use_eager_fpu() == T. Now that interrupted_kernel_fpu_idle()
does not check __thread_has_fpu() in the use_eager_fpu() case, we
can remove the init_fpu() code from eager_fpu_init() and change
flush_thread() called by do_execve() to initialize FPU.

Note: of course, the change in flush_thread() is horrible and must be
cleanuped. We need the new helper, and flush_thread() should return the
error if init_fpu() fails.

Signed-off-by: Oleg Nesterov <[email protected]>
Reviewed-by: Rik van Riel <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Suresh Siddha <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Borislav Petkov <[email protected]>
  • Loading branch information
oleg-nesterov authored and suryasaimadhu committed Feb 23, 2015
1 parent 4b2e762 commit 110d7f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
7 changes: 7 additions & 0 deletions arch/x86/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,20 @@ void flush_thread(void)

flush_ptrace_hw_breakpoint(tsk);
memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));

drop_init_fpu(tsk);
/*
* Free the FPU state for non xsave platforms. They get reallocated
* lazily at the first use.
*/
if (!use_eager_fpu())
free_thread_xstate(tsk);
else if (!used_math()) {
/* kthread execs. TODO: cleanup this horror. */
if (WARN_ON(init_fpu(current)))
force_sig(SIGKILL, current);
math_state_restore();
}
}

static void hard_disable_TSC(void)
Expand Down
13 changes: 1 addition & 12 deletions arch/x86/kernel/xsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ void eager_fpu_init(void)
{
static __refdata void (*boot_func)(void) = eager_fpu_init_bp;

clear_used_math();
WARN_ON(used_math());
current_thread_info()->status = 0;

if (eagerfpu == ENABLE)
Expand All @@ -703,17 +703,6 @@ void eager_fpu_init(void)
boot_func();
boot_func = NULL;
}

/*
* This is same as math_state_restore(). But use_xsave() is
* not yet patched to use math_state_restore().
*/
init_fpu(current);
__thread_fpu_begin(current);
if (cpu_has_xsave)
xrstor_state(init_xstate_buf, -1);
else
fxrstor_checking(&init_xstate_buf->i387);
}

/*
Expand Down

0 comments on commit 110d7f7

Please sign in to comment.