Browse Source

x86, xsave: Use xsaveopt in context-switch path when supported

xsaveopt is a more optimized form of xsave specifically designed
for the context switch usage. xsaveopt doesn't save the state that's not
modified from the prior xrstor. And if a specific feature state gets
modified to the init state, then xsaveopt just updates the header bit
in the xsave memory layout without updating the corresponding memory
layout.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
LKML-Reference: <20100719230205.604014179@sbs-t61.sc.intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Suresh Siddha 15 years ago
parent
commit
6bad06b768
3 changed files with 15 additions and 4 deletions
  1. 1 1
      arch/x86/include/asm/i387.h
  2. 6 3
      arch/x86/include/asm/xsave.h
  3. 8 0
      arch/x86/kernel/cpu/common.c

+ 1 - 1
arch/x86/include/asm/i387.h

@@ -60,7 +60,7 @@ extern int restore_i387_xstate_ia32(void __user *buf);
 
 
 static __always_inline __pure bool use_xsaveopt(void)
 static __always_inline __pure bool use_xsaveopt(void)
 {
 {
-	return 0;
+	return static_cpu_has(X86_FEATURE_XSAVEOPT);
 }
 }
 
 
 static __always_inline __pure bool use_xsave(void)
 static __always_inline __pure bool use_xsave(void)

+ 6 - 3
arch/x86/include/asm/xsave.h

@@ -125,8 +125,11 @@ static inline void fpu_xsave(struct fpu *fpu)
 {
 {
 	/* This, however, we can work around by forcing the compiler to select
 	/* This, however, we can work around by forcing the compiler to select
 	   an addressing mode that doesn't require extended registers. */
 	   an addressing mode that doesn't require extended registers. */
-	__asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27"
-			     : : "D" (&(fpu->state->xsave)),
-				 "a" (-1), "d"(-1) : "memory");
+	alternative_input(
+		".byte " REX_PREFIX "0x0f,0xae,0x27",
+		".byte " REX_PREFIX "0x0f,0xae,0x37",
+		X86_FEATURE_XSAVEOPT,
+		[fx] "D" (&fpu->state->xsave), "a" (-1), "d" (-1) :
+		"memory");
 }
 }
 #endif
 #endif

+ 8 - 0
arch/x86/kernel/cpu/common.c

@@ -140,10 +140,18 @@ EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
 static int __init x86_xsave_setup(char *s)
 static int __init x86_xsave_setup(char *s)
 {
 {
 	setup_clear_cpu_cap(X86_FEATURE_XSAVE);
 	setup_clear_cpu_cap(X86_FEATURE_XSAVE);
+	setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
 	return 1;
 	return 1;
 }
 }
 __setup("noxsave", x86_xsave_setup);
 __setup("noxsave", x86_xsave_setup);
 
 
+static int __init x86_xsaveopt_setup(char *s)
+{
+	setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
+	return 1;
+}
+__setup("noxsaveopt", x86_xsaveopt_setup);
+
 #ifdef CONFIG_X86_32
 #ifdef CONFIG_X86_32
 static int cachesize_override __cpuinitdata = -1;
 static int cachesize_override __cpuinitdata = -1;
 static int disable_x86_serial_nr __cpuinitdata = 1;
 static int disable_x86_serial_nr __cpuinitdata = 1;