🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21599

Re: [PATCH net-next V2 1/5] net/mlx5: E-switch, add match-metadata allocator for nested VF/SF eswitches

#21599
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 08:32
176 lines
14607 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · 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).

- [Medium] The layout selector added in
  mlx5_esw_match_metadata_alloc()/mlx5_esw_match_metadata_free() is…
- [Medium] The nested layout makes LAG admission and the encodable range
  disagree.
- [Low] The nested layout cuts the per-eswitch vport id space from 4094
  ids (2-4095) to 254 ids (2-255) (`vport_end_ida = (1 <<…

--

net/mlx5: E-switch, add match-metadata allocator for nested VF/SF eswitches

This patch adds a source-port match metadata allocator for nested (virt
LAG) VF/SF eswitches. Its layout is 8 bits for the function's slot in the
LAG xarray plus 8 bits for a per-eswitch vport id. The nested layout is
used for any non-PF eswitch, except one that is virt LAG capable but not
a LAG member.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
> index 1323114ce7f93..3c1355f910906 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

[ ... ]

> +static u32 mlx5_nested_esw_match_metadata_alloc(struct mlx5_eswitch *esw)
> +{
> +	u32 vport_end_ida = (1 << ESW_NESTED_VPORT_BITS) - 1;
> +	u32 max_idx = (1 << ESW_NESTED_IDX_BITS) -
> +		      (1 << (ESW_NESTED_IDX_BITS - ESW_PFNUM_BITS)) - 1;
> +	int idx;
> +	int id;
> +
> +	idx = mlx5_lag_get_member_idx(esw->dev);
> +	if (idx < 0 || idx > max_idx)
> +		return 0;

[Severity: Medium]
Can a LAG member be given a slot that this check then rejects?

mlx5_ldev_add_mdev() hands out slots 0-254:

    err = xa_alloc(&ldev->fns, &idx, fn, XA_LIMIT(0, U8_MAX - 1),
                   GFP_KERNEL);

but max_idx here comes out to 239. A virt LAG VF/SF that lands in slot
240-254 is still a full member. mlx5_virt_lag_nonmember() returns false
for it, it passes the devcom pairing gate in
mlx5_esw_offloads_devcom_init(), and it gets the nested layout.

For such a member, every metadata allocation on its eswitch returns 0
here. esw_offloads_vport_metadata_setup() turns that 0 into -ENOSPC, so
switchdev can never be enabled on that function, and nothing is logged.

The comment above says only slots 0-239 are usable. Should virt LAG
admission stop at the encodable limit, or refuse such a joiner the same
way a late joiner is refused? Then LAG membership and match capability
would agree.

> +
> +	/* Use only non-zero id's (2-255). */
> +	id = ida_alloc_range(&esw->offloads.vport_metadata_ida,
> +			     MLX5_ESW_METADATA_RSVD_UPLINK + 1,
> +			     vport_end_ida, GFP_KERNEL);
> +	if (id < 0)
> +		return 0;

[Severity: Low]
This shrinks the per-eswitch id space from 2-4095 to 2-255. Does anything
make sure a nested eswitch has fewer vports than that needing metadata?

esw_offloads_metadata_init() allocates metadata up front for every vport,
and unwinds on the first failure:

    mlx5_esw_for_each_vport(esw, i, vport) {
        err = esw_offloads_vport_metadata_setup(esw, vport);
        if (err)
            goto metadata_err;

mlx5_esw_vports_init() creates SF vports from mlx5_sf_max_functions(dev),
and that is not limited to PFs:

    for (i = 0; i < mlx5_sf_max_functions(dev); i++) {
        err = mlx5_esw_vport_alloc(esw, idx, base_sf_num + i);

mlx5e_rep_bond_enslave() and the MPESW metadata take ids from the same
ida.

Suppose a nested VF/SF eswitch manager reports around 254 or more SFs.
The ida runs out, this function quietly returns 0, and switchdev enable
fails with -ENOSPC.

Commit a5bfbdfebd53 describes a non-PF eswitch as just the manager plus
uplink, so this may not be reachable today. Would it still be worth
clamping the vport count, or warning when it doesn't fit the 8-bit field?

> +	id = (idx << ESW_NESTED_VPORT_BITS) | id;
> +	return id;
> +}

[ ... ]

>  u32 mlx5_esw_match_metadata_alloc(struct mlx5_eswitch *esw)
>  {
>  	u32 vport_end_ida = (1 << ESW_VPORT_BITS) - 1;
> @@ -3658,6 +3700,9 @@ u32 mlx5_esw_match_metadata_alloc(struct mlx5_eswitch *esw)
>  	int pf_num;
>  	int id;
>  
> +	if (!mlx5_core_is_pf(esw->dev) && !mlx5_virt_lag_nonmember(esw->dev))
> +		return mlx5_nested_esw_match_metadata_alloc(esw);
> +

[Severity: Medium]
Doesn't this condition also choose the nested layout for non-PF eswitches
that have no virt LAG capability at all?

mlx5_virt_lag_nonmember() is:

    return mlx5_virt_lag_is_supported(dev) && !mlx5_lag_dev(dev);

Take a VF/SF eswitch manager without the virt LAG caps (no
multi_uplink_eswitch/lag_master, or num_lag_ports >= 2). For it,
mlx5_virt_lag_nonmember() returns false, so the condition above is true.

Such a device never gets an ldev, because mlx5_lag_add_mdev() returns
early:

    if (!mlx5_lag_is_supported(dev))
        return;

Later in the series this check becomes !mlx5_lag_is_supported(dev) &&
!mlx5_virt_lag_is_supported(dev), which still excludes the device.

So the call chain would be:

esw_offloads_metadata_init()
  esw_offloads_vport_metadata_setup()
    mlx5_esw_match_metadata_alloc()
      mlx5_nested_esw_match_metadata_alloc()
        mlx5_lag_get_member_idx() returns -ENOENT
      returns 0
    returns -ENOSPC

Match metadata is on by default where it is supported. Would switchdev
enable now fail on these devices?

Before this patch they used the PFNUM layout, where mlx5_sd_pf_num_get()
falls back to mlx5_get_dev_index(), and that worked. Non-PF eswitch
managers have been supported regardless of virt LAG caps since commit
a5bfbdfebd53 ("net/mlx5: E-switch, disable host functions for a non PF
e-switch manager").

The new comment in eswitch.h says this split is for a nested (virt LAG)
VF/SF eswitch. Would a condition that requires LAG membership, such as
!mlx5_core_is_pf(dev) && mlx5_lag_dev(dev), better match that intent?
mlx5_esw_match_metadata_free() uses the same condition.

Separately, at this commit even virt LAG capable VFs/SFs cannot get an
ldev. The later patch "net/mlx5: LAG, enable LAG over functions that do
not represent a physical port" fixes that part. The non virt LAG case is
still there at the end of the series.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120075959.2533702-1-tariqt%40nvidia.com
Technical Details
Message-ID: <179550916784.3135.15503627084704234984@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370105-linux-kernel-netdev=dewy.ru
References: <20261120075959.2533702-2-tariqt@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370105-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next V2 1/5] net/mlx5: E-switch, add match-metadata
 allocator for nested VF/SF eswitches
Date: Tue, 24 Nov 2026 08:32:47 +0000
Organization: Usenet Network
Message-ID: <179550916784.3135.15503627084704234984@kernel.org>
References: <20261120075959.2533702-2-tariqt@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4089129"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:GFrvIJs10T3B1dqRWSjLyVcwOHQ= sha256:K6l81aG42eM6IsLz2wVNHkYUt5lUbWL50GHr6AhUwxE=
	sha1:IX5FsRmiBMEcWg7hQIduQO8KVaw= sha256:GqW4yYtGxbssjIPk4aNbCbmrWtSxLGLrRE+Vw1nZWxs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 0BEDB125DE6; Tue, 24 Nov 2026 11:33:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id tOtGabU8lR98;
	Tue, 24 Nov 2026 11:33:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370105-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id A8F51125DE5; Tue, 24 Nov 2026 11:32:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id AD5BD3718A; Tue, 24 Nov 2026 08:32:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795509170;
	b=srrxGY2rlk3c7jAH39uVBeTQW+wTgI1CKqK3+7sMoqUYRIXAYiu5rnE4x0tgAjY4YmzA
	 rrk9blrB8eMAK8yIdW4rhmBzYKFi/IOld0N6KWcttZIRHF3vsZBZ/rWO01uLwAJ+MTGcY
	 9yxUdoZQF2TrzSjU3xswSWwmz4PLocFIVz6Jo/AoqtN3m02/p7wb03OGKuP1+0uzJod25
	 p7EZKBVnYYErJ20BPA08pvKvOTK9wggz5eTQ3Y9MGC6zvijhejnauNXLsrKjpifUsmyQN
	 KxglkqPSGrioRFAiYiry/OZlh3Kh5jcFH9la+t+cl2XhemJ4YmGdfzJd4UJSNaO0oVw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795509170;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=ECIETRSC6AfeLBZCYkHMk7HlVsPbIuG21c9KJDtowxU=;
	b=QzTnA37kuubthvWgm7oAwnY75ysDDp7/VK9anODznK6RF6yii/VYth+HtY/oyLDsZlUx
	 rdZizHwcUxAE5oW4BNsbpEoiaP9tBCt6dY1ocq0B3K0wS/dk7NF0aDmpXWiwru1K/Qb2h
	 C5FZAUf5IwqLaGz9ZJSHGouzsc87tql/C/rbhaKvzXkuoEayC2kjpKYgXMEqy+mv/kWeE
	 F+VXrRElD+KNwYdr9mEkTCF7wruK8x6Jbe8cO8c2SoiY1Td1wftJigQ1dEZIZC4zsKIoF
	 ACSsvikqw2O7POFxcky0v6Dd/0RS1eskTeZZnNqmGfQ2Pq81bQs4od3puSSGHW17F9w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbrvwFj0;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 99331606A693;
	Tue, 24 Nov 2026 08:32:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbrvwFj0
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795509169;
	b=Cy7rJulIPKlYxdQH8EtHw8ocMkqnLblCthGlSbJu+7TlLQXXzuNm/qPkIZgHbLSRohzg
	 zg/3BQJ04l2trIQuT0nozxccFe+93s1CiayPjn9Q4Ux7izLIIgm1ruwwnV0932z39k7tf
	 wYKSWr/IPTUm/ZEw2WhRWRDE7T0BhFr8eLEeZePMCrQwR4nThWc2EME8RuXnlcDSUCN9A
	 RrEEHOIyXHr1utLhw5oUWbR6vVdNtIzV256F3T2hZh7v0i1WuPG0LlAtOiEyBi6mkfjK9
	 rZ4wOZ8eq70Ny3euPD6NWfgNVHXubbfh8cH+cbjDiD33ghn+aRDiBYKvSR1rknZa2Cw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795509169;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=ECIETRSC6AfeLBZCYkHMk7HlVsPbIuG21c9KJDtowxU=;
	b=Y7iIqg37Uco3ecIVwrcPv2pxHcrUc5AqnKrI/QkwdfOItIEUZ/vhs1LOCMo0SdVKe4VD
	 89BEpBJ4JsdzmTC1GrbASXaYlqkXjaMETk/f60l0pcUZeMO9QWS6d7ZS3rF8xk83Dcda7
	 3ksQAmNK+5t/YwuPfofl472hJWEAWtfu7RSvcwpMkBTty/tmmKoxKddHkeWx664uKdzL3
	 L/TiQKLZ4t8q83G+TpwqwJ6Nu6dh2D8FV/WXLEPmgw7IyWE3PCJqwNQ7zDnKE26xbW2P0
	 8+zU8+Q69O1Q6vgxXYxO9uxxNsTP+IS7+HN2DOnBrhVnR6Nu04QZru90B6fwWaPHFeg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NbrvwFj0;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8723606A33E;
	Tue, 24 Nov 2026 08:32:49 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 492471F00A01;
	Tue, 24 Nov 2026 08:32:48 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795509169;
	bh=ECIETRSC6AfeLBZCYkHMk7HlVsPbIuG21c9KJDtowxU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=NbrvwFj053913BQFODsWdbLKV2SHCt5l1HKw6gcNQFMhoqdb2r5ha4MsRi69SWhCp
	 MXpczA/oZpOdn+mPCTWpv+LHiRVL6SQTt4LiLRqZZXINOKVqelh9CN+NfEijUwQvIq
	 s14J4eUYy8e/B9KHZK0SlcVeFT/rrYjc4H/Fizcln04dr0Cznxmkb7KI2i9AI0d3W5
	 tW7tcTcQ4vZMp6JCkfnfNqBK+jsLm81dguQyD2Unek2UiaE4OCrcHVWUTs0YUVeMGR
	 vurn6n1jjrRxcXk9kgQv9qc9Acv+l1cU3QZ4/hVUXnWQ0gx7szsKpZZueDi9ZWu6/a
	 BUnVqJ+pNTORA==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com,
 agoldberger@nvidia.com, gal@nvidia.com, jgg@ziepe.ca, leon@kernel.org,
 linux-rdma@vger.kernel.org, mbloch@nvidia.com, moshe@nvidia.com,
 ohartoov@nvidia.com, saeedm@nvidia.com, shayd@nvidia.com
X-In-Reply-To: <20261120075959.2533702-2-tariqt@nvidia.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list