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 v2] net/mlx5e: Fix deadlock when parsing flow actions fails
Date: Thu, 26 Nov 2026 16:42:16 +0800 [thread overview]
Message-ID: <20261126084216.26436-1-ziyuzhang201@gmail.com> (raw)
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
next reply other threads:[~2026-11-26 8:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 8:42 Ziyu Zhang [this message]
2026-11-26 8:48 ` netdev-bot+sinfo
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=20261126084216.26436-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
all inboxes | Powered by JetHome®