[2/2] KVM: x86: Skip zeroing of MPX state on reset event
diff mbox series

Message ID 20191209201932.14259-3-sean.j.christopherson@intel.com
State New
Headers show
Series
  • KVM: x86: MPX bug fix and cleanup
Related show

Commit Message

Sean Christopherson Dec. 9, 2019, 8:19 p.m. UTC
Don't bother zeroing out MPX state in the guest's FPU on a reset event,
the guest's FPU is always zero allocated and there is no path between
kvm_arch_vcpu_create() and kvm_arch_vcpu_setup() that can lead to guest
MPX state being modified.

No functional change intended.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/x86.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Paolo Bonzini Dec. 10, 2019, 10:22 a.m. UTC | #1
On 09/12/19 21:19, Sean Christopherson wrote:
> Don't bother zeroing out MPX state in the guest's FPU on a reset event,
> the guest's FPU is always zero allocated and there is no path between
> kvm_arch_vcpu_create() and kvm_arch_vcpu_setup() that can lead to guest
> MPX state being modified.
> 
> No functional change intended.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Makes sense, but it's a bit weird to have INIT reset _less_ state than
RESET...  I've queued patch 1 only for now.

Paolo

> ---
>  arch/x86/kvm/x86.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 854ae27bb021..e6f4174f55cd 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9194,15 +9194,14 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
>  	kvm_async_pf_hash_reset(vcpu);
>  	vcpu->arch.apf.halted = false;
>  
> -	if (kvm_mpx_supported()) {
> +	if (kvm_mpx_supported() && init_event) {
>  		void *mpx_state_buffer;
>  
>  		/*
> -		 * To avoid have the INIT path from kvm_apic_has_events() that be
> -		 * called with loaded FPU and does not let userspace fix the state.
> +		 * Temporarily flush the guest's FPU to memory so that zeroing
> +		 * out the MPX areas is done using up-to-date state.
>  		 */
> -		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);
>  		if (mpx_state_buffer)
> @@ -9211,8 +9210,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
>  					XFEATURE_BNDCSR);
>  		if (mpx_state_buffer)
>  			memset(mpx_state_buffer, 0, sizeof(struct mpx_bndcsr));
> -		if (init_event)
> -			kvm_load_guest_fpu(vcpu);
> +		kvm_load_guest_fpu(vcpu);
>  	}
>  
>  	if (!init_event) {
>

Patch
diff mbox series

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 854ae27bb021..e6f4174f55cd 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9194,15 +9194,14 @@  void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 	kvm_async_pf_hash_reset(vcpu);
 	vcpu->arch.apf.halted = false;
 
-	if (kvm_mpx_supported()) {
+	if (kvm_mpx_supported() && init_event) {
 		void *mpx_state_buffer;
 
 		/*
-		 * To avoid have the INIT path from kvm_apic_has_events() that be
-		 * called with loaded FPU and does not let userspace fix the state.
+		 * Temporarily flush the guest's FPU to memory so that zeroing
+		 * out the MPX areas is done using up-to-date state.
 		 */
-		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);
 		if (mpx_state_buffer)
@@ -9211,8 +9210,7 @@  void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 					XFEATURE_BNDCSR);
 		if (mpx_state_buffer)
 			memset(mpx_state_buffer, 0, sizeof(struct mpx_bndcsr));
-		if (init_event)
-			kvm_load_guest_fpu(vcpu);
+		kvm_load_guest_fpu(vcpu);
 	}
 
 	if (!init_event) {