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

Mohsin Bashir posted 2 patches 2 months ago
[PATCH net 2/2] eth: fbnic: Lock the tx_dropped update
Posted by Mohsin Bashir 2 months ago
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")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>
---
 drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
index dc295e1b8516..d0e381ad7bee 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
@@ -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;
-- 
2.47.3
Re: [PATCH net 2/2] eth: fbnic: Lock the tx_dropped update
Posted by Simon Horman 2 months ago
On Fri, Aug 01, 2025 at 07:46:36PM -0700, Mohsin Bashir wrote:
> 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")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Mohsin Bashir <mohsin.bashr@gmail.com>

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.

Reviewed-by: Simon Horman <horms@kernel.org>