From: Jacob Keller <jacob.e.keller@intel.com>
To: Tariq Toukan <tariqt@nvidia.com>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>
Cc: Saeed Mahameed <saeedm@nvidia.com>,
Leon Romanovsky <leon@kernel.org>, Mark Bloch <mbloch@nvidia.com>,
Eran Ben Elisha <eranbe@nvidia.com>, Feng Liu <feliu@nvidia.com>,
Cosmin Ratiu <cratiu@nvidia.com>, Gal Pressman <gal@nvidia.com>,
Simon Horman <horms@kernel.org>, Alexei Lazar <alazar@nvidia.com>,
Nimrod Oren <noren@nvidia.com>,
Carolina Jubran <cjubran@nvidia.com>, Kees Cook <kees@kernel.org>,
Lama Kayal <lkayal@nvidia.com>,
Eran Ben Elisha <eranbe@mellanox.com>,
Saeed Mahameed <saeedm@mellanox.com>,
Haiyang Zhang <haiyangz@microsoft.com>, Joe Damato <joe@dama.to>,
<netdev@vger.kernel.org>, <linux-rdma@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net 4/4] net/mlx5e: Fix publication race for priv->channel_stats[]
Date: Thu, 4 Jun 2026 12:30:32 -0700 [thread overview]
Message-ID: <ffb1c6a3-825f-403f-876f-8f138f29163c@intel.com> (raw)
In-Reply-To: <20260604135041.455754-5-tariqt@nvidia.com>
On 6/4/2026 6:50 AM, Tariq Toukan wrote:
> From: Feng Liu <feliu@nvidia.com>
>
> mlx5e_channel_stats_alloc() publishes a new entry to
> priv->channel_stats[] and then increments priv->stats_nch as a
> publication token, but neither store carries any memory barrier:
>
> priv->channel_stats[ix] = kvzalloc_node(...);
> if (!priv->channel_stats[ix])
> return -ENOMEM;
> priv->stats_nch++;
>
> Concurrent readers compute the loop bound from priv->stats_nch and
> then dereference priv->channel_stats[i] using plain accesses, e.g.
>
> for (i = 0; i < priv->stats_nch; i++) {
> struct mlx5e_channel_stats *cs = priv->channel_stats[i];
> ... cs->rq.packets ...
> }
>
> On weakly-ordered architectures (ARM, PowerPC, RISC-V) the writes to
> channel_stats[ix] and stats_nch may become visible to other CPUs out
> of program order. A reader can observe stats_nch == N while still
> seeing channel_stats[N-1] == NULL, leading to a NULL pointer
> dereference in the channel_stats loop.
>
> This has been observed in production on BlueField-3 DPUs (arm64),
> where ovs-vswitchd queries netdev statistics over netlink during NIC
> bringup, racing mlx5e_open_channel() -> mlx5e_channel_stats_alloc()
> on another CPU:
>
> Unable to handle kernel NULL pointer dereference at virtual address 0x840
> Hardware name: BlueField-3 DPU
> pc : mlx5e_fold_sw_stats64+0x30/0x180 [mlx5_core]
> Call trace:
> mlx5e_fold_sw_stats64+0x30/0x180 [mlx5_core]
> dev_get_stats+0x50/0xc0
> ovs_vport_get_stats+0x38/0xac [openvswitch]
> ovs_vport_cmd_fill_info+0x194/0x290 [openvswitch]
> ovs_vport_cmd_get+0xbc/0x10c [openvswitch]
> genl_family_rcv_msg_doit+0xd0/0x160
> genl_rcv_msg+0xec/0x1f0
> netlink_rcv_skb+0x64/0x130
> genl_rcv+0x40/0x60
> netlink_unicast+0x2fc/0x370
> netlink_sendmsg+0x1dc/0x454
> ...
> __arm64_sys_sendmsg+0x2c/0x40
>
> Order the stats_nch increment through smp_store_release() in the
> writer, paired with smp_load_acquire() of stats_nch in every reader.
> The release/acquire pair establishes the contract:
>
> stats_nch == N => channel_stats[0..N-1] are visible and non-NULL.
>
> Update all readers of priv->stats_nch in mlx5e RX/TX queue stats,
> mlx5e_get_base_stats(), ethtool channels stats, IPoIB stats, the
> sw_stats fold and the HV VHCA stats agent to use smp_load_acquire().
> mlx5e_channel_stats_alloc() (the writer, serialized by state_lock)
> and mlx5e_priv_cleanup() (single-owner teardown) are intentionally
> not modified.
>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
prev parent reply other threads:[~2026-06-04 19:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 13:50 [PATCH net 0/4] net/mlx5e: Fix crashes in dynamic per-channel stats and HV VHCA agent Tariq Toukan
2026-06-04 13:50 ` [PATCH net 1/4] net/mlx5e: Fix HV VHCA stats zero-sized buffer allocation Tariq Toukan
2026-06-04 19:24 ` Jacob Keller
2026-06-04 13:50 ` [PATCH net 2/4] net/mlx5e: Fix HV VHCA stats agent registration race Tariq Toukan
2026-06-04 19:25 ` Jacob Keller
2026-06-04 13:50 ` [PATCH net 3/4] net/mlx5e: Bounds-check stats_nch in mlx5e_get_queue_stats_rx() Tariq Toukan
2026-06-04 19:28 ` Jacob Keller
2026-06-09 1:54 ` Jakub Kicinski
2026-06-04 13:50 ` [PATCH net 4/4] net/mlx5e: Fix publication race for priv->channel_stats[] Tariq Toukan
2026-06-04 19:30 ` Jacob Keller [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=ffb1c6a3-825f-403f-876f-8f138f29163c@intel.com \
--to=jacob.e.keller@intel.com \
--cc=alazar@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=cjubran@nvidia.com \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eranbe@mellanox.com \
--cc=eranbe@nvidia.com \
--cc=feliu@nvidia.com \
--cc=gal@nvidia.com \
--cc=haiyangz@microsoft.com \
--cc=horms@kernel.org \
--cc=joe@dama.to \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=lkayal@nvidia.com \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=noren@nvidia.com \
--cc=pabeni@redhat.com \
--cc=saeedm@mellanox.com \
--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
Powered by JetHome