diff mbox series

[v2,01/18] KVM: nVMX: move host EFER consistency checks to VMFail path

Message ID 20180828160459.14093-2-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: nVMX: add option to perform early consistency checks via H/W | expand

Commit Message

Sean Christopherson Aug. 28, 2018, 4:04 p.m. UTC
Invalid host state related to loading EFER on VMExit causes a
VMFail(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD), not a VMExit.

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

Comments

Jim Mattson Sept. 19, 2018, 8:11 p.m. UTC | #1
On Tue, Aug 28, 2018 at 9:04 AM, Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
> Invalid host state related to loading EFER on VMExit causes a
> VMFail(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD), not a VMExit.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Reviewed-by: Jim Mattson <jmattson@google.com>
Krish Sadhukhan Sept. 20, 2018, 7:44 p.m. UTC | #2
On 08/28/2018 09:04 AM, Sean Christopherson wrote:
> Invalid host state related to loading EFER on VMExit causes a
> VMFail(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD), not a VMExit.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>   arch/x86/kvm/vmx.c | 31 ++++++++++++++++---------------
>   1 file changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 8dae47e7267a..b217614de7ac 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -12316,6 +12316,7 @@ static int nested_vmx_check_nmi_controls(struct vmcs12 *vmcs12)
>   static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>   {
>   	struct vcpu_vmx *vmx = to_vmx(vcpu);
> +	bool ia32e;
>   
>   	if (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
>   	    vmcs12->guest_activity_state != GUEST_ACTIVITY_HLT)
> @@ -12386,6 +12387,21 @@ static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>   	    !nested_cr3_valid(vcpu, vmcs12->host_cr3))
>   		return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
>   
> +	/*
> +	 * If the load IA32_EFER VM-exit control is 1, bits reserved in the
> +	 * IA32_EFER MSR must be 0 in the field for that register. In addition,
> +	 * the values of the LMA and LME bits in the field must each be that of
> +	 * the host address-space size VM-exit control.
> +	 */
> +	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_EFER) {
> +		ia32e = (vmcs12->vm_exit_controls &
> +			 VM_EXIT_HOST_ADDR_SPACE_SIZE) != 0;
> +		if (!kvm_valid_efer(vcpu, vmcs12->host_ia32_efer) ||
> +		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LMA) ||
> +		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LME))
> +			return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
> +	}
> +
>   	/*
>   	 * From the Intel SDM, volume 3:
>   	 * Fields relevant to VM-entry event injection must be set properly.
> @@ -12507,21 +12523,6 @@ static int check_vmentry_postreqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
>   			return 1;
>   	}
>   
> -	/*
> -	 * If the load IA32_EFER VM-exit control is 1, bits reserved in the
> -	 * IA32_EFER MSR must be 0 in the field for that register. In addition,
> -	 * the values of the LMA and LME bits in the field must each be that of
> -	 * the host address-space size VM-exit control.
> -	 */
> -	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_EFER) {
> -		ia32e = (vmcs12->vm_exit_controls &
> -			 VM_EXIT_HOST_ADDR_SPACE_SIZE) != 0;
> -		if (!kvm_valid_efer(vcpu, vmcs12->host_ia32_efer) ||
> -		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LMA) ||
> -		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LME))
> -			return 1;
> -	}
> -
>   	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS) &&
>   		(is_noncanonical_address(vmcs12->guest_bndcfgs & PAGE_MASK, vcpu) ||
>   		(vmcs12->guest_bndcfgs & MSR_IA32_BNDCFGS_RSVD)))

Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 8dae47e7267a..b217614de7ac 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -12316,6 +12316,7 @@  static int nested_vmx_check_nmi_controls(struct vmcs12 *vmcs12)
 static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 {
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
+	bool ia32e;
 
 	if (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
 	    vmcs12->guest_activity_state != GUEST_ACTIVITY_HLT)
@@ -12386,6 +12387,21 @@  static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 	    !nested_cr3_valid(vcpu, vmcs12->host_cr3))
 		return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
 
+	/*
+	 * If the load IA32_EFER VM-exit control is 1, bits reserved in the
+	 * IA32_EFER MSR must be 0 in the field for that register. In addition,
+	 * the values of the LMA and LME bits in the field must each be that of
+	 * the host address-space size VM-exit control.
+	 */
+	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_EFER) {
+		ia32e = (vmcs12->vm_exit_controls &
+			 VM_EXIT_HOST_ADDR_SPACE_SIZE) != 0;
+		if (!kvm_valid_efer(vcpu, vmcs12->host_ia32_efer) ||
+		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LMA) ||
+		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LME))
+			return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
+	}
+
 	/*
 	 * From the Intel SDM, volume 3:
 	 * Fields relevant to VM-entry event injection must be set properly.
@@ -12507,21 +12523,6 @@  static int check_vmentry_postreqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
 			return 1;
 	}
 
-	/*
-	 * If the load IA32_EFER VM-exit control is 1, bits reserved in the
-	 * IA32_EFER MSR must be 0 in the field for that register. In addition,
-	 * the values of the LMA and LME bits in the field must each be that of
-	 * the host address-space size VM-exit control.
-	 */
-	if (vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_EFER) {
-		ia32e = (vmcs12->vm_exit_controls &
-			 VM_EXIT_HOST_ADDR_SPACE_SIZE) != 0;
-		if (!kvm_valid_efer(vcpu, vmcs12->host_ia32_efer) ||
-		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LMA) ||
-		    ia32e != !!(vmcs12->host_ia32_efer & EFER_LME))
-			return 1;
-	}
-
 	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS) &&
 		(is_noncanonical_address(vmcs12->guest_bndcfgs & PAGE_MASK, vcpu) ||
 		(vmcs12->guest_bndcfgs & MSR_IA32_BNDCFGS_RSVD)))