From: Oleg Nesterov <oleg@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Fenghua Yu <fenghua.yu@intel.com>,
Suresh Siddha <suresh.b.siddha@intel.com>,
Bean Anderson <bean@azulsystems.com>,
"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
the arch/x86 maintainers <x86@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/5] x86, fpu: don't drop_fpu() in __restore_xstate_sig() if use_eager_fpu()
Date: Mon, 25 Aug 2014 16:26:41 +0200 [thread overview]
Message-ID: <20140825142641.GA31880@redhat.com> (raw)
In-Reply-To: <CA+55aFyQzvvmWUDA01x69vYkrwUG07q9P3Mv5KaT31pOFsBZGQ@mail.gmail.com>
fix Suresh's email...
And the patch is buggy, fpu_finit(&tsk->thread.fpu) if __copy_from_user()
fails is obviously wrong, but this is fixable.
On 08/24, Linus Torvalds wrote:
>
> I really dislike this one.
>
> If I read it right, you now do *two* math_state_restore calls for each
> FPU signal state restore. That's potentially quite expensive.
Yes, this adds one restore_fpu_checking().
But only if a 32bit task does this. And only if use_eager_fpu(), and in
this case we do this on every context switch unconditionally.
So personally I think it is not that bad. And this allows to do more
cleanups (if this can actually work of course). But I can't really
judge.
> Also, you can actually end up with multiple threads pointing to the
> same math state in init_task.thread.fpu.state, right?
Yes. I think this should be fine, but let me remind that I do not
understand i387.
I think this should be safe, because this thread and/or swapper/0 can
do nothing with with fpu->state, and they should not use fpu. So I
hope that, say, __save_init_fpu() and restore_fpu_checking() can race
with each other using the same fpu->state without any problem.
kernel_fpu_begin() looks fine to, fpu_save_init() should not hurt.
But again, again, this is only my speculation.
> Why is that any
> better than just having the save state temporarily contain garbage?
I do not know if restore_fpu_checking(garbage) is safe without
sanitize_restored_xstate(). Can't this, say, trigger an exception?
But there is another reason. Any preemption will overwrite ->xsave,
and I think this is the main reason why we should be careful.
> The other patches look sane, this one I really don't like. You may
> have good reasons for it, but it's disgusting.
5/5 (and other potential cleanups) depends on this change.
So do you still think this change is really bad? Or perhaps it is just
technically wrong?
We can probably do fault_in_pages() + __copy_from_user_inatomic(), but
this will complicate the code more... Something like
__copy_from_user(&env);
while (!fatal_signal_pending() && !fault_in_pages_readable(buf_fx)) {
return -1;
preempt_disable();
if (!__copy_from_user_in_atomic(buf_fx)) {
sanitize_restored_xstate(...);
math_state_restore();
done = true;
}
preempt_disable();
if (done)
break;
}
not sure this looks better.
Other ideas or should I simply forget about these cleanups?
OK. Given that this patch at least needs more discussion, let me send another
simple fix first. This code calls math_state_restore() without preempt_disable()
and afaics this is very wrong and can lead to FPU corruption: if this task gets
a preemption after __thread_fpu_begin(), __save_init_fpu() will overwrite the
registers we are going to restore.
Btw, do you see any problem with another "shift drop_init_fpu() from
save_xstate_sig() to handle_signal()" fix I sent? I think that Bean Anderson
is right, this should be fixed.
Oleg.
next prev parent reply other threads:[~2014-08-25 14:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-22 17:11 [PATCH 0/1] x86, fpu: shift drop_init_fpu() from save_xstate_sig() to handle_signal() Oleg Nesterov
2014-08-22 17:12 ` [PATCH 1/1] " Oleg Nesterov
2014-08-24 19:47 ` [PATCH 0/5] x86, fpu: make use_eager_fpu() more eager Oleg Nesterov
2014-08-24 19:47 ` [PATCH 1/5] x86, fpu: change sanitize_restored_xstate() and convert_to_fxsr() to accept thread_xstate Oleg Nesterov
2014-08-24 19:47 ` [PATCH 2/5] x86, fpu: don't drop_fpu() in __restore_xstate_sig() if use_eager_fpu() Oleg Nesterov
2014-08-24 20:05 ` Linus Torvalds
2014-08-25 14:26 ` Oleg Nesterov [this message]
2014-08-25 14:41 ` Oleg Nesterov
2014-08-25 16:27 ` Linus Torvalds
2014-08-25 17:09 ` Oleg Nesterov
2014-08-25 17:26 ` Linus Torvalds
2014-08-25 17:39 ` Oleg Nesterov
2014-08-27 17:02 ` Oleg Nesterov
2014-08-24 19:47 ` [PATCH 3/5] x86, fpu: don't drop_fpu() in exit_thread() " Oleg Nesterov
2014-08-24 19:47 ` [PATCH 4/5] x86, fpu: shift init_fpu() from eager_fpu_init() to eager_fpu_init_bp() Oleg Nesterov
2014-08-24 19:47 ` [PATCH 5/5] x86, fpu: sanitize the usage of use_eager_fpu() in switch_fpu_prepare() Oleg Nesterov
2014-08-25 18:08 ` [PATCH] x86, fpu: __restore_xstate_sig()->math_state_restore() needs preempt_disable() Oleg Nesterov
2014-09-02 5:01 ` Suresh Siddha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140825142641.GA31880@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bean@azulsystems.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=suresh.b.siddha@intel.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.