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: Gal Pressman <gal@nvidia.com>, Leon Romanovsky <leon@kernel.org>,
	<linux-rdma@vger.kernel.org>, Mark Bloch <mbloch@nvidia.com>,
	Moshe Shemesh <moshe@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>, Shay Drori <shayd@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>, Uri Dar <udar@nvidia.com>
Subject: [PATCH net-next V2] net/mlx5: E-Switch, Size FDB peer groups for asymmetric peers
Date: Thu, 3 Dec 2026 23:06:04 +0200	[thread overview]
Message-ID: <20261203210604.4092532-1-tariqt@nvidia.com> (raw)

From: Uri Dar <udar@nvidia.com>

The slow path FDB send-to-vport and peer-miss groups are sized from the
local eswitch total_vports, assuming every eswitch that may pair has the
same number of vports. Per-PF VF configuration (e.g. PF_NUM_OF_VF set
differently per port) breaks that assumption: the larger peer installs
rules sized by its own total_vports into the smaller peer's groups,
which cannot hold them, so pairing fails.

In SW and HW steering the flow table is unbounded (max_fte is INT_MAX)
and flow groups are backed by dynamically grown matchers, so size the
peer dependent groups to the architectural vport maximum. FW steering,
whose table is bounded by log_max_ft_size, keeps the current sizing.

Signed-off-by: Uri Dar <udar@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/eswitch_offloads.c     | 35 ++++++++++++-------
 include/linux/mlx5/eswitch.h                  |  2 ++
 2 files changed, 25 insertions(+), 12 deletions(-)

V2:
- Never size the groups below the local total_vports in SW and HW
  steering, so they are not smaller than before when vport match
  metadata is disabled and total_vports exceeds MLX5_ESW_MAX_VPORT_ID.
- Update the comment at the table_size calculation to describe the new
  group sizing and why it may exceed table_size in SW and HW steering.

V1:
https://lore.kernel.org/all/20261116210917.1297111-1-tariqt@nvidia.com/

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 2072921c1fff..32eae1cd7b3a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -1744,6 +1744,18 @@ esw_chains_destroy(struct mlx5_eswitch *esw, struct mlx5_fs_chains *chains)
 
 #endif
 
+/* SW and HW steering tables are unbounded, so they can be sized for any peer,
+ * and never below the local total_vports.
+ * FW steering is bounded by log_max_ft_size, so it uses local total_vports.
+ */
+static int esw_max_vports(const struct mlx5_eswitch *esw)
+{
+	if (esw->dev->priv.steering->mode == MLX5_FLOW_STEERING_MODE_DMFS)
+		return esw->total_vports;
+
+	return max_t(int, esw->total_vports, MLX5_ESW_MAX_VPORT_ID);
+}
+
 static int
 esw_create_send_to_vport_group(struct mlx5_eswitch *esw,
 			       struct mlx5_flow_table *fdb,
@@ -1771,7 +1783,9 @@ esw_create_send_to_vport_group(struct mlx5_eswitch *esw,
 	}
 
 	/* See comment at table_size calculation */
-	count = MLX5_MAX_PORTS * (esw->total_vports * MAX_SQ_NVPORTS + MAX_PF_SQ);
+	count = MLX5_MAX_PORTS *
+		(esw_max_vports(esw) * MAX_SQ_NVPORTS + MAX_PF_SQ);
+
 	MLX5_SET(create_flow_group_in, flow_group_in, start_flow_index, 0);
 	MLX5_SET(create_flow_group_in, flow_group_in, end_flow_index, *ix + count - 1);
 	*ix += count;
@@ -1841,7 +1855,7 @@ esw_create_peer_esw_miss_group(struct mlx5_eswitch *esw,
 			       u32 *flow_group_in,
 			       int *ix)
 {
-	int max_peer_ports = (esw->total_vports - 1) * (MLX5_MAX_PORTS - 1);
+	int max_peer_ports = (esw_max_vports(esw) - 1) * (MLX5_MAX_PORTS - 1);
 	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
 	struct mlx5_flow_group *g;
 	void *match_criteria;
@@ -1959,16 +1973,13 @@ static int esw_create_offloads_fdb_tables(struct mlx5_eswitch *esw)
 		goto ns_err;
 	}
 
-	/* To be strictly correct:
-	 *	MLX5_MAX_PORTS * (esw->total_vports * MAX_SQ_NVPORTS + MAX_PF_SQ)
-	 * should be:
-	 *	esw->total_vports * MAX_SQ_NVPORTS + MAX_PF_SQ +
-	 *	peer_esw->total_vports * MAX_SQ_NVPORTS + MAX_PF_SQ
-	 * but as the peer device might not be in switchdev mode it's not
-	 * possible. We use the fact that by default FW sets max vfs and max sfs
-	 * to the same value on both devices. If it needs to be changed in the future note
-	 * the peer miss group should also be created based on the number of
-	 * total vports of the peer (currently is also uses esw->total_vports).
+	/* The send-to-vport and peer miss groups also hold rules installed by
+	 * peer eswitches, which may have more vports than this one, so they
+	 * are sized by esw_max_vports(). In FW steering that is the local
+	 * total_vports, matching table_size below, so peers are assumed to
+	 * have the same number of vports. In SW and HW steering the groups
+	 * are sized for any peer and extend past table_size, which is fine
+	 * as those tables are unbounded (max_fte is set to INT_MAX).
 	 */
 	table_size = MLX5_MAX_PORTS * (esw->total_vports * MAX_SQ_NVPORTS + MAX_PF_SQ) +
 		     esw->total_vports * MLX5_MAX_PORTS + MLX5_ESW_MISS_FLOWS;
diff --git a/include/linux/mlx5/eswitch.h b/include/linux/mlx5/eswitch.h
index 06d7d634de0d..fbfecbd67ea5 100644
--- a/include/linux/mlx5/eswitch.h
+++ b/include/linux/mlx5/eswitch.h
@@ -107,6 +107,8 @@ bool mlx5_eswitch_vport_match_metadata_enabled(const struct mlx5_eswitch *esw);
 #define ESW_REG_C0_USER_DATA_METADATA_BITS (32 - ESW_SOURCE_PORT_METADATA_BITS)
 #define ESW_REG_C0_USER_DATA_METADATA_MASK GENMASK(ESW_REG_C0_USER_DATA_METADATA_BITS - 1, 0)
 
+#define MLX5_ESW_MAX_VPORT_ID ((1 << ESW_VPORT_BITS) - 1)
+
 static inline u32 mlx5_eswitch_get_vport_metadata_mask(void)
 {
 	return GENMASK(31, 32 - ESW_SOURCE_PORT_METADATA_BITS);

base-commit: c1165beb053a652299b1503b2dd7674ced0b1596
-- 
2.44.0


             reply	other threads:[~2026-12-03 21:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:06 Tariq Toukan [this message]
2026-12-03 21:17 ` [PATCH net-next V2] net/mlx5: E-Switch, Size FDB peer groups for asymmetric peers sashiko-bot

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=20261203210604.4092532-1-tariqt@nvidia.com \
    --to=tariqt@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gal@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=moshe@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=shayd@nvidia.com \
    --cc=udar@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