]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
eth: fbnic: add locking support for hw stats
authorMohsin Bashir <mohsin.bashr@gmail.com>
Thu, 10 Apr 2025 07:08:55 +0000 (00:08 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 15 Apr 2025 09:23:13 +0000 (11:23 +0200)
This patch adds lock protection for the hardware statistics for fbnic.
The hardware statistics access via ndo_get_stats64 is not protected by
the rtnl_lock(). Since these stats can be accessed from different places
in the code such as service task, ethtool, Q-API, and net_device_ops, a
lock-less approach can lead to races.

Note that this patch is not a fix rather, just a prep for the subsequent
changes in this series.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250410070859.4160768-2-mohsin.bashr@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/meta/fbnic/fbnic.h
drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
drivers/net/ethernet/meta/fbnic/fbnic_pci.c

index 4ca7b99ef131532b887d11f7f34ec7e8d8c42d56..80d54edaac5574138fc76f870a3d42cabd543c8f 100644 (file)
@@ -81,6 +81,9 @@ struct fbnic_dev {
 
        /* Local copy of hardware statistics */
        struct fbnic_hw_stats hw_stats;
+
+       /* Lock protecting access to hw_stats */
+       spinlock_t hw_stats_lock;
 };
 
 /* Reserve entry 0 in the MSI-X "others" array until we have filled all
index 89ac6bc8c7fc3c3a6e944889946270bc6fd5afcf..957138cb841edc5062b20a88c8411f77facc5873 100644 (file)
@@ -203,18 +203,28 @@ static void fbnic_get_pcie_stats_asic64(struct fbnic_dev *fbd,
 
 void fbnic_reset_hw_stats(struct fbnic_dev *fbd)
 {
+       spin_lock(&fbd->hw_stats_lock);
        fbnic_reset_rpc_stats(fbd, &fbd->hw_stats.rpc);
        fbnic_reset_pcie_stats_asic(fbd, &fbd->hw_stats.pcie);
+       spin_unlock(&fbd->hw_stats_lock);
 }
 
-void fbnic_get_hw_stats32(struct fbnic_dev *fbd)
+static void __fbnic_get_hw_stats32(struct fbnic_dev *fbd)
 {
        fbnic_get_rpc_stats32(fbd, &fbd->hw_stats.rpc);
 }
 
-void fbnic_get_hw_stats(struct fbnic_dev *fbd)
+void fbnic_get_hw_stats32(struct fbnic_dev *fbd)
 {
-       fbnic_get_hw_stats32(fbd);
+       spin_lock(&fbd->hw_stats_lock);
+       __fbnic_get_hw_stats32(fbd);
+       spin_unlock(&fbd->hw_stats_lock);
+}
 
+void fbnic_get_hw_stats(struct fbnic_dev *fbd)
+{
+       spin_lock(&fbd->hw_stats_lock);
+       __fbnic_get_hw_stats32(fbd);
        fbnic_get_pcie_stats_asic64(fbd, &fbd->hw_stats.pcie);
+       spin_unlock(&fbd->hw_stats_lock);
 }
index 6cbbc2ee3e1f98832a6405767c864d32b58a1015..1f76ebdd6ad18f2281ba673f5720533085096c98 100644 (file)
@@ -292,6 +292,7 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        fbnic_devlink_register(fbd);
        fbnic_dbg_fbd_init(fbd);
+       spin_lock_init(&fbd->hw_stats_lock);
 
        /* Capture snapshot of hardware stats so netdev can calculate delta */
        fbnic_reset_hw_stats(fbd);