patch 'net/mlx5: fix flow workspace double free in Windows' has been queued to stable release 22.11.4

Xueming Li xuemingl at nvidia.com
Mon Dec 11 11:11:17 CET 2023


Hi,

FYI, your patch has been queued to stable release 22.11.4

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/13/23. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging

This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/commit/?h=22.11-staging&id=72ab4bf42fac40554a582226ffbb56b02746147f

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From 72ab4bf42fac40554a582226ffbb56b02746147f Mon Sep 17 00:00:00 2001
From: Bing Zhao <bingz at nvidia.com>
Date: Thu, 26 Oct 2023 12:14:47 +0300
Subject: [PATCH] net/mlx5: fix flow workspace double free in Windows
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit 2ece3b7186b9d22209ac1845f794b91185575a23 ]

The thread specific variable workspace indicated by "key_workspace"
should be freed explicitly when closing a device. For example, in
Linux, when exiting an application, the thread will not exit
explicitly and the thread resources will not be deconstructed.

The commit to solve this introduced a global list to manage the
workspace resources as a garbage collector. It will also be executed
in Windows, but the workspaces have already been freed in the
function mlx5_flow_os_release_workspace().

With this commit, the garbage collector will only be executed in
Linux. The workspace resources management in Windows will remain
the same with some stub function when needed.

Fixes: dc7c5e0aa905 ("net/mlx5: fix flow workspace destruction")

Signed-off-by: Bing Zhao <bingz at nvidia.com>
Acked-by: Matan Azrad <matan at nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_flow_os.c   | 25 +++++++++++++++++++++++++
 drivers/net/mlx5/linux/mlx5_flow_os.h   |  8 ++++++++
 drivers/net/mlx5/mlx5.c                 |  1 -
 drivers/net/mlx5/mlx5_flow.c            | 25 +------------------------
 drivers/net/mlx5/mlx5_flow.h            |  1 -
 drivers/net/mlx5/windows/mlx5_flow_os.c |  6 ++++++
 drivers/net/mlx5/windows/mlx5_flow_os.h |  8 ++++++++
 7 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_flow_os.c b/drivers/net/mlx5/linux/mlx5_flow_os.c
index b139bb75b9..2767b11708 100644
--- a/drivers/net/mlx5/linux/mlx5_flow_os.c
+++ b/drivers/net/mlx5/linux/mlx5_flow_os.c
@@ -8,6 +8,10 @@
 
 /* Key of thread specific flow workspace data. */
 static rte_thread_key key_workspace;
+/* Flow workspace global list head for garbage collector. */
+static struct mlx5_flow_workspace *gc_head;
+/* Spinlock for operating flow workspace list. */
+static rte_spinlock_t mlx5_flow_workspace_lock = RTE_SPINLOCK_INITIALIZER;
 
 int
 mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
@@ -48,6 +52,26 @@ mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
 	return 0;
 }
 
+void
+mlx5_flow_os_workspace_gc_add(struct mlx5_flow_workspace *ws)
+{
+	rte_spinlock_lock(&mlx5_flow_workspace_lock);
+	ws->gc = gc_head;
+	gc_head = ws;
+	rte_spinlock_unlock(&mlx5_flow_workspace_lock);
+}
+
+static void
+mlx5_flow_os_workspace_gc_release(void)
+{
+	while (gc_head) {
+		struct mlx5_flow_workspace *wks = gc_head;
+
+		gc_head = wks->gc;
+		flow_release_workspace(wks);
+	}
+}
+
 int
 mlx5_flow_os_init_workspace_once(void)
 {
@@ -75,4 +99,5 @@ void
 mlx5_flow_os_release_workspace(void)
 {
 	rte_thread_key_delete(key_workspace);
+	mlx5_flow_os_workspace_gc_release();
 }
diff --git a/drivers/net/mlx5/linux/mlx5_flow_os.h b/drivers/net/mlx5/linux/mlx5_flow_os.h
index ed71289322..3f7a94c9ee 100644
--- a/drivers/net/mlx5/linux/mlx5_flow_os.h
+++ b/drivers/net/mlx5/linux/mlx5_flow_os.h
@@ -526,4 +526,12 @@ mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
 			    uint8_t target_protocol,
 			    struct rte_flow_error *error);
 
+/**
+ * Add per thread workspace to the global list for garbage collection.
+ *
+ * @param[in] ws
+ *   Pointer to the flow workspace.
+ */
+void mlx5_flow_os_workspace_gc_add(struct mlx5_flow_workspace *ws);
+
 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index f787ae91fe..1dfd10e7cb 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1743,7 +1743,6 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
 	if (LIST_EMPTY(&mlx5_dev_ctx_list)) {
 		mlx5_os_net_cleanup();
 		mlx5_flow_os_release_workspace();
-		mlx5_flow_workspace_gc_release();
 	}
 	pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
 	if (sh->flex_parsers_dv) {
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index ea0a49827f..01b463adec 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -7544,29 +7544,6 @@ flow_release_workspace(void *data)
 	}
 }
 
