]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
eth: fbnic: Reset MAC stats
authorMohsin Bashir <mohsin.bashr@gmail.com>
Mon, 25 Aug 2025 20:02:03 +0000 (13:02 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 28 Aug 2025 01:56:19 +0000 (18:56 -0700)
Reset the MAC stats as part of the hardware stats reset to ensure
consistency. Currently, hardware stats are reset during device bring-up
and upon experiencing PCI errors; however, MAC stats are being skipped
during these resets.

When fbnic_reset_hw_stats() is called upon recovering from PCI error,
MAC stats are accessed outside the rtnl_lock. The only other access to
MAC stats is via the ethtool API, which is protected by rtnl_lock. This
can result in concurrent access to MAC stats and a potential race. Protect
the fbnic_reset_hw_stats() call in __fbnic_pm_attach() with rtnl_lock to
avoid this.

Note that fbnic_reset_hw_mac_stats() is called outside the hardware
stats lock which protects access to the fbnic_hw_stats. This is intentional
because MAC stats are fetched from the device outside this lock and are
exclusively read via the ethtool API.

Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20250825200206.2357713-4-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
drivers/net/ethernet/meta/fbnic/fbnic_pci.c

index 77182922f0182ebfc92e0ab34b8c30ee85a3a1e9..8aa9a0e286bbc749486e9593f3cede7502fc0c1a 100644 (file)
@@ -1,6 +1,8 @@
 // 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,
@@ -510,6 +512,16 @@ static void fbnic_get_pcie_stats_asic64(struct fbnic_dev *fbd,
                           &pcie->ob_rd_no_np_cred);
 }
 
+static void fbnic_reset_hw_mac_stats(struct fbnic_dev *fbd,
+                                    struct fbnic_mac_stats *mac_stats)
+{
+       const struct fbnic_mac *mac = fbd->mac;
+
+       mac->get_eth_mac_stats(fbd, true, &mac_stats->eth_mac);
+       mac->get_eth_ctrl_stats(fbd, true, &mac_stats->eth_ctrl);
+       mac->get_rmon_stats(fbd, true, &mac_stats->rmon);
+}
+
 void fbnic_reset_hw_stats(struct fbnic_dev *fbd)
 {
        spin_lock(&fbd->hw_stats.lock);
@@ -520,6 +532,16 @@ void fbnic_reset_hw_stats(struct fbnic_dev *fbd)
        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);
 }
 
 void fbnic_init_hw_stats(struct fbnic_dev *fbd)
index 953297f667a25137d651680cfc17249b01cac19c..ef7928b18ac0aad165fc317c0210550baf2c440f 100644 (file)
@@ -491,7 +491,9 @@ static void __fbnic_pm_attach(struct device *dev)
        struct net_device *netdev = fbd->netdev;
        struct fbnic_net *fbn;
 
+       rtnl_lock();
        fbnic_reset_hw_stats(fbd);
+       rtnl_unlock();
 
        if (fbnic_init_failure(fbd))
                return;