net: ti: icssg-prueth: Fix race condition for VLAN table access
authorMD Danish Anwar <danishanwar@ti.com>
Mon, 7 Oct 2024 05:41:24 +0000 (11:11 +0530)
committerDavid S. Miller <davem@davemloft.net>
Wed, 9 Oct 2024 11:18:01 +0000 (12:18 +0100)
The VLAN table is a shared memory between the two ports/slices
in a ICSSG cluster and this may lead to race condition when the
common code paths for both ports are executed in different CPUs.

Fix the race condition access by locking the shared memory access

Fixes: 487f7323f39a ("net: ti: icssg-prueth: Add helper functions to configure FDB")
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Reviewed-by: Roger Quadros <rogerq@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ti/icssg/icssg_config.c
drivers/net/ethernet/ti/icssg/icssg_prueth.c
drivers/net/ethernet/ti/icssg/icssg_prueth.h

index 72ace15..5d2491c 100644 (file)
@@ -735,6 +735,7 @@ void icssg_vtbl_modify(struct prueth_emac *emac, u8 vid, u8 port_mask,
        u8 fid_c1;
 
        tbl = prueth->vlan_tbl;
+       spin_lock(&prueth->vtbl_lock);
        fid_c1 = tbl[vid].fid_c1;
 
        /* FID_C1: bit0..2 port membership mask,
@@ -750,6 +751,7 @@ void icssg_vtbl_modify(struct prueth_emac *emac, u8 vid, u8 port_mask,
        }
 
        tbl[vid].fid_c1 = fid_c1;
+       spin_unlock(&prueth->vtbl_lock);
 }
 EXPORT_SYMBOL_GPL(icssg_vtbl_modify);
 
index 5fd9902..5c20ceb 100644 (file)
@@ -1442,6 +1442,7 @@ static int prueth_probe(struct platform_device *pdev)
                icss_iep_init_fw(prueth->iep1);
        }
 
+       spin_lock_init(&prueth->vtbl_lock);
        /* setup netdev interfaces */
        if (eth0_node) {
                ret = prueth_netdev_init(prueth, eth0_node);
index bba6da2..8722bb4 100644 (file)
@@ -296,6 +296,8 @@ struct prueth {
        bool is_switchmode_supported;
        unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN];
        int default_vlan;
+       /** @vtbl_lock: Lock for vtbl in shared memory */
+       spinlock_t vtbl_lock;
 };
 
 struct emac_tx_ts_response {