Skip to content

Commit 38358fa

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: airoha: Fix PPE table access in airoha_ppe_debugfs_foe_show()
In order to avoid any possible race we need to hold the ppe_lock spinlock accessing the hw PPE table. airoha_ppe_foe_get_entry routine is always executed holding ppe_lock except in airoha_ppe_debugfs_foe_show routine. Fix the problem introducing airoha_ppe_foe_get_entry_locked routine. Fixes: 3fe15c6 ("net: airoha: Introduce PPE debugfs support") Reviewed-by: Dawid Osuchowski <[email protected]> Signed-off-by: Lorenzo Bianconi <[email protected]> Link: https://patch.msgid.link/20250731-airoha_ppe_foe_get_entry_locked-v2-1-50efbd8c0fd6@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f8fded7 commit 38358fa

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

drivers/net/ethernet/airoha/airoha_ppe.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,11 @@ static void airoha_ppe_foe_flow_stats_update(struct airoha_ppe *ppe,
508508
FIELD_PREP(AIROHA_FOE_IB2_NBQ, nbq);
509509
}
510510

511-
struct airoha_foe_entry *airoha_ppe_foe_get_entry(struct airoha_ppe *ppe,
512-
u32 hash)
511+
static struct airoha_foe_entry *
512+
airoha_ppe_foe_get_entry_locked(struct airoha_ppe *ppe, u32 hash)
513513
{
514+
lockdep_assert_held(&ppe_lock);
515+
514516
if (hash < PPE_SRAM_NUM_ENTRIES) {
515517
u32 *hwe = ppe->foe + hash * sizeof(struct airoha_foe_entry);
516518
struct airoha_eth *eth = ppe->eth;
@@ -537,6 +539,18 @@ struct airoha_foe_entry *airoha_ppe_foe_get_entry(struct airoha_ppe *ppe,
537539
return ppe->foe + hash * sizeof(struct airoha_foe_entry);
538540
}
539541

542+
struct airoha_foe_entry *airoha_ppe_foe_get_entry(struct airoha_ppe *ppe,
543+
u32 hash)
544+
{
545+
struct airoha_foe_entry *hwe;
546+
547+
spin_lock_bh(&ppe_lock);
548+
hwe = airoha_ppe_foe_get_entry_locked(ppe, hash);
549+
spin_unlock_bh(&ppe_lock);
550+
551+
return hwe;
552+
}
553+
540554
static bool airoha_ppe_foe_compare_entry(struct airoha_flow_table_entry *e,
541555
struct airoha_foe_entry *hwe)
542556
{
@@ -651,7 +665,7 @@ airoha_ppe_foe_commit_subflow_entry(struct airoha_ppe *ppe,
651665
struct airoha_flow_table_entry *f;
652666
int type;
653667

654-
hwe_p = airoha_ppe_foe_get_entry(ppe, hash);
668+
hwe_p = airoha_ppe_foe_get_entry_locked(ppe, hash);
655669
if (!hwe_p)
656670
return -EINVAL;
657671

@@ -703,7 +717,7 @@ static void airoha_ppe_foe_insert_entry(struct airoha_ppe *ppe,
703717

704718
spin_lock_bh(&ppe_lock);
705719

706-
hwe = airoha_ppe_foe_get_entry(ppe, hash);
720+
hwe = airoha_ppe_foe_get_entry_locked(ppe, hash);
707721
if (!hwe)
708722
goto unlock;
709723

@@ -818,7 +832,7 @@ airoha_ppe_foe_flow_l2_entry_update(struct airoha_ppe *ppe,
818832
u32 ib1, state;
819833
int idle;
820834

821-
hwe = airoha_ppe_foe_get_entry(ppe, iter->hash);
835+
hwe = airoha_ppe_foe_get_entry_locked(ppe, iter->hash);
822836
if (!hwe)
823837
continue;
824838

@@ -855,7 +869,7 @@ static void airoha_ppe_foe_flow_entry_update(struct airoha_ppe *ppe,
855869
if (e->hash == 0xffff)
856870
goto unlock;
857871

858-
hwe_p = airoha_ppe_foe_get_entry(ppe, e->hash);
872+
hwe_p = airoha_ppe_foe_get_entry_locked(ppe, e->hash);
859873
if (!hwe_p)
860874
goto unlock;
861875

0 commit comments

Comments
 (0)