-static struct mlx5_flow_workspace *gc_head;
-static rte_spinlock_t mlx5_flow_workspace_lock = RTE_SPINLOCK_INITIALIZER;
-
-static void
-mlx5_flow_workspace_gc_add(struct mlx5_flow_workspace *ws)
-{
-	rte_spinlock_lock(&mlx5_flow_workspace_lock);
-	ws->gc = gc_head;
-	gc_head = ws;
-	rte_spinlock_unlock(&mlx5_flow_workspace_lock);
-}
-
-void
-mlx5_flow_workspace_gc_release(void)
-{
-	while (gc_head) {
-		struct mlx5_flow_workspace *wks = gc_head;
-
-		gc_head = wks->gc;
-		flow_release_workspace(wks);
-	}
-}
-
 /**
  * Get thread specific current flow workspace.
  *
@@ -7623,7 +7600,7 @@ mlx5_flow_push_thread_workspace(void)
 		data = flow_alloc_thread_workspace();
 		if (!data)
 			return NULL;
-		mlx5_flow_workspace_gc_add(data);
+		mlx5_flow_os_workspace_gc_add(data);
 	} else if (!curr->inuse) {
 		data = curr;
 	} else if (curr->next) {
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 9724b88996..52edc4c961 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -1926,7 +1926,6 @@ struct mlx5_flow_driver_ops {
 struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
 void mlx5_flow_pop_thread_workspace(void);
 struct mlx5_flow_workspace *mlx5_flow_get_thread_workspace(void);
-void mlx5_flow_workspace_gc_release(void);
 
 __extension__
 struct flow_grp_info {
diff --git a/drivers/net/mlx5/windows/mlx5_flow_os.c b/drivers/net/mlx5/windows/mlx5_flow_os.c
index 5013e9f012..f907b21ecc 100644
--- a/drivers/net/mlx5/windows/mlx5_flow_os.c
+++ b/drivers/net/mlx5/windows/mlx5_flow_os.c
@@ -417,6 +417,12 @@ mlx5_flow_os_set_specific_workspace(struct mlx5_flow_workspace *data)
 	return err;
 }
 
+void
+mlx5_flow_os_workspace_gc_add(struct mlx5_flow_workspace *ws)
+{
+	RTE_SET_USED(ws);
+}
+
 int
 mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
 			    uint64_t item_flags,
diff --git a/drivers/net/mlx5/windows/mlx5_flow_os.h b/drivers/net/mlx5/windows/mlx5_flow_os.h
index 1c1c17fc41..856d8ba948 100644
--- a/drivers/net/mlx5/windows/mlx5_flow_os.h
+++ b/drivers/net/mlx5/windows/mlx5_flow_os.h
@@ -473,4 +473,12 @@ mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
 			    uint8_t target_protocol,
 			    struct rte_flow_error *error);
 
+/**
+ * Add per thread workspace to the global list for garbage collection.
+ *
+ * @param[in] ws
+ *   Pointer to the flow workspace.
+ */
+void mlx5_flow_os_workspace_gc_add(struct mlx5_flow_workspace *ws);
+
 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */
-- 
2.25.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-12-11 17:56:24.828112800 +0800
+++ 0052-net-mlx5-fix-flow-workspace-double-free-in-Windows.patch	2023-12-11 17:56:23.037652300 +0800
@@ -1 +1 @@
-From 2ece3b7186b9d22209ac1845f794b91185575a23 Mon Sep 17 00:00:00 2001
+From 72ab4bf42fac40554a582226ffbb56b02746147f Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit 2ece3b7186b9d22209ac1845f794b91185575a23 ]
@@ -21 +23,0 @@
-Cc: stable at dpdk.org
@@ -101 +103 @@
-index 472e830eb0..66b0d1a005 100644
+index f787ae91fe..1dfd10e7cb 100644
@@ -104 +106 @@
-@@ -1926,7 +1926,6 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
+@@ -1743,7 +1743,6 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
@@ -113 +115 @@
-index 2d718bbe33..eb6037326f 100644
+index ea0a49827f..01b463adec 100644
@@ -116 +118 @@
-@@ -8184,29 +8184,6 @@ flow_release_workspace(void *data)
+@@ -7544,29 +7544,6 @@ flow_release_workspace(void *data)
@@ -146 +148 @@
-@@ -8263,7 +8240,7 @@ mlx5_flow_push_thread_workspace(void)
+@@ -7623,7 +7600,7 @@ mlx5_flow_push_thread_workspace(void)
@@ -156 +158 @@
-index a58866b814..f98bc74c9c 100644
+index 9724b88996..52edc4c961 100644
@@ -159 +161 @@
-@@ -2162,7 +2162,6 @@ struct mlx5_flow_driver_ops {
+@@ -1926,7 +1926,6 @@ struct mlx5_flow_driver_ops {


More information about the stable mailing list