x86/xsave changes for v3.17-rc1
Subsystems (2)
Hi Linus,
This is a patchset to support the XSAVES instruction required to support context switch of supervisor-only features in upcoming silicon. This patchset missed the 3.16 merge window, which is why it is based on 3.15-rc7.
-hpa
The following changes since commit c7208164e66f63e3ec1759b98087849286410741:
Linux 3.15-rc7 (2014-05-25 16:06:00 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-xsave-for-linus
for you to fetch changes up to d0f2dd186133a0241a2ccefb188a0e49e8187859:
x86, xsave: Add forgotten inline annotation (2014-06-18 15:19:59 -0700)
----------------------------------------------------------------
Borislav Petkov (1):
x86, xsave: Add forgotten inline annotation
Fenghua Yu (17):
x86/cpufeature.h: Reformat x86 feature macros
x86/xsaves: Detect xsaves/xrstors feature
x86/xsaves: Add a kernel parameter noxsaves to disable xsaves/xrstors x86/alternative: Add alternative_input_2 to support alternative with two features and input x86/xsaves: Change compacted format xsave area header
x86/xsaves: Define macros for xsave instructions
x86/xsaves: Define a macro for handling xsave/xrstor instruction fault x86/xsaves: Use xsaves/xrstors to save and restore xsave area
x86/xsaves: Use xsaves/xrstors for context switch
x86/xsaves: Use xsave/xrstor for saving and restoring user space context x86/xsaves: Clear reserved bits in xsave header
x86/xsaves: Add xsaves and xrstors support for booting time
x86/xsaves: Save xstate to task's xsave area in __save_fpu during booting time x86/xsaves: Call booting time xsaves and xrstors in setup_init_fpu_buf x86/xsaves: Enable xsaves/xrstors
Define kernel API to get address of each state in xsave area
x86/xsaves: Clean up code in xstate offsets computation in xsave area
H. Peter Anvin (1):
x86/xsave: Make it clear that the XSAVE macros use (%edi)/(%rdi)
Documentation/kernel-parameters.txt | 15 ++ arch/x86/include/asm/alternative.h | 14 ++ arch/x86/include/asm/cpufeature.h | 370 +++++++++++++++++----------------- arch/x86/include/asm/fpu-internal.h | 9 +- arch/x86/include/asm/processor.h | 4 +- arch/x86/include/asm/xsave.h | 223 +++++++++++++++----- arch/x86/include/uapi/asm/msr-index.h | 2 + arch/x86/kernel/cpu/common.c | 17 ++ arch/x86/kernel/cpu/scattered.c | 1 - arch/x86/kernel/i387.c | 2 +- arch/x86/kernel/process.c | 1 + arch/x86/kernel/xsave.c | 118 ++++++++++- 12 files changed, 523 insertions(+), 253 deletions(-)
Documentation/kernel-parameters.txt +15 -0
@@ -2124,6 +2124,21 @@ bytes respectively. Such letter suffixes can also be entirely omitted. and restore using xsave. The kernel will fallback to enabling legacy floating-point and sse state. + noxsaveopt [X86] Disables xsaveopt used in saving x86 extended + register states. The kernel will fall back to use + xsave to save the states. By using this parameter, + performance of saving the states is degraded because + xsave doesn't support modified optimization while + xsaveopt supports it on xsaveopt enabled systems. + + noxsaves [X86] Disables xsaves and xrstors used in saving and + restoring x86 extended register state in compacted + form of xsave area. The kernel will fall back to use + xsaveopt and xrstor to save and restore the states + in standard form of xsave area. By using this + parameter, xsave area per process might occupy more + memory on xsaves enabled systems. + eagerfpu= [X86] on enable eager fpu restore off disable eager fpu restore
arch/x86/include/asm/alternative.h +14 -0
@@ -161,6 +161,20 @@ static inline int alternatives_text_reserved(void *start, void *end) asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \ : : "i" (0), ## input) +/* +* This is similar to alternative_input. But it has two features and +* respective instructions. +* +* If CPU has feature2, newinstr2 is used. +* Otherwise, if CPU has feature1, newinstr1 is used. +* Otherwise, oldinstr is used. +*/ +#define alternative_input_2 (oldinstr, newinstr1, feature1, newinstr2, \ + feature2, input...) \ + asm volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, \ + newinstr2, feature2) \ + : : "i" (0), ## input) +/* Like alternative_input, but with a single output argument */ #define alternative_io(oldinstr, newinstr, feature, output, input...) \ asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
arch/x86/include/asm/cpufeature.h +188 -182
414 lines not on this page · raw message
arch/x86/include/asm/fpu-internal.h +6 -3
@@ -508,9 +508,12 @@ static inline void user_fpu_begin(void)static inline void __save_fpu (struct task_struct *tsk) { -if (use_xsave ()) -xsave_state (&tsk->thread.fpu.state->xsave,-1 ); -else +if (use_xsave ()) { +if (unlikely (system_state ==SYSTEM_BOOTING )) +xsave_state_booting (&tsk->thread.fpu.state->xsave,-1 ); +else +xsave_state (&tsk->thread.fpu.state->xsave,-1 ); + }else fpu_fxsave (&tsk->thread.fpu); }
arch/x86/include/asm/processor.h +2 -2
@@ -386,8 +386,8 @@ struct bndcsr_struct {struct xsave_hdr_struct {u64 xstate_bv; -u64 reserved1[2 ]; -u64 reserved2[5 ]; +u64 xcomp_bv; +u64 reserved[6 ]; } __attribute__((packed));struct xsave_struct {
arch/x86/include/asm/xsave.h +167 -56
260 lines not on this page · raw message
arch/x86/include/uapi/asm/msr-index.h +2 -0
@@ -297,6 +297,8 @@#define MSR_IA32_TSC_ADJUST 0x0000003b#define MSR_IA32_BNDCFGS 0x00000d90 +#define MSR_IA32_XSS 0x00000da0 +#define FEATURE_CONTROL_LOCKED (1<<0)#define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1)#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
arch/x86/kernel/cpu/common.c +17 -0
@@ -146,6 +146,7 @@ static int __init x86_xsave_setup(char *s) {setup_clear_cpu_cap (X86_FEATURE_XSAVE );setup_clear_cpu_cap (X86_FEATURE_XSAVEOPT ); +setup_clear_cpu_cap (X86_FEATURE_XSAVES );setup_clear_cpu_cap (X86_FEATURE_AVX );setup_clear_cpu_cap (X86_FEATURE_AVX2 );return 1 ;
@@ -159,6 +160,13 @@ static int __init x86_xsaveopt_setup(char *s) }__setup ("noxsaveopt" , x86_xsaveopt_setup); +static int __init x86_xsaves_setup (char *s) +{ +setup_clear_cpu_cap (X86_FEATURE_XSAVES ); +return 1 ; +} +__setup ("noxsaves" , x86_xsaves_setup); +#ifdef CONFIG_X86_32 static int cachesize_override =-1 ;static int disable_x86_serial_nr =1 ;
@@ -632,6 +640,15 @@ void get_cpu_cap(struct cpuinfo_x86 *c) c->x86_capability[9 ] = ebx; } +/* Extended state features: level 0x0000000d */ +if (c->cpuid_level >=0x0000000d ) { +u32 eax, ebx, ecx, edx; + +cpuid_count (0x0000000d ,1 , &eax, &ebx, &ecx, &edx); + + c->x86_capability[10 ] = eax; + } +/* AMD-defined flags: level 0x80000001 */ xlvl =cpuid_eax (0x80000000 ); c->extended_cpuid_level = xlvl;
arch/x86/kernel/cpu/scattered.c +0 -1
@@ -38,7 +38,6 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) { X86_FEATURE_PTS, CR_EAX, 6, 0x00000006, 0 }, { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 }, - { X86_FEATURE_XSAVEOPT, CR_EAX, 0, 0x0000000d, 1 }, { X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 }, { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_PROC_FEEDBACK, CR_EDX,11, 0x80000007, 0 },
arch/x86/kernel/i387.c +1 -1
@@ -375,7 +375,7 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,/* * These bits must be zero. */ - xsave_hdr->reserved1[0 ] = xsave_hdr->reserved1[1 ] =0 ; +memset (xsave_hdr->reserved,0 ,48 );return ret; }
arch/x86/kernel/process.c +1 -0
@@ -93,6 +93,7 @@ void arch_task_cache_init(void)kmem_cache_create ("task_xstate" , xstate_size, __alignof__(union thread_xstate ),SLAB_PANIC |SLAB_NOTRACK ,NULL ); +setup_xstate_comp (); }/*
arch/x86/kernel/xsave.c +110 -8
176 lines not on this page · raw message