mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 02/10] KVM: X86: Add KVM_REQ_VMEXIT to trigger a nested #vmexit
Date: Wed, 7 Oct 2009 16:31:20 +0200	[thread overview]
Message-ID: <1254925888-13743-3-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1254925888-13743-1-git-send-email-joerg.roedel@amd.com>

In the vcpu_run path the kernel may notice that a #vmexit is
necessary when preemption is already disabled. In the SVM
code an emulation of #vmexit may sleep and can't be executed
with preemtion disabled. This patch begins to solve this
problem by defining a KVM_REQ_VMEXIT bit. When this bit is
set the vcpu_run loop is restarted and a #vmexit is
emulated.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/include/asm/kvm_host.h |    1 +
 arch/x86/kvm/x86.c              |   17 +++++++++++++++++
 include/linux/kvm_host.h        |    1 +
 3 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 179a919..50e5aa4 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -524,6 +524,7 @@ struct kvm_x86_ops {
 	int (*get_tdp_level)(void);
 	u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio);
 	bool (*gb_page_enable)(void);
+	void (*emulate_vmexit)(struct kvm_vcpu *vcpu);
 
 	const struct trace_print_flags *exit_reasons_str;
 };
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 11a6f2f..97e1d9d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3610,6 +3610,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 			r = 0;
 			goto out;
 		}
+		if (test_and_clear_bit(KVM_REQ_VMEXIT, &vcpu->requests))
+			 kvm_x86_ops->emulate_vmexit(vcpu);
 	}
 
 	preempt_disable();
@@ -3638,6 +3640,21 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 	else if (kvm_cpu_has_interrupt(vcpu) || req_int_win)
 		kvm_x86_ops->enable_irq_window(vcpu);
 
+	/*
+	 * With nested KVM the enable_irq_window() function may cause an
+	 * #vmexit if the vcpu is running in guest mode. A #vmexit may sleep
+	 * and can't be executed at this stage. So we use the request field to
+	 * tell KVM that a #vmexit has to be done before we can enter the guest
+	 * again. The code below checks for this request.
+	 */
+	if (vcpu->requests) {
+		local_irq_enable();
+		preempt_enable();
+		r = 1;
+		goto out;
+	}
+
+
 	if (kvm_lapic_enabled(vcpu)) {
 		update_cr8_intercept(vcpu);
 		kvm_lapic_sync_to_vapic(vcpu);
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index b985a29..245463f 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -38,6 +38,7 @@
 #define KVM_REQ_MMU_SYNC           7
 #define KVM_REQ_KVMCLOCK_UPDATE    8
 #define KVM_REQ_KICK               9
+#define KVM_REQ_VMEXIT             10
 
 #define KVM_USERSPACE_IRQ_SOURCE_ID	0
 
-- 
1.6.4.3



  parent reply	other threads:[~2009-10-07 14:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-07 14:31 [PATCH 0/10] KVM: Nested SVM fixes and tracepoint conversion Joerg Roedel
2009-10-07 14:31 ` [PATCH 01/10] KVM: SVM: Notify nested hypervisor of lost event injections Joerg Roedel
2009-10-07 14:31 ` Joerg Roedel [this message]
2009-10-07 14:31 ` [PATCH 03/10] KVM: SVM: Move nested INTR #vmexit into preemtible code Joerg Roedel
2009-10-07 20:58   ` Marcelo Tosatti
2009-10-08  9:12     ` Joerg Roedel
2009-10-07 14:31 ` [PATCH 04/10] KVM: SVM: Add tracepoint for nested vmrun Joerg Roedel
2009-10-07 14:31 ` [PATCH 05/10] KVM: SVM: Add tracepoint for nested #vmexit Joerg Roedel
2009-10-07 14:31 ` [PATCH 06/10] KVM: SVM: Add tracepoint for injected #vmexit Joerg Roedel
2009-10-07 14:31 ` [PATCH 07/10] KVM: SVM: Add tracepoint for #vmexit because intr pending Joerg Roedel
2009-10-07 14:31 ` [PATCH 08/10] KVM: SVM: Add tracepoint for invlpga instruction Joerg Roedel
2009-10-07 14:31 ` [PATCH 09/10] KVM: SVM: Add tracepoint for skinit instruction Joerg Roedel
2009-10-07 14:31 ` [PATCH 10/10] KVM: SVM: Remove nsvm_printk debugging code 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=1254925888-13743-3-git-send-email-joerg.roedel@amd.com \
    --to=joerg.roedel@amd.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®