Skip to contentSkip to conversation

net/mlx5: validate HWS context in meter operations

PATCH In review Gregory Etelson 2 participants 2 messages Oct 27, 2024 – Oct 29, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: validate HWS context in meter operations

HWS context is created during port configuration.

PMD allowed meter operations before port configuration.

The patch rejects HWS meter operations before port configuration.

---
 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(-)
drivers/net/mlx5/mlx5.h +18 -0
index 0e026f7bbb..503366580b 100644
@@ -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_ */
drivers/net/mlx5/mlx5_flow_hw.c +6 -1
index 5b34154bf1..9c33004c09 100644
@@ -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;
drivers/net/mlx5/mlx5_flow_meter.c +40 -0
index 19d8607070..299265f8bc 100644
@@ -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,
Signature · 1 line
2.43.0
Acked-by Dariusz Sosnowski on v1 1/1
#1 lore raw

Hi,

From: Gregory Etelson <[email protected]>
Sent: Sunday, October 27, 2024 5:42 PM
To: [email protected]
Cc: Gregory Etelson; Maayan Kashani; Raslan Darawsheh; Dariusz Sosnowski; Slava Ovsiienko; Bing Zhao; Ori Kam; Suanming Mou; Matan Azrad
Subject: [PATCH] net/mlx5: validate HWS context in meter operations

HWS context is created during port configuration.

PMD allowed meter operations before port configuration.

The patch rejects HWS meter operations before port configuration.

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh