From patchwork Mon Mar 16 13:03:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 12404 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 n2GD4Aqb029878 for ; Mon, 16 Mar 2009 13:04:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757341AbZCPNEK (ORCPT ); Mon, 16 Mar 2009 09:04:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752267AbZCPNEK (ORCPT ); Mon, 16 Mar 2009 09:04:10 -0400 Received: from va3ehsobe003.messaging.microsoft.com ([216.32.180.13]:34434 "EHLO VA3EHSOBE003.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756566AbZCPNEI (ORCPT ); Mon, 16 Mar 2009 09:04:08 -0400 Received: from mail136-va3-R.bigfish.com (10.7.14.245) by VA3EHSOBE003.bigfish.com (10.7.40.23) with Microsoft SMTP Server id 8.1.340.0; Mon, 16 Mar 2009 13:04:05 +0000 Received: from mail136-va3 (localhost.localdomain [127.0.0.1]) by mail136-va3-R.bigfish.com (Postfix) with ESMTP id 8AE9314E01F1; Mon, 16 Mar 2009 13:04:05 +0000 (UTC) X-BigFish: VPS11(z1857rzzz1202hzzz32i63h) X-Spam-TCS-SCL: 2:0 Received: by mail136-va3 (MessageSwitch) id 123720864399004_20631; Mon, 16 Mar 2009 13:04:03 +0000 (UCT) Received: from svlb1extmailp02.amd.com (unknown [139.95.251.11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail136-va3.bigfish.com (Postfix) with ESMTP id E93CE1CE804D; Mon, 16 Mar 2009 13:04:02 +0000 (UTC) Received: from svlb1twp02.amd.com ([139.95.250.35]) by svlb1extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n2GD3uuv022835; Mon, 16 Mar 2009 06:03:59 -0700 X-WSS-ID: 0KGLOA7-04-BNC-01 Received: from SSVLEXBH2.amd.com (ssvlexbh2.amd.com [139.95.53.183]) by svlb1twp02.amd.com (Tumbleweed MailGate 3.5.1) with ESMTP id 2837A1103BC; Mon, 16 Mar 2009 06:03:42 -0700 (PDT) Received: from ssvlexmb2.amd.com ([139.95.53.7]) by SSVLEXBH2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 16 Mar 2009 06:03:48 -0700 Received: from SF30EXMB1.amd.com ([172.20.6.49]) by ssvlexmb2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 16 Mar 2009 06:03:47 -0700 Received: from seurexmb1.amd.com ([165.204.82.130]) by SF30EXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 16 Mar 2009 14:03:45 +0100 Received: from lemmy.amd.com ([165.204.85.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 16 Mar 2009 14:03:45 +0100 Received: by lemmy.amd.com (Postfix, from userid 41430) id 1186C5392D; Mon, 16 Mar 2009 14:03:45 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH] kvm/x86: check KVM_REQ_TLB_FLUSH with irqs disabled Date: Mon, 16 Mar 2009 14:03:45 +0100 Message-ID: <1237208625-2657-1-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.5.6.4 X-OriginalArrivalTime: 16 Mar 2009 13:03:45.0291 (UTC) FILETIME=[A37AB5B0:01C9A637] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org For KVM remote TLB flushes we need to check the KVM_REQ_TLB_FLUSH request flag when the irqs are already disabled. Otherwise there is a small window of time for a race condition where we may enter a guest without doing a requested TLB flush. Signed-off-by: Joerg Roedel --- arch/x86/kvm/x86.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b556b6a..301660a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3108,8 +3108,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) kvm_write_guest_time(vcpu); if (test_and_clear_bit(KVM_REQ_MMU_SYNC, &vcpu->requests)) kvm_mmu_sync_roots(vcpu); - if (test_and_clear_bit(KVM_REQ_TLB_FLUSH, &vcpu->requests)) - kvm_x86_ops->tlb_flush(vcpu); if (test_and_clear_bit(KVM_REQ_REPORT_TPR_ACCESS, &vcpu->requests)) { kvm_run->exit_reason = KVM_EXIT_TPR_ACCESS; @@ -3133,6 +3131,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) local_irq_disable(); + if (test_and_clear_bit(KVM_REQ_TLB_FLUSH, &vcpu->requests)) + kvm_x86_ops->tlb_flush(vcpu); + if (vcpu->requests || need_resched() || signal_pending(current)) { local_irq_enable(); preempt_enable();