Commit 073e627a authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov

x86/fpu/xstate: Use fpstate for os_xsave()

With variable feature sets XSAVE[S] requires to know the feature set for
which the buffer is valid. Retrieve it from fpstate.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211013145323.025695590@linutronix.de
parent be31dfdf
...@@ -105,7 +105,7 @@ EXPORT_SYMBOL(irq_fpu_usable); ...@@ -105,7 +105,7 @@ EXPORT_SYMBOL(irq_fpu_usable);
void save_fpregs_to_fpstate(struct fpu *fpu) void save_fpregs_to_fpstate(struct fpu *fpu)
{ {
if (likely(use_xsave())) { if (likely(use_xsave())) {
os_xsave(&fpu->fpstate->regs.xsave); os_xsave(fpu->fpstate);
/* /*
* AVX512 state is tracked here because its use is * AVX512 state is tracked here because its use is
......
...@@ -349,7 +349,6 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, ...@@ -349,7 +349,6 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx,
if (__copy_from_user(&env, buf, sizeof(env))) if (__copy_from_user(&env, buf, sizeof(env)))
return false; return false;
fpregs = &fpu->fpstate->regs;
/* /*
* By setting TIF_NEED_FPU_LOAD it is ensured that our xstate is * By setting TIF_NEED_FPU_LOAD it is ensured that our xstate is
* not modified on context switch and that the xstate is considered * not modified on context switch and that the xstate is considered
...@@ -367,13 +366,14 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, ...@@ -367,13 +366,14 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx,
* the right place in memory. It's ia32 mode. Shrug. * the right place in memory. It's ia32 mode. Shrug.
*/ */
if (xfeatures_mask_supervisor()) if (xfeatures_mask_supervisor())
os_xsave(&fpregs->xsave); os_xsave(fpu->fpstate);
set_thread_flag(TIF_NEED_FPU_LOAD); set_thread_flag(TIF_NEED_FPU_LOAD);
} }
__fpu_invalidate_fpregs_state(fpu); __fpu_invalidate_fpregs_state(fpu);
__cpu_invalidate_fpregs_state(); __cpu_invalidate_fpregs_state();
fpregs_unlock(); fpregs_unlock();
fpregs = &fpu->fpstate->regs;
if (use_xsave() && !fx_only) { if (use_xsave() && !fx_only) {
if (copy_sigframe_from_user_to_xstate(&fpregs->xsave, buf_fx)) if (copy_sigframe_from_user_to_xstate(&fpregs->xsave, buf_fx))
return false; return false;
......
...@@ -101,16 +101,16 @@ extern void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr); ...@@ -101,16 +101,16 @@ extern void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
* Uses either XSAVE or XSAVEOPT or XSAVES depending on the CPU features * Uses either XSAVE or XSAVEOPT or XSAVES depending on the CPU features
* and command line options. The choice is permanent until the next reboot. * and command line options. The choice is permanent until the next reboot.
*/ */
static inline void os_xsave(struct xregs_state *xstate) static inline void os_xsave(struct fpstate *fpstate)
{ {
u64 mask = xfeatures_mask_all; u64 mask = fpstate->xfeatures;
u32 lmask = mask; u32 lmask = mask;
u32 hmask = mask >> 32; u32 hmask = mask >> 32;
int err; int err;
WARN_ON_FPU(!alternatives_patched); WARN_ON_FPU(!alternatives_patched);
XSTATE_XSAVE(xstate, lmask, hmask, err); XSTATE_XSAVE(&fpstate->regs.xsave, lmask, hmask, err);
/* We should never fault when copying to a kernel buffer: */ /* We should never fault when copying to a kernel buffer: */
WARN_ON_FPU(err); WARN_ON_FPU(err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment