From: Takuya Yoshikawa Subject: Re: [RFC PATCH] KVM: Fix missing lock for kvm_io_bus_unregister_dev() Date: Fri, 10 Dec 2010 02:21:18 +0900 Message-ID: <20101210022118.e608a136.takuya.yoshikawa@gmail.com> References: <20101208014506.4c18b52a.takuya.yoshikawa@gmail.com> <20101208191044.GA12294@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: avi@redhat.com, kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp To: Marcelo Tosatti Return-path: Received: from mail-fx0-f43.google.com ([209.85.161.43]:38918 "EHLO mail-fx0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756561Ab0LISRC (ORCPT ); Thu, 9 Dec 2010 13:17:02 -0500 Received: by fxm18 with SMTP id 18so2721031fxm.2 for ; Thu, 09 Dec 2010 10:17:01 -0800 (PST) In-Reply-To: <20101208191044.GA12294@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: Marcelo Tosatti wrote: > > --- a/arch/x86/kvm/i8254.c > > +++ b/arch/x86/kvm/i8254.c > > @@ -744,9 +744,11 @@ void kvm_free_pit(struct kvm *kvm) > > struct hrtimer *timer; > > > > if (kvm->arch.vpit) { > > + mutex_lock(&kvm->slots_lock); > > kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &kvm->arch.vpit->dev); > > kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, > > &kvm->arch.vpit->speaker_dev); > > + mutex_unlock(&kvm->slots_lock); > > kvm_unregister_irq_mask_notifier(kvm, 0, > > &kvm->arch.vpit->mask_notifier); > > kvm_unregister_irq_ack_notifier(kvm, > > This is supposedly safe because this is only called from vm destroy > context, when dropping the last reference. > I see. Drop this from the next version. > > It seems the best way to fix is to move irq_lock and slots_lock > acquision from kvm_set_irq_routing/kvm_ioapic_destroy/kvm_destroy_pic to > their callers. > Then, the lock acquisition for registeration and unregisteration may be centralized to vm_ioctl. I'm now checking these to reformat the patch. Thanks, Takuya