From: Jason Wang Subject: Re: [PATCH] vhost/vsock: handle vhost_vq_init_access() error Date: Mon, 23 Jan 2017 18:31:56 +0800 Message-ID: <98b5dc3b-9771-3099-e2d6-9ffc56e96f24@redhat.com> References: <20170119104353.28313-1-stefanha@redhat.com> <72eabacf-a303-2648-514b-2db1d73af747@redhat.com> <20170120134017.GA17499@stefanha-x1.localdomain> <20170123095622.GA29186@stefanha-x1.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Cc: Stefan Hajnoczi , kvm@vger.kernel.org, "Michael S. Tsirkin" To: Stefan Hajnoczi Return-path: Received: from mx1.redhat.com ([209.132.183.28]:54536 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750703AbdAWKcC (ORCPT ); Mon, 23 Jan 2017 05:32:02 -0500 In-Reply-To: <20170123095622.GA29186@stefanha-x1.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On 2017年01月23日 17:56, Stefan Hajnoczi wrote: > On Sun, Jan 22, 2017 at 04:16:11PM +0800, Jason Wang wrote: >> >> 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. > No, that won't work because vhost_vq_init_acess() requires that > vq->private_data is non-NULL. > > Stefan Oh right. Then Acked-by: Jason Wang