Commit 087df48c authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov

x86/fpu: Replace KVMs xstate component clearing

In order to prepare for the support of dynamically enabled FPU features,
move the clearing of xstate components to the FPU core code.

No functional change.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Cc: kvm@vger.kernel.org
Link: https://lkml.kernel.org/r/20211013145322.399567049@linutronix.de
parent 18b3fa1a
...@@ -132,6 +132,7 @@ DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx); ...@@ -132,6 +132,7 @@ DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
/* fpstate-related functions which are exported to KVM */ /* fpstate-related functions which are exported to KVM */
extern void fpu_init_fpstate_user(struct fpu *fpu); extern void fpu_init_fpstate_user(struct fpu *fpu);
extern void fpstate_clear_xstate_component(struct fpstate *fps, unsigned int xfeature);
/* KVM specific functions */ /* KVM specific functions */
extern void fpu_swap_kvm_fpu(struct fpu *save, struct fpu *rstor, u64 restore_mask); extern void fpu_swap_kvm_fpu(struct fpu *save, struct fpu *rstor, u64 restore_mask);
......
...@@ -128,7 +128,6 @@ extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS]; ...@@ -128,7 +128,6 @@ extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
extern void __init update_regset_xstate_info(unsigned int size, extern void __init update_regset_xstate_info(unsigned int size,
u64 xstate_mask); u64 xstate_mask);
void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
int xfeature_size(int xfeature_nr); int xfeature_size(int xfeature_nr);
int copy_uabi_from_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf); int copy_uabi_from_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf);
int copy_sigframe_from_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf); int copy_sigframe_from_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf);
......
...@@ -908,7 +908,6 @@ void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr) ...@@ -908,7 +908,6 @@ void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr)
return __raw_xsave_addr(xsave, xfeature_nr); return __raw_xsave_addr(xsave, xfeature_nr);
} }
EXPORT_SYMBOL_GPL(get_xsave_addr);
#ifdef CONFIG_ARCH_HAS_PKEYS #ifdef CONFIG_ARCH_HAS_PKEYS
...@@ -1257,6 +1256,17 @@ void xrstors(struct xregs_state *xstate, u64 mask) ...@@ -1257,6 +1256,17 @@ void xrstors(struct xregs_state *xstate, u64 mask)
WARN_ON_ONCE(err); WARN_ON_ONCE(err);
} }
#if IS_ENABLED(CONFIG_KVM)
void fpstate_clear_xstate_component(struct fpstate *fps, unsigned int xfeature)
{
void *addr = get_xsave_addr(&fps->regs.xsave, xfeature);
if (addr)
memset(addr, 0, xstate_sizes[xfeature]);
}
EXPORT_SYMBOL_GPL(fpstate_clear_xstate_component);
#endif
#ifdef CONFIG_PROC_PID_ARCH_STATUS #ifdef CONFIG_PROC_PID_ARCH_STATUS
/* /*
* Report the amount of time elapsed in millisecond since last AVX512 * Report the amount of time elapsed in millisecond since last AVX512
......
...@@ -21,6 +21,8 @@ extern void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsav ...@@ -21,6 +21,8 @@ extern void __copy_xstate_to_uabi_buf(struct membuf to, struct xregs_state *xsav
extern void fpu__init_cpu_xstate(void); extern void fpu__init_cpu_xstate(void);
extern void fpu__init_system_xstate(void); extern void fpu__init_system_xstate(void);
extern void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr);
/* XSAVE/XRSTOR wrapper functions */ /* XSAVE/XRSTOR wrapper functions */
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
......
...@@ -10705,7 +10705,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) ...@@ -10705,7 +10705,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
vcpu->arch.apf.halted = false; vcpu->arch.apf.halted = false;
if (vcpu->arch.guest_fpu && kvm_mpx_supported()) { if (vcpu->arch.guest_fpu && kvm_mpx_supported()) {
void *mpx_state_buffer; struct fpstate *fpstate = vcpu->arch.guest_fpu->fpstate;
/* /*
* To avoid have the INIT path from kvm_apic_has_events() that be * To avoid have the INIT path from kvm_apic_has_events() that be
...@@ -10713,14 +10713,10 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) ...@@ -10713,14 +10713,10 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
*/ */
if (init_event) if (init_event)
kvm_put_guest_fpu(vcpu); kvm_put_guest_fpu(vcpu);
mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave,
XFEATURE_BNDREGS); fpstate_clear_xstate_component(fpstate, XFEATURE_BNDREGS);
if (mpx_state_buffer) fpstate_clear_xstate_component(fpstate, XFEATURE_BNDCSR);
memset(mpx_state_buffer, 0, sizeof(struct mpx_bndreg_state));
mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu->state.xsave,
XFEATURE_BNDCSR);
if (mpx_state_buffer)
memset(mpx_state_buffer, 0, sizeof(struct mpx_bndcsr));
if (init_event) if (init_event)
kvm_load_guest_fpu(vcpu); kvm_load_guest_fpu(vcpu);
} }
......
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