mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v2] net/mlx5e: Fix deadlock when parsing flow actions fails
@ 2026-11-26  8:42 Ziyu Zhang
  2026-11-26  8:48 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Ziyu Zhang @ 2026-11-26  8:42 UTC (permalink / raw)
  To: saeedm, tariqt, mbloch, leon
  Cc: netdev, linux-rdma, linux-kernel, andrew+netdev, davem, edumazet,
	kuba, pabeni, roid, baijiaju1990, ziyuzhang201

Neighbour and route updates wait for flow->init_done while holding
encap_tbl_lock. Action parsing can expose a flow to these updates by
attaching post-action encap entries in alloc_flow_post_acts(). If a
later allocation or validation fails, cleanup needs encap_tbl_lock to
detach the entries, but the update is still waiting for init_done.

Remove any installed post-action rules first, since a woken update can
free the encap headers they reference. Mark the flow as having failed
action parsing and signal init_done before detaching the entries.

Skip flows that failed action parsing in mlx5e_take_tmp_flow() after
waiting for init_done. A route update can encounter the same flow through
more than one encap entry while holding encap_tbl_lock, before cleanup
can detach the entries. Skipping the flow prevents adding its tmp_list
node twice. The lock prevents detach while the collector waits and
checks the result, so it can take the reference after this check.

Free the post-action attributes on the parse error path before dropping
the caller's reference, so any temporary reference held elsewhere
cannot defer encap detach. Use a separate parse failure flag so the
existing FAILED flag retains its meaning for offload failures.

This possible bug was found by our experimental static analysis tool, which
analyzes lock usage and completion-based synchronization to detect
potential deadlock patterns.

Fixes: 8300f225268b ("net/mlx5e: Create new flow attr for multi table actions")
Signed-off-by: Ziyu Zhang <ziyuzhang201@gmail.com>
---
Changes in v2:
- Skip flows that failed action parsing before adding them to tmp_list.
- Detach their post-action encaps before dropping the caller's reference.

Sashiko's other two findings concern cleanup before reoffload retries.
That cleanup is being discussed separately:
https://lkml.iu.edu/2611.1/02787.html

v1: https://lore.kernel.org/r/20261125042323.88050-1-ziyuzhang201@gmail.com

 .../net/ethernet/mellanox/mlx5/core/en/tc_priv.h   |  1 +
 .../ethernet/mellanox/mlx5/core/en/tc_tun_encap.c  |  6 ++++-
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c    | 31 ++++++++++++++++++++--
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h
index 1ceebab4ce08..a031b85a466f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h
@@ -31,6 +31,7 @@ enum {
 	MLX5E_TC_FLOW_FLAG_SAMPLE                = MLX5E_TC_FLOW_BASE + 10,
 	MLX5E_TC_FLOW_FLAG_USE_ACT_STATS         = MLX5E_TC_FLOW_BASE + 11,
 	MLX5E_TC_FLOW_FLAG_PEER                  = MLX5E_TC_FLOW_BASE + 12,
+	MLX5E_TC_FLOW_FLAG_PARSE_FAILED          = MLX5E_TC_FLOW_BASE + 13,
 };
 
 struct mlx5e_tc_flow_parse_attr {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
index 5e40107efa26..21a03d15c4be 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
@@ -275,6 +275,11 @@ static void mlx5e_take_tmp_flow(struct mlx5e_tc_flow *flow,
 				struct list_head *flow_list,
 				int index)
 {
+	/* Detaching the flow also takes encap_tbl_lock. */
+	wait_for_completion(&flow->init_done);
+	if (flow_flag_test(flow, PARSE_FAILED))
+		return;
+
 	if (IS_ERR(mlx5e_flow_get(flow))) {
 		/* Flow is being deleted concurrently. Wait for it to be
 		 * unoffloaded from hardware, otherwise deleting encap will
@@ -283,7 +288,6 @@ static void mlx5e_take_tmp_flow(struct mlx5e_tc_flow *flow,
 		wait_for_completion(&flow->del_hw_done);
 		return;
 	}
-	wait_for_completion(&flow->init_done);
 
 	flow->tmp_entry_index = index;
 	list_add(&flow->tmp_list, flow_list);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 1d35c97aea0b..9e7850b5e13d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -3748,6 +3748,31 @@ free_flow_post_acts(struct mlx5e_tc_flow *flow)
 	}
 }
 
+static void abort_flow_post_acts(struct mlx5e_tc_flow *flow)
+{
+	struct mlx5e_post_act *post_act = get_post_action(flow->priv);
+	struct mlx5_flow_attr *attr;
+
+	if (flow_flag_test(flow, PARSE_FAILED))
+		return;
+
+	/* Remove hardware rules before an update can free their encap headers. */
+	list_for_each_entry(attr, &flow->attrs, list) {
+		if (list_is_last(&attr->list, &flow->attrs))
+			break;
+		if (!attr->post_act_handle)
+			continue;
+
+		mlx5e_tc_post_act_del(post_act, attr->post_act_handle);
+		attr->post_act_handle = NULL;
+	}
+
+	/* Wake updates before detaching encaps under encap_tbl_lock. */
+	flow_flag_set(flow, PARSE_FAILED);
+	complete_all(&flow->init_done);
+	free_flow_post_acts(flow);
+}
+
 int
 mlx5e_tc_offload_flow_post_acts(struct mlx5e_tc_flow *flow)
 {
@@ -3852,7 +3877,7 @@ out:
 	return 0;
 
 out_free:
-	free_flow_post_acts(flow);
+	abort_flow_post_acts(flow);
 	return err;
 }
 
@@ -4580,8 +4605,10 @@ __mlx5e_add_fdb_flow(struct mlx5e_priv *priv,
 		goto err_free;
 
 	err = parse_tc_fdb_actions(priv, &rule->action, flow, extack);
-	if (err)
+	if (err) {
+		abort_flow_post_acts(flow);
 		goto err_free;
+	}
 
 	err = mlx5e_tc_add_fdb_flow(priv, flow, extack);
 	complete_all(&flow->init_done);
-- 
2.34.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net v2] net/mlx5e: Fix deadlock when parsing flow actions fails
  2026-11-26  8:42 [PATCH net v2] net/mlx5e: Fix deadlock when parsing flow actions fails Ziyu Zhang
@ 2026-11-26  8:48 ` netdev-bot+sinfo
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-11-26  8:48 UTC (permalink / raw)
  To: Ziyu Zhang
  Cc: saeedm, tariqt, mbloch, leon, netdev, linux-rdma, linux-kernel,
	andrew+netdev, davem, edumazet, kuba, pabeni, roid, baijiaju1990

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  8:42 [PATCH net v2] net/mlx5e: Fix deadlock when parsing flow actions fails Ziyu Zhang
2026-11-26  8:48 ` netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®