Skip to content

Commit 1654e95

Browse files
committed
Merge tag 'x86_urgent_for_v5.16_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Borislav Petkov: - Add the model number of a new, Raptor Lake CPU, to intel-family.h - Do not log spurious corrected MCEs on SKL too, due to an erratum - Clarify the path of paravirt ops patches upstream - Add an optimization to avoid writing out AMX components to sigframes when former are in init state * tag 'x86_urgent_for_v5.16_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/cpu: Add Raptor Lake to Intel family x86/mce: Add errata workaround for Skylake SKX37 MAINTAINERS: Add some information to PARAVIRT_OPS entry x86/fpu: Optimize out sigframe xfeatures when in init state
2 parents 35c8fad + fbdb5e8 commit 1654e95

File tree

8 files changed

+71
-4
lines changed

8 files changed

+71
-4
lines changed

Documentation/x86/xstate.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ kernel sends SIGILL to the application. If the process has permission then
6363
the handler allocates a larger xstate buffer for the task so the large
6464
state can be context switched. In the unlikely cases that the allocation
6565
fails, the kernel sends SIGSEGV.
66+
67+
Dynamic features in signal frames
68+
---------------------------------
69+
70+
Dynamcally enabled features are not written to the signal frame upon signal
71+
entry if the feature is in its initial configuration. This differs from
72+
non-dynamic features which are always written regardless of their
73+
configuration. Signal handlers can examine the XSAVE buffer's XSTATE_BV
74+
field to determine if a features was written.

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14412,7 +14412,9 @@ M: Juergen Gross <[email protected]>
1441214412
M: Deep Shah <[email protected]>
1441314413
M: "VMware, Inc." <[email protected]>
1441414414
14415+
1441514416
S: Supported
14417+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/core
1441614418
F: Documentation/virt/paravirt_ops.rst
1441714419
F: arch/*/include/asm/paravirt*.h
1441814420
F: arch/*/kernel/paravirt*

arch/x86/include/asm/fpu/xcr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _ASM_X86_FPU_XCR_H
44

55
#define XCR_XFEATURE_ENABLED_MASK 0x00000000
6+
#define XCR_XFEATURE_IN_USE_MASK 0x00000001
67

78
static inline u64 xgetbv(u32 index)
89
{
@@ -20,4 +21,15 @@ static inline void xsetbv(u32 index, u64 value)
2021
asm volatile("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
2122
}
2223

24+
/*
25+
* Return a mask of xfeatures which are currently being tracked
26+
* by the processor as being in the initial configuration.
27+
*
28+
* Callers should check X86_FEATURE_XGETBV1.
29+
*/
30+
static inline u64 xfeatures_in_use(void)
31+
{
32+
return xgetbv(XCR_XFEATURE_IN_USE_MASK);
33+
}
34+
2335
#endif /* _ASM_X86_FPU_XCR_H */

arch/x86/include/asm/fpu/xstate.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
#define XFEATURE_MASK_FPSTATE (XFEATURE_MASK_USER_RESTORE | \
9393
XFEATURE_MASK_SUPERVISOR_SUPPORTED)
9494

95+
/*
96+
* Features in this mask have space allocated in the signal frame, but may not
97+
* have that space initialized when the feature is in its init state.
98+
*/
99+
#define XFEATURE_MASK_SIGFRAME_INITOPT (XFEATURE_MASK_XTILE | \
100+
XFEATURE_MASK_USER_DYNAMIC)
101+
95102
extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
96103

