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, cjubran@nvidia.com, gal@nvidia.com,
	linux-kernel@vger.kernel.org, shshitrit@nvidia.com
Subject: Re: [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver
Date: Fri, 04 Dec 2026 21:45:45 +0000	[thread overview]
Message-ID: <179642074583.3146.8829437478058646288@kernel.org> (raw)
In-Reply-To: <20261203205721.4090361-2-tariqt@nvidia.com>

Thank you for your contribution! Sashiko AI review found 10 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 6 · Low: 4

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] mlx5_core's fw_reset.c already lists PCI device 0xc2d6 in
  mgt_ifc_device_ids as "BlueField4 MGT interface device ID".
- [Medium] mlx5_nodnic_update_carrier() calls netif_carrier_event()
  whenever the queried port state matches the current carrier state.
- [Medium] In this patch, mlx5_nodnic_close_locked() ->
  mlx5_nodnic_close_queues() frees the FW working buffer, CQ ring, CQ…
- [Medium] net/mlx5: unvalidated log_max_ring_size shift in
  mlx5_nodnic_calc_ring_size()
- [Medium] net/mlx5: unvalidated log_cq_size overflow in
  mlx5_nodnic_init_cq_ring()
- [Medium] net/mlx5: unvalidated UAR shift and BAR0 bounds in
  mlx5_nodnic_init_uar_map()
