Skip to content

Commit 4d6245c

Browse files
committed
Merge branch 'x86-fpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 FPU updates from Ingo Molnar: "Three changes: fix a race that can result in FPU corruption, plus two cleanups" * 'x86-fpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/fpu: Deactivate FPU state after failure during state load x86/fpu/xstate: Make xfeature_is_supervisor()/xfeature_is_user() return bool x86/fpu/xstate: Fix small issues
2 parents c0275ae + bbc5534 commit 4d6245c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

arch/x86/kernel/fpu/signal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
352352
fpregs_unlock();
353353
return 0;
354354
}
355+
fpregs_deactivate(fpu);
355356
fpregs_unlock();
356357
}
357358

@@ -403,6 +404,8 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
403404
}
404405
if (!ret)
405406
fpregs_mark_activate();
407+
else
408+
fpregs_deactivate(fpu);
406409
fpregs_unlock();
407410

408411
err_out:

arch/x86/kernel/fpu/xstate.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,20 @@ int cpu_has_xfeatures(u64 xfeatures_needed, const char **feature_name)
107107
}
108108
EXPORT_SYMBOL_GPL(cpu_has_xfeatures);
109109

110-
static int xfeature_is_supervisor(int xfeature_nr)
110+
static bool xfeature_is_supervisor(int xfeature_nr)
111111
{
112112
/*
113-
* We currently do not support supervisor states, but if
114-
* we did, we could find out like this.
115-
*
116-
* SDM says: If state component 'i' is a user state component,
117-
* ECX[0] return 0; if state component i is a supervisor
118-
* state component, ECX[0] returns 1.
113+
* Extended State Enumeration Sub-leaves (EAX = 0DH, ECX = n, n > 1)
114+
* returns ECX[0] set to (1) for a supervisor state, and cleared (0)
115+
* for a user state.
119116
*/
120117
u32 eax, ebx, ecx, edx;
121118

122119
cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx);
123-
return !!(ecx & 1);
120+
return ecx & 1;
124121
}
125122

126-
static int xfeature_is_user(int xfeature_nr)
123+
static bool xfeature_is_user(int xfeature_nr)
127124
{
128125
return !xfeature_is_supervisor(xfeature_nr);
129126
}
@@ -419,7 +416,8 @@ static void __init setup_init_fpu_buf(void)
419416
print_xstate_features();
420417

421418
if (boot_cpu_has(X86_FEATURE_XSAVES))
422-
init_fpstate.xsave.header.xcomp_bv = (u64)1 << 63 | xfeatures_mask;
419+
init_fpstate.xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
420+
xfeatures_mask;
423421

424422
/*
425423
* Init all the features state with header.xfeatures being 0x0

0 commit comments

Comments
 (0)