Skip to content

Commit 277f2e5

Browse files
authored
Avoid save/restoring AMX registers to avoid a SPR erratum
Intel SPR erratum SPR4 says that if you trip into a vmexit while doing FPU save/restore, your AMX register state might misbehave... and by misbehave, I mean save all zeroes incorrectly, leading to explosions if you restore it. Since we're not using AMX for anything, the simple way to avoid this is to just not save/restore those when we do anything, since we're killing preemption of any sort across our save/restores. If we ever decide to use AMX, it's not clear that we have any way to mitigate this, on Linux...but I am not an expert. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rich Ercolani <[email protected]> Closes #14989 Closes #15168
1 parent f0e34c8 commit 277f2e5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

include/os/linux/kernel/linux/simd_x86.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@
147147
#error "Toolchain needs to support the XSAVE assembler instruction"
148148
#endif
149149

150+
#ifndef XFEATURE_MASK_XTILE
151+
/*
152+
* For kernels where this doesn't exist yet, we still don't want to break
153+
* by save/restoring this broken nonsense.
154+
* See issue #14989 or Intel errata SPR4 for why
155+
*/
156+
#define XFEATURE_MASK_XTILE 0x60000
157+
#endif
158+
150159
#include <linux/mm.h>
151160
#include <linux/slab.h>
152161

@@ -315,18 +324,18 @@ kfpu_begin(void)
315324
uint8_t *state = zfs_kfpu_fpregs[smp_processor_id()];
316325
#if defined(HAVE_XSAVES)
317326
if (static_cpu_has(X86_FEATURE_XSAVES)) {
318-
kfpu_do_xsave("xsaves", state, ~0);
327+
kfpu_do_xsave("xsaves", state, ~XFEATURE_MASK_XTILE);
319328
return;
320329
}
321330
#endif
322331
#if defined(HAVE_XSAVEOPT)
323332
if (static_cpu_has(X86_FEATURE_XSAVEOPT)) {
324-
kfpu_do_xsave("xsaveopt", state, ~0);
333+
kfpu_do_xsave("xsaveopt", state, ~XFEATURE_MASK_XTILE);
325334
return;
326335
}
327336
#endif
328337
if (static_cpu_has(X86_FEATURE_XSAVE)) {
329-
kfpu_do_xsave("xsave", state, ~0);
338+
kfpu_do_xsave("xsave", state, ~XFEATURE_MASK_XTILE);
330339
} else if (static_cpu_has(X86_FEATURE_FXSR)) {
331340
kfpu_save_fxsr(state);
332341
} else {
@@ -376,12 +385,12 @@ kfpu_end(void)
376385
uint8_t *state = zfs_kfpu_fpregs[smp_processor_id()];
377386
#if defined(HAVE_XSAVES)
378387
if (static_cpu_has(X86_FEATURE_XSAVES)) {
379-
kfpu_do_xrstor("xrstors", state, ~0);
388+
kfpu_do_xrstor("xrstors", state, ~XFEATURE_MASK_XTILE);
380389
goto out;
381390
}
382391
#endif
383392
if (static_cpu_has(X86_FEATURE_XSAVE)) {
384-
kfpu_do_xrstor("xrstor", state, ~0);
393+
kfpu_do_xrstor("xrstor", state, ~XFEATURE_MASK_XTILE);
385394
} else if (static_cpu_has(X86_FEATURE_FXSR)) {
386395
kfpu_restore_fxsr(state);
387396
} else {

0 commit comments

Comments
 (0)