mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock
@ 2026-11-30 14:02 Ziyu Zhang
  2026-11-30 14:03 ` netdev-bot+sinfo
  2026-12-01 14:27 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Ziyu Zhang @ 2026-11-30 14:02 UTC (permalink / raw)
  To: saeedm, tariqt, mbloch, leon
  Cc: netdev, linux-rdma, linux-kernel, andrew+netdev, davem, edumazet,
	kuba, pabeni, roid, baijiaju1990, ziyuzhang201

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. Remove post-action
rules, including an extra split rule, before signalling del_hw_done so
the update can release the reformat object safely.

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 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@gmail.com

 .../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));
 	mlx5e_take_all_encap_flows(e, &flow_list);
 
 	if ((e->flags & MLX5_ENCAP_ENTRY_VALID) &&
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..c9a04a01243c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h
@@ -110,7 +110,7 @@ struct mlx5e_tc_flow {
 	struct list_head tmp_list; /* temporary flow list used by neigh update */
 	refcount_t refcnt;
 	struct rcu_head rcu_head;
-	struct completion init_done;
+	bool init_done;
 	struct completion del_hw_done;
 	struct mlx5_flow_attr *attr;
 	struct mlx5_flow_attr *extra_split_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 4f9f8beffbc8..59fb5c15c875 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
@@ -283,7 +283,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);
@@ -315,6 +314,40 @@ static void mlx5e_take_all_route_decap_flows(struct mlx5e_route_entry *r,
 		mlx5e_take_tmp_flow(flow, flow_list, 0);
 }
 
+static bool mlx5e_flow_init_done(struct mlx5e_tc_flow *flow)
+{
+	/* Pair with the release in __mlx5e_add_fdb_flow() before using flow state. */
+	return smp_load_acquire(&flow->init_done);
+}
+
+bool mlx5e_encap_flows_ready(struct mlx5e_encap_entry *e)
+{
+	struct encap_flow_item *efi;
+
+	list_for_each_entry(efi, &e->flows, list) {
+		struct mlx5e_tc_flow *flow;
+
+		flow = container_of(efi, struct mlx5e_tc_flow, encaps[efi->index]);
+		if (!mlx5e_flow_init_done(flow))
+			return false;
+	}
+	return true;
+}
+
+static bool mlx5e_route_flows_ready(struct mlx5e_route_entry *r)
+{
+	struct mlx5e_encap_entry *e;
+	struct mlx5e_tc_flow *flow;
+
+	list_for_each_entry(e, &r->encap_entries, route_list)
+		if (!mlx5e_encap_flows_ready(e))
+			return false;
+	list_for_each_entry(flow, &r->decap_flows, decap_routes)
+		if (!mlx5e_flow_init_done(flow))
+			return false;
+	return true;
+}
+
 typedef bool (match_cb)(struct mlx5e_encap_entry *);
 
 static struct mlx5e_encap_entry *
@@ -1594,8 +1627,6 @@ static int mlx5e_update_route_encaps(struct mlx5e_priv *priv,
 		LIST_HEAD(encap_flows);
 
 		mlx5e_take_all_encap_flows(e, &encap_flows);
-		if (list_empty(&encap_flows))
-			continue;
 
 		if (mlx5e_route_entry_valid(r))
 			mlx5e_invalidate_encap(priv, e, &encap_flows);
@@ -1704,6 +1735,12 @@ static void mlx5e_tc_fib_event_work(struct work_struct *work)
 	if (!mlx5e_route_entry_valid(r) && !replace)
 		goto out;
 
+	/* Setup and error unwind both need encap_tbl_lock. Rescan the route
+	 * after waking, before changing any of its entries.
+	 */
+	wait_event_cmd(esw->offloads.encap_flow_wait, mlx5e_route_flows_ready(r),
+		       mutex_unlock(&esw->offloads.encap_tbl_lock),
+		       mutex_lock(&esw->offloads.encap_tbl_lock));
 	err = mlx5e_update_route_encaps(priv, r, &flow_list, replace);
 	if (err)
 		mlx5_core_warn(priv->mdev, "Failed to update route encaps, %d\n",
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 011741553f5b..1688f8951581 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -2063,11 +2063,21 @@ static void free_branch_attr(struct mlx5e_tc_flow *flow, struct mlx5_flow_attr *
 	kfree(attr);
 }
 
+static void mlx5e_del_post_act_handle(struct mlx5e_tc_flow *flow,
+				      struct mlx5_flow_attr *attr)
+{
+	if (attr->post_act_handle) {
+		mlx5e_tc_post_act_del(get_post_action(flow->priv), attr->post_act_handle);
+		attr->post_act_handle = NULL;
+	}
+}
+
 static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
 				  struct mlx5e_tc_flow *flow)
 {
 	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
 	struct mlx5_flow_attr *attr = flow->attr;
+	struct mlx5_flow_attr *post_attr;
 
 	mlx5e_put_flow_tunnel_id(flow);
 
@@ -2079,6 +2089,11 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
 		else
 			mlx5e_tc_unoffload_fdb_rules(esw, flow, attr);
 	}
+	/* An encap update may free the reformat object once del_hw_done fires. */
+	list_for_each_entry(post_attr, &flow->attrs, list)
+		mlx5e_del_post_act_handle(flow, post_attr);
+	if (flow->extra_split_attr)
+		mlx5e_del_post_act_handle(flow, flow->extra_split_attr);
 	complete_all(&flow->del_hw_done);
 
 	if (mlx5_flow_has_geneve_opt(&attr->parse_attr->spec))
@@ -2105,6 +2120,10 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
 	kvfree(attr->esw_attr->rx_tun_attr);
 	kvfree(attr->parse_attr);
 	kfree(flow->attr);
+
+	/* An unpublished flow can disappear without completing setup. */
+	if (!READ_ONCE(flow->init_done))
+		wake_up_all(&esw->offloads.encap_flow_wait);
 }
 
 struct mlx5_fc *mlx5e_tc_get_counter(struct mlx5e_tc_flow *flow)
@@ -4430,8 +4449,7 @@ mlx5_free_flow_attr_actions(struct mlx5e_tc_flow *flow, struct mlx5_flow_attr *a
 	if (!attr)
 		return;
 
-	if (attr->post_act_handle)
-		mlx5e_tc_post_act_del(get_post_action(flow->priv), attr->post_act_handle);
+	mlx5e_del_post_act_handle(flow, attr);
 
 	mlx5e_tc_tun_encap_dests_unset(flow->priv, flow, attr);
 
@@ -4495,7 +4513,6 @@ mlx5e_alloc_flow(struct mlx5e_priv *priv, int attr_size,
 	INIT_LIST_HEAD(&flow->attrs);
 	INIT_LIST_HEAD(&flow->peer_flows);
 	refcount_set(&flow->refcnt, 1);
-	init_completion(&flow->init_done);
 	init_completion(&flow->del_hw_done);
 
 	*__flow = flow;
@@ -4584,7 +4601,6 @@ __mlx5e_add_fdb_flow(struct mlx5e_priv *priv,
 		goto err_free;
 
 	err = mlx5e_tc_add_fdb_flow(priv, flow, extack);
-	complete_all(&flow->init_done);
 	if (err) {
 		if (!(err == -ENETUNREACH && mlx5_lag_is_multipath(in_mdev)))
 			goto err_free;
@@ -4592,6 +4608,9 @@ __mlx5e_add_fdb_flow(struct mlx5e_priv *priv,
 		add_unready_flow(flow);
 	}
 
+	/* Publish the initialized attributes to neighbour and FIB updates. */
+	smp_store_release(&flow->init_done, true);
+	wake_up_all(&priv->mdev->priv.eswitch->offloads.encap_flow_wait);
 	return flow;
 
 err_free:
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h
index e1b8cb78369f..e953a7864408 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.h
@@ -215,6 +215,7 @@ void mlx5e_tc_encap_flows_del(struct mlx5e_priv *priv,
 bool mlx5e_encap_take(struct mlx5e_encap_entry *e);
 void mlx5e_encap_put(struct mlx5e_priv *priv, struct mlx5e_encap_entry *e);
 
+bool mlx5e_encap_flows_ready(struct mlx5e_encap_entry *e);
 void mlx5e_take_all_encap_flows(struct mlx5e_encap_entry *e, struct list_head *flow_list);
 void mlx5e_put_flow_list(struct mlx5e_priv *priv, struct list_head *flow_list);
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 174197f69888..62005751706f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -2571,6 +2571,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
 	esw->mode = MLX5_ESWITCH_LEGACY;
 
 	mutex_init(&esw->offloads.encap_tbl_lock);
+	init_waitqueue_head(&esw->offloads.encap_flow_wait);
 	hash_init(esw->offloads.encap_tbl);
 	mutex_init(&esw->offloads.decap_tbl_lock);
 	hash_init(esw->offloads.decap_tbl);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index 48eb6acc1e87..f969007fc971 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -321,6 +321,7 @@ struct mlx5_esw_offload {
 	struct xarray vport_reps;
 	struct xarray peer_flows;
 	struct mutex peer_mutex;
+	wait_queue_head_t encap_flow_wait;
 	struct mutex encap_tbl_lock; /* protects encap_tbl */
 	DECLARE_HASHTABLE(encap_tbl, 8);
 	struct mutex decap_tbl_lock; /* protects decap_tbl */
-- 
2.39.5 (Apple Git-154)


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

* Re: [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock
  2026-11-30 14:02 [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock Ziyu Zhang
@ 2026-11-30 14:03 ` netdev-bot+sinfo
  2026-12-01 14:27 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-30 14:03 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] 3+ messages in thread

