public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vhost-vdpa: Fix some error handling path in vhost_vdpa_process_iotlb_msg()
@ 2022-05-22 13:59 Christophe JAILLET
  2022-05-23  4:41 ` Jason Wang
  2022-05-26 23:25 ` Michael S. Tsirkin
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2022-05-22 13:59 UTC (permalink / raw)
  To: dan.carpenter, Michael S. Tsirkin, Jason Wang, Gautam Dawar
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, kvm,
	virtualization, netdev

In the error paths introduced by the commit in the Fixes tag, a mutex may
be left locked.
Add the correct goto instead of a direct return.

Fixes: a1468175bb17 ("vhost-vdpa: support ASID based IOTLB API")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
WARNING: This patch only fixes the goto vs return mix-up in this function.
However, the 2nd hunk looks really spurious to me. I think that the:
-		return -EINVAL;
+		r = -EINVAL;
+		goto unlock;
should be done only in the 'if (!iotlb)' block.

As I don't know this code, I just leave it as-is but draw your attention
in case this is another bug lurking.
---
 drivers/vhost/vdpa.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 1f1d1c425573..3e86080041fc 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1000,7 +1000,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
 		if (!as) {
 			dev_err(&v->dev, "can't find and alloc asid %d\n",
 				asid);
-			return -EINVAL;
+			r = -EINVAL;
+			goto unlock;
 		}
 		iotlb = &as->iotlb;
 	} else
@@ -1013,7 +1014,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
 		}
 		if (!iotlb)
 			dev_err(&v->dev, "no iotlb for asid %d\n", asid);
-		return -EINVAL;
+		r = -EINVAL;
+		goto unlock;
 	}
 
 	switch (msg->type) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] vhost-vdpa: Fix some error handling path in vhost_vdpa_process_iotlb_msg()
  2022-05-22 13:59 [PATCH] vhost-vdpa: Fix some error handling path in vhost_vdpa_process_iotlb_msg() Christophe JAILLET
@ 2022-05-23  4:41 ` Jason Wang
  2022-05-23 10:33   ` Stefano Garzarella
  2022-05-26 23:25 ` Michael S. Tsirkin
  1 sibling, 1 reply; 4+ messages in thread
From: Jason Wang @ 2022-05-23  4:41 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Dan Carpenter, Michael S. Tsirkin, Gautam Dawar, linux-kernel,
	kernel-janitors, kvm, virtualization, netdev

On Sun, May 22, 2022 at 9:59 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> In the error paths introduced by the commit in the Fixes tag, a mutex may
> be left locked.
> Add the correct goto instead of a direct return.
>
> Fixes: a1468175bb17 ("vhost-vdpa: support ASID based IOTLB API")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> WARNING: This patch only fixes the goto vs return mix-up in this function.
> However, the 2nd hunk looks really spurious to me. I think that the:
> -               return -EINVAL;
> +               r = -EINVAL;
> +               goto unlock;
> should be done only in the 'if (!iotlb)' block.

It should be fine, the error happen if

1) the batched ASID based request is not equal (the first if)
2) there's no IOTLB for this ASID (the second if)

But I agree the code could be tweaked to use two different if instead
of using a or condition here.

Acked-by: Jason Wang <jasowang@redhat.com>

>
> As I don't know this code, I just leave it as-is but draw your attention
> in case this is another bug lurking.
> ---
>  drivers/vhost/vdpa.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 1f1d1c425573..3e86080041fc 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1000,7 +1000,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
>                 if (!as) {
>                         dev_err(&v->dev, "can't find and alloc asid %d\n",
>                                 asid);
> -                       return -EINVAL;
> +                       r = -EINVAL;
> +                       goto unlock;
>                 }
>                 iotlb = &as->iotlb;
>         } else
> @@ -1013,7 +1014,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
>                 }
>                 if (!iotlb)
>                         dev_err(&v->dev, "no iotlb for asid %d\n", asid);
> -               return -EINVAL;
> +               r = -EINVAL;
> +               goto unlock;
>         }
>
>         switch (msg->type) {
> --
> 2.34.1
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vhost-vdpa: Fix some error handling path in vhost_vdpa_process_iotlb_msg()
  2022-05-23  4:41 ` Jason Wang
