diff mbox series

[v3] KVM nVMX: MSRs should not be stored if VM-entry fails during or after loading guest state

Message ID 20181205000013.13474-2-krish.sadhukhan@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v3] KVM nVMX: MSRs should not be stored if VM-entry fails during or after loading guest state | expand

Commit Message

Krish Sadhukhan Dec. 5, 2018, midnight UTC
According to section "VM-entry Failures During or After Loading Guest State"
in Intel SDM vol 3C,

	"No MSRs are saved into the VM-exit MSR-store area."

when bit 31 of the exit reason is set.

Reported-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Suggested-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
---
 arch/x86/kvm/vmx.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Jim Mattson Dec. 5, 2018, 5:55 p.m. UTC | #1
On Tue, Dec 4, 2018 at 4:24 PM Krish Sadhukhan
<krish.sadhukhan@oracle.com> wrote:
>
> According to section "VM-entry Failures During or After Loading Guest State"
> in Intel SDM vol 3C,
>
>         "No MSRs are saved into the VM-exit MSR-store area."
>
> when bit 31 of the exit reason is set.
>
> Reported-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Suggested-by: Jim Mattson <jmattson@google.com>
> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
> ---
>  arch/x86/kvm/vmx.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 4555077..4d153935 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -13827,6 +13827,18 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
>                  * L2 to IDT_VECTORING_INFO_FIELD.
>                  */
>                 vmcs12_save_pending_event(vcpu, vmcs12);
> +
> +               /*
> +                * According to spec, there's no need to store the guest's
> +                * MSRs if the exit is due to a VM-entry failure that occurs
> +                * during or after loading the guest state. Since this exit
> +                * does not fall in that category, we need to save the MSRs.
> +                */

I'm still not a fan of this comment, but it's good enough.

Reviewed-by: Jim Mattson <jmattson@google.com>
Paolo Bonzini Dec. 14, 2018, 10:57 a.m. UTC | #2
On 05/12/18 01:00, Krish Sadhukhan wrote:
> According to section "VM-entry Failures During or After Loading Guest State"
> in Intel SDM vol 3C,
> 
> 	"No MSRs are saved into the VM-exit MSR-store area."
> 
> when bit 31 of the exit reason is set.
> 
> Reported-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Suggested-by: Jim Mattson <jmattson@google.com>
> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
> ---
>  arch/x86/kvm/vmx.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 4555077..4d153935 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -13827,6 +13827,18 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
>  		 * L2 to IDT_VECTORING_INFO_FIELD.
>  		 */
>  		vmcs12_save_pending_event(vcpu, vmcs12);
> +
> +		/*
> +		 * According to spec, there's no need to store the guest's
> +		 * MSRs if the exit is due to a VM-entry failure that occurs
> +		 * during or after loading the guest state. Since this exit
> +		 * does not fall in that category, we need to save the MSRs.
> +		 */
> +		if (nested_vmx_store_msr(vcpu,
> +					 vmcs12->vm_exit_msr_store_addr,
> +					 vmcs12->vm_exit_msr_store_count))
> +			nested_vmx_abort(vcpu,
> +					 VMX_ABORT_SAVE_GUEST_MSR_FAIL);
>  	}
>  
>  	/*
> @@ -14159,10 +14171,6 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
>  		 * immutable.
>  		 */
>  		nested_flush_cached_shadow_vmcs12(vcpu, vmcs12);
> -
> -		if (nested_vmx_store_msr(vcpu, vmcs12->vm_exit_msr_store_addr,
> -					 vmcs12->vm_exit_msr_store_count))
> -			nested_vmx_abort(vcpu, VMX_ABORT_SAVE_GUEST_MSR_FAIL);
>  	} else {
>  		/*
>  		 * The only expected VM-instruction error is "VM entry with
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4555077..4d153935 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -13827,6 +13827,18 @@  static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
 		 * L2 to IDT_VECTORING_INFO_FIELD.
 		 */
 		vmcs12_save_pending_event(vcpu, vmcs12);
+
+		/*
+		 * According to spec, there's no need to store the guest's
+		 * MSRs if the exit is due to a VM-entry failure that occurs
+		 * during or after loading the guest state. Since this exit
+		 * does not fall in that category, we need to save the MSRs.
+		 */
+		if (nested_vmx_store_msr(vcpu,
+					 vmcs12->vm_exit_msr_store_addr,
+					 vmcs12->vm_exit_msr_store_count))
+			nested_vmx_abort(vcpu,
+					 VMX_ABORT_SAVE_GUEST_MSR_FAIL);
 	}
 
 	/*
@@ -14159,10 +14171,6 @@  static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
 		 * immutable.
 		 */
 		nested_flush_cached_shadow_vmcs12(vcpu, vmcs12);
-
-		if (nested_vmx_store_msr(vcpu, vmcs12->vm_exit_msr_store_addr,
-					 vmcs12->vm_exit_msr_store_count))
-			nested_vmx_abort(vcpu, VMX_ABORT_SAVE_GUEST_MSR_FAIL);
 	} else {
 		/*
 		 * The only expected VM-instruction error is "VM entry with