Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: ziyuzhang201@gmail.com
Cc: saeedm@nvidia.com, tariqt@nvidia.com, mbloch@nvidia.com,
	leon@kernel.org, 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
Subject: Re: [PATCH net v3] net/mlx5e: Wait for flow setup outside encap_tbl_lock
Date: Tue, 01 Dec 2026 14:27:26 +0000	[thread overview]
Message-ID: <179613524627.3146.8229945560228350466@kernel.org> (raw)
In-Reply-To: <20261130140215.66953-1-ziyuzhang201@gmail.com>

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

      parent reply	other threads:[~2026-12-01 14:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=179613524627.3146.8229945560228350466@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --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 \
    --cc=ziyuzhang201@gmail.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