From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [patch 2/4] KVM: move coalesced_mmio locking to its own device Date: Sun, 24 May 2009 17:04:52 +0300 Message-ID: <4A195404.8040406@redhat.com> References: <20090520184841.954066003@localhost.localdomain> <20090520185134.623968425@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Gregory Haskins To: Marcelo Tosatti Return-path: Received: from mx2.redhat.com ([66.187.237.31]:33816 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbZEXOEy (ORCPT ); Sun, 24 May 2009 10:04:54 -0400 In-Reply-To: <20090520185134.623968425@localhost.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: Marcelo Tosatti wrote: > Get rid of kvm->lock dependency on coalesced_mmio methods. Use an > atomic variable instead to guarantee only one vcpu is batching > data into the ring at a given time. > > Signed-off-by: Marcelo Tosatti > > Index: kvm-irqlock/virt/kvm/coalesced_mmio.c > =================================================================== > --- kvm-irqlock.orig/virt/kvm/coalesced_mmio.c > +++ kvm-irqlock/virt/kvm/coalesced_mmio.c > @@ -26,9 +26,12 @@ static int coalesced_mmio_in_range(struc > if (!is_write) > return 0; > > - /* kvm->lock is taken by the caller and must be not released before > - * dev.read/write > - */ > + /* > + * Some other vcpu might be batching data into the ring, > + * fallback to userspace. Ordering not our problem. > + */ > + if (!atomic_add_unless(&dev->in_use, 1, 1)) > + return 0; > > Ordering with simultaneous writes is indeed not our problem, but the ring may contain ordered writes (even by the same vcpu!) Suggest our own lock here. in_use is basically a homemade lock, better to use the factory made ones which come with a warranty. -- error compiling committee.c: too many arguments to function