97104
extern void __init update_regset_xstate_info(unsigned int size,

arch/x86/include/asm/intel-family.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
#define INTEL_FAM6_ALDERLAKE 0x97 /* Golden Cove / Gracemont */
109109
#define INTEL_FAM6_ALDERLAKE_L 0x9A /* Golden Cove / Gracemont */
110110

111+
#define INTEL_FAM6_RAPTOR_LAKE 0xB7
112+
111113
/* "Small Core" Processors (Atom) */
112114

113115
#define INTEL_FAM6_ATOM_BONNELL 0x1C /* Diamondville, Pineview */

arch/x86/kernel/cpu/cpuid-deps.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static const struct cpuid_dep cpuid_deps[] = {
7676
{ X86_FEATURE_SGX1, X86_FEATURE_SGX },
7777
{ X86_FEATURE_SGX2, X86_FEATURE_SGX1 },
7878
{ X86_FEATURE_XFD, X86_FEATURE_XSAVES },
79+
{ X86_FEATURE_XFD, X86_FEATURE_XGETBV1 },
7980
{ X86_FEATURE_AMX_TILE, X86_FEATURE_XFD },
8081
{}
8182
};

arch/x86/kernel/cpu/mce/intel.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,13 @@ bool intel_filter_mce(struct mce *m)
547547
{
548548
struct cpuinfo_x86 *c = &boot_cpu_data;
549549

550-
/* MCE errata HSD131, HSM142, HSW131, BDM48, and HSM142 */
550+
/* MCE errata HSD131, HSM142, HSW131, BDM48, HSM142 and SKX37 */
551551
if ((c->x86 == 6) &&
552552
((c->x86_model == INTEL_FAM6_HASWELL) ||
553553
(c->x86_model == INTEL_FAM6_HASWELL_L) ||
554554
(c->x86_model == INTEL_FAM6_BROADWELL) ||
555-
(c->x86_model == INTEL_FAM6_HASWELL_G)) &&
555+
(c->x86_model == INTEL_FAM6_HASWELL_G) ||
556+
(c->x86_model == INTEL_FAM6_SKYLAKE_X)) &&
556557
(m->bank == 0) &&
557558
((m->status & 0xa0000000ffffffff) == 0x80000000000f0005))
558559
return true;

arch/x86/kernel/fpu/xstate.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <asm/cpufeature.h>
66
#include <asm/fpu/xstate.h>
7+
#include <asm/fpu/xcr.h>
78

89
#ifdef CONFIG_X86_64
910
DECLARE_PER_CPU(u64, xfd_state);
@@ -198,6 +199,32 @@ static inline void os_xrstor_supervisor(struct fpstate *fpstate)
198199
XSTATE_XRESTORE(&fpstate->regs.xsave, lmask, hmask);
199200
}
200201

202+
/*
203+
* XSAVE itself always writes all requested xfeatures. Removing features
204+
* from the request bitmap reduces the features which are written.
205+
* Generate a mask of features which must be written to a sigframe. The
206+
* unset features can be optimized away and not written.
207+
*
208+
* This optimization is user-visible. Only use for states where
209+
* uninitialized sigframe contents are tolerable, like dynamic features.
210+
*
211+
* Users of buffers produced with this optimization must check XSTATE_BV
212+
* to determine which features have been optimized out.
213+
*/
214+
static inline u64 xfeatures_need_sigframe_write(void)
215+
{
216+
u64 xfeaures_to_write;
217+
218+
/* In-use features must be written: */
219+
xfeaures_to_write = xfeatures_in_use();
220+
221+
/* Also write all non-optimizable sigframe features: */
222+
xfeaures_to_write |= XFEATURE_MASK_USER_SUPPORTED &
223+
~XFEATURE_MASK_SIGFRAME_INITOPT;
224+
225+
return xfeaures_to_write;
226+
}
227+
201228
/*
202229
* Save xstate to user space xsave area.
203230
*
@@ -220,10 +247,16 @@ static inline int xsave_to_user_sigframe(struct xregs_state __user *buf)
220247
*/
221248
struct fpstate *fpstate = current->thread.fpu.fpstate;
222249
u64 mask = fpstate->user_xfeatures;
223-
u32 lmask = mask;
224-
u32 hmask = mask >> 32;
250+
u32 lmask;
251+
u32 hmask;
225252
int err;
226253

254+
/* Optimize away writing unnecessary xfeatures: */
255+
if (fpu_state_size_dynamic())
256+
mask &= xfeatures_need_sigframe_write();
257+
258+
lmask = mask;
259+
hmask = mask >> 32;
227260
xfd_validate_state(fpstate, mask, false);
228261

229262
stac();

0 commit comments

Comments
 (0)