net/mlx5: fix meter flow counter translation
authorShun Hao <shunh@nvidia.com>
Wed, 4 Aug 2021 07:26:46 +0000 (10:26 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 4 Aug 2021 09:24:21 +0000 (11:24 +0200)
When a flow rule 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@dpdk.org
Signed-off-by: Shun Hao <shunh@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/net/mlx5/mlx5_flow_dv.c

index 4644ae4..f54440c 100644 (file)
@@ -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) {