- [Low] nodnic_ifc.h declares working_buffer_addr_l in
  mlx5_ifc_nodnic_port_settings_bits as a plain 32-bit address dword (u8…
- [Low] mlx5_nodnic_wait_fw_init() is meant to tolerate up to
  MLX5_NODNIC_FW_INIT_TIMEOUT_MS (120 s) of FW initialization ('pre-…
- [Low] mlx5_nodnic_read_mac_address() combines two FW-provided dwords
  (MLX5_NODNIC_PORT_MAC_ADDR_H/L) with u64_to_ether_addr(), and…
- [Low] net/mlx5: nodnic: unused definitions and over-exported local
  helpers

--

net/mlx5: nodnic: Introduce the mlx5_nodnic driver

This adds mlx5_nodnic, a PCI netdev driver for DRAM-less ConnectX NIC
functions. The device is configured through a VSC config-space gateway.
The patch implements probe/remove (FLR, FW readiness, interface
negotiation, caps discovery), ring/CQ/working-buffer setup, a link event
IRQ, and ndo_open/ndo_stop.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
> new file mode 100644
> index 0000000000000..738722671090b
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c

[ ... ]

> +int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_ring *work_buf = &dev->priv->working_buffer;
> +	u32 size = SZ_1K << dev->log_working_buffer_size;
> +	int err;
> +
> +	err = mlx5_nodnic_alloc_ring(dev, work_buf, size);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_write_ring_addr(dev, work_buf->dma_handle,
> +					  MLX5_NODNIC_PORT_WORK_BUF_ADDR_H,
> +					  MLX5_NODNIC_PORT_WORK_BUF_ADDR_L);

[Severity: Low]
Does this use the right layout for working_buffer_addr_l? In
nodnic_ifc.h it is declared as a plain 32-bit dword:

	u8 working_buffer_addr_l[0x20];

mlx5_nodnic_write_ring_addr() treats it as nodnic_q_addr_l instead. It
reads the register back, sets only the top 20 bits:

	MLX5_SET(nodnic_q_addr_l, &addr_l, q_addr_l,
		 lower_32_bits(dma_handle) >> 12);

and then writes back whatever the device returned in the low 12 bits.

cq_dbr_addr_l is also a plain dword, and mlx5_nodnic_init_cq_dbr()
writes it as a full lower_32_bits() value.

Is either the register definition or the accessor wrong here? If the low
12 bits read back as nonzero, the working buffer address given to FW
would not match the buffer that was allocated.

> +	if (err)
> +		goto err_free_working_buffer;

[ ... ]

> +static void mlx5_nodnic_close_queues(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_priv *priv = dev->priv;
> +
> +	mlx5_nodnic_free_ring(dev, &priv->working_buffer);
> +	mlx5_nodnic_close_cq(&priv->cq);
> +	mlx5_nodnic_close_rq(dev);
> +	mlx5_nodnic_close_sq(dev);
> +	mlx5_nodnic_free_dbr(dev, &priv->dbr);
> +}

[Severity: Medium]
Can the device still DMA into these buffers after they are freed? This
frees the working buffer, CQ ring, CQ DBR, SQ/RQ rings and the shared DBR
while their bus addresses are still programmed in the NODNIC config
registers. In this patch nothing disables the port or clears bus
mastering first.

Later in the series, "net/mlx5: nodnic: Implement data path" adds
mlx5_nodnic_deactivate_queues() -> mlx5_nodnic_quiesce_port(). That
clears dma_en/network_en, or calls pci_clear_master() if that fails,
before close_queues(). This covers the rings, CQ and DBRs.

The working buffer is still an open question at the end of the series.
It is the FW's own backing store ("for FW use only"). It is freed on
every ndo_stop while the function stays in NO_DRAM_NIC mode with bus
mastering still enabled.

The remove path has the same ordering:

mlx5_nodnic_remove_one()
    mlx5_nodnic_cleanup_netdev()
        unregister_netdev() -> ndo_stop -> mlx5_nodnic_close_queues()
            mlx5_nodnic_free_ring(dev, &priv->working_buffer)
    mlx5_nodnic_dev_cleanup()
        mlx5_nodnic_write_nic_interface(dev, ..._INTERFACE_DISABLED)
        mlx5_nodnic_wait_fw_init(dev, "teardown")

So FW runs its NODNIC teardown, and also spends the time between close
and the next open, with working_buffer_addr pointing at memory that has
already gone back to the allocator.

Is FW access to the working buffer gated by the port dma_en bit, or by
the NODNIC interface state? If it is the interface state, should the
working buffer be freed only after the interface is disabled and FW
teardown has completed?

> +
> +static void mlx5_nodnic_update_carrier(struct mlx5_nodnic_priv *priv,
> +				       __be32 event)
> +{
> +	u32 port_state = MLX5_GET(nodnic_port_event, &event, port_state);
> +	bool up = port_state == MLX5_NODNIC_PORT_STATE_ACTIVE;
> +
> +	/* Force re-notification if state is unchanged */
> +	if (up == netif_carrier_ok(priv->netdev)) {
> +		netif_carrier_event(priv->netdev);
> +		return;
> +	}

[Severity: Medium]
Will this report a link flap on every ifup while the link is down?

This function is also reached from the synchronous open path:

mlx5_nodnic_open_locked()
    mlx5_nodnic_refresh_carrier_locked()
        mlx5_nodnic_update_carrier()

Carrier is always off at that point, because both
mlx5_nodnic_create_netdev() and mlx5_nodnic_close_locked() call
netif_carrier_off(). If port_state is not active, up is false and equals
netif_carrier_ok(), so netif_carrier_event() runs. That increments both
carrier_up_count and carrier_down_count and fires a linkwatch event,
although the link never changed.

The forced re-notification only seems meaningful for the async event IRQ
path. This behaviour is the same at the end of the series.

> +	if (up) {
> +		netif_carrier_on(priv->netdev);
> +		netdev_info(priv->netdev, "Link up\n");

[ ... ]

> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
> new file mode 100644
> index 0000000000000..b905deda56dcd
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c

[ ... ]

> +static int mlx5_nodnic_wait_fw_init(struct mlx5_nodnic_core_dev *dev,
> +				    const char *init_state)
> +{

[ ... ]

> +	do {
> +		err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
> +		if (err)
> +			return err;

[Severity: Low]
Should an acquire failure here be retried until end, rather than ending
the wait? The loop is meant to allow up to
MLX5_NODNIC_FW_INIT_TIMEOUT_MS (120 s), but any failure from
mlx5_nodnic_vsc_context_acquire() returns immediately.

mlx5_nodnic_vsc_gw_lock() gives up with -EBUSY after VSC_MAX_RETRIES
iterations of usleep_range(1000, 2000), which is roughly 2-4 seconds.
mlx5_nodnic_vsc_gw_set_space() returns -EINVAL if the control status
field reads 0.

Suppose the VSC gateway is briefly busy or unavailable while FW is still
initializing, for example right after pcie_flr(). Then
mlx5_nodnic_dev_init(), and so probe, would fail after a few seconds
rather than waiting out the full timeout.

In the "teardown" call from mlx5_nodnic_dev_cleanup(), the error is
ignored. mlx5_nodnic_pci_close() then runs without confirming that FW
has left the initializing state.

> +
> +		err = mlx5_nodnic_get_fw_initializing(dev, &fw_initializing);
> +		mlx5_nodnic_vsc_context_release(dev->vsc_ctx);

[ ... ]

> +int mlx5_nodnic_read_mac_address(struct mlx5_nodnic_core_dev *dev)
> +{

[ ... ]

> +	mac = ((u64)mac_h << 32) | mac_l;
> +
> +	u64_to_ether_addr(mac, dev->mac_address);
> +
> +	return 0;
> +}

[Severity: Low]
What happens if FW reports an all-zero, multicast or broadcast address
here? The value goes straight to eth_hw_addr_set() in
mlx5_nodnic_build_netdev() and is never checked with
is_valid_ether_addr(). The netdev ops also lack an ndo_validate_addr,
so dev_open() will not reject it either.

mlx5e already expects zero MACs from FW and falls back to
eth_hw_addr_random() in mlx5e_set_netdev_dev_addr(). Would something
similar fit here, or should probe fail instead?

[ ... ]

> +static const struct pci_device_id mlx5_nodnic_core_pci_table[] = {
> +	{ PCI_VDEVICE(MELLANOX, 0xc2d6) }, /* BlueField-4 nodnic rshim PF */
> +	{ }
> +};

[Severity: Medium]
How does this interact with mlx5_core sync FW reset? mlx5_core already
lists this ID in mgt_ifc_device_ids in
drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c:

	{ PCI_VDEVICE(MELLANOX, 0xc2d6) }, /* BlueField4 MGT interface device ID */

When mlx5_check_dev_ids() checks that every function under the bridge
is a PF of the device, it skips this ID. So mlx5_core will ack and run
a sync FW reset with this function present:

mlx5_sync_reset_request_event()
    mlx5_is_reset_now_capable()
        mlx5_check_dev_ids()        <- skips 0xc2d6
mlx5_sync_pci_reset()
    mlx5_pci_link_toggle()
        pci_save_state() / pci_cfg_access_lock() on each sibling
        pcie_capability_set_word(bridge, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_LD)
        ...
        pci_restore_state()

The link toggle resets every function below the bridge, including the
one mlx5_nodnic drives. Restoring config space does not bring back the
device-internal NODNIC state:

  - nic_interface set to NO_DRAM_NIC
  - the ring, CQ, DBR and working buffer addresses written through VSC
  - the port network enable bits

mlx5_nodnic_core_driver only has probe and remove, with no err_handler
and no reset_prepare/reset_done. The driver is not told about the reset
and keeps MLX5_NODNIC_STATE_OPENED set.

Reset notification hooks alone would not cover this either. The link
toggle writes LNKCTL directly and never calls the PCI core reset
callbacks.

Later in the series, "net/mlx5: nodnic: Add health monitoring" makes
this worse. During the toggle, iseg MMIO reads return 0xffffffff, or
nic_state reads as disabled or sw reset. dev->state then latches
NODNIC_DEVICE_STATE_INTERNAL_ERROR and nothing clears it. After that,
mlx5_nodnic_open_locked() fails with -EIO until the driver is unbound
and rebound.

With this driver bound, does the assumption in mlx5_core that nothing
in the kernel drives 0xc2d6 still hold? Is some coordination needed
between fw_reset.c and this driver across a sync reset?

> +
> +MODULE_DEVICE_TABLE(pci, mlx5_nodnic_core_pci_table);

[ ... ]

> @@ -0,0 +1,841 @@
> +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
> +// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +
> +#include <linux/bitops.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/etherdevice.h>
> +#include <linux/ethtool.h>
> +#include <linux/interrupt.h>
> +#include <linux/log2.h>
> +#include <linux/pci.h>
> +#include <linux/sizes.h>
> +#include <net/netdev_lock.h>
> +#include <net/net_namespace.h>
> +
> +#include "en.h"
> +#include "nodnic_ifc.h"
> +#include "nodnic.h"
> +#include "nodnic_pci_vsc.h"
> +
> +#define MLX5_NODNIC_CQ_INIT_CMD_SN cpu_to_be32(2 << 28)
> +
> +static int mlx5_nodnic_write_ring_addr(struct mlx5_nodnic_core_dev *dev,
> +				       dma_addr_t dma_handle, u32 offset_h,
> +				       u32 offset_l)
> +{
> +	__be32 addr_h, addr_l;
> +	int err;
> +
> +	addr_h = cpu_to_be32(upper_32_bits(dma_handle));
> +	err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset_h, addr_h);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write ring addr high: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset_l, &addr_l);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev, "failed to read ring addr low: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	MLX5_SET(nodnic_q_addr_l, &addr_l, q_addr_l,
> +		 lower_32_bits(dma_handle) >> 12);
> +
> +	err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset_l, addr_l);
> +	if (err)
> +		mlx5_nodnic_core_err(dev, "failed to write ring addr low: %d\n",
> +				     err);
> +	return err;
> +}
> +
> +static u32 mlx5_nodnic_calc_ring_size(struct mlx5_nodnic_core_dev *dev,
> +				      int stride)
> +{
> +	u32 ring_size = MLX5_NODNIC_RING_ENTRIES * stride;
> +	u32 max_supported = 1U << dev->log_max_ring_size;
> +
> +	return min(ring_size, max_supported);
> +}
> +
> +static int mlx5_nodnic_write_ring_size(struct mlx5_nodnic_core_dev *dev,
> +				       int offset, int size)
> +{
> +	__be32 addr_l;
> +	int err;
> +
> +	err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset, &addr_l);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev, "failed to read ring size: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	MLX5_SET(nodnic_q_addr_l, &addr_l, log_size, ilog2(size));
> +
> +	err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset, addr_l);
> +	if (err)
> +		mlx5_nodnic_core_err(dev, "failed to write ring size: %d\n",
> +				     err);
> +	return err;
> +}
> +
> +static int mlx5_nodnic_read_qn(struct mlx5_nodnic_core_dev *dev,
> +			       struct mlx5_nodnic_ring *ring, u32 offset)
> +{
> +	__be32 qn_dword;
> +	int err;
> +
> +	err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset, &qn_dword);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev, "failed to read queue number: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	ring->qn = MLX5_GET(nodnic_ring_q_number, &qn_dword, queue_number);
> +
> +	return 0;
> +}
> +
> +static int mlx5_nodnic_write_ring_dbr_addr(struct mlx5_nodnic_core_dev *dev,
> +					   u32 ring_offset)
> +{
> +	int off_h = ring_offset + MLX5_NODNIC_RING_DBR_ADDR_H;
> +	int off_l = ring_offset + MLX5_NODNIC_RING_DBR_ADDR_L;
> +	struct mlx5_nodnic_dbr *dbr = &dev->priv->dbr;
> +	__be32 dbr_h, dbr_l;
> +	int err;
> +
> +	dbr_l = 0;
> +	MLX5_SET(nodnic_ring_dbr_addr_l, &dbr_l, db_record_addr_l,
> +		 (u32)(dbr->dma_handle >> 2));
> +	err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, off_l, dbr_l);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write ring DBR addr low: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	dbr_h = cpu_to_be32(upper_32_bits(dbr->dma_handle));
> +	err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, off_h, dbr_h);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write ring DBR addr high: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	return 0;
> +}
> +
> +static int mlx5_nodnic_alloc_ring(struct mlx5_nodnic_core_dev *dev,
> +				  struct mlx5_nodnic_ring *ring, int size)
> +{
> +	dma_addr_t dma_handle;

[Severity: Low]
Some code in this patch is dead, and some has wider scope than it
needs. Both stay that way through the end of the series.

struct mlx5_nodnic_working_buffer is never used.
mlx5_nodnic_priv::working_buffer is a struct mlx5_nodnic_ring, and
nothing else refers to this type.

mlx5_nodnic_vsc_cfg_write_cpu32() is defined, and declared in
nodnic_pci_vsc.h, but nothing in the series calls it.

The helpers listed under the VSC-gated helpers comment in nodnic.h are
only called from the file that defines them. In en_cfg.c these are
mlx5_nodnic_open_rq(), mlx5_nodnic_open_sq(), mlx5_nodnic_open_cq(),
mlx5_nodnic_init_working_buffer(), mlx5_nodnic_enable_port() and
mlx5_nodnic_disable_port(). In main.c they are
mlx5_nodnic_get_fw_initializing(), mlx5_nodnic_set_nic_interface(),
mlx5_nodnic_check_supported(), mlx5_nodnic_write_nic_interface(),
mlx5_nodnic_read_config(), mlx5_nodnic_validate_port_link_type() and
mlx5_nodnic_read_mac_address().

Could these be made static and the declarations dropped? The note that
the caller must hold the VSC context could stay as a comment on the
definitions. mlx5_nodnic_enable_port() and mlx5_nodnic_disable_port()
have no callers at all in this patch. They would fit better in the
patch that first uses them.

> +	void *buf;
> +
> +	buf = dma_alloc_coherent(dev->device, size, &dma_handle, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	*ring = (struct mlx5_nodnic_ring) {
> +		.wq		= buf,
> +		.dma_handle	= dma_handle,
> +		.size		= size,
> +	};
> +
> +	return 0;
> +}
> +
> +static void mlx5_nodnic_free_ring(struct mlx5_nodnic_core_dev *dev,
> +				  struct mlx5_nodnic_ring *ring)
> +{
> +	dma_free_coherent(dev->device, ring->size, ring->wq,
> +			  ring->dma_handle);
> +	memset(ring, 0, sizeof(*ring));
> +}
> +
> +static int mlx5_nodnic_init_ring(struct mlx5_nodnic_core_dev *dev,
> +				 struct mlx5_nodnic_ring *ring, u32 ring_offset,
> +				 int stride)
> +{
> +	int ring_addr_h = ring_offset + MLX5_NODNIC_RING_ADDR_H;
> +	int ring_addr_l = ring_offset + MLX5_NODNIC_RING_ADDR_L;
> +	int size, err;
> +
> +	size = mlx5_nodnic_calc_ring_size(dev, stride);
> +
> +	err = mlx5_nodnic_alloc_ring(dev, ring, size);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_write_ring_addr(dev, ring->dma_handle, ring_addr_h,
> +					  ring_addr_l);
> +	if (err)
> +		goto err_ring_free;
> +
> +	err = mlx5_nodnic_write_ring_size(dev, ring_addr_l, size);
> +	if (err)
> +		goto err_ring_free;
> +
> +	ring->num_entries = size / stride;
> +
> +	err = mlx5_nodnic_read_qn(dev, ring,
> +				  ring_offset + MLX5_NODNIC_RING_QUEUE_NUMBER);
> +	if (err)
> +		goto err_ring_free;
> +
> +	err = mlx5_nodnic_write_ring_dbr_addr(dev, ring_offset);
> +	if (err)
> +		goto err_ring_free;
> +
> +	return 0;
> +
> +err_ring_free:
> +	mlx5_nodnic_free_ring(dev, ring);
> +	return err;
> +}
> +
> +static int mlx5_nodnic_alloc_dbr(struct mlx5_nodnic_core_dev *dev,
> +				 struct mlx5_nodnic_dbr *dbr)
> +{
> +	const u32 bytes = MLX5_NODNIC_DBR_WORDS * sizeof(__be32);
> +	dma_addr_t dma_handle;
> +	void *buf;
> +
> +	buf = dma_alloc_coherent(dev->device, bytes, &dma_handle, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	*dbr = (struct mlx5_nodnic_dbr) {
> +		.db		= (__be32 *)buf,
> +		.alloc_size	= bytes,
> +		.dma_handle	= dma_handle,
> +	};
> +
> +	return 0;
> +}
> +
> +static void mlx5_nodnic_free_dbr(struct mlx5_nodnic_core_dev *dev,
> +				 struct mlx5_nodnic_dbr *dbr)
> +{
> +	if (!dbr->db)
> +		return;
> +
> +	dma_free_coherent(dev->device, dbr->alloc_size, dbr->db,
> +			  dbr->dma_handle);
> +}
> +
> +static int mlx5_nodnic_init_cq_dbr(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_dbr *dbr = &dev->priv->cq.dbr;
> +	__be32 dbr_h, dbr_l;
> +	int err;
> +
> +	err = mlx5_nodnic_alloc_dbr(dev, dbr);
> +	if (err)
> +		return err;
> +
> +	dbr_l = cpu_to_be32(lower_32_bits(dbr->dma_handle));
> +	err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx,
> +					     MLX5_NODNIC_CQ_DBR_ADDR_L,
> +					     dbr_l);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write CQ DBR addr low: %d\n",
> +				     err);
> +		goto err_free_dbr;
> +	}
> +
> +	dbr_h = cpu_to_be32(upper_32_bits(dbr->dma_handle));
> +	err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx,
> +					     MLX5_NODNIC_CQ_DBR_ADDR_H,
> +					     dbr_h);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write CQ DBR addr high: %d\n",
> +				     err);
> +		goto err_free_dbr;
> +	}
> +
> +	dev->priv->cq.dbr.db[1] = MLX5_NODNIC_CQ_INIT_CMD_SN;
> +
> +	return 0;
> +
> +err_free_dbr:
> +	mlx5_nodnic_free_dbr(dev, &dev->priv->cq.dbr);
> +	return err;
> +}
> +
> +static void mlx5_nodnic_cleanup_cq_dbr(struct mlx5_nodnic_core_dev *dev)
> +{
> +	mlx5_nodnic_free_dbr(dev,  &dev->priv->cq.dbr);
> +}
> +
> +/* log_cq_size should be read after rq and sq ring sizes were set. */
> +static int mlx5_nodnic_read_cq_ring_size(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_cq *cq = &dev->priv->cq;
> +	__be32 cq_addr_l;
> +	u32 log_cq_size;
> +	int err;
> +
> +	err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx,
> +					    MLX5_NODNIC_PORT_CQ_ADDR_L,
> +					    &cq_addr_l);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev, "failed to read CQ ring size: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	log_cq_size = MLX5_GET(nodnic_q_addr_l, &cq_addr_l, log_size);
> +	cq->num_entries = 1ULL << log_cq_size;

