* [PATCH net] net: ti: icssg-prueth: Add lock to stats
@ 2025-03-14 10:27 MD Danish Anwar
2025-03-19 14:17 ` Simon Horman
2025-03-20 10:30 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: MD Danish Anwar @ 2025-03-14 10:27 UTC (permalink / raw)
To: Sai Krishna, Meghana Malladi, Diogo Ivo, Paolo Abeni,
Jakub Kicinski, Eric Dumazet, David S. Miller, Andrew Lunn
Cc: linux-kernel, netdev, linux-arm-kernel, srk, Vignesh Raghavendra,
Roger Quadros, danishanwar
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: c1e10d5dc7a1 ("net: ti: icssg-prueth: Add ICSSG Stats")
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
---
NOTE: This was suggested by Jakub Kicinski <kuba@kernel.org> [1] to get
this as bug fix in net during upstreaming of FW Stats for ICSSG driver
This patch doesn't depend on [1] and can be applied cleanly on net/main
[1] https://lore.kernel.org/all/20250306165513.541ff46e@kernel.org/
drivers/net/ethernet/ti/icssg/icssg_prueth.c | 1 +
drivers/net/ethernet/ti/icssg/icssg_prueth.h | 2 ++
drivers/net/ethernet/ti/icssg/icssg_stats.c | 4 ++++
3 files changed, 7 insertions(+)
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index 00ed97860547..9a75733e3f8f 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -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);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
index 329b46e9ee53..f41786b05741 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -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 {
diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.c b/drivers/net/ethernet/ti/icssg/icssg_stats.c
index 8800bd3a8d07..6f0edae38ea2 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_stats.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_stats.c
@@ -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,
@@ -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)
base-commit: 4003c9e78778e93188a09d6043a74f7154449d43
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: ti: icssg-prueth: Add lock to stats
2025-03-14 10:27 [PATCH net] net: ti: icssg-prueth: Add lock to stats MD Danish Anwar
@ 2025-03-19 14:17 ` Simon Horman
2025-03-20 10:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2025-03-19 14:17 UTC (permalink / raw)
To: MD Danish Anwar
Cc: Sai Krishna, Meghana Malladi, Diogo Ivo, Paolo Abeni,
Jakub Kicinski, Eric Dumazet, David S. Miller, Andrew Lunn,
linux-kernel, netdev, linux-arm-kernel, srk, Vignesh Raghavendra,
Roger Quadros
On Fri, Mar 14, 2025 at 03:57:21PM +0530, MD Danish Anwar wrote:
> 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: c1e10d5dc7a1 ("net: ti: icssg-prueth: Add ICSSG Stats")
> Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
> ---
> NOTE: This was suggested by Jakub Kicinski <kuba@kernel.org> [1] to get
> this as bug fix in net during upstreaming of FW Stats for ICSSG driver
> This patch doesn't depend on [1] and can be applied cleanly on net/main
>
> [1] https://lore.kernel.org/all/20250306165513.541ff46e@kernel.org/
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: ti: icssg-prueth: Add lock to stats
2025-03-14 10:27 [PATCH net] net: ti: icssg-prueth: Add lock to stats MD Danish Anwar
2025-03-19 14:17 ` Simon Horman
@ 2025-03-20 10:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-20 10:30 UTC (permalink / raw)
To: MD Danish Anwar
Cc: saikrishnag, m-malladi, diogo.ivo, pabeni, kuba, edumazet, davem,
andrew+netdev, linux-kernel, netdev, linux-arm-kernel, srk,
vigneshr, rogerq
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Fri, 14 Mar 2025 15:57:21 +0530 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [net] net: ti: icssg-prueth: Add lock to stats
https://git.kernel.org/netdev/net/c/47a9b5e52abd
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-20 10:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-14 10:27 [PATCH net] net: ti: icssg-prueth: Add lock to stats MD Danish Anwar
2025-03-19 14:17 ` Simon Horman
2025-03-20 10:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).