[PATCH 20.11] vhost: fix async access

Xueming(Steven) Li xuemingl at nvidia.com
Mon Jun 20 09:01:53 CEST 2022


Hi David,

Applied, thanks!

> -----Original Message-----
> From: David Marchand <david.marchand at redhat.com>
> Sent: Friday, June 17, 2022 1:52 PM
> To: Xueming(Steven) Li <xuemingl at nvidia.com>; stable at dpdk.org
> Cc: Sunil Pai G <sunil.pai.g at intel.com>; Maxime Coquelin <maxime.coquelin at redhat.com>; Patrick Fu <patrick.fu at intel.com>; Jiayu Hu
> <jiayu.hu at intel.com>
> Subject: [PATCH 20.11] vhost: fix async access
> 
> [ upstream commit 2d47fd3dfb596d266b89d82c2c4b2351c3d6fe20 ]
> 
> vq->async accesses must be protected with vq->access_lock.
> 
> Fixes: eb666d24085f ("vhost: fix async unregister deadlock")
> Fixes: 0c0935c5f794 ("vhost: allow to check in-flight packets for async vhost")
> 
> Signed-off-by: David Marchand <david.marchand at redhat.com>
> Acked-by: Sunil Pai G <sunil.pai.g at intel.com>
> Reviewed-by: Maxime Coquelin <maxime.coquelin at redhat.com>
> ---
>  lib/librte_vhost/vhost.c | 27 +++++++++++----------------
>  1 file changed, 11 insertions(+), 16 deletions(-)
> 
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 1a7c240492..40a2554417 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -1693,31 +1693,26 @@ int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
>  	if (vq == NULL)
>  		return ret;
> 
> -	ret = 0;
> -
> -	if (!vq->async_registered)
> -		return ret;
> -
>  	if (!rte_spinlock_trylock(&vq->access_lock)) {
>  		VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. "
>  			"virt queue busy.\n");
> -		return -1;
> +		return ret;
>  	}
> 
> -	if (vq->async_pkts_inflight_n) {
> +	if (!vq->async_registered) {
> +		ret = 0;
> +	} else if (vq->async_pkts_inflight_n) {
>  		VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. "
>  			"async inflight packets must be completed before unregistration.\n");
> -		ret = -1;
> -		goto out;
> -	}
> -
> -	vhost_free_async_mem(vq);
> +	} else {
> +		ret = 0;
> +		vhost_free_async_mem(vq);
> 
> -	vq->async_ops.transfer_data = NULL;
> -	vq->async_ops.check_completed_copies = NULL;
> -	vq->async_registered = false;
> +		vq->async_ops.transfer_data = NULL;
> +		vq->async_ops.check_completed_copies = NULL;
> +		vq->async_registered = false;
> +	}
> 
> -out:
>  	rte_spinlock_unlock(&vq->access_lock);
> 
>  	return ret;
> --
> 2.36.1



More information about the stable mailing list