Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: tariqt@nvidia.com
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
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	[thread overview]
Message-ID: <179630359095.3146.11442998864309690747@kernel.org> (raw)
In-Reply-To: <20261202130435.3442321-1-tariqt@nvidia.com>

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

      parent reply	other threads:[~2026-12-03 13:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 13:04 [PATCH net] net/mlx5: Fix divide by zero when a function has no completion EQs Tariq Toukan
2026-12-02 13:08 ` netdev-bot+sinfo
2026-12-03 13:28   ` Dragos Tatulea
2026-12-03 13:13 ` netdev-bot+sashiko [this message]

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=179630359095.3146.11442998864309690747@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=edumazet@kernel.org \
    --cc=gal@nvidia.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=parav@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=shayd@nvidia.com \
    --cc=shshitrit@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=willemb@google.com \
    --cc=yishaih@nvidia.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