Skip to content

Commit 6bad06b

Browse files
Suresh SiddhaH. Peter Anvin
authored andcommitted
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 <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 29104e1 commit 6bad06b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

arch/x86/include/asm/i387.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern int restore_i387_xstate_ia32(void __user *buf);
6060

6161
static __always_inline __pure bool use_xsaveopt(void)
6262
{
63-
return 0;
63+
return static_cpu_has(X86_FEATURE_XSAVEOPT);
6464
}
6565

6666
static __always_inline __pure bool use_xsave(void)

arch/x86/include/asm/xsave.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ static inline void fpu_xsave(struct fpu *fpu)
125125
{
126126
/* This, however, we can work around by forcing the compiler to select
127127
an addressing mode that doesn't require extended registers. */
128-
__asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27"
129-
: : "D" (&(fpu->state->xsave)),
130-
"a" (-1), "d"(-1) : "memory");
128+
alternative_input(
129+
".byte " REX_PREFIX "0x0f,0xae,0x27",
130+
".byte " REX_PREFIX "0x0f,0xae,0x37",
131+
X86_FEATURE_XSAVEOPT,
132+
[fx] "D" (&fpu->state->xsave), "a" (-1), "d" (-1) :
133+
"memory");
131134
}
132135
#endif

arch/x86/kernel/cpu/common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,18 @@ EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
140140
static int __init x86_xsave_setup(char *s)
141141
{
142142
setup_clear_cpu_cap(X86_FEATURE_XSAVE);
143+
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
143144
return 1;
144145
}
145146
__setup("noxsave", x86_xsave_setup);
146147

148+
static int __init x86_xsaveopt_setup(char *s)
149+
{
150+
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
151+
return 1;
152+
}
153+
__setup("noxsaveopt", x86_xsaveopt_setup);
154+
147155
#ifdef CONFIG_X86_32
148156
static int cachesize_override __cpuinitdata = -1;
149157
static int disable_x86_serial_nr __cpuinitdata = 1;

0 commit comments

Comments
 (0)