๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24940

Re: [PATCH net] net/mlx4: fix missing error code in SR-IOV validation

#24940
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 03:17
151 lines
12935 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท 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 fix is incomplete.
- [Low] The commit message understates the impact and leaves out when the
  bug triggers.

--

net/mlx4: fix missing error code in SR-IOV validation

The patch sets err to -EINVAL when SRIOV_VALID_STATE() fails in the
non-SYS_EQS branch of mlx4_load_one(). Before this, the function jumped
to err_sriov with err still 0 and reported success.

> Otherwise, mlx4_load_one() may return success even though
> SR-IOV initialization failed.

[Severity: Low]
This isn't a bug, but could the commit message describe the impact more
precisely?

When mlx4_load_one() returns 0 here, the err_sriov->err_adev unwind has
already done all of this:

  - disabled SR-IOV
  - decremented pf_loading
  - freed dev_vfs
  - released HCA ownership
  - freed dev_cap
  - cleaned up the adev state

Probe or a reload then reports success for a device that has already
been torn down.

It could also say when SRIOV_VALID_STATE() can fail. As far as I can
tell, the only way is through the failure exits of mlx4_enable_sriov(),
when dev->flags already has MLX4_FLAG_SRIOV set (existing_vfs != 0):

drivers/net/ethernet/mellanox/mlx4/main.c:mlx4_enable_sriov() {
    ...
disable_sriov:
	atomic_dec(&pf_loading);
free_mem:
	dev->persist->num_vfs = 0;
	kfree(dev->dev_vfs);
	dev->dev_vfs = NULL;
	return dev_flags & ~MLX4_FLAG_MASTER;
}

If the dev_vfs allocation fails, for example, this leaves MLX4_FLAG_SRIOV
set without MLX4_FLAG_MASTER.

The Fixes: target 7ae0e400cd93 goes back to 2014. Should this also carry
Cc: stable@vger.kernel.org? Documentation/process/maintainer-netdev.rst
now asks netdev patches to follow the standard stable rules.

> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
> index 036135df23bf1..c3661a346c19e 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
> @@ -3519,6 +3519,7 @@ static int mlx4_load_one(struct pci_dev *pdev, int pci_dev_data,
>  				dev->flags = dev_flags;
>  				if (!SRIOV_VALID_STATE(dev->flags)) {
>  					mlx4_err(dev, "Invalid SRIOV state\n");
> +					err = -EINVAL;
>  					goto err_sriov;
>  				}
>  				err = mlx4_reset(dev);

[Severity: High]
Are there two more SR-IOV validation sites in mlx4_load_one() with the
same problem? Both jump to err_fw while err is still 0 from the
successful mlx4_QUERY_DEV_CAP() just before:

drivers/net/ethernet/mellanox/mlx4/main.c:mlx4_load_one() {
    ...
			err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
			if (err) {
				mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
				goto err_fw;
			}

			if (mlx4_check_dev_cap(dev, dev_cap, nvfs))
				goto err_fw;
    ...
}

The second one is in the legacy-mode else branch, which runs on the
second pass after goto slave_start.

mlx4_check_dev_cap() returns MLX4_DEV_CAP_CHECK_NUM_VFS_ABOVE_64 (-1)
when 64 or more VFs are requested and the firmware lacks
MLX4_DEV_CAP_FLAG2_80_VFS. Both callers drop that value.

The err_fw->err_mfunc->err_cmd->err_sriov->err_adev unwind closes the
firmware and cleans up the command interface. It then frees dev_vfs,
releases ownership, frees dev_cap and calls mlx4_adev_cleanup(). After
that it returns err, which is still 0:

err_sriov:
	...
	kfree(priv->dev.dev_vfs);

	if (!mlx4_is_slave(dev))
		mlx4_free_ownership(dev);

	kfree(dev_cap);

err_adev:
	mlx4_adev_cleanup(dev);
	return err;

__mlx4_init_one() takes the 0 as success, so probe completes and devlink
is registered. mlx4_restart_one_up() also continues into
restore_current_port_types() on the torn-down device.

A later devlink reload then runs
mlx4_devlink_reload_down()->mlx4_restart_one_down()->mlx4_unload_one().
That issues firmware commands through the cleaned-up command interface
and calls mlx4_adev_cleanup() a second time:

drivers/net/ethernet/mellanox/mlx4/intf.c:mlx4_adev_cleanup() {
	struct mlx4_priv *priv = mlx4_priv(dev);

	kfree(priv->adev);
	ida_free(&mlx4_adev_ida, priv->adev_idx);
}

Can this free priv->adev twice and call ida_free() twice on the same id?
If the failure is at the second-pass legacy site, mlx4_unload_one() would
also call kfree(dev->dev_vfs) a second time.

This looks reachable by loading mlx4_core with num_vfs=64 on a ConnectX-2
class device whose firmware lacks MLX4_DEV_CAP_FLAG2_80_VFS.
__mlx4_init_one() accepts that value.

Should both mlx4_check_dev_cap() failure paths also set err, for example
to -EINVAL? Passing the raw -1 through would show up as -EPERM.

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130031453.15554-1-mdshahid03%40gmail.com
Technical Details
Message-ID: <179609503866.3146.730672463716113079@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374671-linux-kernel-netdev=dewy.ru
References: <20261130031453.15554-1-mdshahid03@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374671-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/mlx4: fix missing error code in SR-IOV validation
Date: Tue, 01 Dec 2026 03:17:18 +0000
Organization: Usenet Network
Message-ID: <179609503866.3146.730672463716113079@kernel.org>
References: <20261130031453.15554-1-mdshahid03@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1600752"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:MtH2aNP3/YQahCm0hcUeplBL22U= sha256:lnq/bvAdN4RnWVth20bwkMgPpc9kY+51CwdP/xOUGQE=
	sha1:1WP9c1G9HTenDrfvCaIUDk0s454= sha256:kAS/gJRa9WLHkq39Q8KbhsfjmozBR8g5jzBdjnPyVm8=
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 4207F11721E; Tue,  1 Dec 2026 06:17:39 +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 vZP9sUEzYOsm;
	Tue,  1 Dec 2026 06:17:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374671-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id E48BD117216; Tue,  1 Dec 2026 06:17:25 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 19EA52642F; Tue,  1 Dec 2026 03:17:24 +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=1796095041;
	b=mjIjtY/1A5f7mxMChISrjO++hRMHQeU90281InipojwuWYgd7JSOrj37uyzW7JQI4g5H
	 B4JTUOEqQwylZ8S2C/3uFbOH72zsf7/NHSDqUMmfj0WwIb0ooUqur3zI7L5bFLa6Ii1Bp
	 P/LW9k8pvtwsM/wzbJ1JiWgGiyk6obr61G3tNPklLBIZL23n9uxaYgzvL9y+XnQfJkq7D
	 QtVEGgjs+TuZxkqKxDJlblZprVllBHB1XOZwHcROLUPSHd0xbfFfH7N8MJTnd17ZD3zpK
	 9tmf0hnpz4uI7FGXLp/PwyOEOzpUcTvNwClIzoy8lAHDYnKQHSfA6Odd3b5W5geQEfQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796095041;
	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=xo6+wY6b1YORP79UahtxHT0GFN/uCT1mFYMzMfWOYPc=;
	b=edVGg0afSoNX3SHizpBhXN45aWP3FURn8SBTTWy8vsJnrpM25r27KXin1d4sqER97E+f
	 4NDGbJbeZoYY124EciXhCJQ1tKmd0pgBMm7H640CeMAHV/JurTd7FyFf5Q/tcG3vn2O6q
	 tEdLKyKAIDydtSGb9oFVjd6YBjCh84zoGwpd2a3bcIOPUsVQkix5twVRIk/NEji9ghSi8
	 CIadm/JbujPMw9JQ5aKghzUgEkXg8yfFxQJebNxr7nPYHXyu1E2xhG/6Yh4GBDan8FKzT
	 WaUHP6EtbvHwYUUysZI+x3TbTN6YN7DCD3EbpGMeC2+Ak83+6fAEGqryyDT8qTpTKSA==
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=QhRmfq0n;
	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 1F8E9606A330;
	Tue,  1 Dec 2026 03:17:21 +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=QhRmfq0n
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=1796095040;
	b=I1GEuJzJzGoC2OocO+uvyGMiJgb9xSe3J2TNCj0vN3ohVl1NPSPwZMZDbC+g82a+z4Dn
	 lLYh8qBKUhDp+ucnuyeCDkzWsTy54PMptt7vwmhfeQoDZwHBFSHJC+rE0fOoywwNpMBA1
	 AVWPdH1EP/VixpGuEcxdY7vhW0e77cjdyprCS08X/7lUBWqlOFiFP2zsvc/f19ruPKSZK
	 7AspurC1Sjo41JuO37G9BdNdQE8IBHg3cMfqybhuNGB1cNxLL8YnO5YyD5dDd0Eu/ftpw
	 am45hxRM7D0o9l+ul6fjbsHOmUuAiNJHZ3oJ1yRKdIr6+2AKEWNFAFwvFknu2cKRx0g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796095040;
	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=xo6+wY6b1YORP79UahtxHT0GFN/uCT1mFYMzMfWOYPc=;
	b=Hn9YkPViGqvmTLDKrLcqZjXQoZILBG61BBjR4mM7k2DD06ogF/uKUof8Xf/mC3fAMmLr
	 PVLg6K8b/NyzoRf6gZPg6NrFNclBslZDCtkf6zQXTWBv3NaHjTX4TDF+v0eaOzTLdynaS
	 33hjkWqtQsbiJZXddC4XDMdkrlyj3fQ910WGcN3QvEUAkx3Un5ouAcH3cPTFCMZdujMBz
	 /7pMCeC6Wu5YkYErgByhdNLCL+kqQul2pID89HKGoBxWnO5Okg0wTAv3RI2S95ZbPNNwW
	 qXqXfabdyZjgswrY4gYyenhESaL8miPJTn2WybFZHW6ER6WbjMK2Fv6NHthp9ypItWw==
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=QhRmfq0n;
	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 3C6B5606A31A;
	Tue,  1 Dec 2026 03:17:19 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 260051F00893;
	Tue,  1 Dec 2026 03:17:19 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796095039;
	bh=xo6+wY6b1YORP79UahtxHT0GFN/uCT1mFYMzMfWOYPc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=QhRmfq0n2u+igDX1Pm97CUt3oMILcyEWLDakPPEKlhZ+XeV9X4ICHzo7exfjB9Fwa
	 vVeya1uMfpd7TVV+PO6+gyGRoqq+H2MnuyZdWy9KJBRtfNVBuXZYNct+gTYg1Lgu/A
	 Faejjd6+sVFb+Cp1ZgCTwRpJvKL2aLnqLKlqb3IowdsoBGoZfZTHCGUF+fvhHlp7Lu
	 Yhc1y4eidcMH8IqSoMeHL5e2GDaOEPi91F9rTlPJT52K5rGt04Iq/nSNPW/WrOIa27
	 V8ZBKsvignpAA7vZso6EsXIhIbYZ558CgFMQq1pc6GsfuuL7xshKPeVGoTfQZev37a
	 TCRp4sPs5kGAA==
X-Cc: tariqt@nvidia.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, matanb@mellanox.com,
 ogerlitz@mellanox.com, jackm@dev.mellanox.co.il, netdev@vger.kernel.org,
 linux-rdma@vger.kernel.org
X-In-Reply-To: <20261130031453.15554-1-mdshahid03@gmail.com>
X-sashiko-severity: High
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