DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/mlx5: validate HWS context in meter operations
@ 2024-10-27 15:42 Gregory Etelson
  0 siblings, 0 replies; only message in thread
From: Gregory Etelson @ 2024-10-27 15:42 UTC (permalink / raw)
  To: dev
  Cc: getelson,  ,
	rasland, Dariusz Sosnowski, Viacheslav Ovsiienko, Bing Zhao,
	Ori Kam, Suanming Mou, Matan Azrad

HWS context is created during port configuration.

PMD allowed meter operations before port configuration.

The patch rejects HWS meter operations before port configuration.

Signed-off-by: Gregory Etelson <getelson@nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
---
 drivers/net/mlx5/mlx5.h            | 18 ++++++++++++++
 drivers/net/mlx5/mlx5_flow_hw.c    |  7 +++++-
 drivers/net/mlx5/mlx5_flow_meter.c | 40 ++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 0e026f7bbb..503366580b 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -2682,4 +2682,22 @@ int mlx5_quota_query(struct rte_eth_dev *dev, uint32_t queue,
 int mlx5_alloc_srh_flex_parser(struct rte_eth_dev *dev);
 
 void mlx5_free_srh_flex_parser(struct rte_eth_dev *dev);
+
+/* mlx5_flow_hw.c */
+struct rte_pmd_mlx5_host_action;
+
+struct mlx5dr_action *
+mlx5_flow_hw_get_dr_action(struct rte_eth_dev *dev,
+			   struct rte_pmd_mlx5_host_action *action,
+			   void **release_data);
+
+void
+mlx5_flow_hw_put_dr_action(struct rte_eth_dev *dev,
+			   enum rte_flow_action_type type,
+			   void *release_data);
+
+bool
+mlx5_hw_ctx_validate(const struct rte_eth_dev *dev,
+		     struct rte_flow_error *error);
+
 #endif /* RTE_PMD_MLX5_H_ */
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index 5b34154bf1..9c33004c09 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -208,7 +208,12 @@ mlx5_destroy_multi_pattern_segment(struct mlx5_multi_pattern_segment *segment);
 static __rte_always_inline enum mlx5_indirect_list_type
 flow_hw_inlist_type_get(const struct rte_flow_action *actions);
 
-static bool
+static int
+flow_hw_allocate_actions(struct rte_eth_dev *dev,
+			 uint64_t action_flags,
+			 struct rte_flow_error *error);
+
+bool
 mlx5_hw_ctx_validate(const struct rte_eth_dev *dev, struct rte_flow_error *error)
 {
 	const struct mlx5_priv *priv = dev->data->dev_private;
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index 19d8607070..299265f8bc 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -745,6 +745,10 @@ mlx5_flow_mtr_cap_get(struct rte_eth_dev *dev,
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_hca_qos_attr *qattr = &priv->sh->cdev->config.hca_attr.qos;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL))
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "non-template flow engine was not configured");
 	if (!priv->mtr_en)
 		return -rte_mtr_error_set(error, ENOTSUP,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
@@ -903,6 +907,12 @@ mlx5_flow_meter_profile_get(struct rte_eth_dev *dev,
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL)) {
+		rte_mtr_error_set(error, EINVAL,
+				  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+				  "non-template flow engine was not configured");
+		return NULL;
+	}
 	if (!priv->mtr_en) {
 		rte_mtr_error_set(error, ENOTSUP,
 				  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
@@ -939,6 +949,10 @@ mlx5_flow_meter_profile_hws_add(struct rte_eth_dev *dev,
 	struct mlx5_flow_meter_profile *fmp;
 	int ret;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL))
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "non-template flow engine was not configured");
 	if (priv->shared_host)
 		return -rte_mtr_error_set(error, ENOTSUP, RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
 					  "Meter profiles cannot be created on guest port");
@@ -1167,6 +1181,10 @@ mlx5_flow_meter_policy_hws_validate(struct rte_eth_dev *dev,
 	int ret;
 	int i;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL))
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "non-template flow engine was not configured");
 	if (!priv->mtr_en || !priv->sh->meter_aso_en)
 		return -rte_mtr_error_set(error, ENOTSUP,
 				RTE_MTR_ERROR_TYPE_METER_POLICY,
@@ -1496,6 +1514,12 @@ mlx5_flow_meter_policy_get(struct rte_eth_dev *dev,
 	struct mlx5_priv *priv = dev->data->dev_private;
 	uint32_t policy_idx;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL)) {
+		rte_mtr_error_set(error, EINVAL,
+				  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+				  "non-template flow engine was not configured");
+		return NULL;
+	}
 	if (!priv->mtr_en) {
 		rte_mtr_error_set(error, ENOTSUP,
 				  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
@@ -1645,6 +1669,10 @@ mlx5_flow_meter_policy_hws_add(struct rte_eth_dev *dev,
 		[1] = { .type = RTE_FLOW_ITEM_TYPE_END }
 	};
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL))
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "non-template flow engine was not configured");
 	if (!priv->mtr_policy_arr)
 		return mlx5_flow_meter_policy_add(dev, policy_id, policy, error);
 	mtr_policy = mlx5_flow_meter_policy_find(dev, policy_id, NULL);
@@ -2230,6 +2258,10 @@ mlx5_flow_meter_hws_create(struct rte_eth_dev *dev, uint32_t meter_id,
 	struct mlx5_hw_q_job *job;
 	int ret;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL))
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "non-template flow engine was not configured");
 	if (!priv->mtr_profile_arr ||
 	    !priv->mtr_policy_arr ||
 	    !priv->mtr_bulk.aso)
@@ -2520,6 +2552,10 @@ mlx5_flow_meter_enable(struct rte_eth_dev *dev,
 	struct mlx5_flow_meter_info *fm;
 	int ret;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL))
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "non-template flow engine was not configured");
 	if (!priv->mtr_en)
 		return -rte_mtr_error_set(error, ENOTSUP,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
@@ -2609,6 +2645,10 @@ mlx5_flow_meter_profile_update(struct rte_eth_dev *dev,
 			       MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CIR;
 	int ret;
 
+	if (mlx5_hws_active(dev) && !mlx5_hw_ctx_validate(dev, NULL))
+		return -rte_mtr_error_set(error, EINVAL,
+					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+					  "non-template flow engine was not configured");
 	if (!priv->mtr_en)
 		return -rte_mtr_error_set(error, ENOTSUP,
 					  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-27 15:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-27 15:42 [PATCH] net/mlx5: validate HWS context in meter operations Gregory Etelson

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).