Skip to content

Commit 9f61eb2

Browse files
Mohsin BashirPaolo Abeni
authored andcommitted
eth: fbnic: add locking support for hw stats
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 <[email protected]> Signed-off-by: Mohsin Bashir <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 24e31e4 commit 9f61eb2

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

drivers/net/ethernet/meta/fbnic/fbnic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ struct fbnic_dev {
8181

8282
/* Local copy of hardware statistics */
8383
struct fbnic_hw_stats hw_stats;
84+
85+
/* Lock protecting access to hw_stats */
86+
spinlock_t hw_stats_lock;
8487
};
8588

8689
/* Reserve entry 0 in the MSI-X "others" array until we have filled all

drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,28 @@ static void fbnic_get_pcie_stats_asic64(struct fbnic_dev *fbd,
203203

204204
void fbnic_reset_hw_stats(struct fbnic_dev *fbd)
205205
{
206+
spin_lock(&fbd->hw_stats_lock);
206207
fbnic_reset_rpc_stats(fbd, &fbd->hw_stats.rpc);
207208
fbnic_reset_pcie_stats_asic(fbd, &fbd->hw_stats.pcie);
209+
spin_unlock(&fbd->hw_stats_lock);
208210
}
209211

210-
void fbnic_get_hw_stats32(struct fbnic_dev *fbd)
212+
static void __fbnic_get_hw_stats32(struct fbnic_dev *fbd)
211213
{
212214
fbnic_get_rpc_stats32(fbd, &fbd->hw_stats.rpc);
213215
}
214216

215-
void fbnic_get_hw_stats(struct fbnic_dev *fbd)
217+
void fbnic_get_hw_stats32(struct fbnic_dev *fbd)
216218
{
217-
fbnic_get_hw_stats32(fbd);
219+
spin_lock(&fbd->hw_stats_lock);
220+
__fbnic_get_hw_stats32(fbd);
221+
spin_unlock(&fbd->hw_stats_lock);
222+
}
218223

224+
void fbnic_get_hw_stats(struct fbnic_dev *fbd)
225+
{
226+
spin_lock(&fbd->hw_stats_lock);
227+
__fbnic_get_hw_stats32(fbd);
219228
fbnic_get_pcie_stats_asic64(fbd, &fbd->hw_stats.pcie);
229+
spin_unlock(&fbd->hw_stats_lock);
220230
}

drivers/net/ethernet/meta/fbnic/fbnic_pci.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
292292

293293
fbnic_devlink_register(fbd);
294294
fbnic_dbg_fbd_init(fbd);
295+
spin_lock_init(&fbd->hw_stats_lock);
295296

296297
/* Capture snapshot of hardware stats so netdev can calculate delta */
297298
fbnic_reset_hw_stats(fbd);

0 commit comments

Comments
 (0)