[PATCH v2] vhost: fix deadlock when handling user messages

Xia, Chenbo chenbo.xia at intel.com
Fri May 6 10:19:00 CEST 2022


> -----Original Message-----
> From: Ma, WenwuX <wenwux.ma at intel.com>
> Sent: Friday, May 6, 2022 12:17 AM
> To: maxime.coquelin at redhat.com; Xia, Chenbo <chenbo.xia at intel.com>;
> dev at dpdk.org
> Cc: Hu, Jiayu <jiayu.hu at intel.com>; Wang, Yinan <yinan.wang at intel.com>; He,
> Xingguang <xingguang.he at intel.com>; Ma, WenwuX <wenwux.ma at intel.com>;
> stable at dpdk.org
> Subject: [PATCH v2] vhost: fix deadlock when handling user messages
> 
> In vhost_user_msg_handler(), if vhost message handling
> failed, we should check whether the queue is locked and
> release the lock before returning. Or, it will cause a
> deadlock later.
> 
> Fixes: 7f31d4ea05ca ("vhost: fix lock on device readiness notification")
> Cc: stable at dpdk.org
> 
> Signed-off-by: Wenwu Ma <wenwux.ma at intel.com>
> ---
>  lib/vhost/vhost_user.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index 1d390677fa..4baf969ee0 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -2976,7 +2976,6 @@ vhost_user_msg_handler(int vid, int fd)
>  		return -1;
>  	}
> 
> -	ret = 0;
>  	request = ctx.msg.request.master;
>  	if (request > VHOST_USER_NONE && request < VHOST_USER_MAX &&
>  			vhost_message_str[request]) {
> @@ -3113,9 +3112,11 @@ vhost_user_msg_handler(int vid, int fd)
>  		send_vhost_reply(dev, fd, &ctx);
>  	} else if (ret == RTE_VHOST_MSG_RESULT_ERR) {
>  		VHOST_LOG_CONFIG(ERR, "(%s) vhost message handling failed.\n",
> dev->ifname);
> -		return -1;
> +		ret = -1;
> +		goto unlock;
>  	}
> 
> +	ret = 0;
>  	for (i = 0; i < dev->nr_vring; i++) {
>  		struct vhost_virtqueue *vq = dev->virtqueue[i];
>  		bool cur_ready = vq_is_ready(dev, vq);
> @@ -3126,10 +3127,11 @@ vhost_user_msg_handler(int vid, int fd)
>  		}
>  	}
> 
> +unlock:
>  	if (unlock_required)
>  		vhost_user_unlock_all_queue_pairs(dev);
> 
> -	if (!virtio_is_ready(dev))
> +	if (ret != 0 || !virtio_is_ready(dev))
>  		goto out;
> 
>  	/*
> @@ -3156,7 +3158,7 @@ vhost_user_msg_handler(int vid, int fd)
>  	}
> 
>  out:
> -	return 0;
> +	return ret;
>  }
> 
>  static int process_slave_message_reply(struct virtio_net *dev,
> --
> 2.25.1

'vhost: fix deadlock when message handling failed' may be a better title.

Reviewed-by: Chenbo Xia <chenbo.xia at intel.com>



More information about the stable mailing list