From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzNfP-0003BC-8A for qemu-devel@nongnu.org; Thu, 09 Aug 2012 04:00:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzNfO-00019l-62 for qemu-devel@nongnu.org; Thu, 09 Aug 2012 04:00:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30547) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzNfN-00019d-U7 for qemu-devel@nongnu.org; Thu, 09 Aug 2012 04:00:26 -0400 Message-ID: <50236E10.8030709@redhat.com> Date: Thu, 09 Aug 2012 10:00:16 +0200 From: Paolo Bonzini 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: Content-Type: text/plain; charset=ISO-8859-1 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: liu ping fan Cc: kvm@vger.kernel.org, Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, Blue Swirl , Avi Kivity , Anthony Liguori , Stefan Hajnoczi , =?ISO-8859-1?Q?Andreas_F=E4rber?= Il 09/08/2012 09:28, liu ping fan ha scritto: >> > 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() > No ref() for dev here, while we have ref to flatview+radix in my patches. > I use rcu to protect radix+flatview+mr refered. As to dev, its ref has > inc when it is added into mem view -- that is > memory_region_add_subregion -> memory_region_get() { > if(atomic_add_and_return()) dev->ref++ }. > So not until reclaimer of mem view, the dev's ref is hold by mem view. > In a short word, rcu protect mem view, while device is protected by refcnt. But the RCU critical section should not include the whole processing of MMIO, only the walk of the memory map. And in general I think this is a bit too tricky... I understand not adding refcounting to all of bottom halves, timers, etc., but if you are using a device you should have explicit ref/unref pairs. Paolo