[v2,2/2] net/mlx5: fix modify flex item error

Message ID 20240223032155.182162-3-rongweil@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Series Fix modify flex item error |


Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build fail github build: failed
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Rongwei Liu Feb. 23, 2024, 3:21 a.m. UTC
  In the rte_flow_field_data structure, the flex item handle is part
of union with other members like level/tag_index.

If the user wants to modify the flex item as source or destination,
there should not be any checking against zero.

Signed-off-by: Rongwei Liu <rongweil@nvidia.com>
Fixes: c23626f27b09 ("ethdev: add MPLS header modification")
Cc: michaelba@nvidia.com
Cc: stable@dpdk.org
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
 drivers/net/mlx5/mlx5_flow.c    | 2 +-
 drivers/net/mlx5/mlx5_flow_hw.c | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 2b2ae62618..d8ed1ed6f6 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -2384,7 +2384,7 @@  int
 flow_validate_modify_field_level(const struct rte_flow_field_data *data,
 				 struct rte_flow_error *error)
-	if (data->level == 0)
+	if (data->level == 0 || data->field == RTE_FLOW_FIELD_FLEX_ITEM)
 		return 0;
 	if (data->field != RTE_FLOW_FIELD_TAG &&
 	    data->field != (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG)
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index bcf43f5457..5b269b9c82 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -5036,7 +5036,8 @@  flow_hw_validate_action_modify_field(struct rte_eth_dev *dev,
 	ret = flow_validate_modify_field_level(&action_conf->dst, error);
 	if (ret)
 		return ret;
-	if (!flow_hw_modify_field_is_geneve_opt(action_conf->dst.field)) {
+	if (action_conf->dst.field != RTE_FLOW_FIELD_FLEX_ITEM &&
+	    !flow_hw_modify_field_is_geneve_opt(action_conf->dst.field)) {
 		if (action_conf->dst.tag_index &&
 			return rte_flow_error_set(error, EINVAL,
@@ -5061,7 +5062,8 @@  flow_hw_validate_action_modify_field(struct rte_eth_dev *dev,
 				"destination field mask and template are not equal");
 	if (action_conf->src.field != RTE_FLOW_FIELD_POINTER &&
 	    action_conf->src.field != RTE_FLOW_FIELD_VALUE) {
-		if (!flow_hw_modify_field_is_geneve_opt(action_conf->src.field)) {
+		if (action_conf->src.field != RTE_FLOW_FIELD_FLEX_ITEM &&
+		    !flow_hw_modify_field_is_geneve_opt(action_conf->src.field)) {
 			if (action_conf->src.tag_index &&
 				return rte_flow_error_set(error, EINVAL,