lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241109092024.4039494-1-zhangheng@kylinos.cn>
Date: Sat,  9 Nov 2024 17:20:24 +0800
From: zhangheng <zhangheng@...inos.cn>
To: davem@...emloft.net,
	edumazet@...gle.com,
	kuba@...nel.org,
	pabeni@...hat.com
Cc: netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	zhangheng <zhangheng@...inos.cn>
Subject: [PATCH 3/4] net: korina: staging: octeon: Use DEV_STAT_INC()

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@...inos.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