Skip to contentSkip to conversation

eth: fbnic: Fix drop stats support

PATCH Applied Mohsin Bashir 3 participants 6 messages Aug 2, 2025 – Aug 5, 2025

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

cover eth: fbnic: Fix drop stats support

Fix hardware drop stats support on the TX path of fbnic by addressing two
issues: ensure that tx_dropped stats are correctly copied to the rtnl_link_stats64 struct, and protect the copying of drop stats from fdb->hw_stats to the local variable with the hw_stats_lock to ensure consistency.

Mohsin Bashir (2):
eth: fbnic: Fix tx_dropped reporting
eth: fbnic: Lock the tx_dropped update

 drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/2 eth: fbnic: Fix tx_dropped reporting

Correctly copy the tx_dropped stats from the fbd->hw_stats to the rtnl_link_stats64 struct.

Fixes 5f8bd2ce8269 ("eth: fbnic: add support for TMI stats")
---
 drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +4 -4
index 7bd7812d9c06..dc295e1b8516 100644
@@ -420,16 +420,16 @@ static void fbnic_get_stats64(struct net_device *dev,
 	tx_packets = stats->packets;
 	tx_dropped = stats->dropped;
 
-	stats64->tx_bytes = tx_bytes;
-	stats64->tx_packets = tx_packets;
-	stats64->tx_dropped = tx_dropped;
-
 	/* Record drops from Tx HW Datapath */
 	tx_dropped += fbd->hw_stats.tmi.drop.frames.value +
 		      fbd->hw_stats.tti.cm_drop.frames.value +
 		      fbd->hw_stats.tti.frame_drop.frames.value +
 		      fbd->hw_stats.tti.tbi_drop.frames.value;
 
+	stats64->tx_bytes = tx_bytes;
+	stats64->tx_packets = tx_packets;
+	stats64->tx_dropped = tx_dropped;
+
 	for (i = 0; i < fbn->num_tx_queues; i++) {
 		struct fbnic_ring *txr = fbn->tx[i];
 
Signature · 1 line
2.47.3
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH net 1/2] eth: fbnic: Fix tx_dropped reporting

Quoted 6 lines · Mohsin Bashir

Correctly copy the tx_dropped stats from the fbd->hw_stats to the rtnl_link_stats64 struct.

Fixes 5f8bd2ce8269 ("eth: fbnic: add support for TMI stats")

Thanks,

I note that the local variable tx_dropped was being saved to stats64 before it's values were accumulated from hw_stats.

#3 lore raw

PATCH 2/2 eth: fbnic: Lock the tx_dropped update

In reply to Mohsin Bashir

Wrap copying of drop stats on TX path from fbd->hw_stats by the hw_stats_lock. Currently, it is being performed outside the lock and another thread accessing fbd->hw_stats can lead to inconsistencies.

Fixes 5f8bd2ce8269 ("eth: fbnic: add support for TMI stats")
---
 drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +2 -0
index dc295e1b8516..d0e381ad7bee 100644
@@ -421,10 +421,12 @@ static void fbnic_get_stats64(struct net_device *dev,
 	tx_dropped = stats->dropped;
 
 	/* Record drops from Tx HW Datapath */
+	spin_lock(&fbd->hw_stats_lock);
 	tx_dropped += fbd->hw_stats.tmi.drop.frames.value +
 		      fbd->hw_stats.tti.cm_drop.frames.value +
 		      fbd->hw_stats.tti.frame_drop.frames.value +
 		      fbd->hw_stats.tti.tbi_drop.frames.value;
+	spin_unlock(&fbd->hw_stats_lock);
 
 	stats64->tx_bytes = tx_bytes;
 	stats64->tx_packets = tx_packets;
Signature · 1 line
2.47.3
reviewer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH net 2/2] eth: fbnic: Lock the tx_dropped update

Quoted 7 lines · Mohsin Bashir

Wrap copying of drop stats on TX path from fbd->hw_stats by the hw_stats_lock. Currently, it is being performed outside the lock and another thread accessing fbd->hw_stats can lead to inconsistencies.

Fixes 5f8bd2ce8269 ("eth: fbnic: add support for TMI stats")

Thanks,

I note that hw_stats_lock is documented as protecting hw_stats. And that it is already used for that purpose elsewhere in fbnic_get_stats64().

I do wonder if some refactoring could allow only locking hw_stats_lock once in fbnic_get_stats64(). But that line of thought doesn't effect the correctness of this patch.

#5 lore raw
In reply to Mohsin Bashir
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 11 lines · On Fri, 1 Aug 2025 19:46:34 -0700 you wrote:

Fix hardware drop stats support on the TX path of fbnic by addressing two
issues: ensure that tx_dropped stats are correctly copied to the rtnl_link_stats64 struct, and protect the copying of drop stats from fdb->hw_stats to the local variable with the hw_stats_lock to ensure consistency.

Mohsin Bashir (2):
eth: fbnic: Fix tx_dropped reporting
eth: fbnic: Lock the tx_dropped update

[...]

Here is the summary with links:
- [net,1/2] eth: fbnic: Fix tx_dropped reporting

    https://git.kernel.org/netdev/net/c/2972395d8fad
  - [net,2/2] eth: fbnic: Lock the tx_dropped update
    https://git.kernel.org/netdev/net/c/53abd9c86fd0

You are awesome, thank you!

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