In RTE flow, if a counter action is before a meter which has
non-termination policy, the counter value only includes packets not
being dropped.

This patch fixes this issue by differentiating the order of counter and
non-termination meter:
1. counter + meter, counts all packets hitting this flow.
2. meter + counter, only counts packets not being dropped.

Fixes: 51ec04dc7bcf ("net/mlx5: connect meter policy to created flows")
Cc: sta...@dpdk.org

Signed-off-by: Shun Hao <sh...@nvidia.com>
Acked-by: Matan Azrad <ma...@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 78cb38d42b..28afdfe011 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -5271,6 +5271,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
        uint32_t flow_id = 0;
        uint32_t flow_id_reversed = 0;
        uint8_t flow_id_bits = 0;
+       bool after_meter = false;
        int shift;
 
        /* Prepare the suffix subflow items. */
@@ -5337,6 +5338,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
                                tag_action = actions_pre++;
                                action_cur = actions_pre++;
                        }
+                       after_meter = true;
                        break;
                case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
                case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
@@ -5365,6 +5367,11 @@ flow_meter_split_prep(struct rte_eth_dev *dev,
                                                MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
                        }
                        break;
+               case RTE_FLOW_ACTION_TYPE_COUNT:
+                       if (fm->def_policy)
+                               action_cur = after_meter ?
+                                               actions_sfx++ : actions_pre++;
+                       break;
                default:
                        break;
                }
@@ -6393,8 +6400,10 @@ flow_create_split_meter(struct rte_eth_dev *dev,
                if (!fm->def_policy && !is_mtr_hierarchy &&
                    (!has_modify || !fm->drop_cnt))
                        set_mtr_reg = false;
-               /* Prefix actions: meter, decap, encap, tag, jump, end. */
-               act_size = sizeof(struct rte_flow_action) * (actions_n + 6) +
+               /* Prefix actions: meter, decap, encap, tag, jump, end, cnt. */
+#define METER_PREFIX_ACTION 7
+               act_size = (sizeof(struct rte_flow_action) *
+                           (actions_n + METER_PREFIX_ACTION)) +
                           sizeof(struct mlx5_rte_flow_action_set_tag);
                /* Suffix items: tag, vlan, port id, end. */
 #define METER_SUFFIX_ITEM 4
-- 
2.20.0

Reply via email to