[Severity: Medium]
Can the CQ size computed here overflow? log_size is a 6-bit field, and
mlx5_nodnic_read_cq_ring_size() does not check it before shifting.
cq->num_entries is a signed int. A log_cq_size of 31 makes it INT_MIN,
and for 32 and above the 64-bit result is truncated to 0.

The multiplication in mlx5_nodnic_init_cq_ring() overflows even
earlier. cq->num_entries * MLX5_NODNIC_CQE_SIZE_B is a signed int
product, so log_cq_size == 25 already gives 2^31. That is undefined,
and in practice it becomes INT_MIN. The negative int is then passed as
the size to mlx5_nodnic_alloc_ring() and sign-extended to a huge size_t
in dma_alloc_coherent(). For larger values the product wraps to 0. We
then get either a zero-size allocation or a CQ with zero entries
programmed into the device.

This does not need misbehaving FW. Suppose the device drops off the bus
during ndo_open. Config reads then return 0xffffffff, which
mlx5_nodnic_vsc_wait_on_flag(ctx, 1) accepts as a completed read, and
log_size reads as 63.

What is the largest CQ size the device can legitimately report? Should
log_cq_size be range-checked here? Should num_entries and the size
argument to mlx5_nodnic_alloc_ring() also be unsigned?

> +	cq->log_num_entries = log_cq_size;
> +
> +	return 0;
> +}
> +
> +static int mlx5_nodnic_init_cq_ring(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_cq *cq = &dev->priv->cq;
> +	struct mlx5_nodnic_ring *ring;
> +	int err;
> +
> +	ring = &cq->ring;
> +
> +	err = mlx5_nodnic_read_cq_ring_size(dev);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_alloc_ring(dev, ring,
> +				     cq->num_entries * MLX5_NODNIC_CQE_SIZE_B);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_write_ring_addr(dev, ring->dma_handle,
> +					  MLX5_NODNIC_PORT_CQ_ADDR_H,
> +					  MLX5_NODNIC_PORT_CQ_ADDR_L);
> +	if (err)
> +		goto err_free_cq;
> +
> +	return 0;
> +
> +err_free_cq:
> +	mlx5_nodnic_free_ring(dev, &cq->ring);
> +	return err;
> +}
> +
> +static void mlx5_nodnic_cleanup_cq_ring(struct mlx5_nodnic_core_dev *dev)
> +{
> +	mlx5_nodnic_free_ring(dev, &dev->priv->cq.ring);
> +}
> +
> +static int mlx5_nodnic_read_cq_n(struct mlx5_nodnic_core_dev *dev)
> +{
> +	__be32 cq_n;
> +	int err;
> +
> +	err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, MLX5_NODNIC_CQ_N,
> +					    &cq_n);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev, "failed to read CQ number: %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	dev->priv->cq.cqn = MLX5_GET(nodnic_cqn, &cq_n, cq_n);
> +
> +	return 0;
> +}
> +
> +int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_ring *work_buf = &dev->priv->working_buffer;
> +	u32 size = SZ_1K << dev->log_working_buffer_size;
> +	int err;
> +
> +	err = mlx5_nodnic_alloc_ring(dev, work_buf, size);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_write_ring_addr(dev, work_buf->dma_handle,
> +					  MLX5_NODNIC_PORT_WORK_BUF_ADDR_H,
> +					  MLX5_NODNIC_PORT_WORK_BUF_ADDR_L);
> +	if (err)
> +		goto err_free_working_buffer;
> +
> +	return 0;
> +
> +err_free_working_buffer:
> +	mlx5_nodnic_free_ring(dev, work_buf);
> +	return err;
> +}
> +
> +int mlx5_nodnic_open_cq(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_cq *cq = &dev->priv->cq;
> +	int err;
> +
> +	cq->cc = 0;
> +
> +	err = mlx5_nodnic_init_cq_ring(dev);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_init_cq_dbr(dev);
> +	if (err)
> +		goto err_cleanup_ring;
> +
> +	err = mlx5_nodnic_read_cq_n(dev);
> +	if (err)
> +		goto err_cleanup_dbr;
> +
> +	return 0;
> +
> +err_cleanup_dbr:
> +	mlx5_nodnic_cleanup_cq_dbr(dev);
> +err_cleanup_ring:
> +	mlx5_nodnic_cleanup_cq_ring(dev);
> +	return err;
> +}
> +
> +static void mlx5_nodnic_close_cq(struct mlx5_nodnic_cq *cq)
> +{
> +	struct mlx5_nodnic_core_dev *dev =
> +		container_of(cq, struct mlx5_nodnic_priv, cq)->core_dev;
> +
> +	mlx5_nodnic_cleanup_cq_dbr(dev);
> +	mlx5_nodnic_cleanup_cq_ring(dev);
> +}
> +
> +int mlx5_nodnic_open_sq(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_priv *priv = dev->priv;
> +	struct mlx5_nodnic_sq *sq = &priv->sq;
> +	struct mlx5_nodnic_ring *ring;
> +	int err;
> +
> +	sq->netdev = priv->netdev;
> +	sq->device = dev->device;
> +	sq->pc = 0;
> +	sq->cc = 0;
> +	ring = &sq->ring;
> +
> +	err = mlx5_nodnic_init_ring(dev, ring, MLX5_NODNIC_SEND_RING_OFFSET,
> +				    MLX5_NODNIC_SQ_WQEBB_B);
> +	if (err)
> +		return err;
> +
> +	ring->lkey = dev->lkey;
> +
> +	return 0;
> +}
> +
> +static void mlx5_nodnic_close_sq(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_sq *sq = &dev->priv->sq;
> +
> +	mlx5_nodnic_free_ring(dev, &sq->ring);
> +}
> +
> +int mlx5_nodnic_open_rq(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_rq *rq = &dev->priv->rq;
> +	struct mlx5_nodnic_ring *ring;
> +	int err;
> +
> +	rq->pc = 0;
> +	rq->cc = 0;
> +	ring = &rq->ring;
> +
> +	err = mlx5_nodnic_init_ring(dev, ring, MLX5_NODNIC_RECEIVE_RING_OFFSET,
> +				    MLX5_NODNIC_RQ_STRIDE_BYTES);
> +	if (err)
> +		return err;
> +
> +	ring->lkey = dev->lkey;
> +
> +	return 0;
> +}
> +
> +static void mlx5_nodnic_close_rq(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_rq *rq = &dev->priv->rq;
> +
> +	mlx5_nodnic_free_ring(dev, &rq->ring);
> +}
> +
> +static int mlx5_nodnic_open_queues(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
> +	int err;
> +
> +	/* one doorbell record shared by both SQ and RQ */
> +	err = mlx5_nodnic_alloc_dbr(dev, &dev->priv->dbr);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
> +	if (err)
> +		goto err_free_dbr;
> +
> +	err = mlx5_nodnic_open_sq(dev);
> +	if (err)
> +		goto err_release_vsc;
> +
> +	err = mlx5_nodnic_open_rq(dev);
> +	if (err)
> +		goto err_close_sq;
> +
> +	err = mlx5_nodnic_open_cq(dev);
> +	if (err)
> +		goto err_close_rq;
> +
> +	err = mlx5_nodnic_init_working_buffer(dev);
> +	if (err)
> +		goto err_close_cq;
> +
> +	mlx5_nodnic_vsc_context_release(vsc_ctx);
> +
> +	return 0;
> +
> +err_close_cq:
> +	mlx5_nodnic_close_cq(&dev->priv->cq);
> +err_close_rq:
> +	mlx5_nodnic_close_rq(dev);
> +err_close_sq:
> +	mlx5_nodnic_close_sq(dev);
> +err_release_vsc:
> +	mlx5_nodnic_vsc_context_release(vsc_ctx);
> +err_free_dbr:
> +	mlx5_nodnic_free_dbr(dev, &dev->priv->dbr);
> +
> +	return err;
> +}
> +
> +static void mlx5_nodnic_close_queues(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_priv *priv = dev->priv;
> +
> +	mlx5_nodnic_free_ring(dev, &priv->working_buffer);
> +	mlx5_nodnic_close_cq(&priv->cq);
> +	mlx5_nodnic_close_rq(dev);
> +	mlx5_nodnic_close_sq(dev);
> +	mlx5_nodnic_free_dbr(dev, &priv->dbr);
> +}
> +
> +static void mlx5_nodnic_update_carrier(struct mlx5_nodnic_priv *priv,
> +				       __be32 event)
> +{
> +	u32 port_state = MLX5_GET(nodnic_port_event, &event, port_state);
> +	bool up = port_state == MLX5_NODNIC_PORT_STATE_ACTIVE;
> +
> +	/* Force re-notification if state is unchanged */
> +	if (up == netif_carrier_ok(priv->netdev)) {
> +		netif_carrier_event(priv->netdev);
> +		return;
> +	}
> +	if (up) {
> +		netif_carrier_on(priv->netdev);
> +		netdev_info(priv->netdev, "Link up\n");
> +	} else {
> +		netif_carrier_off(priv->netdev);
> +		netdev_info(priv->netdev, "Link down\n");
> +	}
> +}
> +
> +static int mlx5_nodnic_refresh_carrier_locked(struct mlx5_nodnic_priv *priv)
> +{
> +	struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> +	struct mlx5_nodnic_vsc_ctx *vsc_ctx;
> +	__be32 event;
> +	int err;
> +
> +	vsc_ctx = dev->vsc_ctx;
> +	err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_vsc_cfg_read_be32(vsc_ctx, MLX5_NODNIC_PORT_EVENT,
> +					    &event);
> +	mlx5_nodnic_vsc_context_release(vsc_ctx);
> +
> +	if (!err)
> +		mlx5_nodnic_update_carrier(priv, event);
> +
> +	return err;
> +}
> +
> +void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv)
> +{
> +	mutex_lock(&priv->state_lock);
> +	if (test_bit(MLX5_NODNIC_STATE_OPENED, &priv->state))
> +		mlx5_nodnic_refresh_carrier_locked(priv);
> +	mutex_unlock(&priv->state_lock);
> +}
> +
> +int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
> +	__be32 val = 0;
> +	int err;
> +
> +	/* data_msix_en, event_msix_en must be set before activating port */
> +	MLX5_SET(nodnic_port_network, &val, data_msix_en, 1);
> +	MLX5_SET(nodnic_port_network, &val, event_msix_en, 1);
> +	err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> +					     val);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write port network (msix): %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	MLX5_SET(nodnic_port_network, &val, network_en, 1);
> +	MLX5_SET(nodnic_port_network, &val, receive_filter_en, BIT(0));
> +
> +	err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> +					     val);
> +	if (err) {
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write port network (enable): %d\n",
> +				     err);
> +		return err;
> +	}
> +
> +	/* Enable bus mastering only now, after the writes above, so the
> +	 * device can't resume DMA with stale state.
> +	 */
> +	pci_set_master(dev->pdev);
> +
> +	/* dma enabling requires a separate write */
> +	MLX5_SET(nodnic_port_network, &val, dma_en, 1);
> +
> +	err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> +					     val);
> +	if (err)
> +		mlx5_nodnic_core_err(dev,
> +				     "failed to write port network (dma): %d\n",
> +				     err);
> +
> +	return err;
> +}
> +
> +void mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
> +	__be32 val;
> +	int err;
> +
> +	err = mlx5_nodnic_vsc_cfg_read_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> +					    &val);
> +	if (err)
> +		goto out;
> +
> +	MLX5_SET(nodnic_port_network, &val, dma_en, 0);
> +	MLX5_SET(nodnic_port_network, &val, network_en, 0);
> +	err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> +					     val);
> +	if (err)
> +		goto out;
> +
> +	/* data_msix_en, event_msix_en can't be modified while port is active */
> +	MLX5_SET(nodnic_port_network, &val, data_msix_en, 0);
> +	MLX5_SET(nodnic_port_network, &val, event_msix_en, 0);
> +	err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> +					     val);
> +
> +out:
> +	if (err)
> +		mlx5_nodnic_core_warn(dev,
> +				      "failed to read/write to vsc err %d\n",
> +				      err);
> +}
> +
> +static int mlx5_nodnic_init_uar_map(struct mlx5_nodnic_core_dev *dev)
> +{
> +	void __iomem *base;
> +	phys_addr_t paddr;
> +	u32 uar_page_size;
> +
> +	uar_page_size = 1U << dev->log_uar_page_size;
> +
> +	paddr = dev->bar_addr +
> +		((phys_addr_t)dev->send_ring0_uar_index * uar_page_size);
> +
> +	base = ioremap(paddr, uar_page_size);

[Severity: Medium]
Are the FW-supplied values checked before they are used to build this
mapping? log_uar_page_size is an 8-bit field that
mlx5_nodnic_read_uar_size() stores without any check. So
1U << dev->log_uar_page_size is undefined for values of 32 and above.
send_ring0_uar_index is a full 32-bit value, also unchecked, from
mlx5_nodnic_read_uar_index().

paddr is computed as dev->bar_addr plus index * page size. It goes to
ioremap() without a check for overflow, and without a check that the
range lies inside BAR 0. A bad value maps whatever sits at that
physical address, outside the region claimed by pci_request_regions().
dev->uar_base is also where the TX doorbell is meant to be written.

A surprise link drop can produce such values. In
mlx5_nodnic_read_config(), suppose reads start returning 0xffffffff
after mlx5_nodnic_read_cqe_format(). mlx5_nodnic_validate_feature_caps()
then passes, because every required capability bit reads as set.
log_uar_page_size becomes 0xff and send_ring0_uar_index 0xffffffff.

The iseg mapping in mlx5_nodnic_pci_init() has a similar gap.
ioremap(dev->bar_addr, sizeof(*dev->iseg)) never checks that
pci_resource_len(pdev, 0) is at least sizeof(*dev->iseg).

Would it make sense to validate the UAR offset and size against
pci_resource_len(dev->pdev, 0) in mlx5_nodnic_read_config()? A bad
value would then fail probe rather than the first ndo_open.

> +	if (!base) {
> +		mlx5_nodnic_core_err(dev, "failed to map UAR\n");
> +		return -ENOMEM;
> +	}
> +
> +	dev->uar_base = base;
> +
> +	return 0;
> +}
> +
> +static void mlx5_nodnic_cleanup_uar_map(struct mlx5_nodnic_core_dev *dev)
> +{
> +	if (!dev->uar_base)
> +		return;
> +
> +	iounmap(dev->uar_base);
> +	dev->uar_base = NULL;
> +}
> +
> +static int mlx5_nodnic_open_locked(struct net_device *netdev)
> +{
> +	struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> +	struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> +	int err;
> +
> +	err = mlx5_nodnic_init_uar_map(dev);
> +	if (err)
> +		return err;
> +
> +	err = mlx5_nodnic_open_queues(dev);
> +	if (err)
> +		goto err_uar;
> +
> +	set_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
> +
> +	err = mlx5_nodnic_refresh_carrier_locked(priv);
> +	if (err)
> +		netdev_err(netdev, "Failed to query carrier, err=%d\n", err);
> +
> +	return 0;
> +
> +err_uar:
> +	mlx5_nodnic_cleanup_uar_map(dev);
> +	return err;
> +}
> +
> +int mlx5_nodnic_open(struct net_device *netdev)
> +{
> +	struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> +	int err;
> +
> +	mutex_lock(&priv->state_lock);
> +	err = mlx5_nodnic_open_locked(netdev);
> +	mutex_unlock(&priv->state_lock);
> +
> +	return err;
> +}
> +
> +static int mlx5_nodnic_close_locked(struct net_device *netdev)
> +{
> +	struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> +	struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> +
> +	clear_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
> +	netif_carrier_off(netdev);
> +	netdev_info(netdev, "Link down\n");
> +	mlx5_nodnic_close_queues(dev);
> +
> +	return 0;
> +}
> +
> +int mlx5_nodnic_close(struct net_device *netdev)
> +{
> +	struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> +	int err = 0;
> +
> +	mutex_lock(&priv->state_lock);
> +	if (!test_bit(MLX5_NODNIC_STATE_OPENED, &priv->state)) {
> +		mutex_unlock(&priv->state_lock);
> +		return 0;
> +	}
> +
> +	err = mlx5_nodnic_close_locked(netdev);
> +	mutex_unlock(&priv->state_lock);
> +
> +	mlx5_nodnic_cleanup_uar_map(priv->core_dev);
> +
> +	return err;
> +}
> +
> +static const struct net_device_ops mlx5_nodnic_netdev_ops = {
> +	.ndo_open		= mlx5_nodnic_open,
> +	.ndo_stop		= mlx5_nodnic_close,
> +};
> +
> +void mlx5_nodnic_build_netdev(struct net_device *netdev)
> +{
> +	struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> +	struct mlx5_nodnic_core_dev *core_dev;
> +
> +	core_dev = priv->core_dev;
> +
> +	SET_NETDEV_DEV(netdev, core_dev->device);
> +
> +	netdev->netdev_ops = &mlx5_nodnic_netdev_ops;
> +	netdev->request_ops_lock = true;
> +
> +	eth_hw_addr_set(netdev, core_dev->mac_address);
> +}
> +
> +static void mlx5_nodnic_init_priv(struct mlx5_nodnic_priv *priv,
> +				  struct net_device *netdev,
> +				  struct mlx5_nodnic_core_dev *core_dev)
> +{
> +	priv->netdev = netdev;
> +	priv->core_dev = core_dev;
> +	mutex_init(&priv->state_lock);
> +}
> +
> +static void mlx5_nodnic_cleanup_priv(struct mlx5_nodnic_priv *priv)
> +{
> +	mutex_destroy(&priv->state_lock);
> +}
> +
> +struct net_device *mlx5_nodnic_create_netdev(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_priv *priv;
> +	struct net_device *netdev;
> +
> +	netdev = alloc_etherdev_mqs(sizeof(struct mlx5_nodnic_priv), 1, 1);
> +	if (!netdev)
> +		return NULL;
> +
> +	priv = netdev_priv(netdev);
> +	mlx5_nodnic_init_priv(priv, netdev, dev);
> +	dev->priv = priv;
> +
> +	netif_carrier_off(netdev);
> +	netif_tx_disable(netdev);
> +	dev_net_set(netdev, &init_net);
> +
> +	return netdev;
> +}
> +
> +void mlx5_nodnic_cleanup_netdev(struct mlx5_nodnic_core_dev *dev)
> +{
> +	struct mlx5_nodnic_priv *priv;
> +	struct net_device *netdev;
> +
> +	if (!dev->priv)
> +		return;
> +
> +	priv = dev->priv;
> +	netdev = priv->netdev;
> +	if (!netdev)
> +		return;
> +
> +	if (dev->netdev_registered) {
> +		netif_device_detach(netdev);
> +		unregister_netdev(netdev);
> +		dev->netdev_registered = false;
> +	}
> +
> +	mlx5_nodnic_cleanup_priv(priv);
> +	dev->priv = NULL;
> +
> +	free_netdev(netdev);
> +}

