Skip to contentSkip to conversation

x86/fpu/xstate: Move XSAVES state init to a function

PATCH New Yu-cheng Yu 2 participants 2 messages Jan 24, 2017 – Jan 25, 2017 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/fpu/xstate: Move XSAVES state init to a function

Make XSTATE init similar to existing code; move it to a separate function. There is no functionality change.

---
 arch/x86/include/asm/fpu/internal.h | 11 +++++++++++
 arch/x86/kernel/fpu/core.c          |  8 +-------
 2 files changed, 12 insertions(+), 7 deletions(-)
arch/x86/include/asm/fpu/internal.h +11 -0
index d4a6849..7fed690 100644
@@ -87,6 +87,17 @@ static __always_inline __pure bool use_fxsr(void)
 #else
 static inline void fpstate_init_soft(struct swregs_state *soft) {}
 #endif
+
+static inline void fpstate_init_xstate(struct xregs_state *xsave)
+{
+	/*
+	 * XRSTORS requires that these bits set in xcomp_bv, or it will
+	 * trigger #GP. Make sure they are replaced after memset().
+	 */
+	xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
+				 xfeatures_mask;
+}
+
 static inline void fpstate_init_fxstate(struct fxregs_state *fx)
 {
 	fx->cwd = 0x37f;
arch/x86/kernel/fpu/core.c +1 -7
index de72344..5763b27 100644
@@ -179,14 +179,8 @@ void fpstate_init(union fpregs_state *state)
 
 	memset(state, 0, fpu_kernel_xstate_size);
 
-	/*
-	 * XRSTORS requires that this bit is set in xcomp_bv, or
-	 * it will #GP. Make sure it is replaced after the memset().
-	 */
 	if (static_cpu_has(X86_FEATURE_XSAVES))
-		state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
-					       xfeatures_mask;
-
+		fpstate_init_xstate(&state->xsave);
 	if (static_cpu_has(X86_FEATURE_FXSR))
 		fpstate_init_fxstate(&state->fxsave);
 	else
Signature · 1 line
1.9.1
#1 lore raw
x86/fpu/xstate: Move XSAVES state init to a function
Commit-ID:  a5828ed3d03d38399159dc17a98cefde3109a66b
Gitweb:     http://git.kernel.org/tip/a5828ed3d03d38399159dc17a98cefde3109a66b
Author:     Yu-cheng Yu <[email protected]>
AuthorDate: Tue, 24 Jan 2017 10:25:46 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 25 Jan 2017 08:25:12 +0100

x86/fpu/xstate: Move XSAVES state init to a function

Make XSTATE init similar to existing code; move it to a separate function. There is no functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ravi V. Shankar <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Minor cleanliness edits. ]
---
 arch/x86/include/asm/fpu/internal.h | 10 ++++++++++
 arch/x86/kernel/fpu/core.c          |  9 +--------
 2 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/fpu/internal.h +10 -0
index d4a6849..255645f 100644
@@ -87,6 +87,16 @@ extern void fpstate_init_soft(struct swregs_state *soft);
 #else
 static inline void fpstate_init_soft(struct swregs_state *soft) {}
 #endif
+
+static inline void fpstate_init_xstate(struct xregs_state *xsave)
+{
+	/*
+	 * XRSTORS requires these bits set in xcomp_bv, or it will
+	 * trigger #GP:
+	 */
+	xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | xfeatures_mask;
+}
+
 static inline void fpstate_init_fxstate(struct fxregs_state *fx)
 {
 	fx->cwd = 0x37f;
arch/x86/kernel/fpu/core.c +1 -8
index de72344..e1114f0 100644
@@ -9,7 +9,6 @@
 #include <asm/fpu/regset.h>
 #include <asm/fpu/signal.h>
 #include <asm/fpu/types.h>
-#include <asm/fpu/xstate.h>
 #include <asm/traps.h>
 
 #include <linux/hardirq.h>
@@ -179,14 +178,8 @@ void fpstate_init(union fpregs_state *state)
 
 	memset(state, 0, fpu_kernel_xstate_size);
 
-	/*
-	 * XRSTORS requires that this bit is set in xcomp_bv, or
-	 * it will #GP. Make sure it is replaced after the memset().
-	 */
 	if (static_cpu_has(X86_FEATURE_XSAVES))
-		state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
-					       xfeatures_mask;
-
+		fpstate_init_xstate(&state->xsave);
 	if (static_cpu_has(X86_FEATURE_FXSR))
 		fpstate_init_fxstate(&state->fxsave);
 	else