Commit 110d7f75 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Borislav Petkov

x86/fpu: Don't abuse FPU in kernel threads if use_eager_fpu()

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: default avatarOleg Nesterov <oleg@redhat.com>
Reviewed-by: default avatarRik van Riel <riel@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Suresh Siddha <sbsiddha@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/20150119185212.GD16427@redhat.comSigned-off-by: default avatarBorislav Petkov <bp@suse.de>
parent 4b2e762e
...@@ -130,6 +130,7 @@ void flush_thread(void) ...@@ -130,6 +130,7 @@ void flush_thread(void)
flush_ptrace_hw_breakpoint(tsk); flush_ptrace_hw_breakpoint(tsk);
memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array)); memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
drop_init_fpu(tsk); drop_init_fpu(tsk);
/* /*
* Free the FPU state for non xsave platforms. They get reallocated * Free the FPU state for non xsave platforms. They get reallocated
...@@ -137,6 +138,12 @@ void flush_thread(void) ...@@ -137,6 +138,12 @@ void flush_thread(void)
*/ */
if (!use_eager_fpu()) if (!use_eager_fpu())
free_thread_xstate(tsk); 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) static void hard_disable_TSC(void)
......
...@@ -688,7 +688,7 @@ void eager_fpu_init(void) ...@@ -688,7 +688,7 @@ void eager_fpu_init(void)
{ {
static __refdata void (*boot_func)(void) = eager_fpu_init_bp; static __refdata void (*boot_func)(void) = eager_fpu_init_bp;
clear_used_math(); WARN_ON(used_math());
current_thread_info()->status = 0; current_thread_info()->status = 0;
if (eagerfpu == ENABLE) if (eagerfpu == ENABLE)
...@@ -703,17 +703,6 @@ void eager_fpu_init(void) ...@@ -703,17 +703,6 @@ void eager_fpu_init(void)
boot_func(); boot_func();
boot_func = NULL; 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);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment