From: Stefan Hajnoczi Subject: Re: [PATCH] vhost/vsock: handle vhost_vq_init_access() error Date: Fri, 20 Jan 2017 13:40:17 +0000 Message-ID: <20170120134017.GA17499@stefanha-x1.localdomain> References: <20170119104353.28313-1-stefanha@redhat.com> <72eabacf-a303-2648-514b-2db1d73af747@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Nq2Wo0NMKNjxTN9z" Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" To: Jason Wang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:58008 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751996AbdATNkT (ORCPT ); Fri, 20 Jan 2017 08:40:19 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BA224E4D2 for ; Fri, 20 Jan 2017 13:40:20 +0000 (UTC) Content-Disposition: inline In-Reply-To: <72eabacf-a303-2648-514b-2db1d73af747@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2017 at 11:23:13AM +0800, Jason Wang wrote: >=20 >=20 > On 2017=E5=B9=B401=E6=9C=8819=E6=97=A5 18:43, Stefan Hajnoczi wrote: > > Propagate the error when vhost_vq_init_access() fails and set > > vq->private_data to NULL. > >=20 > > Signed-off-by: Stefan Hajnoczi > > --- > > drivers/vhost/vsock.c | 13 +++++++++---- > > 1 file changed, 9 insertions(+), 4 deletions(-) > >=20 > > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > > index bbbf5885..ce5e63d 100644 > > --- a/drivers/vhost/vsock.c > > +++ b/drivers/vhost/vsock.c > > @@ -373,6 +373,7 @@ static void vhost_vsock_handle_rx_kick(struct vhost= _work *work) > > static int vhost_vsock_start(struct vhost_vsock *vsock) > > { > > + struct vhost_virtqueue *vq; > > size_t i; > > int ret; > > @@ -383,19 +384,20 @@ static int vhost_vsock_start(struct vhost_vsock *= vsock) > > goto err; > > for (i =3D 0; i < ARRAY_SIZE(vsock->vqs); i++) { > > - struct vhost_virtqueue *vq =3D &vsock->vqs[i]; > > + vq =3D &vsock->vqs[i]; > > mutex_lock(&vq->mutex); > > if (!vhost_vq_access_ok(vq)) { > > ret =3D -EFAULT; > > - mutex_unlock(&vq->mutex); > > goto err_vq; > > } > > if (!vq->private_data) { > > vq->private_data =3D vsock; > > - vhost_vq_init_access(vq); > > + ret =3D vhost_vq_init_access(vq); > > + if (ret) > > + goto err_vq; > > } > > mutex_unlock(&vq->mutex); > > @@ -405,8 +407,11 @@ static int vhost_vsock_start(struct vhost_vsock *v= sock) > > return 0; > > err_vq: > > + vq->private_data =3D NULL; >=20 > Looks like this will be done twice? Here we still hold the vq mutex. If we release the mutex then a virtqueue kick could be processed. Stefan --Nq2Wo0NMKNjxTN9z Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJYghNBAAoJEJykq7OBq3PIw4cH/jLc8FYqHjmGv1tgfPYvMSsG dox5E510UGCilLQqLac1RQGGp4mqpBugYuFgAZ7y4XtU6W0b1elvh6wyBpeLgS0w 8ENc33LHYBlajti8IYi7PZ4U6RX/xXfFqwoN5fVYWNpeM12KUmziYfZ3fZ4eEsvc mVDnybQRNjSUERgWtwpHFv/S2RhNVHx++rW3HY2voxpeqr3JaRb7SGzZdODoK9ot qF0F2GNRjUg0Pf5eDZHrouehtBL7+ckTsfPAGqvV+DZQoAwYgNNzWgweVPHvGfrV +o1gI+HlWspoyb7r8AEagGHn9uQtNlwHNXmTyJk6jC/S9CR4B/SB65opt9EouQk= =49vp -----END PGP SIGNATURE----- --Nq2Wo0NMKNjxTN9z--