Skip to content

Commit

Permalink
net: ti: icssg-prueth: Add lock to stats
Browse files Browse the repository at this point in the history
Currently the API emac_update_hardware_stats() reads different ICSSG
stats without any lock protection.

This API gets called by .ndo_get_stats64() which is only under RCU
protection and nothing else. Add lock to this API so that the reading of
statistics happens during lock.

Fixes: c1e10d5 ("net: ti: icssg-prueth: Add ICSSG Stats")
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250314102721.1394366-1-danishanwar@ti.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
MD Danish Anwar authored and Paolo Abeni committed Mar 20, 2025
1 parent f3009d0 commit 47a9b5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/ti/icssg/icssg_prueth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@ static int prueth_probe(struct platform_device *pdev)
}

spin_lock_init(&prueth->vtbl_lock);
spin_lock_init(&prueth->stats_lock);
/* setup netdev interfaces */
if (eth0_node) {
ret = prueth_netdev_init(prueth, eth0_node);
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/ti/icssg/icssg_prueth.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ struct prueth {
int default_vlan;
/** @vtbl_lock: Lock for vtbl in shared memory */
spinlock_t vtbl_lock;
/** @stats_lock: Lock for reading icssg stats */
spinlock_t stats_lock;
};

struct emac_tx_ts_response {
Expand Down
4 changes: 4 additions & 0 deletions drivers/net/ethernet/ti/icssg/icssg_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void emac_update_hardware_stats(struct prueth_emac *emac)
u32 val, reg;
int i;

spin_lock(&prueth->stats_lock);

for (i = 0; i < ARRAY_SIZE(icssg_all_miig_stats); i++) {
regmap_read(prueth->miig_rt,
base + icssg_all_miig_stats[i].offset,
Expand All @@ -51,6 +53,8 @@ void emac_update_hardware_stats(struct prueth_emac *emac)
emac->pa_stats[i] += val;
}
}

spin_unlock(&prueth->stats_lock);
}

void icssg_stats_work_handler(struct work_struct *work)
Expand Down

0 comments on commit 47a9b5e

Please sign in to comment.