Netdev List
 help / color / mirror / Atom feed
From: Etienne AUJAMES <eaujames@ddn.com>
To: Tariq Toukan <tariqt@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	Dragos Tatulea <dtatulea@nvidia.com>,
	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>
Subject: [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path
Date: Wed, 25 Nov 2026 19:24:23 +0100	[thread overview]
Message-ID: <awcn1-LpcFgzRKgq@eaujamesFR0130> (raw)

mlx5i_complete_rx_cqe() uses the parent's rq->ix to index the child
PKEY priv's channel_stats[]. The child only populates entries for its
own channels, so on a parent channel with a higher index the entry is
NULL and the stat accounting crashes.

The race occurs between mlx5i_complete_rx_cqe() and mlx5i_pkey_open()
(bringing the PKEY interface up). Once the QPN is registered in
hardware by mlx5_fs_add_rx_underlay_qpn(), packets for the PKEY can
be received before all the channel_stats entries are allocated.

Look the entry up through a new mlx5e_channel_stats_get() helper that
checks ix against mlx5e_stats_nch_read(). This is safe because
mlx5e_channel_stats_alloc() allocates entries in order and
stats_nch is published with smp_store_release() after the entry is
stored, so every ix < stats_nch is non-NULL (paired with the acquire
in mlx5e_stats_nch_read()).

Fall back to the parent's rq->stats when the child has no entry for that
index. The fallback runs in the same parent NAPI context, so it adds no
new data race.

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    | 10 ++++++++++
 drivers/net/ethernet/mellanox/mlx5/core/en_rx.c |  4 +++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index a3945195f454..478fea5bfc69 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -998,6 +998,16 @@ static inline void mlx5e_stats_nch_write(struct mlx5e_priv *priv, u16 n)
 	smp_store_release(&priv->stats_nch, n);
 }
 
+static inline
+struct mlx5e_channel_stats *mlx5e_channel_stats_get(struct mlx5e_priv *priv,
+						    int channel)
+{
+	if (channel >= mlx5e_stats_nch_read(priv))
+		return NULL;
+
+	return priv->channel_stats[channel];
+}
+
 struct mlx5e_dev {
 	struct net_device *netdev;
 	struct devlink_port dl_port;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 1586cb2404c0..5f2347672cf3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -2529,6 +2529,7 @@ static inline void mlx5i_complete_rx_cqe(struct mlx5e_rq *rq,
 					 u32 cqe_bcnt,
 					 struct sk_buff *skb)
 {
+	struct mlx5e_channel_stats *channel_stats;
 	struct mlx5e_rq_stats *stats;
 	struct net_device *netdev;
 	struct mlx5e_priv *priv;
@@ -2552,7 +2553,8 @@ static inline void mlx5i_complete_rx_cqe(struct mlx5e_rq *rq,
 	}
 
 	priv = mlx5i_epriv(netdev);
-	stats = &priv->channel_stats[rq->ix]->rq;
+	channel_stats = mlx5e_channel_stats_get(priv, rq->ix);
+	stats = likely(channel_stats) ? &channel_stats->rq : rq->stats;
 
 	flags_rqpn = be32_to_cpu(cqe->flags_rqpn);
 	g = (flags_rqpn >> 28) & 3;
-- 
2.56.1


             reply	other threads:[~2026-11-25 18:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 18:24 Etienne AUJAMES [this message]
2026-11-25 18:27 ` [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path netdev-bot+sinfo
2026-11-25 19:17   ` Etienne AUJAMES

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=awcn1-LpcFgzRKgq@eaujamesFR0130 \
    --to=eaujames@ddn.com \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=feliu@nvidia.com \
    --cc=guillaume.courrier@cea.fr \
    --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