x86/fpu: Reset MXCSR to default in kernel_fpu_begin()
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 16 Jun 2020 09:12:57 +0000 (11:12 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Jul 2020 07:33:59 +0000 (09:33 +0200)
commit041ee87d2fafe0c23ded3b5e072b03102be66893
tree93664f239bf60dee4b82153b14f92eb25d03efa5
parent328d258d58b4407a0a4c93eb92e306eef13cf037
x86/fpu: Reset MXCSR to default in kernel_fpu_begin()

[ Upstream commit 7ad816762f9bf89e940e618ea40c43138b479e10 ]

Previously, kernel floating point code would run with the MXCSR control
register value last set by userland code by the thread that was active
on the CPU core just before kernel call. This could affect calculation
results if rounding mode was changed, or a crash if a FPU/SIMD exception
was unmasked.

Restore MXCSR to the kernel's default value.

 [ bp: Carve out from a bigger patch by Petteri, add feature check, add
   FNINIT call too (amluto). ]

Signed-off-by: Petteri Aimonen <jpa@git.mail.kapsi.fi>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=207979
Link: https://lkml.kernel.org/r/20200624114646.28953-2-bp@alien8.de
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/include/asm/fpu/internal.h
arch/x86/kernel/fpu/core.c