netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/4] net: korina: staging: octeon: Use DEV_STAT_INC()
@ 2024-11-09  9:20 zhangheng
  2024-11-11 17:36 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: zhangheng @ 2024-11-09  9:20 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni; +Cc: netdev, linux-kernel, zhangheng

syzbot/KCSAN reported that races happen when multiple CPUs updating
dev->stats.tx_error concurrently. Adopt SMP safe DEV_STATS_INC() to
update the dev->stats fields.

Signed-off-by: zhangheng <zhangheng@kylinos.cn>
---
 drivers/net/ethernet/korina.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/korina.c b/drivers/net/ethernet/korina.c
index 81cf3361a1e5..f08f6f115ce6 100644
--- a/drivers/net/ethernet/korina.c
+++ b/drivers/net/ethernet/korina.c
@@ -514,7 +514,7 @@ static netdev_tx_t korina_send_packet(struct sk_buff *skb,
 	return NETDEV_TX_OK;
 
 drop_packet:
-	dev->stats.tx_dropped++;
+	DEV_STATS_INC(dev, tx_dropped);
 	dev_kfree_skb_any(skb);
 	spin_unlock_irqrestore(&lp->lock, flags);
 
@@ -619,8 +619,8 @@ static int korina_rx(struct net_device *dev, int limit)
 
 		if (!(devcs & ETH_RX_ROK)) {
 			/* Update statistics counters */
-			dev->stats.rx_errors++;
-			dev->stats.rx_dropped++;
+			DEV_STATS_INC(dev, rx_errors);
+			DEV_STATS_INC(dev, rx_dropped);
 			if (devcs & ETH_RX_CRC)
 				dev->stats.rx_crc_errors++;
 			if (devcs & ETH_RX_LE)
@@ -657,12 +657,12 @@ static int korina_rx(struct net_device *dev, int limit)
 
 		/* Pass the packet to upper layers */
 		napi_gro_receive(&lp->napi, skb);
-		dev->stats.rx_packets++;
-		dev->stats.rx_bytes += pkt_len;
+		DEV_STATS_INC(dev, rx_packets);
+		DEV_STATS_ADD(dev, tx_bytes, pkt_len);
 
 		/* Update the mcast stats */
 		if (devcs & ETH_RX_MP)
-			dev->stats.multicast++;
+			DEV_STATS_INC(dev, multicast);
 
 		lp->rx_skb[lp->rx_next_done] = skb_new;
 		lp->rx_skb_dma[lp->rx_next_done] = ca;
@@ -780,39 +780,38 @@ static void korina_tx(struct net_device *dev)
 		devcs = lp->td_ring[lp->tx_next_done].devcs;
 		if ((devcs & (ETH_TX_FD | ETH_TX_LD)) !=
 				(ETH_TX_FD | ETH_TX_LD)) {
-			dev->stats.tx_errors++;
-			dev->stats.tx_dropped++;
+			DEV_STATS_INC(dev, tx_errors);
+			DEV_STATS_INC(dev, tx_dropped);
 
 			/* Should never happen */
 			printk(KERN_ERR "%s: split tx ignored\n",
 							dev->name);
 		} else if (devcs & ETH_TX_TOK) {
-			dev->stats.tx_packets++;
-			dev->stats.tx_bytes +=
-					lp->tx_skb[lp->tx_next_done]->len;
+			DEV_STATS_INC(dev, tx_packets);
+			DEV_STATS_ADD(dev, tx_bytes, lp->tx_skb[lp->tx_next_done]->len);
 		} else {
-			dev->stats.tx_errors++;
-			dev->stats.tx_dropped++;
+			DEV_STATS_INC(dev, tx_errors);
+			DEV_STATS_INC(dev, tx_dropped);
 
 			/* Underflow */
 			if (devcs & ETH_TX_UND)
-				dev->stats.tx_fifo_errors++;
+				DEV_STATS_INC(dev, tx_fifo_errors);
 
 			/* Oversized frame */
 			if (devcs & ETH_TX_OF)
-				dev->stats.tx_aborted_errors++;
+				DEV_STATS_INC(dev, tx_aborted_errors);
 
 			/* Excessive deferrals */
 			if (devcs & ETH_TX_ED)
-				dev->stats.tx_carrier_errors++;
+				DEV_STATS_INC(dev, tx_carrier_errors);
 
 			/* Collisions: medium busy */
 			if (devcs & ETH_TX_EC)
-				dev->stats.collisions++;
+				DEV_STATS_INC(dev, collisions);
 
 			/* Late collision */
 			if (devcs & ETH_TX_LC)
-				dev->stats.tx_window_errors++;
+				DEV_STATS_INC(dev, tx_window_errors);
 		}
 
 		/* We must always free the original skb */
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-11 17:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-09  9:20 [PATCH 3/4] net: korina: staging: octeon: Use DEV_STAT_INC() zhangheng
2024-11-11 17:36 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).