From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3PiK-0005Aa-Qf for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:13:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z3PiF-0005lB-QF for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:13:44 -0400 Date: Fri, 12 Jun 2015 15:13:36 +0100 From: Stefan Hajnoczi Message-ID: <20150612141336.GA31283@stefanha-thinkpad.redhat.com> References: <1433936297-7098-1-git-send-email-yarygin@linux.vnet.ibm.com> <1433936297-7098-3-git-send-email-yarygin@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="82I3+IH0IqGh5yIs" Content-Disposition: inline In-Reply-To: <1433936297-7098-3-git-send-email-yarygin@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 2/3] virtio-blk: Use blk_drain() to drain IO requests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Yarygin Cc: Kevin Wolf , qemu-block@nongnu.org, Ekaterina Tumanova , qemu-devel@nongnu.org, Christian Borntraeger , Stefan Hajnoczi , Cornelia Huck , Paolo Bonzini --82I3+IH0IqGh5yIs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 10, 2015 at 02:38:16PM +0300, Alexander Yarygin wrote: > Each call of the virtio_blk_reset() function calls blk_drain_all(), > which works for all existing BlockDriverStates, while draining only > one is needed. >=20 > This patch replaces blk_drain_all() by blk_drain() in virtio_blk_reset(). >=20 > Cc: Christian Borntraeger > Cc: Cornelia Huck > Cc: Kevin Wolf > Cc: Paolo Bonzini > Cc: Stefan Hajnoczi > Signed-off-by: Alexander Yarygin > --- > hw/block/virtio-blk.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) >=20 > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c > index e6afe97..2009092 100644 > --- a/hw/block/virtio-blk.c > +++ b/hw/block/virtio-blk.c > @@ -652,15 +652,16 @@ static void virtio_blk_reset(VirtIODevice *vdev) > { > VirtIOBlock *s =3D VIRTIO_BLK(vdev); > =20 > - if (s->dataplane) { > - virtio_blk_data_plane_stop(s->dataplane); > - } > - > /* > * This should cancel pending requests, but can't do nicely until th= ere > * are per-device request lists. > */ > - blk_drain_all(); > + blk_drain(s->blk); > + > + if (s->dataplane) { > + virtio_blk_data_plane_stop(s->dataplane); > + } This is unsafe now. virtio_blk_reset() is called from the vcpu thread while the virtqueue processing may be running in an IOThread. blk_drain() does not acquire AioContext so it races with the IOThread. Try: ctx =3D bdrv_get_aio_context(s->blk); aio_context_acquire(ctx); blk_drain(s->blk); if (s->dataplane) { virtio_blk_data_plane_stop(s->dataplane); } aio_context_release(ctx); --82I3+IH0IqGh5yIs Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVeukQAAoJEJykq7OBq3PIAQoH/0xjJgGIKq7ugKRJ993sS9oq yHhV4kL2toJSyCUlXWPjeqHmoHyQcHojm0OOU7OjzUEorkbl13MziSjPUaoNBunB Jk3q62g1HR0EOj+L7biHos1ruq2Mot+lhjdROFwHzjx9JAAOoKEf3GPvK3xi9XFM utxn9MAd91gbppZc+LJUPhEvT0uEGinSGB7Gt5af6gEV3GeqpCWxX/zPLJiAJ2OE mKIDB70uiA3sLlhBNxvgs5qLO1VqoSFp45Zidy6s0xBU8PeI8seysFQd2Fzx3sOD f5j8pUre1Q9lxI5P9JjDEBCP2h70Gkxy1eWBV1leHm3td/1o5C2+k5xR9xJQ/Rc= =7utK -----END PGP SIGNATURE----- --82I3+IH0IqGh5yIs--