]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: ti: icssg-prueth: Add lock to stats
authorMD Danish Anwar <danishanwar@ti.com>
Fri, 14 Mar 2025 10:27:21 +0000 (15:57 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 28 Mar 2025 21:03:28 +0000 (22:03 +0100)
[ Upstream commit 47a9b5e52abd2b717dfc8b9460589f89936d93cf ]

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>
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/ti/icssg/icssg_prueth.c
drivers/net/ethernet/ti/icssg/icssg_prueth.h
drivers/net/ethernet/ti/icssg/icssg_stats.c

index cb11635a8d12099570a89dd6b8216e3b436e2ad5..6f0700d156e71043a670de70337a56921fa03fd3 100644 (file)
@@ -1555,6 +1555,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);
index 5473315ea204069dbe4e581706f05fab22440944..e456a11c5d4e38d3dfdc5b8421abcf41d0b83315 100644 (file)
@@ -297,6 +297,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 {
index 8800bd3a8d074c19f857646e05893d186fbab127..6f0edae38ea242394d9e92e6a0d0cd9736e9b448 100644 (file)
@@ -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)