[dpdk-dev] [PATCH v1 1/2] net/mlx5: fix meter flow counter traslation

Shun Hao shunh at nvidia.com
Wed Aug 4 09:26:46 CEST 2021


When an RTE flow uses a meter without any modify packet action,
there will be an internal drop flow with meter counter created,
matching the same 5-tuple as the original flow.

In this case, the meter flow count action is wrongly reused as the
original flow counter, leading to wrong flow statistics.

Add a check in the count action translation to detect the meter case
and use the meter drop dedicated counter in the meter 5-tuple flow
only.

Fixes: f3191849f2c2 ("net/mlx5: support flow count action handle")
Cc: stable at dpdk.org

Signed-off-by: Shun Hao <shunh at nvidia.com>
Acked-by: Matan Azrad <matan at nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_dv.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 4644ae46bd..f54440c6f5 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -12824,13 +12824,26 @@ flow_dv_translate(struct rte_eth_dev *dev,
 			action_flags |= MLX5_FLOW_ACTION_AGE;
 			break;
 		case MLX5_RTE_FLOW_ACTION_TYPE_COUNT:
-			flow->counter = (uint32_t)(uintptr_t)(action->conf);
-			cnt_act = flow_dv_counter_get_by_idx(dev, flow->counter,
-							     NULL);
-			__atomic_fetch_add(&cnt_act->shared_info.refcnt, 1,
-					   __ATOMIC_RELAXED);
-			/* Save information first, will apply later. */
-			action_flags |= MLX5_FLOW_ACTION_COUNT;
+			cnt_act = flow_dv_counter_get_by_idx(dev,
+					(uint32_t)(uintptr_t)action->conf,
+					NULL);
+			MLX5_ASSERT(cnt_act != NULL);
+			/**
+			 * When creating meter drop flow in drop table, the
+			 * counter should not overwrite the rte flow counter.
+			 */
+			if (attr->group == MLX5_FLOW_TABLE_LEVEL_METER &&
+			    dev_flow->dv.table_id == MLX5_MTR_TABLE_ID_DROP) {
+				dev_flow->dv.actions[actions_n++] =
+							cnt_act->action;
+			} else {
+				flow->counter =
+					(uint32_t)(uintptr_t)(action->conf);
+				__atomic_fetch_add(&cnt_act->shared_info.refcnt,
+						1, __ATOMIC_RELAXED);
+				/* Save information first, will apply later. */
+				action_flags |= MLX5_FLOW_ACTION_COUNT;
+			}
 			break;
 		case RTE_FLOW_ACTION_TYPE_COUNT:
 			if (!dev_conf->devx) {
-- 
2.20.0



More information about the dev mailing list