Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Alexander Duyck
Fri, 13 Nov 2026 20:41
[net PATCH 3/6] fbnic: Cover all of the HW stats with the stats lock
Author: Alexander Duyck
Date: Fri, 13 Nov 2026 20:41
Date: Fri, 13 Nov 2026 20:41
158 lines
17192 bytes
17192 bytes
From: Alexander Duyck <alexanderduyck@fb.com>
The hw_stats lock covers the PHY, TMI, TTI, RPC, RXB, queue and PCIe
stats, but the MAC stats are left to RTNL: the fbnic_reset_hw_stats
function resets them outside the lock and asserts RTNL, on the grounds
that the ethtool API is their only other user and holds RTNL. That is no
longer the case. ethtool only takes RTNL on the Netlink path for the
operations a driver lists in op_needs_rtnl, and fbnic lists only the
pause getter among the stats ones, so the eth-mac, eth-ctrl and rmon
getters update the MAC stats with only the netdev instance lock held,
racing each other and the reset.
Take the stats lock around the MAC stats updates in those getters and in
the reset, and drop the RTNL assertion. Take it in the pause getter as
well: it still runs under RTNL, but that no longer serializes it against
the reset once the reset does not rely on RTNL. The PCIe stats debugfs
read never needed RTNL, as the fbnic_get_hw_stats function updates those
stats under the stats lock, so drop it there too. The values are printed
from their 64-bit fields without the lock, as the counters keep changing
during the read anyway.
The issue was found by code review.
Fixes: 45079e00133e ("net: ethtool: optionally skip rtnl_lock on Netlink path for GET ops")
Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
---
drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c | 3 ---
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 8 ++++++++
drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c | 13 +------------
3 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c b/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c
index f9e879be254d..65bea571c0cc 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c
@@ -3,7 +3,6 @@
#include <linux/debugfs.h>
#include <linux/pci.h>
-#include <linux/rtnetlink.h>
#include <linux/seq_file.h>
#include "fbnic.h"
@@ -607,7 +606,6 @@ static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v)
{
struct fbnic_dev *fbd = s->private;
- rtnl_lock();
fbnic_get_hw_stats(fbd);
seq_printf(s, "ob_rd_tlp: %llu\n", fbd->hw_stats.pcie.ob_rd_tlp.value);
@@ -626,7 +624,6 @@ static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v)
fbd->hw_stats.pcie.ob_rd_no_cpl_cred.value);
seq_printf(s, "ob_rd_no_np_cred: %llu\n",
fbd->hw_stats.pcie.ob_rd_no_np_cred.value);
- rtnl_unlock();
return 0;
}
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
index e774740fcb5d..b300017b53d4 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
@@ -1867,12 +1867,14 @@ fbnic_get_pause_stats(struct net_device *netdev,
mac_stats = &fbd->hw_stats.mac;
+ spin_lock(&fbd->hw_stats.lock);
fbd->mac->get_pause_stats(fbd, false, &mac_stats->pause);
pause_stats->tx_pause_frames = mac_stats->pause.tx_pause_frames.value;
pause_stats->rx_pause_frames = mac_stats->pause.rx_pause_frames.value;
tx_ps_events = mac_stats->pause.tx_pause_storm_events.value;
pause_stats->tx_pause_storm_events = tx_ps_events;
+ spin_unlock(&fbd->hw_stats.lock);
}
static void
@@ -1928,6 +1930,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev,
mac_stats = &fbd->hw_stats.mac;
mac = fbd->mac;
+ spin_lock(&fbd->hw_stats.lock);
mac->get_eth_mac_stats(fbd, false, &mac_stats->eth_mac);
fbnic_set_counter(ð_mac_stats->FramesTransmittedOK,
@@ -1956,6 +1959,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev,
&mac_stats->eth_mac.BroadcastFramesReceivedOK);
fbnic_set_counter(ð_mac_stats->FrameTooLongErrors,
&mac_stats->eth_mac.FrameTooLongErrors);
+ spin_unlock(&fbd->hw_stats.lock);
}
static void
@@ -1968,12 +1972,14 @@ fbnic_get_eth_ctrl_stats(struct net_device *netdev,
mac_stats = &fbd->hw_stats.mac;
+ spin_lock(&fbd->hw_stats.lock);
fbd->mac->get_eth_ctrl_stats(fbd, false, &mac_stats->eth_ctrl);
eth_ctrl_stats->MACControlFramesReceived =
mac_stats->eth_ctrl.MACControlFramesReceived.value;
eth_ctrl_stats->MACControlFramesTransmitted =
mac_stats->eth_ctrl.MACControlFramesTransmitted.value;
+ spin_unlock(&fbd->hw_stats.lock);
}
static const struct ethtool_rmon_hist_range fbnic_rmon_ranges[] = {
@@ -2003,6 +2009,7 @@ fbnic_get_rmon_stats(struct net_device *netdev,
mac_stats = &fbd->hw_stats.mac;
+ spin_lock(&fbd->hw_stats.lock);
fbd->mac->get_rmon_stats(fbd, false, &mac_stats->rmon);
rmon_stats->undersize_pkts =
@@ -2018,6 +2025,7 @@ fbnic_get_rmon_stats(struct net_device *netdev,
rmon_stats->hist[i] = mac_stats->rmon.hist[i].value;
rmon_stats->hist_tx[i] = mac_stats->rmon.hist_tx[i].value;
}
+ spin_unlock(&fbd->hw_stats.lock);
*ranges = fbnic_rmon_ranges;
}
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
index 8084a63dd807..307d5e737848 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) Meta Platforms, Inc. and affiliates. */
-#include <linux/rtnetlink.h>
-
#include "fbnic.h"
static void fbnic_hw_stat_rst32(struct fbnic_dev *fbd, u32 reg,
@@ -559,17 +557,8 @@ void fbnic_reset_hw_stats(struct fbnic_dev *fbd)
fbnic_reset_rxb_stats(fbd, &fbd->hw_stats.rxb);
fbnic_reset_hw_rxq_stats(fbd, fbd->hw_stats.hw_q);
fbnic_reset_pcie_stats_asic(fbd, &fbd->hw_stats.pcie);
- spin_unlock(&fbd->hw_stats.lock);
-
- /* Once registered, the only other access to MAC stats is via the
- * ethtool API which is protected by the rtnl_lock. The call to
- * fbnic_reset_hw_stats() during PCI recovery is also protected
- * by the rtnl_lock hence, we don't need the spinlock to access
- * the MAC stats.
- */
- if (fbd->netdev)
- ASSERT_RTNL();
fbnic_reset_hw_mac_stats(fbd, &fbd->hw_stats.mac);
+ spin_unlock(&fbd->hw_stats.lock);
}
void fbnic_init_hw_stats(struct fbnic_dev *fbd)
Re: [net PATCH 3/6] fbnic: Cover all of the HW stats with the stats lock
Author: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 21:14
Date: Tue, 17 Nov 2026 21:14
92 lines
11411 bytes
11411 bytes
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] The commit message and Fixes: tag describe a race that cannot
happen at this commit.
--
fbnic: Cover all of the HW stats with the stats lock
This patch puts the fbnic MAC stats under hw_stats.lock. The lock is now
taken in the ethtool pause, eth-mac, eth-ctrl and rmon getters and in
fbnic_reset_hw_stats(), and the ASSERT_RTNL() is gone. It also drops
rtnl_lock() from the PCIe stats debugfs read.
> That is no
> longer the case. ethtool only takes RTNL on the Netlink path for the
> operations a driver lists in op_needs_rtnl, and fbnic lists only the
> pause getter among the stats ones, so the eth-mac, eth-ctrl and rmon
> getters update the MAC stats with only the netdev instance lock held,
> racing each other and the reset.
[ ... ]
> Fixes: 45079e00133e ("net: ethtool: optionally skip rtnl_lock on Netlink path for GET ops")
[Severity: Medium]
Can the race described here actually happen at this commit?
fbnic is ops-locked. fbnic_netdev_alloc() sets queue_mgmt_ops
unconditionally:
netdev->queue_mgmt_ops = &fbnic_queue_mgmt_ops;
That makes netdev_need_ops_lock() true, so netdev_lock_ops() really takes
netdev->lock for this device.
ethnl_default_doit() takes that lock around prepare_data() whether or not
RTNL is needed:
if (need_rtnl)
rtnl_lock();
netdev_lock_ops(req_info->dev);
}
ret = ops->prepare_data(req_info, reply_data, info);
The dump path does the same, and the notify path asserts the same lock.
The only core callers of the fbnic get_eth_mac_stats, get_eth_ctrl_stats,
get_rmon_stats and get_pause_stats callbacks are stats_prepare_data() and
pause_prepare_data(). So the getters are already serialized against each
other by the instance lock.
fbnic_reset_hw_stats() has two callers. fbnic_init_hw_stats() runs from
fbnic_probe() before the netdev is allocated or registered, so no ethtool
request can reach the device yet. __fbnic_pm_attach() holds the same
instance lock around the reset:
rtnl_lock();
netdev_lock(netdev);
fbnic_reset_hw_stats(fbd);
Nothing else touches fbd->hw_stats.mac or calls the fbd->mac->get_*_stats
callbacks.
After 45079e00133e, the old comment and ASSERT_RTNL() in
fbnic_reset_hw_stats() were out of date. But netdev->lock still seems to
serialize every path that touches the MAC stats.
The locking change itself looks fine as a consistency cleanup. Later in
this series the reset moves into __fbnic_pm_resume() and runs under
hw_stats.lock only, without netdev_lock. That later change is what makes
the lock added here necessary.
Could the commit message say that the instance lock already serializes
these paths, and that this patch makes hw_stats.lock the single
protection to prepare for the later reset move? Could the Fixes: tag
also be dropped, or could the message name a path that actually reaches
the race? As written, the tag may lead to this being backported to
stable as a fix for a race that does not exist there.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179460241885.8819.7179935130629202331.stgit%40ahduyck-xeon-server.home.arpa
Re: [net PATCH 3/6] fbnic: Cover all of the HW stats with the stats lock
Author: Alexander Duyck
Date: Tue, 17 Nov 2026 22:01
Date: Tue, 17 Nov 2026 22:01
109 lines
16370 bytes
16370 bytes
On Tue, Nov 17, 2026 at 1:14 PM <netdev-bot+sashiko@kernel.org> wrote:
>
> 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] The commit message and Fixes: tag describe a race that cannot
> happen at this commit.
>
> --
>
> fbnic: Cover all of the HW stats with the stats lock
>
> This patch puts the fbnic MAC stats under hw_stats.lock. The lock is now
> taken in the ethtool pause, eth-mac, eth-ctrl and rmon getters and in
> fbnic_reset_hw_stats(), and the ASSERT_RTNL() is gone. It also drops
> rtnl_lock() from the PCIe stats debugfs read.
>
> > That is no
> > longer the case. ethtool only takes RTNL on the Netlink path for the
> > operations a driver lists in op_needs_rtnl, and fbnic lists only the
> > pause getter among the stats ones, so the eth-mac, eth-ctrl and rmon
> > getters update the MAC stats with only the netdev instance lock held,
> > racing each other and the reset.
>
> [ ... ]
>
> > Fixes: 45079e00133e ("net: ethtool: optionally skip rtnl_lock on Netlink path for GET ops")
>
> [Severity: Medium]
> Can the race described here actually happen at this commit?
>
> fbnic is ops-locked. fbnic_netdev_alloc() sets queue_mgmt_ops
> unconditionally:
>
> netdev->queue_mgmt_ops = &fbnic_queue_mgmt_ops;
>
> That makes netdev_need_ops_lock() true, so netdev_lock_ops() really takes
> netdev->lock for this device.
>
> ethnl_default_doit() takes that lock around prepare_data() whether or not
> RTNL is needed:
>
> if (need_rtnl)
> rtnl_lock();
> netdev_lock_ops(req_info->dev);
> }
> ret = ops->prepare_data(req_info, reply_data, info);
>
> The dump path does the same, and the notify path asserts the same lock.
> The only core callers of the fbnic get_eth_mac_stats, get_eth_ctrl_stats,
> get_rmon_stats and get_pause_stats callbacks are stats_prepare_data() and
> pause_prepare_data(). So the getters are already serialized against each
> other by the instance lock.
>
> fbnic_reset_hw_stats() has two callers. fbnic_init_hw_stats() runs from
> fbnic_probe() before the netdev is allocated or registered, so no ethtool
> request can reach the device yet. __fbnic_pm_attach() holds the same
> instance lock around the reset:
>
> rtnl_lock();
> netdev_lock(netdev);
>
> fbnic_reset_hw_stats(fbd);
>
> Nothing else touches fbd->hw_stats.mac or calls the fbd->mac->get_*_stats
> callbacks.
>
> After 45079e00133e, the old comment and ASSERT_RTNL() in
> fbnic_reset_hw_stats() were out of date. But netdev->lock still seems to
> serialize every path that touches the MAC stats.
>
> The locking change itself looks fine as a consistency cleanup. Later in
> this series the reset moves into __fbnic_pm_resume() and runs under
> hw_stats.lock only, without netdev_lock. That later change is what makes
> the lock added here necessary.
This is the key piece here. The locking change is fine, however it
seems to be hung up on the commit message below.
> Could the commit message say that the instance lock already serializes
> these paths, and that this patch makes hw_stats.lock the single
> protection to prepare for the later reset move? Could the Fixes: tag
> also be dropped, or could the message name a path that actually reaches
> the race? As written, the tag may lead to this being backported to
> stable as a fix for a race that does not exist there.
Admittedly the MAC stats were not really the focus of the change. It
was more about the PCIe stats as we were stuck under the RTNL with it
and it didn't make sense to lock PCIe stats under a networking lock.
The whole point of the patch set was two fold. First was to
consolidate everything under one lock as we were dealing with RTNL,
netdev instance lock, and HW stats lock. Rather than have 3 locks we
could place it all under 1 and that is a significant cleanup and
enables the initialization/reset fixes as the AI agent correctly
pointed out.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads