Skip to contentSkip to conversation

net: mvpp2: Prevent parser TCAM memory corruption

PATCH Applied Tobias Waldekranz 3 participants 3 messages Apr 1, 2025 – Apr 2, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 net: mvpp2: Prevent parser TCAM memory corruption

Protect the parser TCAM/SRAM memory, and the cached (shadow) SRAM information, from concurrent modifications.

Both the TCAM and SRAM tables are indirectly accessed by configuring an index register that selects the row to read or write to. This means that operations must be atomic in order to, e.g., avoid spreading writes across multiple rows. Since the shadow SRAM array is used to find free rows in the hardware table, it must also be protected in order to avoid TOCTOU errors where multiple cores allocate the same row.

This issue was detected in a situation where mvpp2_set_rx_mode() ran concurrently on two CPUs. In this particular case the MVPP2_PE_MAC_UC_PROMISCUOUS entry was corrupted, causing the classifier unit to drop all incoming unicast - indicated by the rx_classifier_drops counter.

Fixes 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375 network unit")

---

v4 -> v5:
- Fix incorrect indentation (Jakub)
- Use double-underbar prefix instead of _unlocked suffix (Jakub)

v3 -> v4:
- Move memory allocations outside of atomic region in mvpp2_prs_default_init() (Maxime)

v2 -> v3:
- Note the fact that prs_spinlock also protects the SRAM shadow table (Andrew)
- Add lockdep assertions for HW table accesses (Andrew/Jakub)
- Add locking to the init path, since it uses the table access functions that are now annotated with lockdep assertions

v1 -> v2:
- Parser memory is never modified from hard IRQ context, so settle for disabling bottom halves in critical sections. (Maxime)

 drivers/net/ethernet/marvell/mvpp2/mvpp2.h    |   3 +
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   |   3 +-
 .../net/ethernet/marvell/mvpp2/mvpp2_prs.c    | 201 ++++++++++++------
 3 files changed, 140 insertions(+), 67 deletions(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2.h +3 -0
index 44fe9b68d1c2..061fcd444d50 100644
@@ -1113,6 +1113,9 @@ struct mvpp2 {
 
 	/* Spinlocks for CM3 shared memory configuration */
 	spinlock_t mss_spinlock;
+
+	/* Spinlock for shared PRS parser memory and shadow table */
+	spinlock_t prs_spinlock;
 };
 
 struct mvpp2_pcpu_stats {
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +2 -1
index 566c12c89520..416a926a8281 100644
@@ -7723,8 +7723,9 @@ static int mvpp2_probe(struct platform_device *pdev)
 	if (mvpp2_read(priv, MVPP2_VER_ID_REG) == MVPP2_VER_PP23)
 		priv->hw_version = MVPP23;
 
-	/* Init mss lock */
+	/* Init locks for shared packet processor resources */
 	spin_lock_init(&priv->mss_spinlock);
+	spin_lock_init(&priv->prs_spinlock);
 
 	/* Initialize network controller */
 	err = mvpp2_init(pdev, priv);
drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c +135 -66

536 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by Tested-by on v5 1/1
#1 lore raw

Hi Tobias,

Quoted 17 lines · On Tue, 1 Apr 2025 08:58:04 +0200 Tobias Waldekranz <[email protected]>…

Protect the parser TCAM/SRAM memory, and the cached (shadow) SRAM information, from concurrent modifications.

Both the TCAM and SRAM tables are indirectly accessed by configuring an index register that selects the row to read or write to. This means that operations must be atomic in order to, e.g., avoid spreading writes across multiple rows. Since the shadow SRAM array is used to find free rows in the hardware table, it must also be protected in order to avoid TOCTOU errors where multiple cores allocate the same row.

This issue was detected in a situation where mvpp2_set_rx_mode() ran concurrently on two CPUs. In this particular case the MVPP2_PE_MAC_UC_PROMISCUOUS entry was corrupted, causing the classifier unit to drop all incoming unicast - indicated by the rx_classifier_drops counter.

Quoted 3 lines
Fixes 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375 network unit")

---

It looks pretty good, I ran my no-so-stressfull tests to make sure filtering / promisc paths still work and without warning, which is the case :)

Thanks !

Maxime

#2 lore raw
In reply to Tobias Waldekranz
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Tue, 1 Apr 2025 08:58:04 +0200 you wrote:

Protect the parser TCAM/SRAM memory, and the cached (shadow) SRAM information, from concurrent modifications.

Both the TCAM and SRAM tables are indirectly accessed by configuring an index register that selects the row to read or write to. This means that operations must be atomic in order to, e.g., avoid spreading writes across multiple rows. Since the shadow SRAM array is used to find free rows in the hardware table, it must also be protected in order to avoid TOCTOU errors where multiple cores allocate the same row.

Quoted 1 line

[...]

Here is the summary with links:
- [v5] net: mvpp2: Prevent parser TCAM memory corruption

    https://git.kernel.org/netdev/net/c/96844075226b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html