๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26397

Re: [PATCH net] net/mlx5: Fix divide by zero when a function has no completion EQs

#26397
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 13:13
116 lines
12423 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: a function with zero completion EQs can
  still load, and the divide by zero is still reachable.
- [Low] The new -EINVAL in alloc_rmap() (eq.c:933-934) does more than
  disable aRFS.

--

net/mlx5: Fix divide by zero when a function has no completion EQs

This patch adds a zero check on max_comp_eqs to the aRFS version of
alloc_rmap(). The check stops a divide by zero in alloc_irq_cpu_rmap() when
an administrator sets max_io_eqs to 0 and ODP is enabled. For non-SF
functions, alloc_rmap() now returns -EINVAL in that case.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> index d11ec263d53c9..0795ee24ad7f2 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
> @@ -930,6 +930,9 @@ static int alloc_rmap(struct mlx5_core_dev *mdev)
>  	if (mlx5_core_is_sf(mdev))
>  		return 0;
>  
> +	if (!eq_table->max_comp_eqs)
> +		return -EINVAL;

[Severity: High]
Does this check close the divide by zero for every function that has
zero completion EQs?

The check is only compiled into the CONFIG_RFS_ACCEL variant of
alloc_rmap(). The other stub still accepts the zero value:

#else
static int alloc_rmap(struct mlx5_core_dev *mdev) { return 0; }

The check also comes after the mlx5_core_is_sf() early return, so SFs
never reach it, whatever the build config.

With max_io_eqs=0 and CONFIG_INFINIBAND_ON_DEMAND_PAGING=y, get_num_eqs()
computes max_num_eqs_24b (0 + 4) minus MLX5_MAX_ASYNC_EQS (4), which is 0.
mlx5_eq_table_create() still succeeds for SFs on any build, and for
PFs/VFs on CONFIG_RFS_ACCEL=n builds. The exported mlx5_comp_vectors_max()
then returns 0 to callers that divide by it:

drivers/vfio/pci/mlx5/cmd.c:mlx5vf_create_cq() {
    ...
	vector = raw_smp_processor_id() % mlx5_comp_vectors_max(mdev);
    ...
}

Here mdev is the PF core dev returned by mlx5_vf_get_core_dev(). This code
runs when VFIO dirty page tracking starts. For example, the ECPF admin sets
max_io_eqs=0 for the host PF, and the host kernel is built without
CONFIG_RFS_ACCEL. The host kernel would then hit a divide error here.

mlx5_ib does the same in drivers/infiniband/hw/mlx5/main.c:

	dev->ib_dev.num_comp_vectors    = mlx5_comp_vectors_max(mdev);

That value then reaches ib_cq_pool_get(), which is used by nvme-rdma,
nvmet-rdma, iser, isert and srpt:

	vector = comp_vector_hint % num_comp_vectors;

It also reaches ipoib_transport_dev_init() in legacy IPoIB:

	cq_attr.comp_vector = req_vec % priv->ca->num_comp_vectors;

Would it be better to reject max_comp_eqs == 0 where it is set, in
mlx5_eq_table_create() or get_num_eqs()? That would cover every config and
every user of mlx5_comp_vectors_max(). The check in this patch only
protects alloc_irq_cpu_rmap(), on aRFS builds, for non-SFs.

[Severity: Low]
The commit message says:

  Handle the zero case by returning an error for non SFs: aRFS
  can't function without it.

This -EINVAL does more than disable aRFS. mlx5_eq_table_create() treats it
as fatal and destroys the async EQs:

	err = alloc_rmap(dev);
	if (err) {
		mlx5_core_err(dev, "Failed to allocate rmap\n");
		goto err_rmap;
	}

mlx5_load() then aborts with "Failed to create EQs". As a result, a VF or
host PF with max_io_eqs=0 no longer loads at all. Meanwhile,
mlx5_devlink_port_fn_max_io_eqs_set() still accepts 0 with only an
overflow check.

Failing the load seems reasonable, because returning 0 here would leave
max_comp_eqs == 0 visible to the mlx5_comp_vectors_max() users mentioned
above.

Could the commit message say that the whole function fails to load? And
could the error message be more specific than "Failed to allocate rmap"?
Nothing actually failed to allocate here; the real cause is the devlink
max_io_eqs setting.

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202130435.3442321-1-tariqt%40nvidia.com
Technical Details
Message-ID: <179630359095.3146.11442998864309690747@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376624-linux-kernel-netdev=dewy.ru
References: <20261202130435.3442321-1-tariqt@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376624-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/mlx5: Fix divide by zero when a function has no
 completion EQs
