Re: [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock

From: Tariq Toukan

Date: Tue Dec 01 2026 - 12:15:12 EST




On 30/11/2026 16:02, Ziyu Zhang wrote:
A post action can attach an FDB flow to an encap entry before flow
setup finishes. A neighbour or FIB update can then take encap_tbl_lock
and wait for init_done. For a TUN_RX flow the add path still needs the
same mutex in mlx5e_attach_decap_route(), so even a successful add can
block indefinitely. Parse error cleanup also needs the mutex to detach
the flow.

Wait on the eswitch until all flows attached to the affected entry or
route are ready. Drop encap_tbl_lock while sleeping and rescan the lists
under the mutex before applying the update. A waiter holds no reference
to a partially initialized flow. Failed adds can therefore tear it down
and wake the waiter after detach. Successful adds publish their state
before waking waiters, as do flows retained for multipath retry.

Process the encap entry even if no flow reference could be taken. A new
flow can reuse that entry before the deleting flow detaches, so the FIB
event must invalidate or rebuild its cached header.

unrelated change?

Remove post-action
rules, including an extra split rule, before signalling del_hw_done so
the update can release the reformat object safely.


unrelated change?

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@xxxxxxxxx>
---
Changes in v3:
- Drop encap_tbl_lock while waiting for flow setup in both the neighbour
and FIB update paths. Rescan after wakeup so failed adds can detach.
- Update the encap entry even with an empty flow list and retire
post-action rules before signalling del_hw_done.

v2: https://lore.kernel.org/r/20261126084216.26436-1-ziyuzhang201@xxxxxxxxx

.../ethernet/mellanox/mlx5/core/en/rep/tc.c | 3 ++
.../ethernet/mellanox/mlx5/core/en/tc_priv.h | 2 +-
.../mellanox/mlx5/core/en/tc_tun_encap.c | 43 +++++++++++++++++--
.../net/ethernet/mellanox/mlx5/core/en_tc.c | 27 ++++++++++--
.../net/ethernet/mellanox/mlx5/core/en_tc.h | 1 +
.../net/ethernet/mellanox/mlx5/core/eswitch.c | 1 +
.../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 +
7 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
index e1ebc9b2d061..1522458213bf 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
@@ -103,6 +103,9 @@ void mlx5e_rep_update_flows(struct mlx5e_priv *priv,
if (encap_connected == neigh_connected && ether_addr_equal(e->h_dest, ha))
goto unlock;
+ wait_event_cmd(esw->offloads.encap_flow_wait, mlx5e_encap_flows_ready(e),
+ mutex_unlock(&esw->offloads.encap_tbl_lock),
+ mutex_lock(&esw->offloads.encap_tbl_lock));

How do you bound this wait?

Today the update keeps encap_tbl_lock while it waits, so no new flow
can attach, and it only waits for the flows that are already in setup.

Thanks,
Tariq