* Re: [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock
  2026-11-30 14:02 [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock Ziyu Zhang
  2026-11-30 14:03 ` netdev-bot+sinfo
@ 2026-12-01 14:27 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 14:27 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 4 potential
issue(s) to consider.

Critical: 0 · High: 2 · Medium: 1 · Low: 1

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 flow's extra-split post-action rule (flow->extra_split_attr)
  keeps pointing at the encap entry's freed pkt_reformat, and the live-…
- [High] Lost wakeup when the flow and the neighbour waiter use different
  eswitches: the neighbour worker can sleep forever in…
- [Medium] The new waits only finish when every flow on the entry or
  route is ready at the same moment, and nothing guarantees that moment…
- [Low] The commit combines three separate fixes under one Fixes: tag.

--

net/mlx5e: Wait for flow setup outside encap_tbl_lock

This patch replaces the per-flow init_done completion with a bool and a
per-eswitch waitqueue. Neighbour and FIB updates now sleep with
encap_tbl_lock dropped until every flow on the affected encap entry or
route is ready. It also processes encap entries that have an empty flow
list, and removes post-action rules (including the extra split rule)
before signalling del_hw_done.

> 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 e1ebc9b2d061d..1522458213bff 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));

[Severity: High]
Can this waiter end up sleeping on a different eswitch's waitqueue than
the one the flow wakes?

Here esw comes from priv. mlx5e_rep_neigh_update() derives priv from
e->out_dev while it holds rtnl_lock:

mlx5e_rep_neigh_update()
    rtnl_lock();
    ...
    while ((e = mlx5e_get_next_init_encap(nhe, e)) != NULL)
        mlx5e_rep_update_flows(netdev_priv(e->out_dev), e, neigh_connected, ha);

get_route_and_out_devs() can return a peer PF's uplink as out_dev.
mlx5e_is_valid_eswitch_fwd_dev() accepts it through is_lag_dev() or
is_multiport_eligible() in multipath/LAG or MPESW setups. The encap entry
and its e->flows list, though, belong to flow->priv's eswitch.

The flow side only wakes the waitqueue of its own eswitch:

__mlx5e_add_fdb_flow()
    smp_store_release(&flow->init_done, true);
    wake_up_all(&priv->mdev->priv.eswitch->offloads.encap_flow_wait);

mlx5e_tc_del_fdb_flow()
    if (!READ_ONCE(flow->init_done))
        wake_up_all(&esw->offloads.encap_flow_wait);

Suppose a flow on PF0 is still being set up, its out_dev is PF1's uplink,
and a neighbour update for the tunnel nexthop arrives. Would the worker
then stay in TASK_UNINTERRUPTIBLE with rtnl_lock held until some
unrelated flow on PF1 happens to be added?

The old per-flow completion did not depend on which eswitch the waiter
used.

The repeated mlx5e_encap_flows_ready() walk also runs under the peer
eswitch's encap_tbl_lock, not the lock that protects e->flows. The
existing list walk in this function already had that problem, but the
rescan loop makes the window larger.

>  	mlx5e_take_all_encap_flows(e, &flow_list);
>  
>  	if ((e->flags & MLX5_ENCAP_ENTRY_VALID) &&
> 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 4f9f8beffbc8d..59fb5c15c875e 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

[ ... ]

> @@ -1594,8 +1627,6 @@ static int mlx5e_update_route_encaps(struct mlx5e_priv *priv,
>  		LIST_HEAD(encap_flows);
>  
>  		mlx5e_take_all_encap_flows(e, &encap_flows);
> -		if (list_empty(&encap_flows))
> -			continue;

[Severity: Low]
This isn't a bug, but the patch seems to put three separate changes under
one Fixes: tag:

  - replacing the init_done completion with a bool plus a waitqueue
  - removing the list_empty() skip here
  - deleting the post-act and extra split handles before
    complete_all(&flow->del_hw_done) in mlx5e_tc_del_fdb_flow()

The list_empty() skip came from 8914add2c9e5, and the extra_split_attr
handling was added by 16bb8c613379. Neither comes from the cited
8300f225268b.

The last two changes fix problems that occur even without an init_done
waiter. Could they go into their own patches with matching Fixes: tags,
so they can be backported, bisected and reverted separately?

>  
>  		if (mlx5e_route_entry_valid(r))
>  			mlx5e_invalidate_encap(priv, e, &encap_flows);
> @@ -1704,6 +1735,12 @@ static void mlx5e_tc_fib_event_work(struct work_struct *work)
>  	if (!mlx5e_route_entry_valid(r) && !replace)
>  		goto out;
>  
> +	/* Setup and error unwind both need encap_tbl_lock. Rescan the route
> +	 * after waking, before changing any of its entries.
> +	 */
> +	wait_event_cmd(esw->offloads.encap_flow_wait, mlx5e_route_flows_ready(r),
> +		       mutex_unlock(&esw->offloads.encap_tbl_lock),
> +		       mutex_lock(&esw->offloads.encap_tbl_lock));

[Severity: Medium]
What guarantees that this wait finishes while new flows keep attaching to
the route?

mlx5e_route_flows_ready() and mlx5e_encap_flows_ready() walk the live
r->encap_entries, e->flows and r->decap_flows lists. While
encap_tbl_lock is dropped, other __mlx5e_add_fdb_flow() callers can
attach new flows with init_done == false through mlx5e_attach_encap() or
mlx5e_attach_decap_route(). Flower offload on reps does not take rtnl.

Each publish wakes the waiter, which can then find another unready flow
and go back to sleep. Consider a steady stream of inserts that share one
tunnel, for example OVS offloading many flows to the same VXLAN remote
from several handler threads. Could this worker then hold rtnl_lock in
TASK_UNINTERRUPTIBLE for as long as the stream lasts?

The new wait in mlx5e_rep_update_flows() follows the same pattern.

The old wait ran under encap_tbl_lock, so the set of flows it waited on
was fixed.

>  	err = mlx5e_update_route_encaps(priv, r, &flow_list, replace);
>  	if (err)
>  		mlx5_core_warn(priv->mdev, "Failed to update route encaps, %d\n",
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> index 011741553f5b9..1688f8951581e 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

[ ... ]

> @@ -2079,6 +2089,11 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
>  		else
>  			mlx5e_tc_unoffload_fdb_rules(esw, flow, attr);
>  	}
> +	/* An encap update may free the reformat object once del_hw_done fires. */
> +	list_for_each_entry(post_attr, &flow->attrs, list)
> +		mlx5e_del_post_act_handle(flow, post_attr);
> +	if (flow->extra_split_attr)
> +		mlx5e_del_post_act_handle(flow, flow->extra_split_attr);
>  	complete_all(&flow->del_hw_done);

[Severity: High]
The commit message says the post-action rules, "including an extra split
rule", are removed "before signalling del_hw_done so the update can
release the reformat object safely". That covers flows being deleted.
What about live flows with an extra split rule during an encap update?

extra_split_attr_dests() struct-copies the dests after split_count into
attr2, including pkt_reformat and the encap flags:

	for (i = split_count, j = 0; i < esw_attr->out_count; i++, j++)
		esw_attr2->dests[j] = esw_attr->dests[i];

attr2 is offloaded as its own post-act rule. It is stored only in
flow->extra_split_attr and is not linked into flow->attrs. Both
mlx5e_tc_unoffload_flow_post_acts() and mlx5e_tc_offload_flow_post_acts()
only walk flow->attrs.

On a neighbour down or MAC change, mlx5e_tc_encap_flows_del() calls
mlx5_packet_reformat_dealloc() on e->pkt_reformat.
mlx5e_invalidate_encap() does the same on a FIB event, and with this
patch it also runs when the flow list is empty. At that point the extra
split rule is still installed and still references the freed reformat.

mlx5e_reoffload_encap() then updates only
mlx5e_tc_get_encap_attr(flow)->esw_attr->dests[]. The extra split rule
is never rebuilt with the new e->pkt_reformat.

Take a rule with split_count > 0 (for example a vlan push) that has both
a plain uplink and an encap mirred after the split. Would the mirrored
copy then be sent through a released reformat object? In HWS/SWS modes
another tunnel could reuse that object.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130140215.66953-1-ziyuzhang201%40gmail.com

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

end of thread, other threads:[~2026-12-01 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 14:02 [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock Ziyu Zhang
2026-11-30 14:03 ` netdev-bot+sinfo
2026-12-01 14:27 ` netdev-bot+sashiko

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®