Skip to contentSkip to conversation

non-template fixes set

PATCH In review Bing Zhao 2 participants 6 messages Jul 23, 2024 – Aug 29, 2024 Network drivers

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

cover non-template fixes set

A set for cumulative fixes of non-template API support.

Bing Zhao (4):
net/mlx5/hws: fix state detection of queue full in polling net/mlx5: fix releasing order of compatible matcher net/mlx5: fix matcher mask translation
net/mlx5: fix log error on non-template rule destroy

 drivers/net/mlx5/hws/mlx5dr_bwc.c |  4 +++-
 drivers/net/mlx5/hws/mlx5dr_bwc.h |  1 -
 drivers/net/mlx5/mlx5_flow_dv.c   |  1 +
 drivers/net/mlx5/mlx5_flow_hw.c   | 37 +++++++++++--------------------
 4 files changed, 17 insertions(+), 26 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/4 net/mlx5/hws: fix state detection of queue full in polling

The sending queue (SQ) size of BWC API is not fixed and the same as that of other HWS rule insertion SQs. When checking the queue full state, the number of queue entries and the used entries should be used instead of the macro "MLX5DR_BWC_MATCHER_REHASH_QUEUE_SZ".

Or else, when resizing the matcher and moving the rules, sometimes it would fail incorrectly. For example, once a hiccup of generating CQE happened, the polling of CQ exited directly without any retry. Then there was no enough room for the next rule to be moved.

Using the correct state of a SQ will solve this issue, the polling of associative CQ will continue until a new CQE is generated.

