From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiLo1-0001TV-R7 for qemu-devel@nongnu.org; Tue, 22 Mar 2016 08:53:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiLnw-00063T-TR for qemu-devel@nongnu.org; Tue, 22 Mar 2016 08:53:05 -0400 Date: Tue, 22 Mar 2016 20:52:54 +0800 From: Fam Zheng Message-ID: <20160322125254.GB9749@ad.usersys.redhat.com> References: <1458123018-18651-1-git-send-email-famz@redhat.com> <1458123018-18651-5-git-send-email-famz@redhat.com> <20160317150057.GP14062@stefanha-x1.localdomain> <56EAC82A.50907@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56EAC82A.50907@redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 4/4] virtio-blk: Clean up start/stop with mutex and BH List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Stefan Hajnoczi , qemu-devel@nongnu.org, tubo@linux.vnet.ibm.com, Stefan Hajnoczi , cornelia.huck@de.ibm.com, borntraeger@de.ibm.com On Thu, 03/17 16:07, Paolo Bonzini wrote: > > > On 17/03/2016 16:00, Stefan Hajnoczi wrote: > >> > + data = g_new(VirtIOBlockStartData, 1); > >> > + data->vblk = vblk; > >> > + data->bh = aio_bh_new(s->ctx, virtio_blk_data_plane_start_bh_cb, data); > >> > + qemu_bh_schedule(data->bh); > >> > + qemu_mutex_unlock(&s->start_stop_lock); > >> > return; > > This BH usage pattern is dangerous: > > > > 1. The BH is created and scheduled. > > 2. Before the BH executes the device is unrealized. > > 3. The data->bh pointer is inaccessible so we have a dangling BH that > > will access vblk after vblk has been freed. > > > > In some cases it can be safe but I don't see why the pattern is safe in > > this case. Either the BH needs to hold some sort of reference to keep > > vblk alive, or vblk needs to know about pending BHs so they can be > > deleted. > > You're right. After unrealizing virtio_blk_data_plane_stop has set of > vblk->dataplane_started = false, so that's covered. However, you still > need an object_ref/object_object_unref pair. Is it safe to call object_unref outside BQL? Fam