From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 13/15] hotplug: introduce qdev_unplug_complete() to remove device from views Date: Wed, 08 Aug 2012 13:07:27 +0300 Message-ID: <50223A5F.5060206@redhat.com> References: <1344407156-25562-1-git-send-email-qemulist@gmail.com> <1344407156-25562-14-git-send-email-qemulist@gmail.com> <502236D8.3040902@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Jan Kiszka , Marcelo Tosatti , Liu Ping Fan , qemu-devel@nongnu.org, Blue Swirl , Anthony Liguori , Stefan Hajnoczi , =?ISO-8859-15?Q?Andreas_F=E4rber?= To: Paolo Bonzini Return-path: In-Reply-To: <502236D8.3040902@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org List-Id: kvm.vger.kernel.org On 08/08/2012 12:52 PM, Paolo Bonzini wrote: > Il 08/08/2012 08:25, Liu Ping Fan ha scritto: >> +void qdev_unplug_complete(DeviceState *dev, Error **errp) >> +{ >> + /* isolate from mem view */ >> + qdev_unmap(dev); >> + qemu_lock_devtree(); >> + /* isolate from device tree */ >> + qdev_unset_parent(dev); >> + qemu_unlock_devtree(); >> + object_unref(OBJECT(dev)); > > Rather than deferring the free, you should defer the unref. Otherwise > the following can happen when you have "real" RCU access to the memory > map on the read-side: > > VCPU thread I/O thread > ===================================================================== > get MMIO request > rcu_read_lock() > walk memory map > qdev_unmap() > lock_devtree() > ... > unlock_devtree > unref dev -> refcnt=0, free enqueued > ref() > rcu_read_unlock() > free() > unref should follow either synchronize_rcu(), or be in a call_rcu() callback (deferring the unref). IMO synchronize_rcu() is sufficient here, unplug is a truly slow path, esp. on real hardware. -- error compiling committee.c: too many arguments to function From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sz3Au-0002iY-7t for qemu-devel@nongnu.org; Wed, 08 Aug 2012 06:07:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sz3At-00022q-7K for qemu-devel@nongnu.org; Wed, 08 Aug 2012 06:07:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53913) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sz3As-00022f-Uk for qemu-devel@nongnu.org; Wed, 08 Aug 2012 06:07:35 -0400 Message-ID: <50223A5F.5060206@redhat.com> Date: Wed, 08 Aug 2012 13:07:27 +0300 From: Avi Kivity MIME-Version: 1.0 References: <1344407156-25562-1-git-send-email-qemulist@gmail.com> <1344407156-25562-14-git-send-email-qemulist@gmail.com> <502236D8.3040902@redhat.com> In-Reply-To: <502236D8.3040902@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 13/15] hotplug: introduce qdev_unplug_complete() to remove device from views List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: kvm@vger.kernel.org, Jan Kiszka , Marcelo Tosatti , Liu Ping Fan , qemu-devel@nongnu.org, Blue Swirl , Anthony Liguori , Stefan Hajnoczi , =?ISO-8859-15?Q?Andreas_F=E4rber?= On 08/08/2012 12:52 PM, Paolo Bonzini wrote: > Il 08/08/2012 08:25, Liu Ping Fan ha scritto: >> +void qdev_unplug_complete(DeviceState *dev, Error **errp) >> +{ >> + /* isolate from mem view */ >> + qdev_unmap(dev); >> + qemu_lock_devtree(); >> + /* isolate from device tree */ >> + qdev_unset_parent(dev); >> + qemu_unlock_devtree(); >> + object_unref(OBJECT(dev)); > > Rather than deferring the free, you should defer the unref. Otherwise > the following can happen when you have "real" RCU access to the memory > map on the read-side: > > VCPU thread I/O thread > ===================================================================== > get MMIO request > rcu_read_lock() > walk memory map > qdev_unmap() > lock_devtree() > ... > unlock_devtree > unref dev -> refcnt=0, free enqueued > ref() > rcu_read_unlock() > free() > unref should follow either synchronize_rcu(), or be in a call_rcu() callback (deferring the unref). IMO synchronize_rcu() is sufficient here, unplug is a truly slow path, esp. on real hardware. -- error compiling committee.c: too many arguments to function