[3/4,v2,nVMX] : Move the checks for Guest Control Registers and Guest MSRs to a separate function
diff mbox series

Message ID 20190327215650.11825-4-krish.sadhukhan@oracle.com
State New
Headers show
Series
  • [1/4,v2,nVMX] : Check "load IA32_PAT" VM-exit control on vmentry of nested guests
Related show

Commit Message

Krish Sadhukhan March 27, 2019, 9:56 p.m. UTC
Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx/nested.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

Comments

Sean Christopherson April 2, 2019, 6:26 p.m. UTC | #1
On Wed, Mar 27, 2019 at 05:56:49PM -0400, Krish Sadhukhan wrote:

It'd be nice to have a short blurb here stating that the intent is to
match the organization in the SDM.

> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 25 +++++++++++++++++++------
>  1 file changed, 19 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index b8bd449350b4..87449b67eaf2 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -2674,6 +2674,24 @@ static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu,
>  	return r;
>  }
>  
> +/*
> + * Checks related to Control Registers, Debug Registers and MSRs in
> + * Guest State Area.
> + */
> +static int nested_check_guest_ctrl_dbg_regs_msrs(struct kvm_vcpu *vcpu,
> +						 struct vmcs12 *vmcs12)

I like the idea of shortening the function name, but "ctrl_dbg_regs" is a
bit confusing, e.g. one might think "ctrl" in this context refers to the
VMCS's control bit/field.

What about nested_check_guest_crs_drs_msrs()?

> +{
> +	if (!nested_guest_cr0_valid(vcpu, vmcs12->guest_cr0) ||
> +	    !nested_guest_cr4_valid(vcpu, vmcs12->guest_cr4))
> +		return 1;
> +
> +	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) &&
> +	    !kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, vmcs12->guest_ia32_pat))
> +		return 1;
> +
> +	return 0;
> +}
> +
>  static int nested_vmx_check_vmentry_postreqs(struct kvm_vcpu *vcpu,
>  					     struct vmcs12 *vmcs12,
>  					     u32 *exit_qual)
> @@ -2682,12 +2700,7 @@ static int nested_vmx_check_vmentry_postreqs(struct kvm_vcpu *vcpu,
>  
>  	*exit_qual = ENTRY_FAIL_DEFAULT;
>  
> -	if (!nested_guest_cr0_valid(vcpu, vmcs12->guest_cr0) ||
> -	    !nested_guest_cr4_valid(vcpu, vmcs12->guest_cr4))
> -		return 1;
> -
> -	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) &&
> -	    !kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, vmcs12->guest_ia32_pat))
> +	if (nested_check_guest_ctrl_dbg_regs_msrs(vcpu, vmcs12))
>  		return 1;
>  
>  	if (nested_vmx_check_vmcs_link_ptr(vcpu, vmcs12)) {
> -- 
> 2.17.2
>

Patch
diff mbox series

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index b8bd449350b4..87449b67eaf2 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2674,6 +2674,24 @@  static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu,
 	return r;
 }
 
+/*
+ * Checks related to Control Registers, Debug Registers and MSRs in
+ * Guest State Area.
+ */
+static int nested_check_guest_ctrl_dbg_regs_msrs(struct kvm_vcpu *vcpu,
+						 struct vmcs12 *vmcs12)
+{
+	if (!nested_guest_cr0_valid(vcpu, vmcs12->guest_cr0) ||
+	    !nested_guest_cr4_valid(vcpu, vmcs12->guest_cr4))
+		return 1;
+
+	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) &&
+	    !kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, vmcs12->guest_ia32_pat))
+		return 1;
+
+	return 0;
+}
+
 static int nested_vmx_check_vmentry_postreqs(struct kvm_vcpu *vcpu,
 					     struct vmcs12 *vmcs12,
 					     u32 *exit_qual)
@@ -2682,12 +2700,7 @@  static int nested_vmx_check_vmentry_postreqs(struct kvm_vcpu *vcpu,
 
 	*exit_qual = ENTRY_FAIL_DEFAULT;
 
-	if (!nested_guest_cr0_valid(vcpu, vmcs12->guest_cr0) ||
-	    !nested_guest_cr4_valid(vcpu, vmcs12->guest_cr4))
-		return 1;
-
-	if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PAT) &&
-	    !kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, vmcs12->guest_ia32_pat))
+	if (nested_check_guest_ctrl_dbg_regs_msrs(vcpu, vmcs12))
 		return 1;
 
 	if (nested_vmx_check_vmcs_link_ptr(vcpu, vmcs12)) {