net/mlx5: fix the implicit tag insertion in sample flow

Message ID 20220310040010.12454-1-jiaweiw@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: fix the implicit tag insertion in sample flow |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Jiawei Wang March 10, 2022, 4 a.m. UTC
  The flow with sample action was split into two sub-flows,
and the implicit tag action with unique id was added in the prefix
sub-flow, the suffix sub-flow used the tag item to match with that
unique id, and the implicit set tag action was inserted next to
the sample action.

While there's either PUSH VLAN action or ENCAP action preceding the
sample action, implicit set tag action was added after PUSH VLAN or
ENCAP actions, causing flow creation failure due to rdma-core
does not support this action order.

This patch ensures the implicit set tag action is inserted before
either PUSH VLAN or encap action (if any) in the prefix sub-flow.

Fixes: 6a951567c159 ("net/mlx5: support E-Switch mirroring and jump in one flow")
Cc: stable@dpdk.org

Signed-off-by: Jiawei Wang <jiaweiw@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.c | 63 ++++++++++++++++++++++++++++++++++--
 1 file changed, 61 insertions(+), 2 deletions(-)
  

Comments

Raslan Darawsheh March 10, 2022, 3:39 p.m. UTC | #1
Hi,

> -----Original Message-----
> From: Jiawei(Jonny) Wang <jiaweiw@nvidia.com>
> Sent: Thursday, March 10, 2022 6:00 AM
> To: Slava Ovsiienko <viacheslavo@nvidia.com>; Matan Azrad
> <matan@nvidia.com>; Ori Kam <orika@nvidia.com>
> Cc: dev@dpdk.org; Raslan Darawsheh <rasland@nvidia.com>;
> stable@dpdk.org
> Subject: [PATCH] net/mlx5: fix the implicit tag insertion in sample flow
> 
> The flow with sample action was split into two sub-flows,
> and the implicit tag action with unique id was added in the prefix
> sub-flow, the suffix sub-flow used the tag item to match with that
> unique id, and the implicit set tag action was inserted next to
> the sample action.
> 
> While there's either PUSH VLAN action or ENCAP action preceding the
> sample action, implicit set tag action was added after PUSH VLAN or
> ENCAP actions, causing flow creation failure due to rdma-core
> does not support this action order.
> 
> This patch ensures the implicit set tag action is inserted before
> either PUSH VLAN or encap action (if any) in the prefix sub-flow.
> 
> Fixes: 6a951567c159 ("net/mlx5: support E-Switch mirroring and jump in one
> flow")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jiawei Wang <jiaweiw@nvidia.com>
> Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index a690e2d337..d26454a1b1 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -5831,8 +5831,9 @@  flow_sample_split_prep(struct rte_eth_dev *dev,
 	struct mlx5_rte_flow_item_tag *tag_mask;
 	struct rte_flow_action_jump *jump_action;
 	uint32_t tag_id = 0;
-	int index;
 	int append_index = 0;
+	int set_tag_idx = -1;
+	int index;
 	int ret;
 
 	if (sample_action_pos < 0)
@@ -5841,6 +5842,52 @@  flow_sample_split_prep(struct rte_eth_dev *dev,
 					  NULL, "invalid position of sample "
 					  "action in list");
 	/* Prepare the actions for prefix and suffix flow. */
+	if (add_tag) {
+		/* Update the new added tag action index preceding
+		 * the PUSH_VLAN or ENCAP action.
+		 */
+		const struct rte_flow_action_raw_encap *raw_encap;
+		const struct rte_flow_action *action = actions;
+		int encap_idx;
+		int action_idx = 0;
+		int raw_decap_idx = -1;
+		int push_vlan_idx = -1;
+		for (; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
+			switch (action->type) {
+			case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
+				raw_decap_idx = action_idx;
+				break;
+			case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
+				raw_encap = action->conf;
+				if (raw_encap->size >
+					MLX5_ENCAPSULATION_DECISION_SIZE) {
+					encap_idx = raw_decap_idx != -1 ?
+						    raw_decap_idx : action_idx;
+					if (encap_idx < sample_action_pos &&
+					    push_vlan_idx == -1)
+						set_tag_idx = encap_idx;
+				}
+				break;
+			case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+			case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
+				encap_idx = action_idx;
+				if (encap_idx < sample_action_pos &&
+				    push_vlan_idx == -1)
+					set_tag_idx = encap_idx;
+				break;
+			case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
+			case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
+				push_vlan_idx = action_idx;
+				if (push_vlan_idx < sample_action_pos)
+					set_tag_idx = action_idx;
+				break;
+			default:
+				break;
+			}
+			action_idx++;
+		}
+	}
+	/* Prepare the actions for prefix and suffix flow. */
 	if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
 		index = qrss_action_pos;
 		/* Put the preceding the Queue/RSS action into prefix flow. */
@@ -5857,6 +5904,14 @@  flow_sample_split_prep(struct rte_eth_dev *dev,
 		memcpy(actions_sfx, actions + qrss_action_pos,
 		       sizeof(struct rte_flow_action));
 		actions_sfx++;
+	} else if (add_tag && set_tag_idx >= 0) {
+		if (set_tag_idx > 0)
+			memcpy(actions_pre, actions,
+			       sizeof(struct rte_flow_action) * set_tag_idx);
+		memcpy(actions_pre + set_tag_idx + 1, actions + set_tag_idx,
+		       sizeof(struct rte_flow_action) *
+		       (sample_action_pos - set_tag_idx));
+		index = sample_action_pos;
 	} else {
 		index = sample_action_pos;
 		if (index != 0)
@@ -5898,13 +5953,17 @@  flow_sample_split_prep(struct rte_eth_dev *dev,
 				RTE_FLOW_ITEM_TYPE_END,
 		};
 		/* Prepare the tag action in prefix subflow. */
-		actions_pre[index++] =
+		set_tag_idx = (set_tag_idx == -1) ? index : set_tag_idx;
+		actions_pre[set_tag_idx] =
 			(struct rte_flow_action){
 			.type = (enum rte_flow_action_type)
 				MLX5_RTE_FLOW_ACTION_TYPE_TAG,
 			.conf = set_tag,
 		};
+		/* Update next sample position due to add one tag action */
+		index += 1;
 	}
+	/* Copy the sample action into prefix flow. */
 	memcpy(actions_pre + index, actions + sample_action_pos,
 	       sizeof(struct rte_flow_action));
 	index += 1;