From: Oleg Nesterov <oleg@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Chuck Ebbert <chuckebbert.lk@gmail.com>,
Jan Kratochvil <jan.kratochvil@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 0/1] i387: ptrace breaks the lazy-fpu-restore logic
Date: Mon, 16 Apr 2012 22:47:56 +0200 [thread overview]
Message-ID: <20120416204756.GA24884@redhat.com> (raw)
In-Reply-To: <CA+55aFzeLqBMJ_tGyKh7EJhqWwPkD7DfggZ=NDmxwi3gYNjkdA@mail.gmail.com>
On 04/15, Linus Torvalds wrote:
>
> Put another way: I do think it would be a good idea to do the "reset
> last_cpu" in copy_thread() too. It doesn't really cost us anything,
> and it's cleaner to always just make sure that last_cpu is "valid"
> (even if the fpu_owner_task is *also* used to invalidate it, and even
> if we never use the lazy restore if fpu_counter is zero and thus
> fpu.preload isn't set).
Yes, this was my thinking too, and initially I was going to include
this change into this patch. But lets do it separately.
I feel we need some cleanups. For example, it seems that flush_thread()
can do this too, although in this case we can rely on __thread_fpu_end()
which clears fpu_owner_task.
So I am just sending your one-liner, and according to my testing it
fixes the problem.
And A couple of off-topic questions...
Why unlazy_fpu() clears ->fpu_counter? Afaics, this doesn't make
sense and unneeded.
And it is not clear to me why init_fpu() does unlazy_fpu(), afaics
tsk_used_math() "tsk == current" is only possible if this task dumps
the core.
arch_dup_task_struct() checks fpu_allocated(), this doesn't look
exactly right to me. Suppose that a task without PF_USED_MATH uses
FPU only once in the signal handler. If it forks after that, we
allocate and copy fpu->state for no reason. IOW, we probably should
check tsk_used_math() instead, but do memzero(&dst->thread.fpu)
unconditionally. And perhaps this memzero() deserves a helper
which can set .last_cpu = -1, and this is what copy_thread()
should call.
OTOH, this reminds me, a long ago I noticed by accident that all
threads on the testing machine have PF_USED_MATH set. IIRC, This
is because /sbin/init does memset or memcpy and glibc uses xmm
for this. Not that I really suggest this, but perhaps
prctl(PR_DROP_FPU) makes some sense.
Oleg.
next prev parent reply other threads:[~2012-04-16 20:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-14 23:52 ptrace && fpu_lazy_restore Oleg Nesterov
2012-04-14 23:59 ` Oleg Nesterov
2012-04-15 2:03 ` Linus Torvalds
2012-04-15 22:38 ` Oleg Nesterov
2012-04-15 23:42 ` Linus Torvalds
2012-04-15 23:46 ` Linus Torvalds
2012-04-16 20:47 ` Oleg Nesterov [this message]
2012-04-16 20:48 ` [PATCH 1/1] i387: ptrace breaks the lazy-fpu-restore logic Oleg Nesterov
2012-04-16 22:09 ` Oleg Nesterov
2012-04-17 0:05 ` [tip:x86/urgent] " tip-bot for Oleg Nesterov
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=20120416204756.GA24884@redhat.com \
--to=oleg@redhat.com \
--cc=chuckebbert.lk@gmail.com \
--cc=hpa@zytor.com \
--cc=jan.kratochvil@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox