Skip to contentSkip to conversation

Nested SVM Interrupt Fixes

PATCH In review Alexander Graf 4 participants 19 messages Sep 18, 2009 – Sep 27, 2009

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

cover Nested SVM Interrupt Fixes

Looking through the interrupt handling paths I stumbled across several inconsitencies in the interrupt handling paths.

Using this patchset, running the most recent KVM version in nested KVM works again.

Alexander Graf (5):
Implement #NMI exiting for nested SVM
Don't call svm_complete_interrupts for nested guests Don't #VMEXIT(INTR) if we still have event_inj waiting Don't bail when injecting an event in nested SVM Notify nested hypervisor of lost event injections

 arch/x86/kvm/svm.c |   79 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 68 insertions(+), 11 deletions(-)
#1 lore raw

PATCH 1/5 Implement #NMI exiting for nested SVM

When injecting an NMI to the l1 guest while it was running the l2 guest, we didn't #VMEXIT but just injected the NMI to the l2 guest.

Let's be closer to real hardware and #VMEXIT if we're supposed to do so.

---
 arch/x86/kvm/svm.c |   38 ++++++++++++++++++++++++++++++++------
 1 files changed, 32 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +32 -6
index 9a4daca..f12a669 100644
@@ -1375,6 +1375,21 @@ static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
 	return nested_svm_exit_handled(svm);
 }
 
+static inline int nested_svm_nmi(struct vcpu_svm *svm)
+{
+	if (!is_nested(svm))
+		return 0;
+
+	svm->vmcb->control.exit_code = SVM_EXIT_NMI;
+
+	if (nested_svm_exit_handled(svm)) {
+		nsvm_printk("VMexit -> NMI\n");
+		return 1;
+	}
+
+	return 0;
+}
+
 static inline int nested_svm_intr(struct vcpu_svm *svm)
 {
 	if (!is_nested(svm))
@@ -2462,7 +2477,9 @@ static int svm_nmi_allowed(struct kvm_vcpu *vcpu)
 	struct vcpu_svm *svm = to_svm(vcpu);
 	struct vmcb *vmcb = svm->vmcb;
 	return !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
-		!(svm->vcpu.arch.hflags & HF_NMI_MASK);
+		!(svm->vcpu.arch.hflags & HF_NMI_MASK) &&
+		gif_set(svm) &&
+		!is_nested(svm);
 }
 
 static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)
@@ -2488,22 +2505,31 @@ static void enable_irq_window(struct kvm_vcpu *vcpu)
 	struct vcpu_svm *svm = to_svm(vcpu);
 	nsvm_printk("Trying to open IRQ window\n");
 
-	nested_svm_intr(svm);
+	if (nested_svm_intr(svm))
+		return;
 
 	/* In case GIF=0 we can't rely on the CPU to tell us when
 	 * GIF becomes 1, because that's a separate STGI/VMRUN intercept.
 	 * The next time we get that intercept, this function will be
 	 * called again though and we'll get the vintr intercept. */
