Received: from eggs.gnu.org ([2001:4830:134:3::10]:43413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfTh2-0007Y2-Pv for qemu-devel@nongnu.org; Fri, 25 Sep 2015 10:09:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfTh1-0007NH-OZ for qemu-devel@nongnu.org; Fri, 25 Sep 2015 10:09:44 -0400 From: Alberto Garcia In-Reply-To: <1442497700-2536-6-git-send-email-kwolf@redhat.com> References: <1442497700-2536-1-git-send-email-kwolf@redhat.com> <1442497700-2536-6-git-send-email-kwolf@redhat.com> Date: Fri, 25 Sep 2015 16:09:35 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH 05/16] block: Convert bs->file to BdrvChild List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-block@nongnu.org Cc: jcody@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, stefanha@redhat.com, mreitz@redhat.com On Thu 17 Sep 2015 03:48:09 PM CEST, Kevin Wolf wrote: > @@ -1929,6 +1925,11 @@ void bdrv_close(BlockDriverState *bs) > bdrv_unref(backing_hd); > } > > + if (bs->file != NULL) { > + bdrv_unref(bs->file->bs); > + bs->file = NULL; > + } > + > QLIST_FOREACH_SAFE(child, &bs->children, next, next) { > /* TODO Remove bdrv_unref() from drivers' close function and use > * bdrv_unref_child() here */ > @@ -1953,11 +1954,6 @@ void bdrv_close(BlockDriverState *bs) > bs->options = NULL; > QDECREF(bs->full_open_options); > bs->full_open_options = NULL; > - > - if (bs->file != NULL) { > - bdrv_unref(bs->file); > - bs->file = NULL; > - } > } You are moving bdrv_unref(bs->file) up in the function and this seems to be causing a problem, by turning this: bs->drv->bdrv_close(bs); bs->drv = NULL; bdrv_unref(bs->file); into this: bs->drv->bdrv_close(bs); bdrv_unref(bs->file); bs->drv = NULL; In the latter case, closing bs->file calls aio_poll(). This can trigger new requests on bs, which at that point has a valid pointer to a BlockDriver that has already been closed. If throttling is enabled on bs those requests might be queued for later. At the point in which those requests are scheduled bs->drv is already NULL, crashing QEMU. I can reproduce this easily with x-data-plane=on. I sent a separate patch that moves the bdrv_io_limits_disable() call to the beginning of bdrv_close(). That solves the crash, but I guess that this patch should also be changed. Berto