Skip to contentSkip to conversation

net/mlx5/hws: fix bug in pattern creation

PATCH New Erez Shitrit 1 participant 4 messages Mar 20, 2023 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5/hws: fix bug in pattern creation

When creating a new pattern the data area should be clean, otherwise when the data will come from the arg object it will do OR operation on the data part in the pattern.

Fixes f8c8a6d8440d ("net/mlx5/hws: add action object")
---
 drivers/net/mlx5/hws/mlx5dr_cmd.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/net/mlx5/hws/mlx5dr_cmd.c +14 -2
index a444fb4438..0adcedd9c9 100644
@@ -523,9 +523,11 @@ mlx5dr_cmd_header_modify_pattern_create(struct ibv_context *ctx,
 	uint32_t in[MLX5_ST_SZ_DW(create_header_modify_pattern_in)] = {0};
 	uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
 	struct mlx5dr_devx_obj *devx_obj;
-	void *pattern_data;
+	uint64_t *pattern_data;
+	int num_of_actions;
 	void *pattern;
 	void *attr;
+	int i;
 
 	if (pattern_length > MAX_ACTIONS_DATA_IN_HEADER_MODIFY) {
 		DR_LOG(ERR, "Pattern length %d exceeds limit %d",
@@ -551,9 +553,19 @@ mlx5dr_cmd_header_modify_pattern_create(struct ibv_context *ctx,
 	/* Pattern_length is in ddwords */
 	MLX5_SET(header_modify_pattern_in, pattern, pattern_length, pattern_length / (2 * DW_SIZE));
 
-	pattern_data = MLX5_ADDR_OF(header_modify_pattern_in, pattern, pattern_data);
+	pattern_data = (uint64_t *)MLX5_ADDR_OF(header_modify_pattern_in, pattern, pattern_data);
 	memcpy(pattern_data, actions, pattern_length);
 
+	num_of_actions = pattern_length / MLX5DR_MODIFY_ACTION_SIZE;
+	for (i = 0; i < num_of_actions; i++) {
+		int type;
+
+		type = MLX5_GET(set_action_in, &pattern_data[i], action_type);
+		if (type != MLX5_MODIFICATION_TYPE_COPY)
+			/* Action typ-copy use all bytes for control */
+			MLX5_SET(set_action_in, &pattern_data[i], data, 0);
+	}
+
 	devx_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out, sizeof(out));
 	if (!devx_obj->obj) {
 		DR_LOG(ERR, "Failed to create header_modify_pattern");
Signature · 1 line
2.18.2
#1 lore raw

PATCH 1/1 net/mlx5/hws: shared context uses defaults from local context

Fix default miss behavior for shared resources, the problem could happen in two cases:
When the table created, the default miss should go to the alias ft that will direct it back to local context.

When the rule is without specific hit address and we are in a shared RTC from here it should be redirected back to the local context.

Fixes ce946c7d3999 ("net/mlx5/hws: support ibv context shared with local one")
---
 drivers/net/mlx5/hws/mlx5dr_action.c |  9 ++++++++-
 drivers/net/mlx5/hws/mlx5dr_table.c  | 29 ++++++++++++++++++++++------
 2 files changed, 31 insertions(+), 7 deletions(-)
drivers/net/mlx5/hws/mlx5dr_action.c +8 -1
index 2db62635c1..77cf1f5132 100644
@@ -1751,8 +1751,15 @@ int mlx5dr_action_get_default_stc(struct mlx5dr_context *ctx,
 		goto free_nop_dw6;
 	}
 
-	stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
 	stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
+	if (!mlx5dr_context_shared_gvmi_used(ctx)) {
+		stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
+	} else {
+		/* On shared gvmi the default hit behavior is jump to alias end ft */
+		stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
+		stc_attr.dest_table_id = ctx->gvmi_res[tbl_type].aliased_end_ft->id;
+	}
+
 	ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
 					     &default_stc->default_hit);
 	if (ret) {
drivers/net/mlx5/hws/mlx5dr_table.c +23 -6
index 327e2ec710..0e5e9b49ab 100644
@@ -272,6 +272,9 @@ static void mlx5dr_table_uninit_shared_ctx_res(struct mlx5dr_table *tbl)
 /* called under spin_lock ctx->ctrl_lock */
 static int mlx5dr_table_init_shared_ctx_res(struct mlx5dr_context *ctx, struct mlx5dr_table *tbl)
 {
+	struct mlx5dr_cmd_ft_modify_attr ft_attr = {0};
+	int ret;
+
 	if (!mlx5dr_context_shared_gvmi_used(ctx))
 		return 0;
 
@@ -288,8 +291,22 @@ static int mlx5dr_table_init_shared_ctx_res(struct mlx5dr_context *ctx, struct m
 		goto clean_local_ft;
 	}
 
+	/* On shared gvmi the default behavior is jump to alias end ft */
+	mlx5dr_cmd_set_attr_connect_miss_tbl(tbl->ctx,
+					     tbl->fw_ft_type,
+					     tbl->type,
+					     &ft_attr);
+
+	ret = mlx5dr_cmd_flow_table_modify(tbl->ft, &ft_attr);
+	if (ret) {
+		DR_LOG(ERR, "Failed to point table to its default miss");
+		goto clean_shared_res;
+	}
+
 	return 0;
 
+clean_shared_res:
+	mlx5dr_table_put_shared_gvmi_res(tbl);
 clean_local_ft:
 	mlx5dr_table_destroy_default_ft(tbl, tbl->local_ft);
 	return rte_errno;
@@ -337,20 +354,20 @@ static int mlx5dr_table_init(struct mlx5dr_table *tbl)
 		return rte_errno;
 	}
 
-	ret = mlx5dr_action_get_default_stc(ctx, tbl->type);
+	ret = mlx5dr_table_init_shared_ctx_res(ctx, tbl);
 	if (ret)
 		goto tbl_destroy;
 
-	ret = mlx5dr_table_init_shared_ctx_res(ctx, tbl);
+	ret = mlx5dr_action_get_default_stc(ctx, tbl->type);
 	if (ret)
-		goto put_stc;
+		goto free_shared_ctx;
 
 	pthread_spin_unlock(&ctx->ctrl_lock);
 
 	return 0;
 
-put_stc:
-	mlx5dr_action_put_default_stc(ctx, tbl->type);
+free_shared_ctx:
+	mlx5dr_table_uninit_shared_ctx_res(tbl);
 tbl_destroy:
 	mlx5dr_table_destroy_default_ft(tbl, tbl->ft);
 	pthread_spin_unlock(&ctx->ctrl_lock);
@@ -363,8 +380,8 @@ static void mlx5dr_table_uninit(struct mlx5dr_table *tbl)
 		return;
 	pthread_spin_lock(&tbl->ctx->ctrl_lock);
 	mlx5dr_action_put_default_stc(tbl->ctx, tbl->type);
-	mlx5dr_table_destroy_default_ft(tbl, tbl->ft);
 	mlx5dr_table_uninit_shared_ctx_res(tbl);
+	mlx5dr_table_destroy_default_ft(tbl, tbl->ft);
 	pthread_spin_unlock(&tbl->ctx->ctrl_lock);
 }
 
Signature · 1 line
2.18.2
#2 lore raw

PATCH 1/1 net/mlx5/hws: keep all jumbo tag for deletion

In reply to Erez Shitrit

In cases with more than one STE we didn't update the whole tag of the match jumbo STE, the ste_attr that keeps that indication was not updated at the last iteration.
Now we indicate it is a jumbo frame before saving the tag for coming deletion of it.

Fixes 405242c52dd5 ("net/mlx5/hws: add rule object")
---
 drivers/net/mlx5/hws/mlx5dr_rule.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mlx5/hws/mlx5dr_rule.c +4 -1
index 9d5e5b11a5..2418ca0b26 100644
@@ -116,6 +116,9 @@ static void
 mlx5dr_rule_save_delete_info(struct mlx5dr_rule *rule,
 			     struct mlx5dr_send_ste_attr *ste_attr)
 {
+	struct mlx5dr_match_template *mt = rule->matcher->mt;
+	bool is_jumbo = mlx5dr_matcher_mt_is_jumbo(mt);
+
 	if (unlikely(mlx5dr_matcher_req_fw_wqe(rule->matcher))) {
 		uint8_t *src_tag;
 
@@ -136,7 +139,7 @@ mlx5dr_rule_save_delete_info(struct mlx5dr_rule *rule,
 		return;
 	}
 
-	if (ste_attr->wqe_tag_is_jumbo)
+	if (is_jumbo)
 		memcpy(rule->tag.jumbo, ste_attr->wqe_data->jumbo, MLX5DR_JUMBO_TAG_SZ);
 	else
 		memcpy(rule->tag.match, ste_attr->wqe_data->tag, MLX5DR_MATCH_TAG_SZ);
Signature · 1 line
2.18.2
#3 lore raw

PATCH 1/1 net/mlx5/hws: add check for modify-header actions

In reply to Erez Shitrit

Allow only actions that are currently supported.

Fixes f8c8a6d8440d ("net/mlx5/hws: add action object")
---
 drivers/common/mlx5/mlx5_prm.h        |  1 +
 drivers/net/mlx5/hws/mlx5dr_action.c  |  6 ++++++
 drivers/net/mlx5/hws/mlx5dr_pat_arg.c | 16 ++++++++++++++++
 drivers/net/mlx5/hws/mlx5dr_pat_arg.h |  2 ++
 4 files changed, 25 insertions(+)
drivers/common/mlx5/mlx5_prm.h +1 -0
index 4b0a56f4e5..0b6dc43752 100644
@@ -715,6 +715,7 @@ enum {
 	MLX5_MODIFICATION_TYPE_REMOVE = 0x5,
 	MLX5_MODIFICATION_TYPE_NOP = 0x6,
 	MLX5_MODIFICATION_TYPE_REMOVE_WORDS = 0x7,
+	MLX5_MODIFICATION_TYPE_MAX,
 };
 
 /* The field of packet to be modified. */
drivers/net/mlx5/hws/mlx5dr_action.c +6 -0
index 77cf1f5132..2d93be717f 100644
@@ -1603,6 +1603,12 @@ mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
 		goto free_action;
 	}
 
+	if (!mlx5dr_pat_arg_verify_actions(pattern, pattern_sz / MLX5DR_MODIFY_ACTION_SIZE)) {
+		DR_LOG(ERR, "One of the actions is not supported\n");
+		rte_errno = EINVAL;
+		goto free_action;
+	}
+
 	if (pattern_sz / MLX5DR_MODIFY_ACTION_SIZE == 1) {
 		/* Optimize single modiy action to be used inline */
 		action->modify_header.single_action = pattern[0];
drivers/net/mlx5/hws/mlx5dr_pat_arg.c +16 -0
index 6ed04dac6d..830bc08678 100644
@@ -441,6 +441,22 @@ mlx5dr_arg_create_modify_header_arg(struct mlx5dr_context *ctx,
 	return 0;
 }
 
+bool mlx5dr_pat_arg_verify_actions(__be64 pattern[], uint16_t num_of_actions)
+{
+	int i;
+
+	for (i = 0; i < num_of_actions; i++) {
+		u8 action_id =
+			MLX5_GET(set_action_in, &pattern[i], action_type);
+		if (action_id >= MLX5_MODIFICATION_TYPE_MAX) {
+			DR_LOG(ERR, "Invalid action %u\n", action_id);
+			return false;
+		}
+	}
+
+	return true;
+}
+
 int mlx5dr_pat_arg_create_modify_header(struct mlx5dr_context *ctx,
 					struct mlx5dr_action *action,
 					size_t pattern_sz,
drivers/net/mlx5/hws/mlx5dr_pat_arg.h +2 -0
index 92db6d6aee..ec467dbb4b 100644
@@ -53,6 +53,8 @@ int mlx5dr_pat_init_pattern_cache(struct mlx5dr_pattern_cache **cache);
 
 void mlx5dr_pat_uninit_pattern_cache(struct mlx5dr_pattern_cache *cache);
 
+bool mlx5dr_pat_arg_verify_actions(__be64 pattern[], uint16_t num_of_actions);
+
 int mlx5dr_pat_arg_create_modify_header(struct mlx5dr_context *ctx,
 					struct mlx5dr_action *action,
 					size_t pattern_sz,
Signature · 1 line
2.18.2