Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path
@ 2026-11-25 18:24 Etienne AUJAMES
  2026-11-25 18:27 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Etienne AUJAMES @ 2026-11-25 18:24 UTC (permalink / raw)
  To: Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Dragos Tatulea,
	Mark Bloch
  Cc: netdev, linux-rdma, Feng Liu, David S. Miller, COURRIER Guillaume

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path
  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-26 18:27 ` netdev-bot+sashiko
  2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-25 18:27 UTC (permalink / raw)
  To: Etienne AUJAMES
  Cc: Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Dragos Tatulea,
	Mark Bloch, netdev, linux-rdma, Feng Liu, David S. Miller,
	COURRIER Guillaume

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path
  2026-11-25 18:27 ` netdev-bot+sinfo
@ 2026-11-25 19:17   ` Etienne AUJAMES
  0 siblings, 0 replies; 5+ messages in thread
From: Etienne AUJAMES @ 2026-11-25 19:17 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Dragos Tatulea,
	Mark Bloch, netdev, linux-rdma, Feng Liu, David S. Miller,
	COURRIER Guillaume

On 25/11/26, netdev-bot+sinfo@kernel.org wrote:
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.
This was hit in production with MOFED 24.10 on RHEL8.10 with an
ConnectX6 hardware.

>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.
The crash occurred at network startup on node reboot, reproducing in
roughly 90% of attempts. Crash analysis indicated that it was
triggered by a BFD protocol message received on the child interface
(the node hosts the "bird" routing daemon).
ibdump captures show BFD packets arriving at about 625 packets/s
(1.6 ms interval) on that child interface (PKey).

>  - What hardware the change was tested on. For driver fixes please
>    mention the device (and if relevant firmware version) used for
>    testing, or say that the change was not tested on real hardware.
Replacing the network card did not resolve the issue.
After downgrading MOFED to 5.8, the crash could no longer be
reproduced.
The patch itself was validated directly on the node with a MOFED 24.10
build containing the 5a799714e8 backport ("net/mlx5e: Fix publication
race for priv->channel_stats[]") and this fix.

Thanks,

Etienne

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path
  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-26 14:41 ` Dragos Tatulea
  2026-11-26 18:27 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: Dragos Tatulea @ 2026-11-26 14:41 UTC (permalink / raw)
  To: Etienne AUJAMES
  Cc: Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Mark Bloch, netdev,
	linux-rdma, Feng Liu, David S. Miller, COURRIER Guillaume

Hi Etienne,

Thanks for your patch!

On Wed, Nov 25, 2026 at 19:24:23 +0100, Etienne AUJAMES wrote:
> 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.
>

There are 2 issues here, each needs its own fix:

a) Packets shouldn't be steered to the parent RQ before the pkey netdev
channel stats are allocated. Fix by moving the flow steering setup
(mlx5_fs_add_rx_underlay_qpn()) after the channel open in
mlx5i_pkey_open().

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net/mlx5e: guard child PKEY channel stats lookup in rx path
  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-26 14:41 ` Dragos Tatulea
@ 2026-11-26 18:27 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26 18:27 UTC (permalink / raw)
  To: eaujames
  Cc: tariqt, saeedm, leon, dtatulea, mbloch, netdev, linux-rdma, feliu,
	davem, guillaume.courrier, kuba

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

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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] When the child PKEY priv has no channel_stats entry for the
  parent RQ index, the new fallback in mlx5i_complete_rx_cqe()…

--

net/mlx5e: guard child PKEY channel stats lookup in rx path

This adds a helper, mlx5e_channel_stats_get(), that checks the channel
index against stats_nch. mlx5i_complete_rx_cqe() now uses it to look up
the child PKEY priv's channel_stats[]. If the child has no entry for the
parent's rq->ix, the stats go to the parent's rq->stats instead.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> index 1586cb2404c01..5f2347672cf33 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c

[ ... ]

> @@ -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;

[Severity: Medium]

Does this fallback count child PKEY traffic on the parent netdev?

For a parent RQ, rq->stats points into the parent priv:

mlx5e_init_rxq_rq() {
    ...
	rq->stats        = &c->priv->channel_stats[c->ix]->rq;
    ...
}

When the lookup returns NULL, the csum_complete/csum_none updates and the
packets/bytes updates at the end of mlx5i_complete_rx_cqe() all land on
the parent. The skb itself is still delivered to the child:

	skb->dev = netdev;

	stats->packets++;
	stats->bytes += cqe_bcnt;

mlx5i_grp_sw_update_stats() only sums a netdev's own
channel_stats[0..stats_nch). So the parent's rx_packets/rx_bytes would be
too high, and the child's would be missing these packets.

For these indexes, isn't this the same misattribution that b5e23931c45a
("net/mlx5e: IPoIB, Fix child PKEY interface stats on rx path") fixed?

Could this also last beyond the window in mlx5i_pkey_open() between
mlx5_fs_add_rx_underlay_qpn() and mlx5e_open_channels()?

The child's channel count defaults to:

mlx5e_build_nic_params() {
    ...
	params->num_channels = min_t(unsigned int, MLX5E_MAX_NUM_CHANNELS / 2,
				     priv->max_nch);
    ...
}

mlx5i_pkey_ethtool_ops has no set_channels, so the child can't change
this value.

The parent can be raised above 128 channels with ethtool -L as long as no
child exists yet, because mlx5i_set_channels() only refuses when:

	if (ipriv->num_sub_interfaces > 0) {

On hosts where max_nch is above 128, a child could then be created after
the parent was raised. Every child packet that RSS steers to a parent RQ
with rq->ix >= the child's stats_nch would then be counted on the parent
for good, not just during the open race.

The commit message says the fallback "adds no new data race", but it
doesn't mention that the per-netdev RX counters become wrong. Should the
fallback avoid charging the parent's rq->stats? If the current behaviour
is intended, could the commit message describe it?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/awcn1-LpcFgzRKgq%40eaujamesFR0130

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-26 18:27 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox