Skip to content

Commit

Permalink
x86/fpu: Add XFD state to fpstate
Browse files Browse the repository at this point in the history
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 <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211021225527.10184-15-chang.seok.bae@intel.com
  • Loading branch information
ChangSeokBae authored and Borislav Petkov committed Oct 26, 2021
1 parent dae1bd5 commit 8bf2675
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arch/x86/include/asm/fpu/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ struct fpstate {
/* @user_xfeatures: xfeatures valid in UABI buffers */
u64 user_xfeatures;

/* @xfd: xfeatures disabled to trap userspace use. */
u64 xfd;

/* @is_valloc: Indicator for dynamically allocated state */
unsigned int is_valloc : 1;

Expand Down
2 changes: 2 additions & 0 deletions arch/x86/kernel/fpu/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#ifdef CONFIG_X86_64
DEFINE_STATIC_KEY_FALSE(__fpu_state_size_dynamic);
DEFINE_PER_CPU(u64, xfd_state);
#endif

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

void fpstate_reset(struct fpu *fpu)
Expand Down
4 changes: 4 additions & 0 deletions arch/x86/kernel/fpu/xstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <asm/cpufeature.h>
#include <asm/fpu/xstate.h>

#ifdef CONFIG_X86_64
DECLARE_PER_CPU(u64, xfd_state);
#endif

static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask)
{
/*
Expand Down

0 comments on commit 8bf2675

Please sign in to comment.