Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Tariq Toukan <tariqt@nvidia.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: Fernando Fernandez Mancera <fmancera@suse.de>,
	Gal Pressman <gal@nvidia.com>, Ido Schimmel <idosch@nvidia.com>,
	Jianbo Liu <jianbol@nvidia.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Leon Romanovsky <leon@kernel.org>, <linux-rdma@vger.kernel.org>,
	Maor Dickman <maord@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	Roi Dayan <roid@nvidia.com>, Saeed Mahameed <saeedm@nvidia.com>,
	Shay Drory <shayd@nvidia.com>, Tariq Toukan <tariqt@nvidia.com>
Subject: [PATCH net] net/mlx5e: TC, use the owner eswitch for encap neigh updates
Date: Wed, 25 Nov 2026 23:06:29 +0200	[thread overview]
Message-ID: <20261125210629.239095-1-tariqt@nvidia.com> (raw)

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


             reply	other threads:[~2026-11-25 21:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 21:06 Tariq Toukan [this message]
2026-11-26 21:07 ` [PATCH net] net/mlx5e: TC, use the owner eswitch for encap neigh updates sashiko-bot
2026-11-26 21:45 ` netdev-bot+sashiko

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=20261125210629.239095-1-tariqt@nvidia.com \
    --to=tariqt@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fmancera@suse.de \
    --cc=gal@nvidia.com \
    --cc=idosch@nvidia.com \
    --cc=jianbol@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=maord@nvidia.com \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=roid@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=shayd@nvidia.com \
    --cc=willemb@google.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