linux/arch/x86/kernel/fpu
Adamos Ttofari 10e4b5166d x86/fpu: Keep xfd_state in sync with MSR_IA32_XFD
Commit 672365477a ("x86/fpu: Update XFD state where required") and
commit 8bf26758ca ("x86/fpu: Add XFD state to fpstate") introduced a
per CPU variable xfd_state to keep the MSR_IA32_XFD value cached, in
order to avoid unnecessary writes to the MSR.

On CPU hotplug MSR_IA32_XFD is reset to the init_fpstate.xfd, which
wipes out any stale state. But the per CPU cached xfd value is not
reset, which brings them out of sync.

As a consequence a subsequent xfd_update_state() might fail to update
the MSR which in turn can result in XRSTOR raising a #NM in kernel
space, which crashes the kernel.

To fix this, introduce xfd_set_state() to write xfd_state together
with MSR_IA32_XFD, and use it in all places that set MSR_IA32_XFD.

Fixes: 672365477a ("x86/fpu: Update XFD state where required")
Signed-off-by: Adamos Ttofari <attofari@amazon.de>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240322230439.456571-1-chang.seok.bae@intel.com

Closes: https://lore.kernel.org/lkml/20230511152818.13839-1-attofari@amazon.de
2024-03-24 04:03:54 +01:00
..
bugs.c x86/msr: Prepare for including <linux/percpu.h> into <asm/msr.h> 2024-03-04 12:01:39 +01:00
context.h x86/fpu: Invalidate FPU state correctly on exec() 2023-08-24 11:01:45 +02:00
core.c arch/x86: Fix typos 2024-01-03 11:46:22 +01:00
init.c x86/fpu: Mark init functions __init 2023-06-16 10:16:01 +02:00
internal.h x86/fpu/signal: Prepare for variable sigframe length 2021-10-26 10:18:09 +02:00
legacy.h x86/fpu: Remove .fixup usage 2021-12-11 09:09:48 +01:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
regset.c x86: Add PTRACE interface for shadow stack 2023-08-02 15:01:51 -07:00
signal.c x86/fpu: Stop relying on userspace for info to fault in xsave buffer 2024-01-30 07:25:48 -08:00
xstate.c x86/fpu: Keep xfd_state in sync with MSR_IA32_XFD 2024-03-24 04:03:54 +01:00
xstate.h x86/fpu: Keep xfd_state in sync with MSR_IA32_XFD 2024-03-24 04:03:54 +01:00