DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dariusz Sosnowski <dsosnowski@nvidia.com>
To: Ori Kam <orika@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>,
	"Matan Azrad" <matan@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Cc: <dev@dpdk.org>
Subject: [PATCH 2/2] net/mlx5: add modify field actions number validation
Date: Wed, 17 May 2023 20:24:46 +0000	[thread overview]
Message-ID: <20230517202446.535778-3-dsosnowski@nvidia.com> (raw)
In-Reply-To: <20230517202446.535778-1-dsosnowski@nvidia.com>

This patch adds validation for the number of modify field actions,
when working with HW Steering.

If translation of modify field actions generated more HW commands
than supported by the FW, then proper error is returned.
Additionally, number of generated commands is logged,
along with a number of NOP commands added.
This validation is only valid for HWS template tables, in groups > 0.

Signed-off-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_hw.c | 51 +++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index 7e0ee8d883..0a7416c7a1 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -1086,6 +1086,53 @@ flow_hw_modify_field_compile(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static uint32_t
+flow_hw_count_nop_modify_field(struct mlx5_hw_modify_header_action *mhdr)
+{
+	uint32_t i;
+	uint32_t nops = 0;
+
+	for (i = 0; i < mhdr->mhdr_cmds_num; ++i) {
+		struct mlx5_modification_cmd cmd = mhdr->mhdr_cmds[i];
+
+		cmd.data0 = rte_be_to_cpu_32(cmd.data0);
+		if (cmd.action_type == MLX5_MODIFICATION_TYPE_NOP)
+			++nops;
+	}
+	return nops;
+}
+
+static int
+flow_hw_validate_compiled_modify_field(struct rte_eth_dev *dev,
+				       const struct mlx5_flow_template_table_cfg *cfg,
+				       struct mlx5_hw_modify_header_action *mhdr,
+				       struct rte_flow_error *error)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
+
+	/*
+	 * Header modify pattern length limitation is only valid for HWS groups, i.e. groups > 0.
+	 * In group 0, MODIFY_FIELD actions are handled with header modify actions
+	 * managed by rdma-core.
+	 */
+	if (cfg->attr.flow_attr.group != 0 &&
+	    mhdr->mhdr_cmds_num > hca_attr->max_header_modify_pattern_length) {
+		uint32_t nops = flow_hw_count_nop_modify_field(mhdr);
+
+		DRV_LOG(ERR, "Too many modify header commands generated from "
+			     "MODIFY_FIELD actions. "
+			     "Generated HW commands = %u (amount of NOP commands = %u). "
+			     "Maximum supported = %u.",
+			     mhdr->mhdr_cmds_num, nops,
+			     hca_attr->max_header_modify_pattern_length);
+		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					  "Number of MODIFY_FIELD actions exceeds maximum "
+					  "supported limit of actions");
+	}
+	return 0;
+}
+
 static int
 flow_hw_represented_port_compile(struct rte_eth_dev *dev,
 				 const struct rte_flow_attr *attr,
@@ -1704,6 +1751,10 @@ __flow_hw_actions_translate(struct rte_eth_dev *dev,
 		uint32_t bulk_size;
 		size_t mhdr_len;
 
+		if (flow_hw_validate_compiled_modify_field(dev, cfg, &mhdr, error)) {
+			__flow_hw_action_template_destroy(dev, acts);
+			return -rte_errno;
+		}
 		acts->mhdr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*acts->mhdr),
 					 0, SOCKET_ID_ANY);
 		if (!acts->mhdr)
-- 
2.25.1


  parent reply	other threads:[~2023-05-17 20:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 20:24 [PATCH 0/2] " Dariusz Sosnowski
2023-05-17 20:24 ` [PATCH 1/2] common/mlx5: query maximum modify header pattern length Dariusz Sosnowski
2023-05-17 20:24 ` Dariusz Sosnowski [this message]
2023-05-24 14:07 ` [PATCH 0/2] net/mlx5: add modify field actions number validation Raslan Darawsheh

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=20230517202446.535778-3-dsosnowski@nvidia.com \
    --to=dsosnowski@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=suanmingm@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).