patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 20.11] vhost: fix async access
@ 2022-06-17  5:52 David Marchand
  2022-06-20  7:01 ` Xueming(Steven) Li
  0 siblings, 1 reply; 2+ messages in thread
From: David Marchand @ 2022-06-17  5:52 UTC (permalink / raw)
  To: xuemingl, stable; +Cc: Sunil Pai G, Maxime Coquelin, Patrick Fu, Jiayu Hu

[ 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@redhat.com>
Acked-by: Sunil Pai G <sunil.pai.g@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@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


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

* RE: [PATCH 20.11] vhost: fix async access
  2022-06-17  5:52 [PATCH 20.11] vhost: fix async access David Marchand
@ 2022-06-20  7:01 ` Xueming(Steven) Li
  0 siblings, 0 replies; 2+ messages in thread
From: Xueming(Steven) Li @ 2022-06-20  7:01 UTC (permalink / raw)
  To: David Marchand, stable; +Cc: Sunil Pai G, Maxime Coquelin, Patrick Fu, Jiayu Hu

Hi David,

Applied, thanks!

> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, June 17, 2022 1:52 PM
> To: Xueming(Steven) Li <xuemingl@nvidia.com>; stable@dpdk.org
> Cc: Sunil Pai G <sunil.pai.g@intel.com>; Maxime Coquelin <maxime.coquelin@redhat.com>; Patrick Fu <patrick.fu@intel.com>; Jiayu Hu
> <jiayu.hu@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@redhat.com>
> Acked-by: Sunil Pai G <sunil.pai.g@intel.com>
> Reviewed-by: Maxime Coquelin <maxime.coquelin@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


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

end of thread, other threads:[~2022-06-20  7:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17  5:52 [PATCH 20.11] vhost: fix async access David Marchand
2022-06-20  7:01 ` Xueming(Steven) Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).