Re: [PATCH 1/1] x86/fpu: math_state_restore() should not blindly disable irqs

From: Oleg Nesterov
Date: Thu Mar 05 2015 - 16:27:42 EST


On 03/05, Ingo Molnar wrote:
>
> * Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> > --- a/arch/x86/kernel/traps.c
> > +++ b/arch/x86/kernel/traps.c
> > @@ -774,7 +774,10 @@ void math_state_restore(void)
> > struct task_struct *tsk = current;
> >
> > if (!tsk_used_math(tsk)) {
> > - local_irq_enable();
> > + bool disabled = irqs_disabled();
> > +
> > + if (disabled)
> > + local_irq_enable();
> > /*
> > * does a slab alloc which can sleep
> > */
> > @@ -785,7 +788,9 @@ void math_state_restore(void)
> > do_group_exit(SIGKILL);
> > return;
> > }
> > - local_irq_disable();
> > +
> > + if (disabled)
> > + local_irq_disable();
> > }
>
> Yuck!
>
> Is there a fundamental reason why we cannot simply enable irqs and
> leave them enabled? Math state restore is not atomic and cannot really
> be atomic.

You know, I didn't even try to verify ;) but see below.

Most probably we can simply enable irqs, yes. But what about older kernels,
how can we check?

And let me repeat, I strongly believe that this !tsk_used_math() case in
math_state_restore() must die. And unlazy_fpu() in init_fpu(). And both
__restore_xstate_sig() and flush_thread() should not use math_state_restore()
at all. At least in its current form.

But this is obviously not -stable material.

That said, I'll try to look into git history tomorrow. The patch above
looks "obviously safe", but perhaps I am paranoid too much...

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/