From 57461cab161ac2c8cc1a96711efba9a8fa519358 Mon Sep 17 00:00:00 2001 From: Michael Baum Date: Mon, 28 Feb 2022 09:09:54 +0200 Subject: [PATCH] net/mlx5: fix check in count action validation The AGE action can be implemented by either counters or ASO mechanism. ASO is more efficient than generating counters just for the purpose of aging, so when ASO is supported its use is preferable. On the other hand, when there is count in the list of actions, the counter is already generated, and it is best to use it for aging even if ASO is supported. On the other hand, when the count action is "indirect", it cannot be used for aging since it may be updated from other flow rules in which it participates. Checking whether ASO is supported depends on both the capability of the device and the flow rule group number, ASO is not supported for group 0. However, the flow_dv_validate() function only checks the capability and ignores the group, allowing inadmissible flow rules. For example, when the device supports ASO and a flow rule is set that combines an indirect counter with aging for group 0, the rule should be rejected, but it is created and does not function properly. This patch updates the counter validation which will also consider the group number when deciding if there is ASO support. Fixes: daed4b6e3db2 ("net/mlx5: use aging by counter when counter exists") Cc: stable@dpdk.org Signed-off-by: Michael Baum Acked-by: Matan Azrad --- drivers/net/mlx5/mlx5_flow_dv.c | 41 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 20e0af29c8..0b9df5f6f1 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -3277,6 +3277,25 @@ flow_dv_validate_action_set_tag(struct rte_eth_dev *dev, return 0; } +/** + * Indicates whether ASO aging is supported. + * + * @param[in] sh + * Pointer to shared device context structure. + * @param[in] attr + * Attributes of flow that includes AGE action. + * + * @return + * True when ASO aging is supported, false otherwise. + */ +static inline bool +flow_hit_aso_supported(const struct mlx5_dev_ctx_shared *sh, + const struct rte_flow_attr *attr) +{ + MLX5_ASSERT(sh && attr); + return (sh->flow_hit_aso_en && (attr->transfer || attr->group)); +} + /** * Validate count action. * @@ -3286,6 +3305,8 @@ flow_dv_validate_action_set_tag(struct rte_eth_dev *dev, * Indicator if action is shared. * @param[in] action_flags * Holds the actions detected until now. + * @param[in] attr + * Attributes of flow that includes this action. * @param[out] error * Pointer to error structure. * @@ -3295,6 +3316,7 @@ flow_dv_validate_action_set_tag(struct rte_eth_dev *dev, static int flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared, uint64_t action_flags, + const struct rte_flow_attr *attr, struct rte_flow_error *error) { struct mlx5_priv *priv = dev->data->dev_private; @@ -3306,10 +3328,10 @@ flow_dv_validate_action_count(struct rte_eth_dev *dev, bool shared, RTE_FLOW_ERROR_TYPE_ACTION, NULL, "duplicate count actions set"); if (shared && (action_flags & MLX5_FLOW_ACTION_AGE) && - !priv->sh->flow_hit_aso_en) + !flow_hit_aso_supported(priv->sh, attr)) return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL, - "old age and shared count combination is not supported"); + "old age and indirect count combination is not supported"); #ifdef HAVE_IBV_FLOW_DEVX_COUNTERS return 0; #endif @@ -5679,7 +5701,7 @@ flow_dv_validate_action_sample(uint64_t *action_flags, case RTE_FLOW_ACTION_TYPE_COUNT: ret = flow_dv_validate_action_count (dev, false, *action_flags | sub_action_flags, - error); + attr, error); if (ret < 0) return ret; *count = act->conf; @@ -7441,7 +7463,7 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, case RTE_FLOW_ACTION_TYPE_COUNT: ret = flow_dv_validate_action_count(dev, shared_count, action_flags, - error); + attr, error); if (ret < 0) return ret; action_flags |= MLX5_FLOW_ACTION_COUNT; @@ -7756,15 +7778,15 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, return ret; /* * Validate the regular AGE action (using counter) - * mutual exclusion with share counter actions. + * mutual exclusion with indirect counter actions. */ - if (!priv->sh->flow_hit_aso_en) { + if (!flow_hit_aso_supported(priv->sh, attr)) { if (shared_count) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL, - "old age and shared count combination is not supported"); + "old age and indirect count combination is not supported"); if (sample_count) return rte_flow_error_set (error, EINVAL, @@ -13416,8 +13438,7 @@ flow_dv_translate(struct rte_eth_dev *dev, */ if (action_flags & MLX5_FLOW_ACTION_AGE) { if ((non_shared_age && count) || - !(priv->sh->flow_hit_aso_en && - (attr->group || attr->transfer))) { + !flow_hit_aso_supported(priv->sh, attr)) { /* Creates age by counters. */ cnt_act = flow_dv_prepare_counter (dev, dev_flow, @@ -17710,7 +17731,7 @@ flow_dv_action_validate(struct rte_eth_dev *dev, "Indirect age action not supported"); return flow_dv_validate_action_age(0, action, dev, err); case RTE_FLOW_ACTION_TYPE_COUNT: - return flow_dv_validate_action_count(dev, true, 0, err); + return flow_dv_validate_action_count(dev, true, 0, NULL, err); case RTE_FLOW_ACTION_TYPE_CONNTRACK: if (!priv->sh->ct_aso_en) return rte_flow_error_set(err, ENOTSUP, -- 2.20.1