@ 2022-05-23 10:33   ` Stefano Garzarella
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Garzarella @ 2022-05-23 10:33 UTC (permalink / raw)
  To: Jason Wang
  Cc: Christophe JAILLET, kvm, Michael S. Tsirkin, netdev,
	kernel-janitors, linux-kernel, virtualization, Gautam Dawar,
	Dan Carpenter

On Mon, May 23, 2022 at 12:41:03PM +0800, Jason Wang wrote:
>On Sun, May 22, 2022 at 9:59 PM Christophe JAILLET
><christophe.jaillet@wanadoo.fr> wrote:
>>
>> In the error paths introduced by the commit in the Fixes tag, a mutex may
>> be left locked.
>> Add the correct goto instead of a direct return.
>>
>> Fixes: a1468175bb17 ("vhost-vdpa: support ASID based IOTLB API")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> WARNING: This patch only fixes the goto vs return mix-up in this function.
>> However, the 2nd hunk looks really spurious to me. I think that the:
>> -               return -EINVAL;
>> +               r = -EINVAL;
>> +               goto unlock;
>> should be done only in the 'if (!iotlb)' block.
>
>It should be fine, the error happen if
>
>1) the batched ASID based request is not equal (the first if)
>2) there's no IOTLB for this ASID (the second if)
>
>But I agree the code could be tweaked to use two different if instead
>of using a or condition here.

Yeah, I think so!

Anyway, this patch LGTM:

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vhost-vdpa: Fix some error handling path in vhost_vdpa_process_iotlb_msg()
  2022-05-22 13:59 [PATCH] vhost-vdpa: Fix some error handling path in vhost_vdpa_process_iotlb_msg() Christophe JAILLET
  2022-05-23  4:41 ` Jason Wang
@ 2022-05-26 23:25 ` Michael S. Tsirkin
  1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2022-05-26 23:25 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: dan.carpenter, Jason Wang, Gautam Dawar, linux-kernel,
	kernel-janitors, kvm, virtualization, netdev

On Sun, May 22, 2022 at 03:59:01PM +0200, Christophe JAILLET wrote:
> In the error paths introduced by the commit in the Fixes tag, a mutex may
> be left locked.
> Add the correct goto instead of a direct return.
> 
> Fixes: a1468175bb17 ("vhost-vdpa: support ASID based IOTLB API")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> WARNING: This patch only fixes the goto vs return mix-up in this function.
> However, the 2nd hunk looks really spurious to me. I think that the:
> -		return -EINVAL;
> +		r = -EINVAL;
> +		goto unlock;
> should be done only in the 'if (!iotlb)' block.
> 
> As I don't know this code, I just leave it as-is but draw your attention
> in case this is another bug lurking.
> ---
>  drivers/vhost/vdpa.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 1f1d1c425573..3e86080041fc 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1000,7 +1000,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
>  		if (!as) {
>  			dev_err(&v->dev, "can't find and alloc asid %d\n",
>  				asid);
> -			return -EINVAL;
> +			r = -EINVAL;
> +			goto unlock;
>  		}
>  		iotlb = &as->iotlb;
>  	} else
> @@ -1013,7 +1014,8 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid,
>  		}
>  		if (!iotlb)
>  			dev_err(&v->dev, "no iotlb for asid %d\n", asid);
> -		return -EINVAL;
> +		r = -EINVAL;
> +		goto unlock;
>  	}
>  
>  	switch (msg->type) {
> -- 
> 2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-26 23:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-22 13:59 [PATCH] vhost-vdpa: Fix some error handling path in vhost_vdpa_process_iotlb_msg() Christophe JAILLET
2022-05-23  4:41 ` Jason Wang
2022-05-23 10:33   ` Stefano Garzarella
2022-05-26 23:25 ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox