All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Etienne AUJAMES" <eaujames@ddn.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH] net/mlx5e: preallocate child PKEY channel_stats at init
Date: Fri, 04 Dec 2026 08:38:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-249403@kernel.org> (raw)
In-Reply-To: <axEqaGn--mwLclsc@eaujamesFR0130>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] net/mlx5e: mlx5i_pkey_dev_init() breaks default RTNL IPoIB
  child creation
- [Medium] net/mlx5e: mlx5e_calc_max_nch() ignores profile features and
  underflows
- [Low] net/mlx5e: data race reading parent num_channels in
  mlx5i_pkey_dev_init()
--

commit 44014ff5da47d2578d00e45f3df8f44769c480ac
Author: Etienne AUJAMES <eaujames@ddn.com>

net/mlx5e: preallocate child PKEY channel_stats at init

This commit preallocates child PKEY channel_stats entries in
mlx5i_pkey_dev_init() for the parent's channel count so packets received
on the parent NAPI before mlx5i_pkey_open() do not dereference a NULL
pointer.  It also replaces the child num_rx_queues check with a check that
priv->max_nch is at least the parent's params.num_channels.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c
> index 5edc392475251..577981ae5ecfd 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c

[ ... ]

> @@ -172,15 +174,22 @@ static int mlx5i_pkey_dev_init(struct net_device *dev)
>  		return -EINVAL;
>  	}
>  
> -	if (dev->num_rx_queues < parent_dev->real_num_rx_queues) {
> +	parent_priv = mlx5i_epriv(parent_dev);
> +	nch = parent_priv->channels.params.num_channels;

[Severity: Low]
Is this read of parent_priv->channels.params.num_channels subject to a
data race with mlx5i_set_coalesce()?

mlx5i_pkey_dev_init() runs under rtnl_lock() without holding
netdev_lock(parent_dev) or parent_priv->state_lock.  Because mlx5i_init()
sets netdev->request_ops_lock = true and mlx5i_ethtool_ops.op_needs_rtnl
omits ETHTOOL_OP_NEEDS_RTNL_SCOALESCE, ethtool -C on the parent runs
without rtnl_lock():

CPU0                                CPU1
mlx5i_pkey_dev_init()               mlx5i_set_coalesce()
  /* rtnl_lock() held */              /* netdev_lock(parent_dev) held */
                                      mutex_lock(&parent_priv->state_lock)
                                      mlx5e_switch_priv_params()
  nch = parent_priv->channels
        .params.num_channels;           priv->channels.params = *new_params;
                                          <-- data race

Because struct mlx5e_params is larger than 8 bytes, the struct assignment
compiles to a memcpy that KCSAN reports as a data race even though
num_channels does not change.  Holding parent_priv->state_lock around the
read would serialize it with mlx5e_switch_priv_params().

> +	if (priv->max_nch < nch) {
>  		mlx5_core_warn(priv->mdev,
> -			       "failed to create child device with rx queues [%d] less than parent's [%d]\n",
> -			       dev->num_rx_queues,
> -			       parent_dev->real_num_rx_queues);
> +			       "failed to create child device with max channel count [%d] less than parent's [%d]\n",
> +			       priv->max_nch, nch);
>  		mlx5i_parent_put(dev);
>  		return -EINVAL;
>  	}

[Severity: High]
Does replacing the num_rx_queues check with priv->max_nch < nch break
default netlink creation of IPoIB PKEY child interfaces?

When a child is created with default queue counts (ip link add link
<parent> name <child> type ipoib pkey <pkey>), ipoib_get_max_num_queues()
sets both num_tx_queues and num_rx_queues to min(num_possible_cpus(), 128),
which matches the parent's default num_channels with no extra TX queue
headroom.  During mlx5e_priv_init(), mlx5e_calc_max_nch() unconditionally
subtracts profile->max_tc when MLX5_CAP_GEN(mdev, ts_cqe_to_dest_cqn) is
set (and mlx5e_qos_max_leaf_nodes(mdev) when QoS is supported), even though
mlx5i_pkey_nic_profile supports neither PTP_TX nor QOS_HTB.

Because the parent allocates 8 * nch TX queues in mlx5_rdma_rn_get_params(),
the parent's max_nch is unaffected while the child's priv->max_nch drops to
at most nch - 1.  This regression causes default RTNL child creation to
fail with -EINVAL on ConnectX HCAs advertising ts_cqe_to_dest_cqn.

[Severity: Medium]
Can mlx5e_calc_max_nch() also underflow tmp or reduce priv->max_nch to 0
for profiles that do not enable QOS_HTB or PTP_TX?

drivers/net/ethernet/mellanox/mlx5/core/en_main.c:mlx5e_calc_max_nch() {
	...
	tmp = netdev->num_tx_queues;
	if (mlx5_qos_is_supported(mdev))
		tmp -= mlx5e_qos_max_leaf_nodes(mdev);
	if (MLX5_CAP_GEN(mdev, ts_cqe_to_dest_cqn))
		tmp -= profile->max_tc;
	tmp = tmp / profile->max_tc;
	max_nch = min_t(unsigned int, max_nch, tmp);
	...
}

Unlike mlx5e_get_max_num_txqs(), which gates both reservations on
mlx5e_profile_feature_cap(profile, QOS_HTB) and PTP_TX, these unchecked
unsigned subtractions wrap tmp near UINT_MAX when netdev->num_tx_queues is
smaller than the subtracted reserve (for example, a default RTNL child with
at most 128 queues when mlx5e_qos_max_leaf_nodes(mdev) is 256), bypassing
the TX queue cap.  When num_tx_queues equals the subtracted reserve,
priv->max_nch becomes 0 and mlx5e_attach_netdev() fails in
netif_set_real_num_rx_queues() with -EINVAL.

Gating these subtractions on mlx5e_profile_feature_cap() to match
mlx5e_get_max_num_txqs() and clamping against unsigned underflow would
avoid both the spurious reduction and the wraparound.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/axEqaGn--mwLclsc@eaujamesFR0130?part=1

  parent reply	other threads:[~2026-12-04  8:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 18:24 [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path Etienne AUJAMES
2026-11-25 18:27 ` netdev-bot+sinfo
2026-11-25 19:17   ` Etienne AUJAMES
2026-11-25 18:31 ` sashiko-bot
2026-11-26 14:41 ` Dragos Tatulea
2026-11-27 11:03   ` Etienne AUJAMES
2026-11-27 13:56     ` Dragos Tatulea
2026-11-27 20:31       ` Etienne AUJAMES
2026-12-03 11:00         ` Dragos Tatulea
2026-11-26 18:27 ` netdev-bot+sashiko
2026-12-03  8:38 ` [PATCH] net/mlx5e: preallocate child PKEY channel_stats at init Etienne AUJAMES
2026-12-03 11:10   ` Dragos Tatulea
2026-12-04  8:38   ` sashiko-bot [this message]
2026-12-04  9:15   ` 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=sashiko-outbox-249403@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eaujames@ddn.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.