Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754030AbbGANdv (ORCPT ); Wed, 1 Jul 2015 09:33:51 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:36838 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753764AbbGANdo (ORCPT ); Wed, 1 Jul 2015 09:33:44 -0400 Subject: Re: [PATCH 3/3] KVM: x86: make vapics_in_nmi_mode atomic To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org References: <1435695558-3168-1-git-send-email-rkrcmar@redhat.com> <1435695558-3168-4-git-send-email-rkrcmar@redhat.com> Cc: kvm@vger.kernel.org, Yoshida Nobuo From: Paolo Bonzini Message-ID: <5593EC35.6060509@redhat.com> Date: Wed, 1 Jul 2015 15:33:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: <1435695558-3168-4-git-send-email-rkrcmar@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2426 Lines: 66 On 30/06/2015 22:19, Radim Krčmář wrote: > Writes were a bit racy, but hard to turn into a bug at the same time. > (Particularly because modern Linux doesn't use this feature anymore.) I suspect patch 2 makes this race much easier to trigger, so it deserves Cc: stable@ as well. Paolo > Signed-off-by: Radim Krčmář > --- > arch/x86/include/asm/kvm_host.h | 2 +- > arch/x86/kvm/i8254.c | 2 +- > arch/x86/kvm/lapic.c | 4 ++-- > 3 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index c7fa57b529d2..2a7f5d782c33 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -607,7 +607,7 @@ struct kvm_arch { > struct kvm_pic *vpic; > struct kvm_ioapic *vioapic; > struct kvm_pit *vpit; > - int vapics_in_nmi_mode; > + atomic_t vapics_in_nmi_mode; > struct mutex apic_map_lock; > struct kvm_apic_map *apic_map; > > diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c > index 4dce6f8b6129..f90952f64e79 100644 > --- a/arch/x86/kvm/i8254.c > +++ b/arch/x86/kvm/i8254.c > @@ -305,7 +305,7 @@ static void pit_do_work(struct kthread_work *work) > * LVT0 to NMI delivery. Other PIC interrupts are just sent to > * VCPU0, and only if its LVT0 is in EXTINT mode. > */ > - if (kvm->arch.vapics_in_nmi_mode > 0) > + if (atomic_read(&kvm->arch.vapics_in_nmi_mode) > 0) > kvm_for_each_vcpu(i, vcpu, kvm) > kvm_apic_nmi_wd_deliver(vcpu); > } > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 8dc32b5a4e0d..954e98a8c2e3 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1264,9 +1264,9 @@ static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val) > if (lvt0_in_nmi_mode) { > apic_debug("Receive NMI setting on APIC_LVT0 " > "for cpu %d\n", apic->vcpu->vcpu_id); > - apic->vcpu->kvm->arch.vapics_in_nmi_mode++; > + atomic_inc(&apic->vcpu->kvm->arch.vapics_in_nmi_mode); > } else > - apic->vcpu->kvm->arch.vapics_in_nmi_mode--; > + atomic_dec(&apic->vcpu->kvm->arch.vapics_in_nmi_mode); > } > } > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/