diff mbox series

[v2,5/6] nVMX x86: Re-organize the code in nested_check_vmentry_prereqs(), that are related to Host Control Registers and MSRs

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

Commit Message

Krish Sadhukhan Nov. 15, 2018, 5:45 a.m. UTC
Separate out the checks in nested_check_vmentry_prereqs(), that are related
to the Host Control Registers and MSRs, to a separate function. The
re-organized cod 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 | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Sean Christopherson Nov. 15, 2018, 6:04 p.m. UTC | #1
On Thu, Nov 15, 2018 at 12:45:53AM -0500, Krish Sadhukhan wrote:
> Separate out the checks in nested_check_vmentry_prereqs(), that are related
> to the Host Control Registers and MSRs, to a separate function. The
> re-organized cod 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 | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 368e38d..93e49aa 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -12518,6 +12518,19 @@ static int nested_check_vm_entry_ctls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs
>  	return 0;
>  }
>  
> +/*
> + * Checks related to Host Control Registers and MSRs
> + */
> +static int nested_check_host_ctl_regs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)

Same comment as earlier, spell out "control" and wrap.

> +{
> +	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)
>  {
>  	if (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
> @@ -12529,9 +12542,7 @@ static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm
>  	    nested_check_vm_entry_ctls(vcpu, vmcs12))
>  		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))
> +	if (nested_check_host_ctl_regs(vcpu, vmcs12))
>  		return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
>  
>  	return 0;
> -- 
> 2.9.5
>
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 368e38d..93e49aa 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -12518,6 +12518,19 @@  static int nested_check_vm_entry_ctls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs
 	return 0;
 }
 
+/*
+ * Checks related to Host Control Registers and MSRs
+ */
+static int nested_check_host_ctl_regs(struct kvm_vcpu *vcpu, 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)
 {
 	if (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
@@ -12529,9 +12542,7 @@  static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm
 	    nested_check_vm_entry_ctls(vcpu, vmcs12))
 		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))
+	if (nested_check_host_ctl_regs(vcpu, vmcs12))
 		return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD;
 
 	return 0;