x86/fpu: Use restore_init_xstate() instead of math_state_restore() on kthread exec
[linux-2.6-block.git] / arch / x86 / kernel / process.c
index 046e2d620bbe7be507808e0f7188c45249f2d69c..6b058296a4569109ee0129af5ca827d61ee16aab 100644 (file)
@@ -69,8 +69,8 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 
        dst->thread.fpu_counter = 0;
        dst->thread.fpu.has_fpu = 0;
-       dst->thread.fpu.last_cpu = ~0;
        dst->thread.fpu.state = NULL;
+       task_disable_lazy_fpu_restore(dst);
        if (tsk_used_math(src)) {
                int err = fpu_alloc(&dst->thread.fpu);
                if (err)
@@ -131,6 +131,7 @@ 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
@@ -138,6 +139,13 @@ void flush_thread(void)
         */
        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);
+               user_fpu_begin();
+               restore_init_xstate();
+       }
 }
 
 static void hard_disable_TSC(void)