Duplicated tag index in pattern template will most likely cause matching failures such as "template tag index is 0 data mask 0xff / tag index is 0 data mask 0xffff / end"
If the upper layer application needs to match the same tag twice with different masks, it should be consolidated into one rte_item with the desired mask. "template tag index is 0 data mask 0xff / tag index is 0 data mask 0xff00 / end" should be present as "template tag index is 0 data mask 0xffff / end" Cc: sta...@dpdk.org Signed-off-by: Rongwei Liu <rongw...@nvidia.com> Acked-by: Viacheslav Ovsiienko <viachesl...@nvidia.com> --- drivers/net/mlx5/mlx5_flow_hw.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index 7e0ee8d883..78011584eb 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -4831,8 +4831,9 @@ flow_hw_pattern_validate(struct rte_eth_dev *dev, struct rte_flow_error *error) { struct mlx5_priv *priv = dev->data->dev_private; - int i; + int i, tag_idx; bool items_end = false; + uint32_t tag_bitmap = 0; if (!attr->ingress && !attr->egress && !attr->transfer) return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR, NULL, @@ -4874,16 +4875,26 @@ flow_hw_pattern_validate(struct rte_eth_dev *dev, switch (type) { case RTE_FLOW_ITEM_TYPE_TAG: { - int reg; const struct rte_flow_item_tag *tag = (const struct rte_flow_item_tag *)items[i].spec; - reg = flow_hw_get_reg_id(RTE_FLOW_ITEM_TYPE_TAG, tag->index); - if (reg == REG_NON) + if (tag == NULL) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "Tag spec is NULL"); + tag_idx = flow_hw_get_reg_id(RTE_FLOW_ITEM_TYPE_TAG, tag->index); + if (tag_idx == REG_NON) return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "Unsupported tag index"); + if (tag_bitmap & (1 << tag_idx)) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ITEM, + NULL, + "Duplicated tag index"); + tag_bitmap |= 1 << tag_idx; break; } case MLX5_RTE_FLOW_ITEM_TYPE_TAG: @@ -4897,6 +4908,12 @@ flow_hw_pattern_validate(struct rte_eth_dev *dev, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "Unsupported internal tag index"); + if (tag_bitmap & (1 << tag->index)) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ITEM, + NULL, + "Duplicated tag index"); + tag_bitmap |= 1 << tag->index; break; } case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT: -- 2.27.0