* Re: [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails
2026-11-25 4:23 [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails Ziyu Zhang
@ 2026-11-25 4:26 ` netdev-bot+sinfo
2026-11-26 4:23 ` sashiko-bot
2026-11-29 4:37 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-25 4:26 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:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
- 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] 4+ messages in thread
* Re: [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails
2026-11-25 4:23 [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails Ziyu Zhang
2026-11-25 4:26 ` netdev-bot+sinfo
@ 2026-11-26 4:23 ` sashiko-bot
2026-11-29 4:37 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-26 4:23 UTC (permalink / raw)
To: Ziyu Zhang; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/mlx5e: skipped encap detach in __mlx5e_add_fdb_flow() on
action parse error
It also noticed 2 related pre-existing issues this patch does not
introduce:
- [High] net/mlx5e: list corruption and encap leak in
mlx5e_tc_tun_encap_dests_set() [1]
- [Critical] net/mlx5e: unguarded TUN_RX state in
mlx5e_tc_add_fdb_flow() on retry [2]
--
commit d3aaf145c0b29688154f5549282aa0654096d594
Author: Ziyu Zhang <ziyuzhang201@gmail.com>
net/mlx5e: Fix deadlock when parsing flow actions fails
This commit marks the flow as FAILED, deletes post action rules, and
completes flow->init_done before detaching encap entries when parsing flow
actions fails, avoiding a deadlock with neighbour and route updates waiting
on flow->init_done under encap_tbl_lock.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index 011741553f5b9..d97612a7190b9 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
[ ... ]
> @@ -4580,8 +4615,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;
> + }
[Severity: Medium]
Does jumping to err_free without calling free_flow_post_acts(flow) leave
the flow attached to e->flows when a waiter is woken on flow->init_done?
Before waiting on flow->init_done, mlx5e_take_tmp_flow() calls
mlx5e_flow_get(flow), raising flow->refcnt to 2. When
parse_tc_fdb_actions() fails after alloc_flow_post_acts() has already
succeeded, waking the waiter in mlx5e_flow_init_failed(flow) and calling
mlx5e_flow_put() at err_free can drop flow->refcnt from 2 to 1 and return
without running mlx5e_tc_del_flow() -> free_flow_post_acts():
CPU0 CPU1
__mlx5e_add_fdb_flow()
parse_tc_fdb_actions()
alloc_flow_post_acts()
/* attaches flow to e1, e2 */
mlx5e_update_route_encaps()
lock(&esw->offloads.encap_tbl_lock)
mlx5e_take_all_encap_flows(e1, ...)
mlx5e_flow_get(flow) /* refcnt=2 */
list_add(&flow->tmp_list, ...)
wait_for_completion(&flow->init_done)
/* later check fails */
del_flow_post_act_handles(flow)
mlx5e_flow_init_failed(flow)
complete_all(&flow->init_done)
mlx5e_flow_put(priv, flow)
/* refcnt 2 -> 1, returns */
mlx5e_take_all_encap_flows(e2, ...)
list_add(&flow->tmp_list, ...)
/* corrupts flow->tmp_list */
Because flow is still on e2->flows, the next iteration of
mlx5e_update_route_encaps() (or another thread acquiring encap_tbl_lock
before CPU1 runs mlx5e_put_flow_list()) takes the flow again and calls
list_add() on an already-linked flow->tmp_list, corrupting the list and
leaking a flow reference.
Calling free_flow_post_acts(flow) before goto err_free, just as
alloc_flow_post_acts() does at out_free, ensures mlx5e_detach_encap()
waits for encap_tbl_lock and removes the flow from e->flows before
__mlx5e_add_fdb_flow() returns.
>
> err = mlx5e_tc_add_fdb_flow(priv, flow, extack);
> complete_all(&flow->init_done);
[Severity: High]
This problem wasn't introduced by this patch, but can a partial failure in
mlx5e_tc_tun_encap_dests_set() [1] corrupt e->flows and leak encap
references when an unready multipath flow is retried?
When mlx5e_tc_add_fdb_flow() calls post_process_attr() ->
mlx5e_tc_tun_encap_dests_set() for a rule with multiple tunnel encap
destinations, each successful mlx5e_attach_encap() links
flow->encaps[out_index].list into e->flows:
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:mlx5e_tc_tun_encap_dests_set() {
...
for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++) {
...
err = mlx5e_attach_encap(priv, flow, attr, out_dev, out_index,
extack, &encap_dev);
dev_put(out_dev);
if (err)
goto out;
...
}
}
If a later destination fails with -ENETUNREACH on a multipath LAG setup,
mlx5e_tc_tun_encap_dests_set() returns without detaching the earlier
destinations, and __mlx5e_add_fdb_flow() queues the flow via
add_unready_flow(flow) instead of freeing it. When
mlx5e_tc_reoffload_flows_work() retries mlx5e_tc_add_fdb_flow(),
mlx5e_attach_encap() runs again from out_index 0, overwriting
flow->encaps[out_index].e and calling list_add() on the already-linked
flow->encaps[out_index].list.
[Severity: Critical]
This problem wasn't introduced by this patch, but can retrying an unready
TUN_RX flow in mlx5e_tc_add_fdb_flow() [2] corrupt r->decap_flows,
leak references, and append duplicate modify-header actions?
In mlx5e_tc_add_fdb_flow(), the TUN_RX handling runs before
post_process_attr():
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:mlx5e_tc_add_fdb_flow() {
...
if (flow_flag_test(flow, TUN_RX)) {
err = mlx5e_attach_decap_route(priv, flow);
if (err)
goto err_out;
if (!attr->chain && esw_attr->int_port &&
attr->action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
...
err = mlx5e_tc_match_to_reg_set(priv->mdev, &parse_attr->mod_hdr_acts,
MLX5_FLOW_NAMESPACE_FDB, VPORT_TO_REG,
metadata);
...
}
}
...
err = post_process_attr(flow, attr, extack);
if (err)
goto err_out;
}
If mlx5e_attach_decap_route() succeeds and post_process_attr() then fails
with -ENETUNREACH on a multipath LAG setup, err_out does not unwind the
TUN_RX state before __mlx5e_add_fdb_flow() calls add_unready_flow(flow).
When mlx5e_tc_reoffload_flows_work() retries mlx5e_tc_add_fdb_flow(),
mlx5e_attach_decap_route() runs a second time on the same flow: for a VF
tunnel decap route it grabs another reference to the mlx5e_route_entry and
calls list_add(&flow->decap_routes, &r->decap_flows) on an already-linked
node, and for an OVS internal port route it overwrites esw_attr->int_port
without releasing the previous reference and appends a duplicate
VPORT_TO_REG action to parse_attr->mod_hdr_acts.
[1] https://sashiko.dev/#/bug/linux-5302f345-b229-43c7-a40a-117aaaf5a0ba
[2] https://sashiko.dev/#/bug/linux-5f514873-9967-4a3f-b7c5-4fc8e750cbf6
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125042323.88050-1-ziyuzhang201@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails
2026-11-25 4:23 [PATCH net] net/mlx5e: Fix deadlock when parsing flow actions fails Ziyu Zhang
2026-11-25 4:26 ` netdev-bot+sinfo
2026-11-26 4:23 ` sashiko-bot
@ 2026-11-29 4:37 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29 4:37 UTC (permalink / raw)
To: ziyuzhang201
Cc: saeedm, tariqt, mbloch, leon, netdev, linux-rdma, linux-kernel,
andrew+netdev, davem, edumazet, kuba, pabeni, roid, baijiaju1990
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The deadlock between encap_tbl_lock and flow->init_done can
still happen after this patch, and in some cases it happens on the…
- [Low] The commit message describes the wrong mechanism for failures in
the checks that parse_tc_fdb_actions() runs after…
- [Low] The new comments state the safety invariant the fix relies on,
but they leave out part of it.
--
net/mlx5e: Fix deadlock when parsing flow actions fails
This patch handles a failure while parsing the actions of an FDB flow.
It first removes the post action rules installed so far. It then marks
the flow FAILED and completes init_done, so neigh and route updaters
waiting on the flow are woken before error cleanup takes encap_tbl_lock
again.
> 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.
[Severity: Low]
Is this the right mechanism for the checks that run after
alloc_flow_post_acts()?
An updater waiting on this flow has already taken a reference in
mlx5e_take_tmp_flow() in en/tc_tun_encap.c:
if (IS_ERR(mlx5e_flow_get(flow))) {
...
wait_for_completion(&flow->del_hw_done);
return;
}
wait_for_completion(&flow->init_done);
So before this patch, err_free -> mlx5e_flow_put() in
__mlx5e_add_fdb_flow() only drops refcnt from 2 to 1. Neither
mlx5e_tc_del_flow() nor mlx5e_detach_encap() runs, and
__mlx5e_add_fdb_flow() returns normally.
In that case the hang looks like a completion that is never signalled,
not a lock cycle. The updater sleeps on init_done forever while holding
encap_tbl_lock, and also rtnl on the neigh path.
If the add path does drop the last reference, mlx5e_flow_get() fails in
the updater. It then waits on del_hw_done instead, which
mlx5e_tc_del_fdb_flow() completes before detaching.
The lock cycle described here only seems to exist for failures inside
alloc_flow_post_acts(), where free_flow_post_acts() takes the lock
directly.
The message also doesn't mention a behaviour change. With the fix, the
woken neigh or route worker usually holds the last reference. It then
runs the full mlx5e_tc_del_flow() teardown from mlx5e_put_flow_list(),
after __mlx5e_add_fdb_flow() has already returned the error.
Could the commit message be updated to describe this?
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index 011741553f5b9..d97612a7190b9 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.
> + */
[Severity: Low]
This isn't a bug, but are these two comments complete?
The route path checks both flags, at different steps. In
en/tc_tun_encap.c, mlx5e_invalidate_encap() and
mlx5e_unoffload_flow_list() check OFFLOADED:
if (!mlx5e_is_offloaded_flow(flow))
continue;
Only mlx5e_reoffload_encap() and mlx5e_reoffload_decap() check FAILED.
The neigh update is also not the only path that releases the encap
header. The route path's mlx5e_invalidate_encap() does too:
if (e->flags & MLX5_ENCAP_ENTRY_VALID) {
e->flags &= ~MLX5_ENCAP_ENTRY_VALID;
mlx5_packet_reformat_dealloc(priv->mdev, e->pkt_reformat);
e->pkt_reformat = NULL;
}
The code is correct today. A failed flow is FAILED and never OFFLOADED,
and the handles are removed before complete_all() whichever updater
wakes.
Could the comments mention both flag checks and the route path dealloc?
[ ... ]
> @@ -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;
> }
[Severity: High]
Can the add thread still deadlock before it reaches this out_free label?
alloc_flow_post_acts() calls post_process_attr() for each post action
attribute in its loop. mlx5e_tc_tun_encap_dests_set() takes and drops
encap_tbl_lock once per attribute, and mlx5e_attach_encap() adds the
flow to e->flows while the lock is held.
Suppose attribute N attaches the flow to encap e1 and drops the lock. A
neigh update or the FIB work can then do:
mlx5e_rep_update_flows() / mlx5e_tc_fib_event_work()
mutex_lock(&esw->offloads.encap_tbl_lock);
mlx5e_take_tmp_flow()
wait_for_completion(&flow->init_done);
Next, attribute N+1 with encap dests reaches:
alloc_flow_post_acts()
post_process_attr()
mlx5e_tc_tun_encap_dests_set()
mutex_lock(&esw->offloads.encap_tbl_lock);
It blocks there before any of its error checks run. The failures in
mlx5e_tc_tun_encap_dests_set() all come after the mutex_lock():
NL_SET_ERR_MSG_MOD(extack, "Requested mirred device not found");
...
err = mlx5e_attach_encap(priv, flow, attr, out_dev, out_index,
extack, &encap_dev);
...
NL_SET_ERR_MSG_MOD(extack, "VF tunnel encap with mirroring is not supported");
So these parse failures would still deadlock. The neigh worker also
holds rtnl, so rtnl would be stuck as well.
A rule like this looks like it creates two post action attributes with
encap dests:
police; tunnel_key set; mirred vxlan0; police; tunnel_key set;
mirred vxlan1
The commit message mentions two successful-setup cases in
mlx5e_tc_add_fdb_flow(): post_process_attr() for the main attribute,
and mlx5e_attach_decap_route() for TUN_RX flows. It doesn't mention
this case inside the alloc_flow_post_acts() loop.
Each place that takes the lock again would need its own early
completion. Would a design change work better? Some options:
- hold encap_tbl_lock across all attaches
- have updaters skip flows that are not yet initialized instead of
sleeping under the mutex
- delay the post action encap attach until init_done is about to be
completed
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125042323.88050-1-ziyuzhang201%40gmail.com
^ permalink raw reply [flat|nested] 4+ messages in thread