From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: KVM: x86: better fix for race between nmi injection and enabling nmi window Date: Thu, 31 Mar 2011 06:30:59 -0300 Message-ID: <20110331093059.GA7259@amt.cnet> References: <20110330163028.GA27365@amt.cnet> <4D936572.3060801@redhat.com> <20110330184703.GC7741@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Avi Kivity , kvm To: Gleb Natapov Return-path: Received: from mx1.redhat.com ([209.132.183.28]:20055 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757005Ab1CaJkj (ORCPT ); Thu, 31 Mar 2011 05:40:39 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2V9edJt024381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 31 Mar 2011 05:40:39 -0400 Content-Disposition: inline In-Reply-To: <20110330184703.GC7741@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Mar 30, 2011 at 08:47:03PM +0200, Gleb Natapov wrote: > On Wed, Mar 30, 2011 at 07:16:34PM +0200, Avi Kivity wrote: > > On 03/30/2011 06:30 PM, Marcelo Tosatti wrote: > > >Based on Gleb's idea, fix race between nmi injection and enabling > > >nmi window in a simpler way. > > > > > >Signed-off-by: Marcelo Tosatti > > > > > >diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > >index a6a129f..9a7cc1be 100644 > > >--- a/arch/x86/kvm/x86.c > > >+++ b/arch/x86/kvm/x86.c > > >@@ -5152,6 +5152,7 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu) > > > static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > > > { > > > int r; > > >+ int nmi_pending; > > > bool req_int_win = !irqchip_in_kernel(vcpu->kvm)&& > > > vcpu->run->request_interrupt_window; > > > > > >@@ -5195,11 +5196,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > > > if (unlikely(r)) > > > goto out; > > > > > >+ nmi_pending = ACCESS_ONCE(vcpu->arch.nmi_pending); > > >+ > > > if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) { > > > inject_pending_event(vcpu); > > > > > > /* enable NMI/IRQ window open exits if needed */ > > >- if (vcpu->arch.nmi_pending) > > >+ if (nmi_pending) > > > kvm_x86_ops->enable_nmi_window(vcpu); > > > else if (kvm_cpu_has_interrupt(vcpu) || req_int_win) > > > kvm_x86_ops->enable_irq_window(vcpu); > > > > > > > What about the check in inject_pending_events()? > > > Didn't we decide that this check is not a problem? Worst that can happen > is NMI injection will be delayed till next exit. Yes.