KVM Archive on lore.kernel.org
 help / color / Atom feed
From: Alexander Graf <agraf@suse.de>
To: kvm@vger.kernel.org
Subject: [PATCH 2/5] Don't call svm_complete_interrupts for nested guests
Date: Fri, 18 Sep 2009 15:00:29 +0200
Message-ID: <1253278832-31803-3-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1253278832-31803-2-git-send-email-agraf@suse.de>

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.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/x86/kvm/svm.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index f12a669..61efd13 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -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) {
-- 
1.6.0.2


  reply index

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18 13:00 [PATCH 0/5] Nested SVM Interrupt Fixes Alexander Graf
2009-09-18 13:00 ` [PATCH 1/5] Implement #NMI exiting for nested SVM Alexander Graf
2009-09-18 13:00   ` Alexander Graf [this message]
2009-09-18 13:00     ` [PATCH 3/5] Don't #VMEXIT(INTR) if we still have event_inj waiting Alexander Graf
2009-09-18 13:00       ` [PATCH 4/5] Don't bail when injecting an event in nested SVM Alexander Graf
2009-09-18 13:00         ` [PATCH 5/5] Notify nested hypervisor of lost event injections Alexander Graf
2009-09-23  1:22           ` Joerg Roedel
2009-09-27 14:18           ` Joerg Roedel
2009-09-23  1:39       ` [PATCH 3/5] Don't #VMEXIT(INTR) if we still have event_inj waiting Joerg Roedel
2009-09-23  8:09         ` Alexander Graf
2009-09-18 13:39     ` [PATCH 2/5] Don't call svm_complete_interrupts for nested guests Jan Kiszka
2009-09-23  1:26     ` Joerg Roedel
2009-09-23  8:04       ` Alexander Graf
2009-09-23  8:05       ` Alexander Graf
2009-09-23  8:28         ` Gleb Natapov
2009-09-18 13:33   ` [PATCH 1/5] Implement #NMI exiting for nested SVM Jan Kiszka
2009-09-18 15:44     ` Alexander Graf
2009-09-18 16:01       ` Jan Kiszka
2009-09-23  1:06   ` Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1253278832-31803-3-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

KVM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \
		kvm@vger.kernel.org
	public-inbox-index kvm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.kvm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git