Date: Thu, 03 Dec 2026 13:13:10 +0000
Organization: Usenet Network
Message-ID: <179630359095.3146.11442998864309690747@kernel.org>
References: <20261202130435.3442321-1-tariqt@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2499581"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7oz1yOAfqFLg+QcYUxgSoNPimPg= sha256:ohE70RQfj2MP+XNFaNNP05Vfa7jrlVxROqXz+27vKss=
	sha1:heKKqwNr/w8G0+7NhfC3oSgn9dI= sha256:QCWyIHEhLjjxYoYKtXAfOlfehJXZQDeHot7InDXSxy0=
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 DF283117958; Thu,  3 Dec 2026 16:13:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.74
X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.24, 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]
	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 SxN8B5UnuSX0;
	Thu,  3 Dec 2026 16:13:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376624-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 A550B117955; Thu,  3 Dec 2026 16:13:17 +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 A112A24E99; Thu,  3 Dec 2026 13:13:14 +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=1796303594;
	b=sQXhN94CmJD4LByOB8BRWZ4uLWRLcjJ4PvzbgtfKRjRdRr9b5e/sWZr7cZzyEkj1Vlup
	 IRbrk+TGmUdPmlmnGmPlnerptXup11o6xirywWa6yxl91XBUh3Y8wVlKkG6HFlNHQe/Lx
	 XTbKYhkfzhdJh6GtNPw7+G4yhLQ4SNxvVeCCYTr05NuhidlsuHHvPu08HZmDGwGSb1W1l
	 lT8zs3LYzxb1VvH0wGl77Wp+wSCjUJMXf8INa84GvXN1dxH8x02qZOxjnrLNITpoHTqiz
	 YwHAWlTwGOxxMHNJoXz67YjnPu4t9uP/5zMzH2KeA3BtOf9K57nAJRyD1F2S3eb2jTQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796303594;
	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=7mDetniSQU3Sn5mP+6WqjQ0eOfF0CsaLrMKNztzEDUw=;
	b=PR8iGRg0ry+kXX90rRBT4weQxov2LkW9yAAzoIIupbjtRhEjsomK8EWUDVLyAyzroT0c
	 z1txfwP5dnGrgOdEkrknzzLXxuVzJ1grGMkOV9xGwkeOMfoWwk0akXKPl7AA5iG//wr0m
	 CauIxBZ3mk02i2Wk/q2VGjmNhU+CiXgAEooHiquY0RcAWT+iCWy91/6WjXnNQYHlhs4Jw
	 XcXe5UmNUzVTSTqRO2+GU+UU83KE+Od639WlAPtAoeM9sCS/NLXsoh+QImxVSLJ7DdUIn
	 RvWE3kaSi6kMs7c/KEyf2E9UekQGvV68v3LreomFuuO1e/pVCTkwTlBpQgw2Qn3Wa+w==
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=Ot5U5Qz+;
	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 EBE93606A338;
	Thu,  3 Dec 2026 13:13:13 +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=Ot5U5Qz+
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=1796303593;
	b=lgLVg5yi6NwfvlUyhECoul8S34D6duQDdJe8Edp9NIvuzgzXJiPgyLWnqPnMPlmeVwrK
	 HbIBNk0yrtI3zSBPX/jPInfamgGa0ajr1KNozMNP12OQuul7VinQ+BuDAgbO6RtJvrM+v
	 wDClAZiDx9SbywjvaBFSVH929BmeP3/7KGWXr2i55OcvZ9WMPEodrvVLQZBM8E9yjuaAA
	 Muhoze3nzefOFLPsTA/WiF8GhHdgbbSWYHVF58Zti+ZDQmoGyH/QPtKxl0smCtgaqBDfm
	 1//nWZp++vBYsKtPrD7WSqa5acMUVUOMCWJr88CjRFP+RGkBoOfAI5+95OmaDXcKhOg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796303593;
	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=7mDetniSQU3Sn5mP+6WqjQ0eOfF0CsaLrMKNztzEDUw=;
	b=xZpmlD8mkYCJSRYYTA8v1jtv4OdW1m4vD2euC9S1Vo18Bt0uALhGW3EPW9HmZdo1D1xg
	 9iUUwdV09Pz0UyVkNTREl9zRrEBJaaf1YuSN06x0R48RQu4VmtonwbDQYAjQCR6dvmzEJ
	 nuSwLTVeh1lLUWEwcNAId4MkTp2PRE6WI9mE9NFzcGo0i9jcDlHbJVHozN4SZkdgMDsZW
	 sBNxPDmVn1PHVfxUlq/PkibjppuQyStHA/3cERJpC87nFL1pekwL6CuHTgO2o3gagSR/D
	 JjE/UQxn2myWGvEtkd7J+HPjIVTUc/Dyu+1RtToDIRKITBSA5vxYULgkVczWqmUAaCQ==
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=Ot5U5Qz+;
	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 16770606A322;
	Thu,  3 Dec 2026 13:13:12 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 794771F000C1;
	Thu,  3 Dec 2026 13:13:11 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796303592;
	bh=7mDetniSQU3Sn5mP+6WqjQ0eOfF0CsaLrMKNztzEDUw=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Ot5U5Qz+96XnuD7/gSiXlONfTa+RKj51m7H9L71ZXKLAjyjFx6rLoFjpaETKxuDc2
	 xuLlvNgHWXhz1KhjdG/IPPSSDClWDGE07O94RleUzGn6daQCAnG5HdAdw5WWq2AF3l
	 uppEQqMHOhbmc9s9UFejbAGOF+ApmgTp21KUyA2lL5jUNZamay21+lQxm8cC2mP23b
	 9NUb3X7ORE6afu8dpEejFGNV3rs/R3hrUMXjkh9Nc+L8NkjuziyET7Tp1wp9ky5d4z
	 /doc/kyvu/rc7YMZa59pP79bWzGon2jebey6HpaLW3YOGAfUIfXouW/9t7hknNW6BH
	 WhvI3amvBxJhQ==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com,
 willemb@google.com, dtatulea@nvidia.com, gal@nvidia.com, jiri@resnulli.us,
 leon@kernel.org, linux-rdma@vger.kernel.org, mbloch@nvidia.com,
 parav@nvidia.com, saeedm@nvidia.com, shshitrit@nvidia.com, shayd@nvidia.com,
 yishaih@nvidia.com
X-In-Reply-To: <20261202130435.3442321-1-tariqt@nvidia.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