Netdev List
 help / color / mirror / Atom feed
From: Ziyu Zhang <ziyuzhang201@gmail.com>
To: saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com, leon@kernel.org
Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, roid@nvidia.com, baijiaju1990@gmail.com,
	ziyuzhang201@gmail.com
Subject: [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails
Date: Wed, 25 Nov 2026 12:23:23 +0800	[thread overview]
Message-ID: <20261125042323.88050-1-ziyuzhang201@gmail.com> (raw)

Neigh and route updates take encap_tbl_lock and then wait for
flow->init_done on every flow attached to the encap entry.  The only
complete_all(&flow->init_done) sits after mlx5e_tc_add_fdb_flow(), so a
flow whose actions fail to parse is never announced to them.

Such a flow can already be visible to the updates:
alloc_flow_post_acts() runs post_process_attr() on each post action
attribute, and mlx5e_tc_tun_encap_dests_set() attaches the flow to
e->flows there.  A later failure in alloc_flow_post_acts() goes through
free_flow_post_acts() -> mlx5_free_flow_attr_actions() ->
mlx5e_tc_tun_encap_dests_unset() -> mlx5e_detach_encap(), which takes
encap_tbl_lock.  The checks parse_tc_fdb_actions() runs after
alloc_flow_post_acts() reach the same detach from mlx5e_flow_put().  An
update that holds the lock and waits for the flow then blocks the
cleanup that would have to wake it, and both sides hang.

When parsing the actions fails, first delete the post action rules
installed so far: a woken neigh update may release e->pkt_reformat,
which those rules still use.  Then mark the flow FAILED and complete
init_done, and only then detach the encap entries.  The neigh paths skip
a flow that is not OFFLOADED and the route paths skip one that is
FAILED, so a woken update leaves the flow alone.  complete_all() is
idempotent, so the second call for a failure inside
alloc_flow_post_acts() is harmless.

Commit 37c3b9fa7ccf ("net/mlx5e: Prevent encap offload when neigh update
is running") fixed the same lock cycle between the encap entries of a
single attribute.  This patch only covers a failure while parsing the
actions.  A successful setup still takes encap_tbl_lock again after a
post action attribute attached the flow, through the encap dests of the
main attribute or mlx5e_attach_decap_route() for TUN_RX flows, and a
waiting update can block it there as well.

Fixes: 8300f225268b ("net/mlx5e: Create new flow attr for multi table actions")
Signed-off-by: Ziyu Zhang <ziyuzhang201@gmail.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_tc.c   | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index b290beb4369a..91e04a84bf07 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -3748,6 +3748,39 @@ free_flow_post_acts(struct mlx5e_tc_flow *flow)
 	}
 }
 
+/* Neigh and route updates wait for init_done while holding
+ * encap_tbl_lock, so the waiters have to be woken before error cleanup
+ * takes that lock again.  A flow that fails here is skipped by them: the
+ * neigh paths check OFFLOADED and the route paths check FAILED.
+ */
+static void mlx5e_flow_init_failed(struct mlx5e_tc_flow *flow)
+{
+	flow_flag_set(flow, FAILED);
+	complete_all(&flow->init_done);
+}
+
+/* Remove the post action rules of a flow that failed to initialize.  A
+ * woken neigh update may release the encap header they point to, so they
+ * have to go before init_done is completed.
+ */
+static void
+del_flow_post_act_handles(struct mlx5e_tc_flow *flow)
+{
+	struct mlx5e_post_act *post_act = get_post_action(flow->priv);
+	struct mlx5_flow_attr *attr;
+
+	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;
+	}
+}
+
 int
 mlx5e_tc_offload_flow_post_acts(struct mlx5e_tc_flow *flow)
 {
@@ -3852,6 +3885,8 @@ alloc_flow_post_acts(struct mlx5e_tc_flow *flow, struct netlink_ext_ack *extack)
 	return 0;
 
 out_free:
+	del_flow_post_act_handles(flow);
+	mlx5e_flow_init_failed(flow);
 	free_flow_post_acts(flow);
 	return err;
 }
@@ -4579,8 +4614,11 @@ __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) {
+		del_flow_post_act_handles(flow);
+		mlx5e_flow_init_failed(flow);
 		goto err_free;
+	}
 
 	err = mlx5e_tc_add_fdb_flow(priv, flow, extack);
 	complete_all(&flow->init_done);
-- 
2.34.1


                 reply	other threads:[~2026-11-25  4:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125042323.88050-1-ziyuzhang201@gmail.com \
    --to=ziyuzhang201@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=baijiaju1990@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=roid@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@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