From patchwork Wed Oct 7 14:31:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 52280 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n97EnQTe022521 for ; Wed, 7 Oct 2009 14:49:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759348AbZJGOcf (ORCPT ); Wed, 7 Oct 2009 10:32:35 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759344AbZJGOcf (ORCPT ); Wed, 7 Oct 2009 10:32:35 -0400 Received: from va3ehsobe002.messaging.microsoft.com ([216.32.180.12]:31212 "EHLO VA3EHSOBE002.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759342AbZJGOce (ORCPT ); Wed, 7 Oct 2009 10:32:34 -0400 Received: from mail68-va3-R.bigfish.com (10.7.14.251) by VA3EHSOBE002.bigfish.com (10.7.40.22) with Microsoft SMTP Server id 8.1.340.0; Wed, 7 Oct 2009 14:31:57 +0000 Received: from mail68-va3 (localhost.localdomain [127.0.0.1]) by mail68-va3-R.bigfish.com (Postfix) with ESMTP id BE61014F83B9; Wed, 7 Oct 2009 14:31:56 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzzz32i6bh64h) X-Spam-TCS-SCL: 3:0 X-FB-SS: 5, Received: by mail68-va3 (MessageSwitch) id 1254925913305298_19104; Wed, 7 Oct 2009 14:31:53 +0000 (UCT) Received: from VA3EHSMHS015.bigfish.com (unknown [10.7.14.249]) by mail68-va3.bigfish.com (Postfix) with ESMTP id A6078BD8061; Wed, 7 Oct 2009 14:31:52 +0000 (UTC) Received: from ausb3extmailp02.amd.com (163.181.251.22) by VA3EHSMHS015.bigfish.com (10.7.99.25) with Microsoft SMTP Server (TLS) id 14.0.482.32; Wed, 7 Oct 2009 14:31:49 +0000 Received: from ausb3twp01.amd.com (ausb3twp01.amd.com [163.181.250.37]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n97EVjYE011337; Wed, 7 Oct 2009 09:31:48 -0500 X-WSS-ID: 0KR5F0U-01-FED-02 X-M-MSG: Received: from sausexbh1.amd.com (sausexbh1.amd.com [163.181.22.101]) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.0) with ESMTP id 2555A10284C2; Wed, 7 Oct 2009 09:31:41 -0500 (CDT) Received: from sausexmb2.amd.com ([163.181.3.157]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Oct 2009 09:31:44 -0500 Received: from SDRSEXMB1.amd.com ([172.20.3.116]) by sausexmb2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Oct 2009 09:31:44 -0500 Received: from seurexmb1.amd.com ([165.204.9.130]) by SDRSEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Oct 2009 16:31:36 +0200 Received: from lemmy.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 7 Oct 2009 16:31:34 +0200 Received: by lemmy.amd.com (Postfix, from userid 41430) id 0B812C9B89; Wed, 7 Oct 2009 16:31:35 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 02/10] KVM: X86: Add KVM_REQ_VMEXIT to trigger a nested #vmexit Date: Wed, 7 Oct 2009 16:31:20 +0200 Message-ID: <1254925888-13743-3-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.6.4.3 In-Reply-To: <1254925888-13743-1-git-send-email-joerg.roedel@amd.com> References: <1254925888-13743-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 07 Oct 2009 14:31:35.0108 (UTC) FILETIME=[DF37B840:01CA475A] MIME-Version: 1.0 X-Reverse-DNS: ausb3extmailp02.amd.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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