Skip to contentSkip to conversation

net/mlx5: flow counter pool fixes

PATCH In review Dariusz Sosnowski 2 participants 4 messages Apr 25, 2025 – May 12, 2025 Network drivers

lore
Share & tools
lore
#0 lore raw

cover net/mlx5: flow counter pool fixes

This patch series includes several fixes for flow counter pool used with HW Steering flow engine.

Dariusz Sosnowski (2):
net/mlx5: fix counter pool init error propagation net/mlx5: fix counter service thread init

 drivers/net/mlx5/mlx5_hws_cnt.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

--
2.39.5

#1 lore raw

PATCH 1/2 net/mlx5: fix counter pool init error propagation

In case of an error in mlx5_hws_cnt_pool_create(), value stored in ret is used as "error code".
There are however a few cases inside this function, when this variable is not set, leading to failed assertions (e.g., when requested number of counters is bigger than maximum supported).

This patch addresses these cases, by propagating the rte_errno set by failing functions.

Fixes e1c83d295dd9 ("net/mlx5: support ASO actions with non-template flow")
---
 drivers/net/mlx5/mlx5_hws_cnt.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +13 -4
index 7b5e7310af..fd12bcd7ec 100644
@@ -704,8 +704,11 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
 	size_t sz;
 
 	mp_name = mlx5_malloc(MLX5_MEM_ZERO, RTE_MEMZONE_NAMESIZE, 0, SOCKET_ID_ANY);
-	if (mp_name == NULL)
+	if (mp_name == NULL) {
+		ret = rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					 "failed to allocate counter pool name prefix");
 		goto error;
+	}
 	snprintf(mp_name, RTE_MEMZONE_NAMESIZE, "MLX5_HWS_CNT_P_%x", dev->data->port_id);
 	pcfg.name = mp_name;
 	pcfg.request_num = nb_counters;
@@ -713,8 +716,10 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
 	if (chost) {
 		pcfg.host_cpool = chost;
 		cpool = mlx5_hws_cnt_pool_init(priv->sh, &pcfg, &cparam, error);
-		if (cpool == NULL)
+		if (cpool == NULL) {
+			ret = -rte_errno;
 			goto error;
+		}
 		ret = mlx5_hws_cnt_pool_action_create(priv, cpool);
 		if (ret != 0) {
 			rte_flow_error_set(error, -ret,
@@ -736,15 +741,19 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
 	cparam.threshold = HWS_CNT_CACHE_THRESHOLD_DEFAULT;
 	cparam.size = HWS_CNT_CACHE_SZ_DEFAULT;
 	cpool = mlx5_hws_cnt_pool_init(priv->sh, &pcfg, &cparam, error);
-	if (cpool == NULL)
+	if (cpool == NULL) {
+		ret = -rte_errno;
 		goto error;
+	}
 	ret = mlx5_hws_cnt_pool_dcs_alloc(priv->sh, cpool, error);
 	if (ret != 0)
 		goto error;
 	sz = RTE_ALIGN_CEIL(mlx5_hws_cnt_pool_get_size(cpool), 4);
 	cpool->raw_mng = mlx5_hws_cnt_raw_data_alloc(priv->sh, sz, error);
-	if (cpool->raw_mng == NULL)
+	if (cpool->raw_mng == NULL) {
+		ret = -rte_errno;
 		goto error;
+	}
 	__hws_cnt_id_load(cpool);
 	/*
 	 * Bump query gen right after pool create so the
Signature · 1 line
2.39.5
#2 lore raw

PATCH 2/2 net/mlx5: fix counter service thread init

In reply to Dariusz Sosnowski

During counter pool initialization (mlx5_hws_cnt_pool_create()), a background service thread is started by mlx5 PMD, which refreshes counter values periodically.

During initialization it might happen that:

- background thread creation succeeds,
- pool creation fails (e.g. due to error in configuration provided by the user).

In this case, the procedure on error rollback will not clean up counter service thread, because rollback assumes that is there is no pool, then there is nothing to clean up.

This patch fixes that, by moving background thread creation to the end of counter pool initialization.
This ensures proper order of resource release during rollback. Also, this patch adds missing "goto error" in case of failure to initialize the service thread.

Fixes 4d368e1da3a4 ("net/mlx5: support flow counter action for HWS")
---
 drivers/net/mlx5/mlx5_hws_cnt.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/mlx5/mlx5_hws_cnt.c +6 -6
index fd12bcd7ec..5c7c0041aa 100644
@@ -729,12 +729,6 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
 		}
 		goto success;
 	}
-	/* init cnt service if not. */
-	if (priv->sh->cnt_svc == NULL) {
-		ret = mlx5_hws_cnt_svc_init(priv->sh, error);
-		if (ret)
-			goto error;
-	}
 	cparam.fetch_sz = HWS_CNT_CACHE_FETCH_DEFAULT;
 	cparam.preload_sz = HWS_CNT_CACHE_PRELOAD_DEFAULT;
 	cparam.q_num = nb_queue;
@@ -769,6 +763,12 @@ mlx5_hws_cnt_pool_create(struct rte_eth_dev *dev,
 				   NULL, "failed to allocate counter actions");
 		goto error;
 	}
+	/* init cnt service if not. */
+	if (priv->sh->cnt_svc == NULL) {
+		ret = mlx5_hws_cnt_svc_init(priv->sh, error);
+		if (ret)
+			goto error;
+	}
 	priv->sh->cnt_svc->refcnt++;
 	cpool->priv = priv;
 	rte_spinlock_lock(&priv->sh->cpool_lock);
Signature · 1 line
2.39.5
#3 lore raw
In reply to Dariusz Sosnowski

Hi,

Quoted 7 lines · Dariusz Sosnowski

This patch series includes several fixes for flow counter pool used with HW Steering flow engine.

Dariusz Sosnowski (2):
net/mlx5: fix counter pool init error propagation net/mlx5: fix counter service thread init

Quoted 6 lines
  drivers/net/mlx5/mlx5_hws_cnt.c | 29 +++++++++++++++++++----------
  1 file changed, 19 insertions(+), 10 deletions(-)

--
2.39.5

Series applied to next-net-mlx,

Signature · 2 lines
Kindest regards
Raslan Darawsheh