Netdev List
 help / color / mirror / Atom feed
From: Dragos Tatulea <dtatulea@nvidia.com>
To: Etienne AUJAMES <eaujames@ddn.com>,
	Tariq Toukan <tariqt@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>, Mark Bloch <mbloch@nvidia.com>
Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	Feng Liu <feliu@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	COURRIER Guillaume <guillaume.courrier@cea.fr>,
	Jean-Francois LASSIGNARDIE <jean-francois.lassignardie@bull.com>
Subject: Re: [PATCH] net/mlx5e: preallocate child PKEY channel_stats at init
Date: Thu, 3 Dec 2026 12:10:03 +0100	[thread overview]
Message-ID: <8a4034fb-64f1-4693-b73f-c3c0eb1331db@nvidia.com> (raw)
In-Reply-To: <axEqaGn--mwLclsc@eaujamesFR0130>

On 03.12.26 09:38, Etienne AUJAMES wrote:
> mlx5i_complete_rx_cqe() uses the parent's rq->ix to index the child PKEY
> priv's channel_stats[]. The child's entries are allocated lazily in
> mlx5e_open_channels(), called from mlx5i_pkey_open(). Once the QPN is
> attached by mlx5_fs_add_rx_underlay_qpn(), the parent's NAPI can receive
> packets for the child before its channel_stats entries exist, and
> dereferences a NULL pointer.
> 
> This issue has been hit in production with a MOFED 24.10:
>  crash> bt -s
>  PID: 0  CPU: 42   COMMAND: "swapper/42"
> ...
>   #7 page_fault+30
>      [exception RIP: mlx5i_handle_rx_cqe+308]
>   #8 mlx5e_poll_rx_cq+154  [mlx5_core]
>   #9 mlx5e_napi_poll+240  [mlx5_core]
>  #10 __napi_poll+45
>  #11 net_rx_action+594
>  #12 __softirqentry_text_start+220
>  #13 irq_exit_rcu+198
>  #14 irq_exit+10
>  #15 do_IRQ+127
> 
>  crash> bt -s 4970
>  PID: 4970 CPU: 49   COMMAND: "ip"
> ...
>   #3 wait_for_completion_timeout+141
>   #4 cmd_exec+2460  [mlx5_core]
>   #5 mlx5_cmd_do+30  [mlx5_core]
>   #6 mlx5_cmd_exec+23  [mlx5_core]
>   #7 mlx5_core_modify_cq+99  [mlx5_core]
>   #8 mlx5_core_modify_cq_moderation+107  [mlx5_core]
>   #9 mlx5e_open_cq+249  [mlx5_core]
>  #10 mlx5e_open_channels+1437  [mlx5_core]
>  #11 mlx5i_pkey_open+157  [mlx5_core]
>  #12 ipoib_ib_dev_open+102  [ib_ipoib]
>  #13 ipoib_open+61  [ib_ipoib]
>  #14 __dev_open+209
>  #15 __dev_change_flags+437
>  #16 dev_change_flags+33
>  #17 do_setlink+2008
>  #18 __rtnl_newlink+1285
>  #19 rtnl_newlink+67
>  #20 rtnetlink_rcv_msg+693
>  #21 netlink_rcv_skb+84
>  #22 netlink_unicast+410
>  #23 netlink_sendmsg+516
> 
> Preallocate the child's channel_stats for the parent's channel count in
> mlx5i_pkey_dev_init(), before the QPN is added to the hash table. The
> parent's channel count cannot change while it has sub-interfaces
> (806a8df7126a), so this covers every rq->ix the parent can use.
> 
> Also reject a child whose max_nch, the size of channel_stats[], is lower
> than the parent's channel count (params.num_channels). This replaces the
> num_rx_queues check: max_nch is never larger than num_rx_queues, and it
> also catches a max_nch reduced below the parent's channel count by
> mlx5e_calc_max_nch().
> 
> Fixes: b5e23931c45a ("net/mlx5e: IPoIB, Fix child PKEY interface stats on rx path")
> Signed-off-by: Etienne AUJAMES <eaujames@ddn.com>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/en.h  |  1 +
>  .../net/ethernet/mellanox/mlx5/core/en_main.c | 29 +++++++++++++++++++
>  .../mellanox/mlx5/core/ipoib/ipoib_vlan.c     | 17 ++++++++---
>  3 files changed, 43 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
> index a3945195f454..069ade83dd48 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
> @@ -1131,6 +1131,7 @@ void mlx5e_trigger_napi_icosq(struct mlx5e_channel *c);
>  void mlx5e_trigger_napi_async_icosq(struct mlx5e_channel *c);
>  void mlx5e_trigger_napi_sched(struct napi_struct *napi);
>  
> +int mlx5e_channel_stats_prealloc(struct mlx5e_priv *priv, int nch);
>  int mlx5e_open_channels(struct mlx5e_priv *priv,
>  			struct mlx5e_channels *chs);
>  void mlx5e_close_channels(struct mlx5e_channels *chs);
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
> index 227695dfa51d..9493964047e0 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
> @@ -2780,6 +2780,35 @@ static int mlx5e_channel_stats_alloc(struct mlx5e_priv *priv, int ix, int cpu)
>  	return 0;
>  }
>  
> +/* Used by a child interface to prealloc channel_stats and prevent a race
> + * between the interface startup and the receive path
> + * (mlx5i_handle_rx_cqe()/mlx5i_pkey_open()).
> + */
> +int mlx5e_channel_stats_prealloc(struct mlx5e_priv *priv, int nch)
> +{
> +	struct mlx5_core_dev *mdev;
> +	int vec_ix;
> +	int cpu;
> +	int err;
> +	int ch;
> +
> +	if (WARN_ON_ONCE(nch > priv->max_nch))
> +		return -EINVAL;
> +
> +	/* On error, channel_stats will be freed by mlx5i_cleanup() */
> +	for (ch = 0; ch < nch; ch++) {
> +		mdev = mlx5_sd_ch_ix_get_dev(priv->mdev, ch);
> +		vec_ix = mlx5_sd_ch_ix_get_vec_ix(mdev, ch);
> +		cpu = mlx5_comp_vector_get_cpu(mdev, vec_ix);
> +
> +		err = mlx5e_channel_stats_alloc(priv, ch, cpu);
> +		if (err)
> +			return err;
> +	}
> +
> +	return 0;
> +}
> +
>  void mlx5e_trigger_napi_icosq(struct mlx5e_channel *c)
>  {
>  	struct mlx5e_icosq *sq = &c->icosq;
> 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 5edc39247525..577981ae5ecf 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib_vlan.c
> @@ -161,7 +161,9 @@ static int mlx5i_pkey_dev_init(struct net_device *dev)
>  {
>  	struct mlx5e_priv *priv = mlx5i_epriv(dev);
>  	struct mlx5i_priv *ipriv, *parent_ipriv;
> +	struct mlx5e_priv *parent_priv;
>  	struct net_device *parent_dev;
> +	int nch, err;
>  
>  	ipriv = priv->ppriv;
>  
> @@ -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;
> +	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;
>  	}
>  
> +	err = mlx5e_channel_stats_prealloc(priv, nch);
> +	if (err) {
> +		mlx5i_parent_put(dev);
> +		return err;
> +	}
> +
>  	/* Get QPN to netdevice hash table from parent */
>  	parent_ipriv = netdev_priv(parent_dev);
>  	ipriv->qpn_htbl = parent_ipriv->qpn_htbl;
This is the type of code that I was trying to avoid. Can you explain why
my suggestion doesn't work:

>>> b) The thing with the resizing of the parent channels. Can be fixed
>>> by allocating the max number of channels for the pkey netdev. AFAIU,
>>> `priv->channels.params.num_channels = priv->max_nch` in
>>> mlx5i_pkey_init() should do the trick.

Thanks,
Dragos

      reply	other threads:[~2026-12-03 11:10 UTC|newest]

Thread overview: 11+ 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-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 [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=8a4034fb-64f1-4693-b73f-c3c0eb1331db@nvidia.com \
    --to=dtatulea@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=eaujames@ddn.com \
    --cc=feliu@nvidia.com \
    --cc=guillaume.courrier@cea.fr \
    --cc=jean-francois.lassignardie@bull.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@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