From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v2] KVM: Fix simultaneous NMIs Date: Tue, 20 Sep 2011 19:24:01 +0300 Message-ID: <4E78BE21.4070508@redhat.com> References: <1316515394-24762-1-git-send-email-avi@redhat.com> <20110920132537.GA27075@amt.cnet> <4E789B72.2050904@redhat.com> <20110920145946.GA28219@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Jan Kiszka To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:14454 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750932Ab1ITQYG (ORCPT ); Tue, 20 Sep 2011 12:24:06 -0400 In-Reply-To: <20110920145946.GA28219@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On 09/20/2011 05:59 PM, Marcelo Tosatti wrote: > On Tue, Sep 20, 2011 at 04:56:02PM +0300, Avi Kivity wrote: > > On 09/20/2011 04:25 PM, Marcelo Tosatti wrote: > > >> > > >> @@ -2827,6 +2828,7 @@ static int kvm_vcpu_ioctl_x86_set_mce(struct kvm_vcpu *vcpu, > > >> static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, > > >> struct kvm_vcpu_events *events) > > >> { > > >> + process_nmi(vcpu); > > >> events->exception.injected = > > >> vcpu->arch.exception.pending&& > > >> !kvm_exception_is_soft(vcpu->arch.exception.nr); > > >> @@ -2844,7 +2846,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, > > >> KVM_X86_SHADOW_INT_MOV_SS | KVM_X86_SHADOW_INT_STI); > > >> > > >> events->nmi.injected = vcpu->arch.nmi_injected; > > >> - events->nmi.pending = vcpu->arch.nmi_pending; > > >> + events->nmi.pending = vcpu->arch.nmi_pending != 0; > > >> events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu); > > >> events->nmi.pad = 0; > > > > > >nmi_queued should also be saved and restored. Not sure if its necessary > > >though. > > > > > >Should at least reset nmi_queued somewhere (set_vcpu_events?). > > > > Did you miss the call to process_nmi()? > > It transfers nmi_queued to nmi_pending with capping. What i mean is that > upon system reset, nmi_queued (which refers to pre-reset system state) > should be zeroed. The is get_events(); for set_events(), process_nmi() does zero nmi_queued() (and then we overwrite nmi_pending). > > > We do have a small issue. If we exit during NMI-blocked-by-STI and > > nmi_pending == 2, then we lose the second interrupt. Should rarely > > happen, since external interrupts never exit in that condition, but > > it's a wart. > > And the above system reset case, you should be able to handle it by > saving/restoring nmi_queued (so that QEMU can zero it in vcpu_reset). We could just add a KVM_CAP (and flag) that extends nmi_pending from a bool to a counter. -- error compiling committee.c: too many arguments to function