From: Jason Wang Subject: Re: [PATCH] vhost/vsock: handle vhost_vq_init_access() error Date: Sun, 22 Jan 2017 16:16:11 +0800 Message-ID: References: <20170119104353.28313-1-stefanha@redhat.com> <72eabacf-a303-2648-514b-2db1d73af747@redhat.com> <20170120134017.GA17499@stefanha-x1.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" To: Stefan Hajnoczi Return-path: Received: from mx1.redhat.com ([209.132.183.28]:53026 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbdAVIQQ (ORCPT ); Sun, 22 Jan 2017 03:16:16 -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 80F4785376 for ; Sun, 22 Jan 2017 08:16:16 +0000 (UTC) In-Reply-To: <20170120134017.GA17499@stefanha-x1.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On 2017年01月20日 21:40, Stefan Hajnoczi wrote: > On Fri, Jan 20, 2017 at 11:23:13AM +0800, Jason Wang wrote: >> >> 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? > Here we still hold the vq mutex. If we release the mutex then a > virtqueue kick could be processed. > > Stefan Ok, then it's better to assign vq->private_data after vhost_vq_init_acess() succeed. Thanks