Skip to content

Commit 26bef13

Browse files
torvaldsH. Peter Anvin
authored andcommitted
x86, fpu, amd: Clear exceptions in AMD FXSAVE workaround
Before we do an EMMS in the AMD FXSAVE information leak workaround we need to clear any pending exceptions, otherwise we trap with a floating-point exception inside this code. Reported-by: halfdog <me@halfdog.net> Tested-by: Borislav Petkov <bp@suse.de> Link: http://lkml.kernel.org/r/CA%2B55aFxQnY_PCG_n4=0w-VG=YLXL-yr7oMxyy0WU2gCBAf3ydg@mail.gmail.com Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent 1739f09 commit 26bef13

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

arch/x86/include/asm/fpu-internal.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,13 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
293293
/* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
294294
is pending. Clear the x87 state here by setting it to fixed
295295
values. "m" is a random variable that should be in L1 */
296-
alternative_input(
297-
ASM_NOP8 ASM_NOP2,
298-
"emms\n\t" /* clear stack tags */
299-
"fildl %P[addr]", /* set F?P to defined value */
300-
X86_FEATURE_FXSAVE_LEAK,
301-
[addr] "m" (tsk->thread.fpu.has_fpu));
296+
if (unlikely(static_cpu_has(X86_FEATURE_FXSAVE_LEAK))) {
297+
asm volatile(
298+
"fnclex\n\t"
299+
"emms\n\t"
300+
"fildl %P[addr]" /* set F?P to defined value */
301+
: : [addr] "m" (tsk->thread.fpu.has_fpu));
302+
}
302303

303304
return fpu_restore_checking(&tsk->thread.fpu);
304305
}

0 commit comments

Comments
 (0)