diff mbox series

[3/6] nVMX x86: Re-organize the code in nested_check_vmentry_prereqs(), that are related to Host State Area

Message ID 20181113061209.6843-4-krish.sadhukhan@oracle.com (mailing list archive)
State New, archived
Headers show
Series [1/6] nVMX x86: Re-name check_vmentry_pre[post]reqs to nested_check_vmentry_pre[post] | expand

Commit Message

Krish Sadhukhan Nov. 13, 2018, 6:12 a.m. UTC
Separate out the checks in nested_check_vmentry_prereqs(), that are related
to the Host State Area, to a separate function. The re-organized code
is easier for readability, enhancement and maintenance.

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Reviewed-by: Mihai Carabas <mihai.carabas@oracle.com>
Reviewed-by: Mark Kanda <mark.kanda@oracle.com>
---
 arch/x86/kvm/vmx.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Comments

Sean Christopherson Nov. 13, 2018, 4:45 p.m. UTC | #1
On Tue, Nov 13, 2018 at 01:12:06AM -0500, Krish Sadhukhan wrote:
> Separate out the checks in nested_check_vmentry_prereqs(), that are related
> to the Host State Area, to a separate function. The re-organized code
> is easier for readability, enhancement and maintenance.
> 
> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Reviewed-by: Mihai Carabas <mihai.carabas@oracle.com>
> Reviewed-by: Mark Kanda <mark.kanda@oracle.com>
> ---
>  arch/x86/kvm/vmx.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index d9f3bc7..735b634 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -12325,11 +12325,25 @@ static int nested_check_guest_state_area(struct vmcs12 *vmcs12)
>  	return 0;
>  }
>  
> +/*
> + * Checks related to Host State Area
> + */
> +static int nested_check_host_state_area(struct vmcs12 *vmcs12)
> +{
> +	if (!nested_host_cr0_valid(vcpu, vmcs12->host_cr0) ||
> +	    !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) ||
> +	    !nested_cr3_valid(vcpu, vmcs12->host_cr3))
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
>  static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
>  {
>  	struct vcpu_vmx *vmx = to_vmx(vcpu);
>  
> -	if (nested_check_guest_state_area(vmcs12))
> +	if (nested_check_guest_state_area(vmcs12) ||
> +	    nested_check_host_state_area(vmcs12))
>  		return VMXERR_ENTRY_INVALID_CONTROL_FIELD;

Host state checks cause VMXERR_ENTRY_INVALID_HOST_STATE_FIELD (look below).

>  
>  	if (nested_vmx_check_io_bitmap_controls(vcpu, vmcs12))
> @@ -12392,11 +12406,6 @@ static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm
>  	if (vmcs12->cr3_target_count > nested_cpu_vmx_misc_cr3_count(vcpu))
>  		return VMXERR_ENTRY_INVALID_CONTROL_FIELD;
>  
> -	if (!nested_host_cr0_valid(vcpu, vmcs12->host_cr0) ||
> -	    !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) ||
> -	    !nested_cr3_valid(vcpu, vmcs12->host_cr3))
> -		return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
> -
>  	/*
>  	 * From the Intel SDM, volume 3:
>  	 * Fields relevant to VM-entry event injection must be set properly.
> -- 
> 2.9.5
>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index d9f3bc7..735b634 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -12325,11 +12325,25 @@  static int nested_check_guest_state_area(struct vmcs12 *vmcs12)
 	return 0;
 }
 
+/*
+ * Checks related to Host State Area
+ */
+static int nested_check_host_state_area(struct vmcs12 *vmcs12)
+{
+	if (!nested_host_cr0_valid(vcpu, vmcs12->host_cr0) ||
+	    !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) ||
+	    !nested_cr3_valid(vcpu, vmcs12->host_cr3))
+		return -EINVAL;
+
+	return 0;
+}
+
 static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 {
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 
-	if (nested_check_guest_state_area(vmcs12))
+	if (nested_check_guest_state_area(vmcs12) ||
+	    nested_check_host_state_area(vmcs12))
 		return VMXERR_ENTRY_INVALID_CONTROL_FIELD;
 
 	if (nested_vmx_check_io_bitmap_controls(vcpu, vmcs12))
@@ -12392,11 +12406,6 @@  static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm
 	if (vmcs12->cr3_target_count > nested_cpu_vmx_misc_cr3_count(vcpu))
 		return VMXERR_ENTRY_INVALID_CONTROL_FIELD;
 
-	if (!nested_host_cr0_valid(vcpu, vmcs12->host_cr0) ||
-	    !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) ||
-	    !nested_cr3_valid(vcpu, vmcs12->host_cr3))
-		return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
-
 	/*
 	 * From the Intel SDM, volume 3:
 	 * Fields relevant to VM-entry event injection must be set properly.