DPDK patches and discussions
 help / color / mirror / Atom feed
From: Erez Shitrit <erezsh@nvidia.com>
To: <dev@dpdk.org>
Cc: <valex@nvidia.com>, Matan Azrad <matan@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Subject: [PATCH 4/4] net/mlx5/hws: add check for modify-header actions
Date: Mon, 20 Mar 2023 16:53:43 +0200	[thread overview]
Message-ID: <20230320145343.449023-4-erezsh@nvidia.com> (raw)
In-Reply-To: <20230320145343.449023-1-erezsh@nvidia.com>


Allow only actions that are currently supported.

Fixes: f8c8a6d8440d ("net/mlx5/hws: add action object")
Reviewed-by: Alex Vesker <valex@nvidia.com>
Signed-off-by: Erez Shitrit <erezsh@nvidia.com>
---
 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(+)

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index 4b0a56f4e5..0b6dc43752 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -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. */
diff --git a/drivers/net/mlx5/hws/mlx5dr_action.c b/drivers/net/mlx5/hws/mlx5dr_action.c
index 77cf1f5132..2d93be717f 100644
--- a/drivers/net/mlx5/hws/mlx5dr_action.c
+++ b/drivers/net/mlx5/hws/mlx5dr_action.c
@@ -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];
diff --git a/drivers/net/mlx5/hws/mlx5dr_pat_arg.c b/drivers/net/mlx5/hws/mlx5dr_pat_arg.c
index 6ed04dac6d..830bc08678 100644
--- a/drivers/net/mlx5/hws/mlx5dr_pat_arg.c
+++ b/drivers/net/mlx5/hws/mlx5dr_pat_arg.c
@@ -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,
diff --git a/drivers/net/mlx5/hws/mlx5dr_pat_arg.h b/drivers/net/mlx5/hws/mlx5dr_pat_arg.h
index 92db6d6aee..ec467dbb4b 100644
--- a/drivers/net/mlx5/hws/mlx5dr_pat_arg.h
+++ b/drivers/net/mlx5/hws/mlx5dr_pat_arg.h
@@ -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,
-- 
2.18.2


      parent reply	other threads:[~2023-03-20 14:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 14:53 [PATCH 1/4] net/mlx5/hws: fix bug in pattern creation Erez Shitrit
2023-03-20 14:53 ` [PATCH 2/4] net/mlx5/hws: shared context uses defaults from local context Erez Shitrit
2023-03-20 14:53 ` [PATCH 3/4] net/mlx5/hws: keep all jumbo tag for deletion Erez Shitrit
2023-03-20 14:53 ` Erez Shitrit [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230320145343.449023-4-erezsh@nvidia.com \
    --to=erezsh@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=valex@nvidia.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).