From: Jason Wang Subject: Re: [PATCH] vhost/vsock: handle vhost_vq_init_access() error Date: Fri, 20 Jan 2017 11:23:13 +0800 Message-ID: <72eabacf-a303-2648-514b-2db1d73af747@redhat.com> References: <20170119104353.28313-1-stefanha@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Cc: "Michael S. Tsirkin" To: Stefan Hajnoczi , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:52302 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751038AbdATDXR (ORCPT ); Thu, 19 Jan 2017 22:23:17 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B300C056791 for ; Fri, 20 Jan 2017 03:23:18 +0000 (UTC) In-Reply-To: <20170119104353.28313-1-stefanha@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 2017年01月19日 18:43, Stefan Hajnoczi wrote: > Propagate the error when vhost_vq_init_access() fails and set > vq->private_data to NULL. > > Signed-off-by: Stefan Hajnoczi > --- > drivers/vhost/vsock.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > 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 = 0; i < ARRAY_SIZE(vsock->vqs); i++) { > - struct vhost_virtqueue *vq = &vsock->vqs[i]; > + vq = &vsock->vqs[i]; > > mutex_lock(&vq->mutex); > > if (!vhost_vq_access_ok(vq)) { > ret = -EFAULT; > - mutex_unlock(&vq->mutex); > goto err_vq; > } > > if (!vq->private_data) { > vq->private_data = vsock; > - vhost_vq_init_access(vq); > + ret = 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 *vsock) > return 0; > > err_vq: > + vq->private_data = NULL; Looks like this will be done twice? Thanks > + mutex_unlock(&vq->mutex); > + > for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) { > - struct vhost_virtqueue *vq = &vsock->vqs[i]; > + vq = &vsock->vqs[i]; > > mutex_lock(&vq->mutex); > vq->private_data = NULL;