From: Brian Gerst <brgerst@gmail.com>
To: hpa@zytor.com
Cc: x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 09/11] x86: Merge fpu_save_init()
Date: Sat, 28 Aug 2010 12:04:36 -0400 [thread overview]
Message-ID: <1283011478-27237-10-git-send-email-brgerst@gmail.com> (raw)
In-Reply-To: <1283011478-27237-1-git-send-email-brgerst@gmail.com>
Merge 32-bit and 64-bit fpu_save_init().
Signed-off-by: Brian Gerst <brgerst@gmail.com>
---
arch/x86/include/asm/i387.h | 88 +++++++++++--------------------------------
1 files changed, 22 insertions(+), 66 deletions(-)
diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
index 768fcb2..58cb6f0 100644
--- a/arch/x86/include/asm/i387.h
+++ b/arch/x86/include/asm/i387.h
@@ -94,36 +94,6 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
return err;
}
-/* AMD CPUs don't save/restore FDP/FIP/FOP unless an exception
- is pending. Clear the x87 state here by setting it to fixed
- values. The kernel data segment can be sometimes 0 and sometimes
- new user value. Both should be ok.
- Use the PDA as safe address because it should be already in L1. */
-static inline void fpu_clear(struct fpu *fpu)
-{
- struct xsave_struct *xstate = &fpu->state->xsave;
- struct i387_fxsave_struct *fx = &fpu->state->fxsave;
-
- /*
- * xsave header may indicate the init state of the FP.
- */
- if (use_xsave() &&
- !(xstate->xsave_hdr.xstate_bv & XSTATE_FP))
- return;
-
- if (unlikely(fx->swd & X87_FSW_ES))
- asm volatile("fnclex");
- alternative_input(ASM_NOP8 ASM_NOP2,
- " emms\n" /* clear stack tags */
- " fildl %%gs:0", /* load to clear state */
- X86_FEATURE_FXSAVE_LEAK);
-}
-
-static inline void clear_fpu_state(struct task_struct *tsk)
-{
- fpu_clear(&tsk->thread.fpu);
-}
-
static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
{
int err;
@@ -177,16 +147,6 @@ static inline void fpu_fxsave(struct fpu *fpu)
: [fx] "R" (&fpu->state->fxsave));
}
-static inline void fpu_save_init(struct fpu *fpu)
-{
- if (use_xsave())
- fpu_xsave(fpu);
- else
- fpu_fxsave(fpu);
-
- fpu_clear(fpu);
-}
-
#else /* CONFIG_X86_32 */
#ifdef CONFIG_MATH_EMULATION
@@ -211,6 +171,19 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
return 0;
}
+static inline void fpu_fxsave(struct fpu *fpu)
+{
+ /* Use more nops than strictly needed in case the compiler
+ varies code */
+ alternative_input(
+ "fnsave %[fx] ;fwait;" GENERIC_NOP2,
+ "fxsave %[fx]\n",
+ X86_FEATURE_FXSR,
+ [fx] "m" (fpu->state->fxsave) : "memory");
+}
+
+#endif /* CONFIG_X86_64 */
+
/* We need a safe address that is cheap to find and that is already
in L1 during context switch. The best choices are unfortunately
different for UP and SMP */
@@ -225,52 +198,35 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
*/
static inline void fpu_save_init(struct fpu *fpu)
{
+ struct i387_fxsave_struct *fx = &fpu->state->fxsave;
+
if (use_xsave()) {
struct xsave_struct *xstate = &fpu->state->xsave;
- struct i387_fxsave_struct *fx = &fpu->state->fxsave;
-
fpu_xsave(fpu);
-
/*
* xsave header may indicate the init state of the FP.
*/
if (!(xstate->xsave_hdr.xstate_bv & XSTATE_FP))
- goto end;
-
+ return;
if (unlikely(fx->swd & X87_FSW_ES))
asm volatile("fnclex");
-
- /*
- * we can do a simple return here or be paranoid :)
- */
- goto clear_state;
+ } else {
+ fpu_fxsave(fpu);
+ if (cpu_has_fxsr && unlikely(fx->swd & X87_FSW_ES))
+ asm volatile("fnclex");
}
- /* Use more nops than strictly needed in case the compiler
- varies code */
- alternative_input(
- "fnsave %[fx] ;fwait;" GENERIC_NOP8 GENERIC_NOP4,
- "fxsave %[fx]\n"
- "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:",
- X86_FEATURE_FXSR,
- [fx] "m" (fpu->state->fxsave),
- [fsw] "m" (fpu->state->fxsave.swd) : "memory");
-clear_state:
/* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
is pending. Clear the x87 state here by setting it to fixed
values. safe_address is a random variable that should be in L1 */
alternative_input(
- GENERIC_NOP8 GENERIC_NOP2,
+ ASM_NOP8 ASM_NOP2,
"emms\n\t" /* clear stack tags */
- "fildl %[addr]", /* set F?P to defined value */
+ "fildl %P[addr]", /* set F?P to defined value */
X86_FEATURE_FXSAVE_LEAK,
[addr] "m" (safe_address));
-end:
- ;
}
-#endif /* CONFIG_X86_64 */
-
static inline void __save_init_fpu(struct task_struct *tsk)
{
fpu_save_init(&tsk->thread.fpu);
--
1.7.2.2
next prev parent reply other threads:[~2010-08-28 16:05 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-28 16:04 x86: FPU cleanups Brian Gerst
2010-08-28 16:04 ` [PATCH 01/11] x86: Use correct type for %cr4 Brian Gerst
2010-08-29 18:24 ` Pekka Enberg
2010-08-28 16:04 ` [PATCH 02/11] x86: Merge fpu_init() Brian Gerst
2010-08-29 18:29 ` Pekka Enberg
2010-08-30 0:44 ` Brian Gerst
2010-08-28 16:04 ` [PATCH 03/11] x86: Merge tolerant_fwait() Brian Gerst
2010-08-29 18:32 ` Pekka Enberg
2010-08-30 0:35 ` Brian Gerst
2010-08-30 5:47 ` Pekka Enberg
2010-08-28 16:04 ` [PATCH 04/11] x86: Merge __save_init_fpu() Brian Gerst
2010-08-29 18:33 ` Pekka Enberg
2010-08-28 16:04 ` [PATCH 05/11] x86-64: Disable preemption when using TS_USEDFPU Brian Gerst
2010-08-29 18:38 ` Pekka Enberg
2010-08-28 16:04 ` [PATCH 06/11] x86-64: Fix %cs value in convert_from_fxsr() Brian Gerst
2010-08-29 18:41 ` Pekka Enberg
2010-08-30 0:25 ` Brian Gerst
2010-08-30 6:44 ` Pekka Enberg
2010-08-30 11:38 ` Brian Gerst
2010-08-28 16:04 ` [PATCH 07/11] x86-64: Simplify constraints for fxsave/fxtstor Brian Gerst
2010-08-29 18:45 ` Pekka Enberg
2010-08-29 23:44 ` Brian Gerst
2010-08-30 5:56 ` Pekka Enberg
2010-08-28 16:04 ` [PATCH 08/11] x86-32: Remove math_emulate stub Brian Gerst
2010-08-29 18:47 ` Pekka Enberg
2010-08-28 16:04 ` Brian Gerst [this message]
2010-08-29 18:54 ` [PATCH 09/11] x86: Merge fpu_save_init() Pekka Enberg
2010-08-28 16:04 ` [PATCH 10/11] x86: Remove unnecessary ifdefs from i387 code Brian Gerst
2010-08-29 19:00 ` Pekka Enberg
2010-08-29 23:38 ` Brian Gerst
2010-08-30 5:44 ` Pekka Enberg
2010-08-30 11:21 ` Brian Gerst
2010-08-30 11:25 ` Pekka Enberg
2010-08-28 16:04 ` [PATCH 11/11] x86: Remove PSHUFB_XMM5_* macros Brian Gerst
2010-08-29 19:02 ` Pekka Enberg
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=1283011478-27237-10-git-send-email-brgerst@gmail.com \
--to=brgerst@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.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 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.