From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] KVM: x86: Fix lost interrupt on irr_pending race Date: Tue, 18 Nov 2014 20:51:04 +0100 Message-ID: <546BA328.9010009@redhat.com> References: <1416174547-5309-1-git-send-email-namit@cs.technion.ac.il> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, wanpeng.li@linux.intel.com, nadav.amit@gmail.com To: Nadav Amit Return-path: Received: from mail-wi0-f180.google.com ([209.85.212.180]:55051 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753829AbaKRTvJ (ORCPT ); Tue, 18 Nov 2014 14:51:09 -0500 Received: by mail-wi0-f180.google.com with SMTP id n3so6568060wiv.1 for ; Tue, 18 Nov 2014 11:51:08 -0800 (PST) In-Reply-To: <1416174547-5309-1-git-send-email-namit@cs.technion.ac.il> Sender: kvm-owner@vger.kernel.org List-ID: On 16/11/2014 22:49, Nadav Amit wrote: > @@ -374,13 +378,15 @@ static inline void apic_clear_irr(int vec, struct kvm_lapic *apic) > > vcpu = apic->vcpu; > > - apic_clear_vector(vec, apic->regs + APIC_IRR); > - if (unlikely(kvm_apic_vid_enabled(vcpu->kvm))) > + if (unlikely(kvm_apic_vid_enabled(vcpu->kvm))) { > /* try to update RVI */ > + apic_clear_vector(vec, apic->regs + APIC_IRR); > kvm_make_request(KVM_REQ_EVENT, vcpu); > - else { > - vec = apic_search_irr(apic); > - apic->irr_pending = (vec != -1); > + } else { > + apic->irr_pending = false; > + apic_clear_vector(vec, apic->regs + APIC_IRR); > + if (apic_search_irr(apic) != -1) > + apic->irr_pending = true; > } > } This is even more tricky than it looks like. :) No one can concurrently look at apic->irr_pending while it is false, in particular apic_sync_pv_eoi_to_guest cannot enable PV EOI by mistake just because it sees a false irr_pending. So it's okay if it is first set to false and then to true. I'll apply the patch tomorrow. Paolo