Skip to content

Commit 8bf2675

Browse files
ChangSeokBaesuryasaimadhu
authored andcommitted
x86/fpu: Add XFD state to fpstate
Add storage for XFD register state to struct fpstate. This will be used to store the XFD MSR state. This will be used for switching the XFD MSR when FPU content is restored. Add a per-CPU variable to cache the current MSR value so the MSR has only to be written when the values are different. Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent dae1bd5 commit 8bf2675

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ struct fpstate {
322322
/* @user_xfeatures: xfeatures valid in UABI buffers */
323323
u64 user_xfeatures;
324324

325+
/* @xfd: xfeatures disabled to trap userspace use. */
326+
u64 xfd;
327+
325328
/* @is_valloc: Indicator for dynamically allocated state */
326329
unsigned int is_valloc : 1;
327330

arch/x86/kernel/fpu/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#ifdef CONFIG_X86_64
2929
DEFINE_STATIC_KEY_FALSE(__fpu_state_size_dynamic);
30+
DEFINE_PER_CPU(u64, xfd_state);
3031
#endif
3132

3233
/* The FPU state configuration data for kernel and user space */
@@ -409,6 +410,7 @@ static void __fpstate_reset(struct fpstate *fpstate)
409410
fpstate->user_size = fpu_user_cfg.default_size;
410411
fpstate->xfeatures = fpu_kernel_cfg.default_features;
411412
fpstate->user_xfeatures = fpu_user_cfg.default_features;
413+
fpstate->xfd = init_fpstate.xfd;
412414
}
413415

414416
void fpstate_reset(struct fpu *fpu)

arch/x86/kernel/fpu/xstate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include <asm/cpufeature.h>
66
#include <asm/fpu/xstate.h>
77

8+
#ifdef CONFIG_X86_64
9+
DECLARE_PER_CPU(u64, xfd_state);
10+
#endif
11+
812
static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask)
913
{
1014
/*

0 commit comments

Comments
 (0)