[Severity: Medium]
Is log_max_ring_size bounded anywhere? It is a 6-bit field, and
mlx5_nodnic_read_ring_config() stores it into dev->log_max_ring_size
without any check. Here it becomes the shift count for a 32-bit value,
so 1U << dev->log_max_ring_size is undefined for any value of 32 or
above. On x86 the shift count is masked, so a reported 32 gives
max_supported = 1.

Values inside the valid shift range can also go wrong. Anything below
ilog2(stride), which is 6 for the SQ and 4 for the RQ, makes size
smaller than one stride. mlx5_nodnic_init_ring() then sets
ring->num_entries = size / stride = 0 and does not fail. If size ends
up 0, we also pass 0 to dma_alloc_coherent() and call ilog2(0) in
mlx5_nodnic_write_ring_size().

A zero-entry ring breaks any num_entries - 1 masking once the data path
is added. Nothing later in the series validates this value.

What range does the spec allow for log_max_ring_size? Should
mlx5_nodnic_read_config() reject values outside it? That way a bad
capability fails probe instead of producing a broken ring on ndo_open.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203205721.4090361-1-tariqt%40nvidia.com

  reply	other threads:[~2026-12-04 21:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 20:57 [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver Tariq Toukan
2026-12-04 21:45   ` netdev-bot+sashiko [this message]
2026-12-03 20:57 ` [PATCH net-next V4 2/5] net/mlx5: nodnic: Implement data path Tariq Toukan
2026-12-04 21:45   ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 3/5] net/mlx5: nodnic: Add TX/RX statistics Tariq Toukan
2026-12-04 21:45   ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 4/5] net/mlx5: nodnic: Add ethtool driver info Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 5/5] net/mlx5: nodnic: Add health monitoring Tariq Toukan
2026-12-04 21:45   ` netdev-bot+sashiko

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=179642074583.3146.8829437478058646288@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=cjubran@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gal@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shshitrit@nvidia.com \
    --cc=tariqt@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