Skip to contentSkip to conversation

net/mlx5: fix mutex unlock in txpp cleanup

PATCH Superseded Chengfeng Ye 2 participants 2 messages Sep 3, 2021 – Sep 20, 2021 Network drivers

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 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")
---
 drivers/net/mlx5/mlx5_txpp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_txpp.c +5 -1
index 4f6da9f2d1..0ece788a84 100644
@@ -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);
Signature · 1 line
2.17.1
#1 lore raw

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

Quoted 41 lines

in these two branches, which may led to deadlock if the function was -----Original Message-----
From: dev <[email protected]> On Behalf Of Chengfeng Ye
Sent: Friday, September 3, 2021 11:44
To: [email protected]
Cc: [email protected]; Chengfeng Ye <[email protected]>; [email protected]
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")
---
 drivers/net/mlx5/mlx5_txpp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/mlx5/mlx5_txpp.c +5 -2
index 4f6da9f2d1..0ece788a84 100644
@@ -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