[v4] net/mlx5: fix mutex unlock in txpp cleanup

Message ID 20210903084349.25168-1-cyeaa@connect.ust.hk (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series [v4] net/mlx5: fix mutex unlock in txpp cleanup |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

YE Chengfeng Sept. 3, 2021, 8:43 a.m. UTC
  The lock sh->txpp.mutex was not correctly released if the function
returned in these two branches, which may led to deadlock if the
function was acquired again.

Fixes: d133f4cdb7 ("net/mlx5: create clock queue for packet pacing")
Cc: stable@dpdk.org

Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
---
 drivers/net/mlx5/mlx5_txpp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Slava Ovsiienko Sept. 20, 2021, 5:23 a.m. UTC | #1
Hi, Chengfeng

Good catch, thank you.
Could we polish the commit message a bit?

"The lock sh->txpp.mutex was not correctly released on all pathes
of cleanup function return, potentially causing the deadlock."

With best regards,
Slava

> in these two branches, which may led to deadlock if the function was
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Chengfeng Ye
> Sent: Friday, September 3, 2021 11:44
> To: david.marchand@redhat.com
> Cc: dev@dpdk.org; Chengfeng Ye <cyeaa@connect.ust.hk>;
> stable@dpdk.org
> Subject: [dpdk-dev] [PATCH v4] net/mlx5: fix mutex unlock in txpp cleanup
> 
> The lock sh->txpp.mutex was not correctly released if the function returned
> in these two branches, which may led to deadlock if the function was
> acquired again.
> 
> Fixes: d133f4cdb7 ("net/mlx5: create clock queue for packet pacing")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
> ---
>  drivers/net/mlx5/mlx5_txpp.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_txpp.c b/drivers/net/mlx5/mlx5_txpp.c
> index 4f6da9f2d1..0ece788a84 100644
> --- a/drivers/net/mlx5/mlx5_txpp.c
> +++ b/drivers/net/mlx5/mlx5_txpp.c
> @@ -961,8 +961,12 @@ mlx5_txpp_stop(struct rte_eth_dev *dev)
>  	MLX5_ASSERT(!ret);
>  	RTE_SET_USED(ret);
>  	MLX5_ASSERT(sh->txpp.refcnt);
> -	if (!sh->txpp.refcnt || --sh->txpp.refcnt)
> +	if (!sh->txpp.refcnt || --sh->txpp.refcnt) {
> +		ret = pthread_mutex_unlock(&sh->txpp.mutex);
> +		MLX5_ASSERT(!ret);
> +		RTE_SET_USED(ret);
>  		return;
> +	}
>  	/* No references any more, do actual destroy. */
>  	mlx5_txpp_destroy(sh);
>  	ret = pthread_mutex_unlock(&sh->txpp.mutex);
> --
> 2.17.1
  

Patch

diff --git a/drivers/net/mlx5/mlx5_txpp.c b/drivers/net/mlx5/mlx5_txpp.c
index 4f6da9f2d1..0ece788a84 100644
--- a/drivers/net/mlx5/mlx5_txpp.c
+++ b/drivers/net/mlx5/mlx5_txpp.c
@@ -961,8 +961,12 @@  mlx5_txpp_stop(struct rte_eth_dev *dev)
 	MLX5_ASSERT(!ret);
 	RTE_SET_USED(ret);
 	MLX5_ASSERT(sh->txpp.refcnt);
-	if (!sh->txpp.refcnt || --sh->txpp.refcnt)
+	if (!sh->txpp.refcnt || --sh->txpp.refcnt) {
+		ret = pthread_mutex_unlock(&sh->txpp.mutex);
+		MLX5_ASSERT(!ret);
+		RTE_SET_USED(ret);
 		return;
+	}
 	/* No references any more, do actual destroy. */
 	mlx5_txpp_destroy(sh);
 	ret = pthread_mutex_unlock(&sh->txpp.mutex);