Skip to contentSkip to conversation

Add some checks before emulating vmrun

PATCH In review Joerg Roedel 3 participants 6 messages Aug 2, 2010 – Aug 3, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add some checks before emulating vmrun

Hi Avi, Marcelo,

as promised here are the patches that add the checks for the vmrun intercept and the being != 0 at vmrun emulation in nested-svm.

Joerg

#5 lore raw

PATCH 2/2 KVM: SVM: Check for asid != 0 on nested vmrun

This patch lets a nested vmrun fail if the L1 hypervisor left the asid zero. This fixes the asid_zero unit test.

---
 arch/x86/kvm/svm.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +3 -0
index 083fa88..7a2feb9 100644
@@ -2020,6 +2020,9 @@ static bool nested_vmcb_checks(struct vmcb *vmcb)
 	if ((vmcb->control.intercept & (1ULL << INTERCEPT_VMRUN)) == 0)
 		return false;
 
+	if (vmcb->control.asid == 0)
+		return false;
+
 	return true;
 }
 
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 1/2 KVM: SVM: Check for nested vmrun intercept before emulating vmrun

In reply to Joerg Roedel

This patch lets the nested vmrun fail if the L1 hypervisor has not intercepted vmrun. This fixes the "vmrun intercept check" unit test.

---
 arch/x86/kvm/svm.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +19 -0
index b44c9cc..083fa88 100644
@@ -2015,6 +2015,14 @@ static bool nested_svm_vmrun_msrpm(struct vcpu_svm *svm)
 	return true;
 }
 
+static bool nested_vmcb_checks(struct vmcb *vmcb)
+{
+	if ((vmcb->control.intercept & (1ULL << INTERCEPT_VMRUN)) == 0)
+		return false;
+
+	return true;
+}
+
 static bool nested_svm_vmrun(struct vcpu_svm *svm)
 {
 	struct vmcb *nested_vmcb;
@@ -2029,6 +2037,17 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
 	if (!nested_vmcb)
 		return false;
 
+	if (!nested_vmcb_checks(nested_vmcb)) {
+		nested_vmcb->control.exit_code    = SVM_EXIT_ERR;
+		nested_vmcb->control.exit_code_hi = 0;
+		nested_vmcb->control.exit_info_1  = 0;
+		nested_vmcb->control.exit_info_2  = 0;
+
+		nested_svm_unmap(page);
+
+		return false;
+	}
+
 	trace_kvm_nested_vmrun(svm->vmcb->save.rip - 3, vmcb_gpa,
 			       nested_vmcb->save.rip,
 			       nested_vmcb->control.int_ctl,
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 1/2] KVM: SVM: Check for nested vmrun intercept before emulating vmrun

Quoted 13 lines · Joerg Roedel

This patch lets the nested vmrun fail if the L1 hypervisor has not intercepted vmrun. This fixes the "vmrun intercept check" unit test.

arch/x86/kvm/svm.c +2 -0
+
  static bool nested_svm_vmrun(struct vcpu_svm *svm)
  {
  	struct vmcb *nested_vmcb;
@@ -2029,6 +2037,17 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
  	if (!nested_vmcb)
  		return false;
 
+	if (!nested_vmcb_checks(nested_vmcb)) {

arch/x86/kvm/svm.c static bool nested_svm_vmrun(struct vcpu_svm *svm) · line 2050

Quoted 10 lines
arch/x86/kvm/svm.c +10 -0
+		nested_vmcb->control.exit_code    = SVM_EXIT_ERR;
+		nested_vmcb->control.exit_code_hi = 0;
+		nested_vmcb->control.exit_info_1  = 0;
+		nested_vmcb->control.exit_info_2  = 0;
+
+		nested_svm_unmap(page);
+
+		return false;
+	}
+

Don't you have to transfer an injected event to exitintinfo?

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw

Re: [PATCH 1/2] KVM: SVM: Check for nested vmrun intercept before emulating vmrun

Quoted 13 lines · Avi Kivity
Quoted 12 lines · Joerg Roedel

This patch lets the nested vmrun fail if the L1 hypervisor has not intercepted vmrun. This fixes the "vmrun intercept check" unit test.

arch/x86/kvm/svm.c +1 -0
+
  static bool nested_svm_vmrun(struct vcpu_svm *svm)
  {
  	struct vmcb *nested_vmcb;
@@ -2029,6 +2037,17 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
  	if (!nested_vmcb)
  		return false;
 
Quoted 13 lines

arch/x86/kvm/svm.c static bool nested_svm_vmrun(struct vcpu_svm *svm) · line 2050

Quoted 11 lines
arch/x86/kvm/svm.c +11 -0
+	if (!nested_vmcb_checks(nested_vmcb)) {
+		nested_vmcb->control.exit_code    = SVM_EXIT_ERR;
+		nested_vmcb->control.exit_code_hi = 0;
+		nested_vmcb->control.exit_info_1  = 0;
+		nested_vmcb->control.exit_info_2  = 0;
+
+		nested_svm_unmap(page);
+
+		return false;
+	}
+

Don't you have to transfer an injected event to exitintinfo?

APM2 seems to be quiet about this. I just tried it out and event_inj still contains the event after a failed vmrun on real hardware. This makes sense because this is no real vmexit because the vm was never entered.

Joerg

#4 lore raw

Re: [PATCH 1/2] KVM: SVM: Check for nested vmrun intercept before emulating vmrun

Quoted 25 lines · Joerg Roedel
Quoted 12 lines · Avi Kivity
Quoted 11 lines · Joerg Roedel

This patch lets the nested vmrun fail if the L1 hypervisor has not intercepted vmrun. This fixes the "vmrun intercept check" unit test.

arch/x86/kvm/svm.c +1 -0
+
   static bool nested_svm_vmrun(struct vcpu_svm *svm)
   {
   	struct vmcb *nested_vmcb;
@@ -2029,6 +2037,17 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
   	if (!nested_vmcb)
   		return false;
 
Quoted 12 lines

arch/x86/kvm/svm.c static bool nested_svm_vmrun(struct vcpu_svm *svm) · line 2050

Quoted 11 lines
arch/x86/kvm/svm.c +11 -0
+	if (!nested_vmcb_checks(nested_vmcb)) {
+		nested_vmcb->control.exit_code    = SVM_EXIT_ERR;
+		nested_vmcb->control.exit_code_hi = 0;
+		nested_vmcb->control.exit_info_1  = 0;
+		nested_vmcb->control.exit_info_2  = 0;
+
+		nested_svm_unmap(page);
+
+		return false;
+	}
+

Don't you have to transfer an injected event to exitintinfo?

Quoted 1 line

APM2 seems to be quiet about this.

Well, my copy says

Quoted 2 lines

The VMRUN instruction then checks the guest state just loaded. If an illegal state has been loaded, the processor exits back to the host (see “#VMEXIT” on page 374).

This matches "illegal state" and "#VMEXIT" but doesn't match "guest state".

Quoted 4 lines

I just tried it out and event_inj
still contains the event after a failed vmrun on real hardware. This makes sense because this is no real vmexit because the vm was never entered.

Okay; will apply the patches.

Signature · 1 line
error compiling committee.c: too many arguments to function