From: Vincent Palatin <vpalatin@chromium.org>
To: Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
x86@kernel.org, Peter Zijlstra <a.p.zijlstra@chello.nl>,
Jarkko Sakkinen <jarkko.sakkinen@intel.com>,
Duncan Laurie <dlaurie@chromium.org>,
Olof Johansson <olofj@chromium.org>,
Vincent Palatin <vpalatin@chromium.org>
Subject: [PATCH] x86, fpu: avoid FPU lazy restore after suspend
Date: Fri, 30 Nov 2012 10:52:03 -0800 [thread overview]
Message-ID: <1354301523-5252-2-git-send-email-vpalatin@chromium.org> (raw)
In-Reply-To: <1354301523-5252-1-git-send-email-vpalatin@chromium.org>
When a cpu enters S3 state, the FPU state is lost.
After resuming for S3, if we try to lazy restore the FPU for a process running
on the same CPU, this will result in a corrupted FPU context.
We can just invalidate the "fpu_owner_task", so nobody will try to
lazy restore a state which no longer exists in the hardware.
Tested with a 64-bit kernel on a 4-core Ivybridge CPU with eagerfpu=off,
by doing thousands of suspend/resume cycles with 4 processes doing FPU
operations running. Without the patch, a process is killed after a
few hundreds cycles by a SIGFPE.
The issue seems to exist since 3.4 (after the FPU lazy restore was actually implemented),
to apply the change to 3.4, "this_cpu_write" needs to be replaced by percpu_write.
Cc: Duncan Laurie <dlaurie@chromium.org>
Cc: Olof Johansson <olofj@chromium.org>
Cc: <stable@kernel.org> [v3.4+] # for 3.4 need to replace this_cpu_write by percpu_write
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
---
arch/x86/kernel/smpboot.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index c80a33b..7610c58 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -68,6 +68,8 @@
#include <asm/mwait.h>
#include <asm/apic.h>
#include <asm/io_apic.h>
+#include <asm/i387.h>
+#include <asm/fpu-internal.h>
#include <asm/setup.h>
#include <asm/uv/uv.h>
#include <linux/mc146818rtc.h>
@@ -1230,6 +1232,9 @@ int native_cpu_disable(void)
clear_local_APIC();
cpu_disable_common();
+
+ /* the FPU context will be lost, nobody owns it */
+ this_cpu_write(fpu_owner_task, NULL);
return 0;
}
--
1.7.7.3
next prev parent reply other threads:[~2012-11-30 18:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-30 18:52 issue with x86 FPU state after suspend to ram Vincent Palatin
2012-11-30 18:52 ` Vincent Palatin [this message]
2012-11-30 18:57 ` [PATCH] x86, fpu: avoid FPU lazy restore after suspend H. Peter Anvin
2012-11-30 19:25 ` Linus Torvalds
2012-11-30 19:38 ` H. Peter Anvin
2012-11-30 19:41 ` Linus Torvalds
2012-11-30 19:51 ` H. Peter Anvin
[not found] ` <CAP_ceTxmMhQeDi=x9HmYke85hKMg3_YhbXSnfDC12rOcocQJpA@mail.gmail.com>
2012-11-30 19:55 ` H. Peter Anvin
2012-11-30 21:45 ` Vincent Palatin
2012-11-30 19:52 ` [PATCH v2] " Vincent Palatin
2012-11-30 20:15 ` [PATCH v3] " Vincent Palatin
2012-11-30 22:10 ` [tip:x86/urgent] x86, fpu: Avoid " tip-bot for Vincent Palatin
2012-11-30 19:26 ` tip-bot for Vincent Palatin
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=1354301523-5252-2-git-send-email-vpalatin@chromium.org \
--to=vpalatin@chromium.org \
--cc=a.p.zijlstra@chello.nl \
--cc=dlaurie@chromium.org \
--cc=hpa@zytor.com \
--cc=jarkko.sakkinen@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=olofj@chromium.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).