Fixes 87026d2e6601 ("net/mlx5/hws: support backward-compatible API")
---
 drivers/net/mlx5/hws/mlx5dr_bwc.c | 4 +++-
 drivers/net/mlx5/hws/mlx5dr_bwc.h | 1 -
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/mlx5/hws/mlx5dr_bwc.c +3 -1
index e0b6390ed9..9233452118 100644
@@ -181,10 +181,10 @@ mlx5dr_bwc_queue_poll(struct mlx5dr_context *ctx,
 		      uint32_t *pending_rules,
 		      bool drain)
 {
-	bool queue_full = *pending_rules == MLX5DR_BWC_MATCHER_REHASH_QUEUE_SZ;
 	struct rte_flow_op_result comp[MLX5DR_BWC_MATCHER_REHASH_BURST_TH];
 	uint16_t burst_th = mlx5dr_bwc_get_burst_th(ctx, queue_id);
 	bool got_comp = *pending_rules >= burst_th;
+	bool queue_full;
 	int err = 0;
 	int ret;
 	int i;
@@ -193,6 +193,8 @@ mlx5dr_bwc_queue_poll(struct mlx5dr_context *ctx,
 	if (!got_comp && !drain)
 		return 0;
 
+	/* The FULL state of a SQ is always a subcondition of the original 'got_comp'. */
+	queue_full = mlx5dr_send_engine_full(&ctx->send_queue[queue_id]);
 	while (queue_full || ((got_comp || drain) && *pending_rules)) {
 		ret = mlx5dr_send_queue_poll(ctx, queue_id, comp, burst_th);
 		if (unlikely(ret < 0)) {
drivers/net/mlx5/hws/mlx5dr_bwc.h +0 -1
index 648443861b..8c3f721ac2 100644
@@ -9,7 +9,6 @@
 #define MLX5DR_BWC_MATCHER_SIZE_LOG_STEP 1
 #define MLX5DR_BWC_MATCHER_REHASH_PERCENT_TH 70
 #define MLX5DR_BWC_MATCHER_REHASH_BURST_TH 32
-#define MLX5DR_BWC_MATCHER_REHASH_QUEUE_SZ 256
 #define MLX5DR_BWC_MATCHER_ATTACH_AT_NUM 255
 
 struct mlx5dr_bwc_matcher {
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/4 net/mlx5: fix releasing order of compatible matcher

In reply to Bing Zhao

The matchers are created and organized in groups, and the groups are managed by a hash list in shared object.

The creation order:
1. If no group, create the group and register it into the hash list. And create the list to save matchers.
2. If no matcher is found, register the matcher and increase the reference count of group.
3. If the matcher exists and can be reused, increase the reference counts of its group and itself.

When dereferencing a matcher, the orders should be reversed.
1. Dereference the matcher and release it when not being used.
2. Dereference the group and release it when not being used.

When the last flow rule on some group was trying to be destroyed, the matcher resource would also be freed in group dereference stage. The group information should be saved locally to get rid of the UAF issue in both stages.

Coverity issue: 426423

Fixes b2845d51c748 ("net/mlx5: support FDB in non-template flow")
---
 drivers/net/mlx5/mlx5_flow_hw.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +7 -13
index d243b59b71..470919fe8a 100644
@@ -13471,22 +13471,16 @@ static int
 flow_hw_unregister_matcher(struct rte_eth_dev *dev,
 			   struct mlx5_flow_dv_matcher *matcher)
 {
-	int ret;
 	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_flow_group *group = matcher->group;
+	int ret = 0;
 
-	if (matcher->matcher_object) {
-		ret = mlx5_hlist_unregister(priv->sh->groups, &matcher->group->entry);
-		if (ret)
-			goto error;
-		if (matcher->group) {
-			ret = mlx5_list_unregister(matcher->group->matchers, &matcher->entry);
-			if (ret)
-				goto error;
-		}
+	if (group) {
+		if (matcher->matcher_object)
+			ret |= mlx5_list_unregister(group->matchers, &matcher->entry);
+		ret |= mlx5_hlist_unregister(priv->sh->groups, &group->entry);
 	}
-	return 0;
-error:
-	return -EINVAL;
+	return ret;
 }
 
 static int flow_hw_register_matcher(struct rte_eth_dev *dev,
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/4 net/mlx5: fix matcher mask translation

In reply to Bing Zhao

In non-template API implementation on HWS, the matcher mask is translated using DV item translation. This is used to find and reuse the same matcher in the PMD for rules insertion when possible.

The flags calculated previously for items should not be passed to avoid incorrectly recognizing the layers. In the meanwhile, unlike in template API, the group information is also needed for the mask translation.

Fixes 27d171b88031 ("net/mlx5: abstract flow action and enable reconfigure")
---
 drivers/net/mlx5/mlx5_flow_dv.c | 1 +
 drivers/net/mlx5/mlx5_flow_hw.c | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5_flow_dv.c +1 -0
index 89057edbcf..a51d4dd1a4 100644
@@ -14538,6 +14538,7 @@ __flow_dv_translate_items_hws(const struct rte_flow_item *items,
 		.next_protocol = 0xff,
 		.attr = &rattr,
 		.rss_desc = &rss_desc,
+		.group = attr->group,
 	};
 	int ret = 0;
 
drivers/net/mlx5/mlx5_flow_hw.c +2 -2
index 470919fe8a..46f6665846 100644
@@ -13682,7 +13682,7 @@ flow_hw_create_flow(struct rte_eth_dev *dev, enum mlx5_flow_type type,
 		.rss_level = 0,
 		.act_flags = action_flags,
 		.tbl_type = 0,
-		};
+	};
 
 	memset(&hw_act, 0, sizeof(hw_act));
 	if (attr->transfer)
@@ -13702,7 +13702,7 @@ flow_hw_create_flow(struct rte_eth_dev *dev, enum mlx5_flow_type type,
 	(*flow)->nt_rule = true;
 	(*flow)->nt2hws->matcher = &matcher;
 	ret = flow_dv_translate_items_hws(items, &flow_attr, &matcher.mask.buf,
-					MLX5_SET_MATCHER_HS_M, &item_flags,
+					MLX5_SET_MATCHER_HS_M, NULL,
 					NULL, error);
 
 	if (ret)
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH 4/4 net/mlx5: fix log error on non-template rule destroy

In reply to Bing Zhao

Log error message is raised on port stop when using same encap action with two different rules.

It is a false alarm, checking return value not equals zero from hlist unregister function was wrong since it returns 1 if the object is still referenced.

Remove the check for return value for encap, decap, modify header and matcher resource release under flow destroy cause all uses list/hlist with return value 0/1.

Fixes ff4064d5b1fe ("net/mlx5: support bulk actions in non-template flow")
---
 drivers/net/mlx5/mlx5_flow_hw.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +4 -9
index 46f6665846..8a59d3c013 100644
@@ -13792,17 +13792,12 @@ flow_hw_destroy(struct rte_eth_dev *dev, struct rte_flow_hw *flow)
 	if (flow->nt2hws->flow_aux)
 		mlx5_free(flow->nt2hws->flow_aux);
 
-	if (flow->nt2hws->rix_encap_decap) {
-		ret = flow_encap_decap_resource_release(dev, flow->nt2hws->rix_encap_decap);
-		if (ret)
-			DRV_LOG(ERR, "failed to release encap decap.");
-	}
+	if (flow->nt2hws->rix_encap_decap)
+		flow_encap_decap_resource_release(dev, flow->nt2hws->rix_encap_decap);
 	if (flow->nt2hws->modify_hdr) {
 		MLX5_ASSERT(flow->nt2hws->modify_hdr->action);
-		ret = mlx5_hlist_unregister(priv->sh->modify_cmds,
-			&flow->nt2hws->modify_hdr->entry);
-		if (ret)
-			DRV_LOG(ERR, "failed to release modify action.");
+		mlx5_hlist_unregister(priv->sh->modify_cmds,
+				      &flow->nt2hws->modify_hdr->entry);
 	}
 	if (flow->nt2hws->matcher)
 		flow_hw_unregister_matcher(dev, flow->nt2hws->matcher);
Signature · 1 line
2.34.1
#5 lore raw
In reply to Bing Zhao

Hi,

From: Bing Zhao <[email protected]>
Sent: Tuesday, July 23, 2024 11:15 AM
To: Dariusz Sosnowski; Slava Ovsiienko; [email protected]; Raslan Darawsheh
Cc: Ori Kam; Suanming Mou; Matan Azrad
Subject: [PATCH 0/4] non-template fixes set

A set for cumulative fixes of non-template API support.

Bing Zhao (4):
net/mlx5/hws: fix state detection of queue full in polling net/mlx5: fix releasing order of compatible matcher net/mlx5: fix matcher mask translation
net/mlx5: fix log error on non-template rule destroy

 drivers/net/mlx5/hws/mlx5dr_bwc.c |  4 +++-
 drivers/net/mlx5/hws/mlx5dr_bwc.h |  1 -
 drivers/net/mlx5/mlx5_flow_dv.c   |  1 +
 drivers/net/mlx5/mlx5_flow_hw.c   | 37 +++++++++++--------------------
 4 files changed, 17 insertions(+), 26 deletions(-)

Series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh