Re: [PATCH 2/5] x86, fpu: don't drop_fpu() in __restore_xstate_sig() if use_eager_fpu()

From: Oleg Nesterov
Date: Wed Aug 27 2014 - 13:43:50 EST


I'm afraid you all already hate me, but let me continue to spam your
mailboxes.

On 08/25, Oleg Nesterov wrote:
>
> I'll try to play with copy_from_user_in_atomic(), if nothing else just
> to complete the discussion and see how the code can look in this case.

OK, to complete the discussion, the code looks simple unless I missed
something,

if (ia32_fxstate) {
/*
* For 32-bit frames with fxstate, copy the user state to the
* thread's fpu state, reconstruct fxstate from the fsave
* header. Sanitize the copied state etc.
*/
struct xsave_struct *xsave = &tsk->thread.fpu.state->xsave;
struct user_i387_ia32_struct env;
bool done;

if (__copy_from_user(&env, buf, sizeof(env))
return -1;

for (done = false; !done; ) {
if (fatal_signal_pending(current) ||
fault_in_pages_readable(buf_fx, state_size))
return -1;

preempt_disable();
pagefault_disable(); /* not really needed */
done = !__copy_from_user_inatomic(xsave, buf_fx, state_size);
pagefault_enable();
if (likely(done)) {
sanitize_restored_xstate(tsk, &env, xstate_bv, fx_only);
if (__thread_has_fpu(tsk))
math_state_restore();
} else {
fpu_finit(&tsk->thread.fpu);
}
preempt_enable();
}

return 0;
}

and in some sense it is even simpler because we do not care about
use_eager_fpu() or set/clear_used_math().

Does it look better than switch_fpu_xstate() hack?


However, this code can race with kernel_fpu_begin() if use_eager_fpu().
I _think_ that kernel_fpu_begin/end and irq_fpu_usable() need cleanups
too and in any case. Will try to do, but I am not sure.

And to spam you even more, I'll send you a couple of other, more simple
cleanups.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/