-	if (gif_set(svm)) {
-		svm_set_vintr(svm);
-		svm_inject_irq(svm, 0x0);
-	}
+	if (!gif_set(svm))
+		return;
+
+	svm_set_vintr(svm);
+	svm_inject_irq(svm, 0x0);
 }
 
 static void enable_nmi_window(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_svm *svm = to_svm(vcpu);
 
+	if (nested_svm_nmi(svm))
+		return;
+
+	/* NMI is deferred until GIF == 1. Setting GIF will cause a #VMEXIT */
+	if (!gif_set(svm))
+		return;
+
 	if ((svm->vcpu.arch.hflags & (HF_NMI_MASK | HF_IRET_MASK))
 	    == HF_NMI_MASK)
 		return; /* IRET will cause a vm exit */
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/5 Don't call svm_complete_interrupts for nested guests

SVM has some cleanup code, that tries to reinject interrupts and exceptions when the guest didn't manage to deal with them yet. It basically transfers them to KVM internal state.

Unfortunately, the internal state is reserved for the L1 guest state, so we shouldn't try to go through that logic when running a nested guest.

When doing something the host KVM can handle, let's just reinject the event into the L2 guest, because we didn't touch its state anyways.

---
 arch/x86/kvm/svm.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +14 -4
index f12a669..61efd13 100644
@@ -2349,7 +2349,10 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 	trace_kvm_exit(exit_code, svm->vmcb->save.rip);
 
 	if (is_nested(svm)) {
+		struct vmcb_control_area *control = &svm->vmcb->control;
 		int vmexit;
+		int type;
+		int vec;
 
 		nsvm_printk("nested handle_exit: 0x%x | 0x%lx | 0x%lx | 0x%lx\n",
 			    exit_code, svm->vmcb->control.exit_info_1,
@@ -2362,9 +2365,18 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 
 		if (vmexit == NESTED_EXIT_DONE)
 			return 1;
-	}
 
-	svm_complete_interrupts(svm);
+		type = control->exit_int_info & SVM_EXITINTINFO_TYPE_MASK;
+		vec = control->exit_int_info & SVM_EXITINTINFO_VEC_MASK;
+		if ((type == SVM_EXITINTINFO_TYPE_INTR) ||
+		    ((type == SVM_EXITINTINFO_TYPE_EXEPT) && !kvm_exception_is_soft(vec))) {
+			control->event_inj = control->exit_int_info;
+			control->event_inj_err = control->exit_int_info_err;
+		}
+	} else {
+		/* Don't interpret exit_info for nested guests */
+		svm_complete_interrupts(svm);
+	}
 
 	if (npt_enabled) {
 		int mmu_reload = 0;
@@ -2602,8 +2614,6 @@ static void svm_complete_interrupts(struct vcpu_svm *svm)
 	case SVM_EXITINTINFO_TYPE_EXEPT:
 		/* In case of software exception do not reinject an exception
 		   vector, but re-execute and instruction instead */
-		if (is_nested(svm))
-			break;
 		if (kvm_exception_is_soft(vector))
 			break;
 		if (exitintinfo & SVM_EXITINTINFO_VALID_ERR) {
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/5 Don't #VMEXIT(INTR) if we still have event_inj waiting

Real hardware would first process the event_inj field and then notify the host that an interrupt is waiting.

Let's do the same and just not EXIT_INTR if we have an event pending for the L2 guest.

---
 arch/x86/kvm/svm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +4 -0
index 61efd13..28fcbd0 100644
@@ -1401,6 +1401,10 @@ static inline int nested_svm_intr(struct vcpu_svm *svm)
 	if (!(svm->vcpu.arch.hflags & HF_HIF_MASK))
 		return 0;
 
+	/* We can't EXIT_INTR when we still have an event to inject */
+	if (svm->vmcb->control.event_inj)
+		return 1;
+
 	svm->vmcb->control.exit_code = SVM_EXIT_INTR;
 
 	if (nested_svm_exit_handled(svm)) {
Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/5 Don't bail when injecting an event in nested SVM

There's a warning to alarm the user when the guest has a valid exit_int_info, but really shouldn't have.

We don't want that warning when running an L2 guest, because we're in control of the state then anyways, so let's not warn when running nested.

---
 arch/x86/kvm/svm.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kvm/svm.c +2 -1
index 28fcbd0..12ec8ee 100644
@@ -2404,7 +2404,8 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 		return 0;
 	}
 
-	if (is_external_interrupt(svm->vmcb->control.exit_int_info) &&
+	if (!is_nested(svm) &&
+	    is_external_interrupt(svm->vmcb->control.exit_int_info) &&
 	    exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR &&
 	    exit_code != SVM_EXIT_NPF && exit_code != SVM_EXIT_TASK_SWITCH)
 		printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 5/5 Notify nested hypervisor of lost event injections

Normally when event_inj is valid the host CPU would write the contents to exit_int_info, so the hypervisor knows that the event wasn't injected.

We failed to do so so far, so let's model closer to the CPU.

---
 arch/x86/kvm/svm.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +16 -0
index 12ec8ee..75e3d75 100644
@@ -1643,6 +1643,22 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
 	nested_vmcb->control.exit_info_2       = vmcb->control.exit_info_2;
 	nested_vmcb->control.exit_int_info     = vmcb->control.exit_int_info;
 	nested_vmcb->control.exit_int_info_err = vmcb->control.exit_int_info_err;
+
+	/*
+	 * If we emulate a VMRUN/#VMEXIT in the same host #vmexit cycle we have
+	 * to make sure that we do not lose injected events. So check event_inj
+	 * here and copy it to exit_int_info if it is valid.
+	 * exit_int_info and event_inj can't be both valid because the below
+	 * case only happens on a VMRUN instruction intercept which has not
+	 * valid exit_int_info set.
+	 */
+	if (vmcb->control.event_inj & SVM_EVTINJ_VALID) {
+		struct vmcb_control_area *nc = &nested_vmcb->control;
+
+		nc->exit_int_info     = vmcb->control.event_inj;
+		nc->exit_int_info_err = vmcb->control.event_inj_err;
+	}
+
 	nested_vmcb->control.tlb_ctl           = 0;
 	nested_vmcb->control.event_inj         = 0;
 	nested_vmcb->control.event_inj_err     = 0;
Signature · 1 line
1.6.0.2
Acked-by on v1 5/5
#6 lore raw

Re: [PATCH 5/5] Notify nested hypervisor of lost event injections

Quoted 6 lines · Alexander Graf

Normally when event_inj is valid the host CPU would write the contents to exit_int_info, so the hypervisor knows that the event wasn't injected.

We failed to do so so far, so let's model closer to the CPU.

The commit-message does not state this explicitly, but this patch fixes a real bug with lost interrupts in nested svm.

Quoted 38 lines
---
 arch/x86/kvm/svm.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +16 -0
index 12ec8ee..75e3d75 100644
@@ -1643,6 +1643,22 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
 	nested_vmcb->control.exit_info_2       = vmcb->control.exit_info_2;
 	nested_vmcb->control.exit_int_info     = vmcb->control.exit_int_info;
 	nested_vmcb->control.exit_int_info_err = vmcb->control.exit_int_info_err;
+
+	/*
+	 * If we emulate a VMRUN/#VMEXIT in the same host #vmexit cycle we have
+	 * to make sure that we do not lose injected events. So check event_inj
+	 * here and copy it to exit_int_info if it is valid.
+	 * exit_int_info and event_inj can't be both valid because the below
+	 * case only happens on a VMRUN instruction intercept which has not
+	 * valid exit_int_info set.
+	 */
+	if (vmcb->control.event_inj & SVM_EVTINJ_VALID) {
+		struct vmcb_control_area *nc = &nested_vmcb->control;
+
+		nc->exit_int_info     = vmcb->control.event_inj;
+		nc->exit_int_info_err = vmcb->control.event_inj_err;
+	}
+
 	nested_vmcb->control.tlb_ctl           = 0;
 	nested_vmcb->control.event_inj         = 0;
 	nested_vmcb->control.event_inj_err     = 0;
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

Re: [PATCH 5/5] Notify nested hypervisor of lost event injections

In reply to Alexander Graf

Hi Avi,

can you pleas apply this patch (only 5/5) directly before Alex does a repost? It is pretty independet from the others and contains an important bugfix for nested svm and should go in as soon as possible.

Joerg

Quoted 44 lines · Alexander Graf

Normally when event_inj is valid the host CPU would write the contents to exit_int_info, so the hypervisor knows that the event wasn't injected.

We failed to do so so far, so let's model closer to the CPU.

---
 arch/x86/kvm/svm.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +16 -0
index 12ec8ee..75e3d75 100644
@@ -1643,6 +1643,22 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
 	nested_vmcb->control.exit_info_2       = vmcb->control.exit_info_2;
 	nested_vmcb->control.exit_int_info     = vmcb->control.exit_int_info;
 	nested_vmcb->control.exit_int_info_err = vmcb->control.exit_int_info_err;
+
+	/*
+	 * If we emulate a VMRUN/#VMEXIT in the same host #vmexit cycle we have
+	 * to make sure that we do not lose injected events. So check event_inj
+	 * here and copy it to exit_int_info if it is valid.
+	 * exit_int_info and event_inj can't be both valid because the below
+	 * case only happens on a VMRUN instruction intercept which has not
+	 * valid exit_int_info set.
+	 */
+	if (vmcb->control.event_inj & SVM_EVTINJ_VALID) {
+		struct vmcb_control_area *nc = &nested_vmcb->control;
+
+		nc->exit_int_info     = vmcb->control.event_inj;
+		nc->exit_int_info_err = vmcb->control.event_inj_err;
+	}
+
 	nested_vmcb->control.tlb_ctl           = 0;
 	nested_vmcb->control.event_inj         = 0;
 	nested_vmcb->control.event_inj_err     = 0;
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

Re: [PATCH 3/5] Don't #VMEXIT(INTR) if we still have event_inj waiting

In reply to Alexander Graf
Quoted 2 lines · Alexander Graf

Real hardware would first process the event_inj field and then notify the host that an interrupt is waiting.

Does it really? I couldn't find this in the SVM spec.

Quoted 2 lines

Let's do the same and just not EXIT_INTR if we have an event pending for the L2 guest.

Anyway. I think this case is handled good enough with patch 5/5. This patch, to be complete must also enable single-steping to exit again after the first instruction of the exception handler has ran to inject the interrupt. But that would make the whole thing rather compĺicated.

Quoted 27 lines
---
 arch/x86/kvm/svm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +4 -0
index 61efd13..28fcbd0 100644
@@ -1401,6 +1401,10 @@ static inline int nested_svm_intr(struct vcpu_svm *svm)
 	if (!(svm->vcpu.arch.hflags & HF_HIF_MASK))
 		return 0;
 
+	/* We can't EXIT_INTR when we still have an event to inject */
+	if (svm->vmcb->control.event_inj)
+		return 1;
+
 	svm->vmcb->control.exit_code = SVM_EXIT_INTR;
 
 	if (nested_svm_exit_handled(svm)) {
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

Re: [PATCH 3/5] Don't #VMEXIT(INTR) if we still have event_inj waiting

Am 22.09.2009 um 18:39 schrieb Joerg Roedel <[email protected]>:

Quoted 6 lines · Alexander Graf
Quoted 3 lines

Real hardware would first process the event_inj field and then notify the
host that an interrupt is waiting.

Does it really? I couldn't find this in the SVM spec.

I didn't see it in the spec either, but that's what I saw real hardware do which is supported by the exit_info validity check in svm.c

Quoted 10 lines
Quoted 4 lines

Let's do the same and just not EXIT_INTR if we have an event pending for the
L2 guest.

Anyway. I think this case is handled good enough with patch 5/5. This patch, to be complete must also enable single-steping to exit again after the first instruction of the exception handler has ran to inject the interrupt. But that would make the whole thing rather compĺicate d.

The NMI injection path has logic for that, but for now it shouldn't hurt - we'll get an interrupt sooner or later.

Quoted 29 lines
Quoted 29 lines

---
arch/x86/kvm/svm.c | 4 ++++

1 files changed, 4 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +4 -0
index 61efd13..28fcbd0 100644
@@ -1401,6 +1401,10 @@ static inline int nested_svm_intr(struct  
 vcpu_svm *svm)
   if (!(svm->vcpu.arch.hflags & HF_HIF_MASK))
       return 0;
 
+    /* We can't EXIT_INTR when we still have an event to inject */
+    if (svm->vmcb->control.event_inj)
+        return 1;
+
   svm->vmcb->control.exit_code = SVM_EXIT_INTR;
 
   if (nested_svm_exit_handled(svm)) {
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw

Re: [PATCH 2/5] Don't call svm_complete_interrupts for nested guests

In reply to Alexander Graf
Quoted 36 lines · Alexander Graf

SVM has some cleanup code, that tries to reinject interrupts and exceptions when the guest didn't manage to deal with them yet. It basically transfers them to KVM internal state.

Unfortunately, the internal state is reserved for the L1 guest state, so we shouldn't try to go through that logic when running a nested guest.

When doing something the host KVM can handle, let's just reinject the event into the L2 guest, because we didn't touch its state anyways.

---
 arch/x86/kvm/svm.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +3 -1
index f12a669..61efd13 100644
@@ -2349,7 +2349,10 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 	trace_kvm_exit(exit_code, svm->vmcb->save.rip);
 
 	if (is_nested(svm)) {
+		struct vmcb_control_area *control = &svm->vmcb->control;
 		int vmexit;
+		int type;
+		int vec;
 
 		nsvm_printk("nested handle_exit: 0x%x | 0x%lx | 0x%lx | 0x%lx\n",
 			    exit_code, svm->vmcb->control.exit_info_1,
@@ -2362,9 +2365,18 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 
 		if (vmexit == NESTED_EXIT_DONE)
 			return 1;
-	}
 

arch/x86/kvm/svm.c static int handle_exit(struct kvm_vcpu *vcpu) · line 2377

Quoted 10 lines
arch/x86/kvm/svm.c +9 -1
-	svm_complete_interrupts(svm);
+		type = control->exit_int_info & SVM_EXITINTINFO_TYPE_MASK;
+		vec = control->exit_int_info & SVM_EXITINTINFO_VEC_MASK;
+		if ((type == SVM_EXITINTINFO_TYPE_INTR) ||
+		    ((type == SVM_EXITINTINFO_TYPE_EXEPT) && !kvm_exception_is_soft(vec))) {
+			control->event_inj = control->exit_int_info;
+			control->event_inj_err = control->exit_int_info_err;
+		}
+	} else {
+		/* Don't interpret exit_info for nested guests */

Doesn't this comment belong to the block above?

Quoted 6 lines
arch/x86/kvm/svm.c +2 -0
+		svm_complete_interrupts(svm);
+	}
 
 	if (npt_enabled) {
 		int mmu_reload = 0;

arch/x86/kvm/svm.c static void svm_complete_interrupts(struct vcpu_svm *svm) · line 2619

Quoted 8 lines
arch/x86/kvm/svm.c +0 -2
@@ -2602,8 +2614,6 @@ static void svm_complete_interrupts(struct vcpu_svm *svm)
 	case SVM_EXITINTINFO_TYPE_EXEPT:
 		/* In case of software exception do not reinject an exception
 		   vector, but re-execute and instruction instead */
-		if (is_nested(svm))
-			break;
 		if (kvm_exception_is_soft(vector))
 			break;
 		if (exitintinfo & SVM_EXITINTINFO_VALID_ERR) {

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#11 lore raw

Re: [PATCH 2/5] Don't call svm_complete_interrupts for nested guests

In reply to Alexander Graf
Quoted 9 lines · Alexander Graf

SVM has some cleanup code, that tries to reinject interrupts and exceptions when the guest didn't manage to deal with them yet. It basically transfers them to KVM internal state.

Unfortunately, the internal state is reserved for the L1 guest state, so we shouldn't try to go through that logic when running a nested guest.

When doing something the host KVM can handle, let's just reinject the event into the L2 guest, because we didn't touch its state anyways.

I don't really understandt what problem this patch addresses. There are situations where we have events to reinject into the l2 guest directly. But the generic reinjection code works fine for it.
The only problematic thing with it is that it implicitly relies on exit_int_info not to be changed in the exit cycle (which would be worth a comment).

Joerg

Quoted 58 lines
---
 arch/x86/kvm/svm.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +14 -4
index f12a669..61efd13 100644
@@ -2349,7 +2349,10 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 	trace_kvm_exit(exit_code, svm->vmcb->save.rip);
 
 	if (is_nested(svm)) {
+		struct vmcb_control_area *control = &svm->vmcb->control;
 		int vmexit;
+		int type;
+		int vec;
 
 		nsvm_printk("nested handle_exit: 0x%x | 0x%lx | 0x%lx | 0x%lx\n",
 			    exit_code, svm->vmcb->control.exit_info_1,
@@ -2362,9 +2365,18 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 
 		if (vmexit == NESTED_EXIT_DONE)
 			return 1;
-	}
 
-	svm_complete_interrupts(svm);
+		type = control->exit_int_info & SVM_EXITINTINFO_TYPE_MASK;
+		vec = control->exit_int_info & SVM_EXITINTINFO_VEC_MASK;
+		if ((type == SVM_EXITINTINFO_TYPE_INTR) ||
+		    ((type == SVM_EXITINTINFO_TYPE_EXEPT) && !kvm_exception_is_soft(vec))) {
+			control->event_inj = control->exit_int_info;
+			control->event_inj_err = control->exit_int_info_err;
+		}
+	} else {
+		/* Don't interpret exit_info for nested guests */
+		svm_complete_interrupts(svm);
+	}
 
 	if (npt_enabled) {
 		int mmu_reload = 0;
@@ -2602,8 +2614,6 @@ static void svm_complete_interrupts(struct vcpu_svm *svm)
 	case SVM_EXITINTINFO_TYPE_EXEPT:
 		/* In case of software exception do not reinject an exception
 		   vector, but re-execute and instruction instead */
-		if (is_nested(svm))
-			break;
 		if (kvm_exception_is_soft(vector))
 			break;
 		if (exitintinfo & SVM_EXITINTINFO_VALID_ERR) {
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw

Re: [PATCH 2/5] Don't call svm_complete_interrupts for nested guests

Am 22.09.2009 um 18:26 schrieb Joerg Roedel <[email protected]>:

Quoted 11 lines · Alexander Graf
Quoted 9 lines

SVM has some cleanup code, that tries to reinject interrupts and exceptions when the guest didn't manage to deal with them yet. It basically transfers them to KVM internal state.

Unfortunately, the internal state is reserved for the L1 guest state, so we shouldn't try to go through that logic when running a nested guest.

When doing something the host KVM can handle, let's just reinject the event into the L2 guest, because we didn't touch its state anyways.

Quoted 6 lines

I don't really understandt what problem this patch addresses. There are situations where we have events to reinject into the l2 guest directly. But the generic reinjection code works fine for it.
The only problematic thing with it is that it implicitly relies on exit_int_info not to be changed in the exit cycle (which would be worth a comment).

It si

Quoted 64 lines

Joerg

Quoted 61 lines

---
arch/x86/kvm/svm.c | 18 ++++++++++++++----

1 files changed, 14 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +3 -0
index f12a669..61efd13 100644
@@ -2349,7 +2349,10 @@ static int handle_exit(struct kvm_vcpu *vcpu)
   trace_kvm_exit(exit_code, svm->vmcb->save.rip);
 
   if (is_nested(svm)) {
+        struct vmcb_control_area *control = &svm->vmcb->control;
       int vmexit;
+        int type;
+        int vec;
 
       nsvm_printk("nested handle_exit: 0x%x | 0x%lx | 0x%lx | 0x%lx 
 \n",
               exit_code, svm->vmcb->control.exit_info_1,
arch/x86/kvm/svm.c +11 -2
@@ -2362,9 +2365,18 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 
       if (vmexit == NESTED_EXIT_DONE)
           return 1;
-    }
 
-    svm_complete_interrupts(svm);
+        type = control->exit_int_info & SVM_EXITINTINFO_TYPE_MASK;
+        vec = control->exit_int_info & SVM_EXITINTINFO_VEC_MASK;
+        if ((type == SVM_EXITINTINFO_TYPE_INTR) ||
+            ((type == SVM_EXITINTINFO_TYPE_EXEPT) && ! 
 kvm_exception_is_soft(vec))) {
+            control->event_inj = control->exit_int_info;
+            control->event_inj_err = control->exit_int_info_err;
+        }
+    } else {
+        /* Don't interpret exit_info for nested guests */
+        svm_complete_interrupts(svm);
+    }
 
   if (npt_enabled) {
       int mmu_reload = 0;
arch/x86/kvm/svm.c +0 -2
@@ -2602,8 +2614,6 @@ static void svm_complete_interrupts(struct  
 vcpu_svm *svm)
   case SVM_EXITINTINFO_TYPE_EXEPT:
       /* In case of software exception do not reinject an exception
          vector, but re-execute and instruction instead */
-        if (is_nested(svm))
-            break;
       if (kvm_exception_is_soft(vector))
           break;
       if (exitintinfo & SVM_EXITINTINFO_VALID_ERR) {
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

Re: [PATCH 2/5] Don't call svm_complete_interrupts for nested guests

In reply to Joerg Roedel

Am 22.09.2009 um 18:26 schrieb Joerg Roedel <[email protected]>:

Quoted 11 lines · Alexander Graf
Quoted 9 lines

SVM has some cleanup code, that tries to reinject interrupts and exceptions when the guest didn't manage to deal with them yet. It basically transfers them to KVM internal state.

Unfortunately, the internal state is reserved for the L1 guest state, so we shouldn't try to go through that logic when running a nested guest.

When doing something the host KVM can handle, let's just reinject the event into the L2 guest, because we didn't touch its state anyways.

Quoted 6 lines

I don't really understandt what problem this patch addresses. There are situations where we have events to reinject into the l2 guest directly. But the generic reinjection code works fine for it.
The only problematic thing with it is that it implicitly relies on exit_int_info not to be changed in the exit cycle (which would be worth a comment).

It simply tries to be too clever. Reevaluating exceptions won't work for example.

Alex

Quoted 64 lines

Joerg

Quoted 61 lines

---
arch/x86/kvm/svm.c | 18 ++++++++++++++----

1 files changed, 14 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +3 -0
index f12a669..61efd13 100644
@@ -2349,7 +2349,10 @@ static int handle_exit(struct kvm_vcpu *vcpu)
   trace_kvm_exit(exit_code, svm->vmcb->save.rip);
 
   if (is_nested(svm)) {
+        struct vmcb_control_area *control = &svm->vmcb->control;
       int vmexit;
+        int type;
+        int vec;
 
       nsvm_printk("nested handle_exit: 0x%x | 0x%lx | 0x%lx | 0x%lx 
 \n",
               exit_code, svm->vmcb->control.exit_info_1,
arch/x86/kvm/svm.c +11 -2
@@ -2362,9 +2365,18 @@ static int handle_exit(struct kvm_vcpu *vcpu)
 
       if (vmexit == NESTED_EXIT_DONE)
           return 1;
-    }
 
-    svm_complete_interrupts(svm);
+        type = control->exit_int_info & SVM_EXITINTINFO_TYPE_MASK;
+        vec = control->exit_int_info & SVM_EXITINTINFO_VEC_MASK;
+        if ((type == SVM_EXITINTINFO_TYPE_INTR) ||
+            ((type == SVM_EXITINTINFO_TYPE_EXEPT) && ! 
 kvm_exception_is_soft(vec))) {
+            control->event_inj = control->exit_int_info;
+            control->event_inj_err = control->exit_int_info_err;
+        }
+    } else {
+        /* Don't interpret exit_info for nested guests */
+        svm_complete_interrupts(svm);
+    }
 
   if (npt_enabled) {
       int mmu_reload = 0;
arch/x86/kvm/svm.c +0 -2
@@ -2602,8 +2614,6 @@ static void svm_complete_interrupts(struct  
 vcpu_svm *svm)
   case SVM_EXITINTINFO_TYPE_EXEPT:
       /* In case of software exception do not reinject an exception
          vector, but re-execute and instruction instead */
-        if (is_nested(svm))
-            break;
       if (kvm_exception_is_soft(vector))
           break;
       if (exitintinfo & SVM_EXITINTINFO_VALID_ERR) {
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#14 lore raw

Re: [PATCH 2/5] Don't call svm_complete_interrupts for nested guests

Quoted 28 lines · Alexander Graf

Am 22.09.2009 um 18:26 schrieb Joerg Roedel <[email protected]>:

Quoted 15 lines · Alexander Graf
Quoted 6 lines

SVM has some cleanup code, that tries to reinject interrupts and exceptions
when the guest didn't manage to deal with them yet. It basically transfers
them to KVM internal state.

Quoted 7 lines

Unfortunately, the internal state is reserved for the L1 guest state, so we
shouldn't try to go through that logic when running a nested guest.

When doing something the host KVM can handle, let's just reinject the event
into the L2 guest, because we didn't touch its state anyways.

Quoted 9 lines

I don't really understandt what problem this patch addresses. There are
situations where we have events to reinject into the l2 guest directly.
But the generic reinjection code works fine for it.
The only problematic thing with it is that it implicitly relies on exit_int_info not to be changed in the exit cycle (which would be worth
a comment).

Quoted 3 lines

It simply tries to be too clever. Reevaluating exceptions won't work for example.

Can you elaborate? What do you mean by "too clever" and why reevaluating exceptions won't work?

--
Gleb.

#15 lore raw

Re: [PATCH 1/5] Implement #NMI exiting for nested SVM

In reply to Alexander Graf
Quoted 37 lines · Alexander Graf

When injecting an NMI to the l1 guest while it was running the l2 guest, we didn't #VMEXIT but just injected the NMI to the l2 guest.

Let's be closer to real hardware and #VMEXIT if we're supposed to do so.

---
 arch/x86/kvm/svm.c |   38 ++++++++++++++++++++++++++++++++------
 1 files changed, 32 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +15 -0
index 9a4daca..f12a669 100644
@@ -1375,6 +1375,21 @@ static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
 	return nested_svm_exit_handled(svm);
 }
 
+static inline int nested_svm_nmi(struct vcpu_svm *svm)
+{
+	if (!is_nested(svm))
+		return 0;
+
+	svm->vmcb->control.exit_code = SVM_EXIT_NMI;
+
+	if (nested_svm_exit_handled(svm)) {
+		nsvm_printk("VMexit -> NMI\n");
+		return 1;
+	}
+
+	return 0;
+}
+
 static inline int nested_svm_intr(struct vcpu_svm *svm)
 {
 	if (!is_nested(svm))

arch/x86/kvm/svm.c static int svm_nmi_allowed(struct kvm_vcpu *vcpu) · line 2481

Quoted 6 lines
arch/x86/kvm/svm.c +2 -1
@@ -2462,7 +2477,9 @@ static int svm_nmi_allowed(struct kvm_vcpu *vcpu)
 	struct vcpu_svm *svm = to_svm(vcpu);
 	struct vmcb *vmcb = svm->vmcb;
 	return !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
-		!(svm->vcpu.arch.hflags & HF_NMI_MASK);
+		!(svm->vcpu.arch.hflags & HF_NMI_MASK) &&
+		gif_set(svm) &&
                ^^^^^^^^^^^^

I'm not claiming to be up-to-date with the SVM code around NMI injection, but this addition irritates me. Can you explain why I don't have to worry that a cleared IF could now defer NMI injections for L1 guests?

Quoted 15 lines
arch/x86/kvm/svm.c +3 -1
+		!is_nested(svm);
 }
 
 static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)
@@ -2488,22 +2505,31 @@ static void enable_irq_window(struct kvm_vcpu *vcpu)
 	struct vcpu_svm *svm = to_svm(vcpu);
 	nsvm_printk("Trying to open IRQ window\n");
 
-	nested_svm_intr(svm);
+	if (nested_svm_intr(svm))
+		return;
 
 	/* In case GIF=0 we can't rely on the CPU to tell us when
 	 * GIF becomes 1, because that's a separate STGI/VMRUN intercept.
 	 * The next time we get that intercept, this function will be

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2519

Quoted 10 lines
arch/x86/kvm/svm.c +5 -4
 	 * called again though and we'll get the vintr intercept. */
-	if (gif_set(svm)) {
-		svm_set_vintr(svm);
-		svm_inject_irq(svm, 0x0);
-	}
+	if (!gif_set(svm))
+		return;
+
+	svm_set_vintr(svm);
+	svm_inject_irq(svm, 0x0);

The last change is pure refactoring that should not belong into this patch, should it?

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2532

Quoted 13 lines
arch/x86/kvm/svm.c +7 -0
 }
 
 static void enable_nmi_window(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_svm *svm = to_svm(vcpu);
 
+	if (nested_svm_nmi(svm))
+		return;
+
+	/* NMI is deferred until GIF == 1. Setting GIF will cause a #VMEXIT */
+	if (!gif_set(svm))
+		return;
+

The second half is an unrelated optimization? Then please file a separate patch.

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2535

Quoted 3 lines
arch/x86/kvm/svm.c +0 -0
 	if ((svm->vcpu.arch.hflags & (HF_NMI_MASK | HF_IRET_MASK))
 	    == HF_NMI_MASK)
 		return; /* IRET will cause a vm exit */

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#16 lore raw

Re: [PATCH 1/5] Implement #NMI exiting for nested SVM

Am 18.09.2009 um 15:33 schrieb Jan Kiszka <[email protected]>:

Quoted 47 lines
Quoted 38 lines · Alexander Graf

When injecting an NMI to the l1 guest while it was running the l2 guest, we didn't #VMEXIT but just injected the NMI to the l2 guest.

Let's be closer to real hardware and #VMEXIT if we're supposed to do so.

---
arch/x86/kvm/svm.c | 38 ++++++++++++++++++++++++++++++++------

1 files changed, 32 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +15 -0
index 9a4daca..f12a669 100644
@@ -1375,6 +1375,21 @@ static int nested_svm_check_exception(struct  
 vcpu_svm *svm, unsigned nr,
   return nested_svm_exit_handled(svm);
 }
 
+static inline int nested_svm_nmi(struct vcpu_svm *svm)
+{
+    if (!is_nested(svm))
+        return 0;
+
+    svm->vmcb->control.exit_code = SVM_EXIT_NMI;
+
+    if (nested_svm_exit_handled(svm)) {
+        nsvm_printk("VMexit -> NMI\n");
+        return 1;
+    }
+
+    return 0;
+}
+
 static inline int nested_svm_intr(struct vcpu_svm *svm)
 {
   if (!is_nested(svm))

arch/x86/kvm/svm.c static int svm_nmi_allowed(struct kvm_vcpu · line 2482

Quoted 7 lines
arch/x86/kvm/svm.c +2 -1
@@ -2462,7 +2477,9 @@ static int svm_nmi_allowed(struct kvm_vcpu  
 *vcpu)
   struct vcpu_svm *svm = to_svm(vcpu);
   struct vmcb *vmcb = svm->vmcb;
   return !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
-        !(svm->vcpu.arch.hflags & HF_NMI_MASK);
+        !(svm->vcpu.arch.hflags & HF_NMI_MASK) &&
+        gif_set(svm) &&
               ^^^^^^^^^^^^
Quoted 4 lines

I'm not claiming to be up-to-date with the SVM code around NMI injection, but this addition irritates me. Can you explain why I don't have to worry that a cleared IF could now defer NMI injections for L1 guests?

It's not about IF, but GIF, which is a special SVM addition that also masks NMIs.

Quoted 14 lines
Quoted 14 lines
arch/x86/kvm/svm.c +1 -0
+        !is_nested(svm);
 }
 

static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)

arch/x86/kvm/svm.c +2 -1
@@ -2488,22 +2505,31 @@ static void enable_irq_window(struct  
 kvm_vcpu *vcpu)
   struct vcpu_svm *svm = to_svm(vcpu);
   nsvm_printk("Trying to open IRQ window\n");
 
-    nested_svm_intr(svm);
+    if (nested_svm_intr(svm))
+        return;
 
Quoted 16 lines

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2519

Quoted 13 lines
arch/x86/kvm/svm.c +5 -4
   /* In case GIF=0 we can't rely on the CPU to tell us when
    * GIF becomes 1, because that's a separate STGI/VMRUN intercept.
    * The next time we get that intercept, this function will be
    * called again though and we'll get the vintr intercept. */
-    if (gif_set(svm)) {
-        svm_set_vintr(svm);
-        svm_inject_irq(svm, 0x0);
-    }
+    if (!gif_set(svm))
+        return;
+
+    svm_set_vintr(svm);
+    svm_inject_irq(svm, 0x0);

The last change is pure refactoring that should not belong into this patch, should it?

It went along the same function and makes the code more alike. But if you feel like this really should be separate, I can split it.

Quoted 7 lines
Quoted 7 lines
arch/x86/kvm/svm.c +0 -0
 }
 
 static void enable_nmi_window(struct kvm_vcpu *vcpu)
 {
   struct vcpu_svm *svm = to_svm(vcpu);
 
Quoted 11 lines

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2532

Quoted 8 lines
arch/x86/kvm/svm.c +7 -0
+    if (nested_svm_nmi(svm))
+        return;
+
+    /* NMI is deferred until GIF == 1. Setting GIF will cause a  
 #VMEXIT */
+    if (!gif_set(svm))
+        return;
+

The second half is an unrelated optimization? Then please file a separate patch.

Nope, it's about not injecting NMIs while GIF is not set again.

Alex

Quoted 10 lines
Quoted 4 lines
arch/x86/kvm/svm.c +0 -0
   if ((svm->vcpu.arch.hflags & (HF_NMI_MASK | HF_IRET_MASK))

== HF_NMI_MASK)
return; /* IRET will cause a vm exit */

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#17 lore raw

Re: [PATCH 1/5] Implement #NMI exiting for nested SVM

Quoted 56 lines · Alexander Graf

Am 18.09.2009 um 15:33 schrieb Jan Kiszka <[email protected]>:

Quoted 49 lines
Quoted 40 lines · Alexander Graf

When injecting an NMI to the l1 guest while it was running the l2 guest, we
didn't #VMEXIT but just injected the NMI to the l2 guest.

Let's be closer to real hardware and #VMEXIT if we're supposed to do so.

---
arch/x86/kvm/svm.c | 38 ++++++++++++++++++++++++++++++++------

1 files changed, 32 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +15 -0
index 9a4daca..f12a669 100644
@@ -1375,6 +1375,21 @@ static int nested_svm_check_exception(struct  
 vcpu_svm *svm, unsigned nr,
   return nested_svm_exit_handled(svm);
 }
 
+static inline int nested_svm_nmi(struct vcpu_svm *svm)
+{
+    if (!is_nested(svm))
+        return 0;
+
+    svm->vmcb->control.exit_code = SVM_EXIT_NMI;
+
+    if (nested_svm_exit_handled(svm)) {
+        nsvm_printk("VMexit -> NMI\n");
+        return 1;
+    }
+
+    return 0;
+}
+
 static inline int nested_svm_intr(struct vcpu_svm *svm)
 {
   if (!is_nested(svm))

arch/x86/kvm/svm.c static int svm_nmi_allowed(struct kvm_vcpu · line 2482

Quoted 7 lines
arch/x86/kvm/svm.c +2 -1
@@ -2462,7 +2477,9 @@ static int svm_nmi_allowed(struct kvm_vcpu  
 *vcpu)
   struct vcpu_svm *svm = to_svm(vcpu);
   struct vmcb *vmcb = svm->vmcb;
   return !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
-        !(svm->vcpu.arch.hflags & HF_NMI_MASK);
+        !(svm->vcpu.arch.hflags & HF_NMI_MASK) &&
+        gif_set(svm) &&
               ^^^^^^^^^^^^
Quoted 4 lines

I'm not claiming to be up-to-date with the SVM code around NMI injection, but this addition irritates me. Can you explain why I don't have to worry that a cleared IF could now defer NMI injections for L1 guests?

Quoted 2 lines

It's not about IF, but GIF, which is a special SVM addition that also masks NMIs.

Ah, now I got it: That's normally a host thing but, due to nesting, we need to consider it for L1, too. OK, something learned today. :)

Quoted 30 lines
Quoted 14 lines
Quoted 14 lines
arch/x86/kvm/svm.c +1 -0
+        !is_nested(svm);
 }
 

static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)

arch/x86/kvm/svm.c +2 -1
@@ -2488,22 +2505,31 @@ static void enable_irq_window(struct  
 kvm_vcpu *vcpu)
   struct vcpu_svm *svm = to_svm(vcpu);
   nsvm_printk("Trying to open IRQ window\n");
 
-    nested_svm_intr(svm);
+    if (nested_svm_intr(svm))
+        return;
 
Quoted 15 lines

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2519

Quoted 13 lines
arch/x86/kvm/svm.c +5 -4
   /* In case GIF=0 we can't rely on the CPU to tell us when
    * GIF becomes 1, because that's a separate STGI/VMRUN intercept.
    * The next time we get that intercept, this function will be
    * called again though and we'll get the vintr intercept. */
-    if (gif_set(svm)) {
-        svm_set_vintr(svm);
-        svm_inject_irq(svm, 0x0);
-    }
+    if (!gif_set(svm))
+        return;
+
+    svm_set_vintr(svm);
+    svm_inject_irq(svm, 0x0);

The last change is pure refactoring that should not belong into this patch, should it?

Quoted 2 lines

It went along the same function and makes the code more alike. But if you feel like this really should be separate, I can split it.

I've been slapped a few times for mixing both, but I'm not the person who will merge it.

Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
arch/x86/kvm/svm.c +0 -0
 }
 
 static void enable_nmi_window(struct kvm_vcpu *vcpu)
 {
   struct vcpu_svm *svm = to_svm(vcpu);
 
Quoted 10 lines

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2532

Quoted 8 lines
arch/x86/kvm/svm.c +7 -0
+    if (nested_svm_nmi(svm))
+        return;
+
+    /* NMI is deferred until GIF == 1. Setting GIF will cause a  
 #VMEXIT */
+    if (!gif_set(svm))
+        return;
+

The second half is an unrelated optimization? Then please file a separate patch.

Quoted 1 line

Nope, it's about not injecting NMIs while GIF is not set again.

Yes, got it.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#18 lore raw

Re: [PATCH 1/5] Implement #NMI exiting for nested SVM

In reply to Alexander Graf
Quoted 37 lines · Alexander Graf

When injecting an NMI to the l1 guest while it was running the l2 guest, we didn't #VMEXIT but just injected the NMI to the l2 guest.

Let's be closer to real hardware and #VMEXIT if we're supposed to do so.

---
 arch/x86/kvm/svm.c |   38 ++++++++++++++++++++++++++++++++------
 1 files changed, 32 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +15 -0
index 9a4daca..f12a669 100644
@@ -1375,6 +1375,21 @@ static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
 	return nested_svm_exit_handled(svm);
 }
 
+static inline int nested_svm_nmi(struct vcpu_svm *svm)
+{
+	if (!is_nested(svm))
+		return 0;
+
+	svm->vmcb->control.exit_code = SVM_EXIT_NMI;
+
+	if (nested_svm_exit_handled(svm)) {
+		nsvm_printk("VMexit -> NMI\n");
+		return 1;
+	}
+
+	return 0;
+}
+
 static inline int nested_svm_intr(struct vcpu_svm *svm)
 {
 	if (!is_nested(svm))

arch/x86/kvm/svm.c static int svm_nmi_allowed(struct kvm_vcpu *vcpu) · line 2482

Quoted 7 lines
arch/x86/kvm/svm.c +3 -1
@@ -2462,7 +2477,9 @@ static int svm_nmi_allowed(struct kvm_vcpu *vcpu)
 	struct vcpu_svm *svm = to_svm(vcpu);
 	struct vmcb *vmcb = svm->vmcb;
 	return !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
-		!(svm->vcpu.arch.hflags & HF_NMI_MASK);
+		!(svm->vcpu.arch.hflags & HF_NMI_MASK) &&
+		gif_set(svm) &&
+		!is_nested(svm);

This check is not sufficient. It assumes that the guest intercepts NMIs for its guests.

arch/x86/kvm/svm.c static void enable_irq_window(struct kvm_vcpu *vcpu) · line 2520

Quoted 10 lines
arch/x86/kvm/svm.c +5 -4
-	if (gif_set(svm)) {
-		svm_set_vintr(svm);
-		svm_inject_irq(svm, 0x0);
-	}
+	if (!gif_set(svm))
+		return;
+
+	svm_set_vintr(svm);
+	svm_inject_irq(svm, 0x0);
 }

As Jan already wrote, please put this in a seperate patch.

Joerg