* [PATCH net] net/mlx5e: TC, use the owner eswitch for encap neigh updates
@ 2026-11-25 21:06 Tariq Toukan
2026-11-26 21:45 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Tariq Toukan @ 2026-11-25 21:06 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Fernando Fernandez Mancera, Gal Pressman, Ido Schimmel,
Jianbo Liu, Kuniyuki Iwashima, Leon Romanovsky, linux-rdma,
Maor Dickman, Mark Bloch, Nikolay Aleksandrov, Roi Dayan,
Saeed Mahameed, Shay Drory, Tariq Toukan
From: Shay Drory <shayd@nvidia.com>
Encap entries are kept in the encap table of the eswitch of the flows
that use them, while the neigh hash entry is attached to the out_dev
uplink. The neigh update and neigh-used paths took the eswitch from
netdev_priv(e->out_dev), assuming out_dev is always the uplink of the
owner eswitch.
Since MPESW peer flows were added, an encap entry of one eswitch can
route through the uplink of another eswitch. A neigh update on that
uplink then:
- takes the wrong encap_tbl_lock,
- adds the slow path rule to the other eswitch's FDB chains, where it
shares a match with the origin flow's rule, while the flow later
removes it from its own eswitch chains. This unbalances the fs_chains
refcount ("Couldn't find table", leaked flow tables on unload) and
with HWS, which emulates same-match NO_APPEND rules with a single
pending rule, fails the origin's slow path update with -EEXIST,
- allocates the packet reformat on the other device, which the owner
eswitch FDB rejects on HWS.
Record the owner eswitch uplink priv in the encap entry and use it for
flow updates and entry release, keeping out_dev for neigh handling.
Fixes: 8ce81fc01b52 ("net/mlx5e: TC, Add peer flow in mpesw mode")
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Jianbo Liu <jianbol@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c | 2 +-
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 3 ++-
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 7 ++++---
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h | 1 +
4 files changed, 8 insertions(+), 5 deletions(-)
---
Answer to an internal sashiko comment:
Could mlx5e_attach_encap() preserve the owner's initialized profile
resources until all foreign neighbour users have finished?
When an mpesw encap owned by uplink B routes through uplink A, unbinding
B's eth-rep auxiliary device can overlap A's neighbour work. In
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c, mlx5e_rep_remove() reaches
owner profile teardown through:
mlx5_eswitch_unregister_vport_reps()
-> mlx5e_vport_rep_unload()
-> mlx5e_vport_uplink_rep_unload()
-> mlx5e_netdev_change_profile()
Unlike normal eswitch disable, this path does not first synchronously
unpair peers. The peer flow created by mlx5e_tc_add_fdb_peer_flow() in
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c is stored on the originating
flow's peer_flows list, rather than B's tc_ht, so B's table cleanup need
not remove the encap.
In drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c,
mlx5e_rep_neigh_cleanup() drains B's work, not A's callbacks.
mlx5e_rep_neigh_update() on A now passes this borrowed owner to
mlx5e_rep_update_flows() in
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c, which dereferences
priv->mdev->priv.eswitch.
The callback holds the rtnl lock, but mlx5e_netdev_change_profile() in
drivers/net/ethernet/mellanox/mlx5/core/en_main.c performs profile cleanup
after mlx5e_uplink_rep_disable() releases that lock. mlx5e_priv_cleanup()
then clears priv with memset(priv, 0, sizeof(*priv)).
Can A's callback therefore dereference a cleared owner->mdev and oops,
or access destroyed owner tc resources during profile replacement?
mlx5e_tc_update_neigh_used_value() and mlx5e_get_next_matching_encap() in
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c also now use this
owner, including for iterator release. An encap reference or a retained
netdev allocation does not preserve those initialized profile resources.
Could owner teardown synchronously remove these foreign encap users and
wait for their callbacks before resetting the profile?
[SD] The stored priv does not add a new lifetime dependency. It has the
same lifetime as flow->priv of the peer flows attached to the entry,
which mlx5e_tc_add_fdb_peer_flow() creates on the peer uplink priv, and
which the neigh update path already dereferenced before this patch,
e.g. in mlx5e_tc_unoffload_fdb_rules() and get_mod_hdr_table(). All
teardown paths (unload, reload, eswitch mode change, module exit)
unpair the eswitches in esw_offloads_disable(), which removes the peer
flows, before the owner uplink representor is unloaded. The window is
only reachable by a manual eth-rep auxiliary unbind while paired, which
this patch does not change.
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c
index 6a8d8aac7d16..a93138692371 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c
@@ -167,7 +167,7 @@ static void mlx5e_rep_neigh_update(struct work_struct *work)
* the next one.
*/
while ((e = mlx5e_get_next_init_encap(nhe, e)) != NULL)
- mlx5e_rep_update_flows(netdev_priv(e->out_dev), e, neigh_connected, ha);
+ mlx5e_rep_update_flows(e->priv, e, neigh_connected, ha);
out:
rtnl_unlock();
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..d43c1d7d5281 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c
@@ -117,7 +117,8 @@ void mlx5e_rep_update_flows(struct mlx5e_priv *priv,
/* Update the encap source mac, in case that we delete
* the flows when encap source mac changed.
*/
- route_dev = __dev_get_by_index(dev_net(priv->netdev), e->route_dev_ifindex);
+ route_dev = __dev_get_by_index(dev_net(e->out_dev),
+ e->route_dev_ifindex);
if (route_dev)
ether_addr_copy(eth->h_source, route_dev->dev_addr);
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..d23cf60613ea 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
@@ -177,7 +177,7 @@ void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv,
return;
}
e->flags |= MLX5_ENCAP_ENTRY_VALID;
- mlx5e_rep_queue_neigh_stats_work(priv);
+ mlx5e_rep_queue_neigh_stats_work(netdev_priv(e->out_dev));
list_for_each_entry(flow, flow_list, tmp_list) {
if (!mlx5e_is_offloaded_flow(flow) || !flow_flag_test(flow, SLOW))
@@ -348,7 +348,7 @@ mlx5e_get_next_matching_encap(struct mlx5e_neigh_hash_entry *nhe,
/* release starting encap */
if (e)
- mlx5e_encap_put(netdev_priv(e->out_dev), e);
+ mlx5e_encap_put(e->priv, e);
if (!next)
return next;
@@ -401,7 +401,7 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe)
* next one.
*/
while ((e = mlx5e_get_next_valid_encap(nhe, e)) != NULL) {
- struct mlx5e_priv *priv = netdev_priv(e->out_dev);
+ struct mlx5e_priv *priv = e->priv;
struct encap_flow_item *efi, *tmp;
struct mlx5_eswitch *esw;
LIST_HEAD(flow_list);
@@ -871,6 +871,7 @@ int mlx5e_attach_encap(struct mlx5e_priv *priv,
init_completion(&e->res_ready);
entry_created = true;
INIT_LIST_HEAD(&e->route_list);
+ e->priv = netdev_priv(mlx5_eswitch_uplink_get_proto_dev(esw, REP_ETH));
tun_info = mlx5e_dup_tun_info(tun_info);
if (!tun_info) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index bcd7b4e814d0..4be0b9fe94cd 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -211,6 +211,7 @@ struct mlx5e_encap_entry {
struct mlx5e_mpls_info mpls_info;
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
+ struct mlx5e_priv *priv;
struct net_device *out_dev;
int route_dev_ifindex;
struct mlx5e_tc_tunnel *tunnel;
base-commit: cc7fe6e741730fef549e484379281736d32746f0
--
2.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net/mlx5e: TC, use the owner eswitch for encap neigh updates
2026-11-25 21:06 [PATCH net] net/mlx5e: TC, use the owner eswitch for encap neigh updates Tariq Toukan
@ 2026-11-26 21:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26 21:45 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, willemb,
fmancera, gal, idosch, jianbol, kuniyu, leon, linux-rdma, maord,
mbloch, razor, roid, saeedm, shayd
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
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 fix does not record the owner eswitch for encap entries
created on a Socket Direct (SD) secondary eswitch, so the neigh-update…
--
net/mlx5e: TC, use the owner eswitch for encap neigh updates
The neigh update and neigh-used paths used to derive the eswitch from
netdev_priv(e->out_dev). In MPESW, an encap entry of one eswitch can route
through another eswitch's uplink, so that eswitch was not always the owner.
This patch records the owner eswitch uplink priv in the encap entry, uses it
for flow updates and entry release, and keeps out_dev for neigh handling.
> 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..d23cf60613ea7 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
[ ... ]
> @@ -871,6 +871,7 @@ int mlx5e_attach_encap(struct mlx5e_priv *priv,
> init_completion(&e->res_ready);
> entry_created = true;
> INIT_LIST_HEAD(&e->route_list);
> + e->priv = netdev_priv(mlx5_eswitch_uplink_get_proto_dev(esw, REP_ETH));
[Severity: High]
Does this record the owner eswitch for encap entries created on a Socket
Direct secondary eswitch? mlx5_eswitch_uplink_get_proto_dev() redirects to
the SD primary:
void *mlx5_eswitch_uplink_get_proto_dev(struct mlx5_eswitch *esw, u8 rep_type)
{
struct mlx5_core_dev *primary = mlx5_sd_get_primary(esw->dev);
if (primary)
esw = primary->priv.eswitch;
return mlx5_eswitch_get_proto_dev(esw, MLX5_VPORT_UPLINK, rep_type);
}
SD secondaries also have no uplink representor of their own, as the comment
in mlx5_eswitch_reload_ib_reps() says:
/* SD secondary devices share the primary's uplink and do not
* have their own uplink representor. Only load VF/SF vports.
*/
Take a tc flower encap rule added on a VF representor of an SD secondary:
- is_peer_flow_needed() handles this case explicitly via
mlx5_lag_is_sd(in_mdev) && !mlx5_sd_is_primary(in_mdev).
- mlx5e_tc_add_fdb_flow() installs the original flow in the secondary's
chains.
- e goes into the secondary's encap_tbl under the secondary's
encap_tbl_lock.
- mlx5e_tc_tun_create_header_ipv4() allocates e->pkt_reformat on the
secondary mdev.
But e->priv->mdev->priv.eswitch is the SD primary's eswitch.
On a neighbour change, mlx5e_rep_neigh_update() calls
mlx5e_rep_update_flows(e->priv, ...). It looks like that would:
- take the primary's encap_tbl_lock while walking e->flows in
mlx5e_take_all_encap_flows(). Meanwhile mlx5e_attach_encap() and
mlx5e_detach_encap() change the same list under the secondary's lock.
- add and remove the slow path and encap rules through the primary's
fs_chains, for flows whose rules live in the secondary's chains.
- allocate the replacement pkt_reformat on the primary mdev. Later,
mlx5e_detach_encap() frees it through mlx5e_encap_dealloc(priv, e) with
the secondary's priv.
The other converted paths have the same problem. When
mlx5e_get_next_matching_encap() calls mlx5e_encap_put(e->priv, e) on the
last reference, it would take the primary's lock and call hash_del_rcu() on
an entry in the secondary's encap_tbl. mlx5e_tc_update_neigh_used_value()
also walks e->flows under the primary's lock.
For SD, the old netdev_priv(e->out_dev) resolved to the same SD primary
uplink, so this behavior is not new. Still, the problem the commit message
describes stays reachable for SD secondary owners, including SD under MPESW.
Would it work better to record the owner eswitch or mdev directly, for
example priv->mdev->priv.eswitch without the SD primary redirection, instead
of an uplink priv?
>
> tun_info = mlx5e_dup_tun_info(tun_info);
> if (!tun_info) {
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125210629.239095-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 21:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 21:06 [PATCH net] net/mlx5e: TC, use the owner eswitch for encap neigh updates Tariq Toukan
2026-11-26 21:45 ` 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