All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] The ice driver may rarely return incorrect statistics counter values
@ 2025-02-21  3:12 Masakazu Asama
  2025-02-24 11:21 ` Przemek Kitszel
  0 siblings, 1 reply; 4+ messages in thread
From: Masakazu Asama @ 2025-02-21  3:12 UTC (permalink / raw)
  To: intel-wired-lan


[-- Attachment #1.1: Type: text/plain, Size: 2241 bytes --]

We have observed a very rare issue in Intel E810 environments where
SNMP-retrieved TX/RX counter values are sometimes nearly twice the actual
values.

Upon investigation, we identified a problem in the process that updates the
transmit and receive ring statistics in the ice driver. This issue occurs
when the counter update process is executed simultaneously on different CPU
cores.

I have attached a patch to fix this issue.

This patch is intended for Linux kernel 5.15 on Ubuntu 22.04, as my
environment is Ubuntu 22.04.

In my test environment, applying this patch prevents the issue from
occurring.

The function ice_update_vsi_ring_stats takes a pointer to a struct ice_vsi
as an argument. This structure is allocated on the heap and shared across
all CPU cores. The function resets the counter values to zero and then
accumulates the values from each ring of the NIC.

However, since struct ice_vsi is shared across all CPU cores, the following
race condition can occur when ice_update_vsi_ring_stats is executed
simultaneously on different CPUs:

1. Multiple CPU cores reset the counter values in struct ice_vsi to zero at
the same time.

2. Each CPU core independently increments the counter values.

As a result, the counter values may be updated to a higher-than-actual
value.

The attached patch modifies the implementation to store the counter values
on the stack, initialize them to zero, increment them with the values from
each ring, and finally update struct ice_vsi. By avoiding the use of shared
data for intermediate calculations, this fix prevents the issue.

In my environment, multiple Intel E810 NICs are bonded together.

I use Zabbix to graph the RX/TX counters of the bonding interface. However,
due to the way bonding ignores decreases in the counters of slave
interfaces, this issue makes the statistics completely unreliable.

Graphs generated from the slave interfaces may appear normal because, even
if the counter temporarily increases, it is corrected in the next
observation.

When I reported this issue to the Ubuntu bug tracking system, I was told to
get it merged upstream first.

I would like this issue to be fixed, but what should I do to get it
accepted?

Any advice would be greatly appreciated.

[-- Attachment #1.2: Type: text/html, Size: 3021 bytes --]

[-- Attachment #2: ice_update_vsi_ring_stats.patch --]
[-- Type: application/octet-stream, Size: 3410 bytes --]

diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index b4c6965a8..38ba46235 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -5746,10 +5746,10 @@ ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
  * @count: number of rings
  */
 static void
-ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi, struct ice_ring **rings,
-			     u16 count)
+ice_update_vsi_tx_ring_stats(u64 *tx_packets, u64 *tx_bytes, u64 *tx_restart,
+		u64 *tx_busy, u64 *tx_linearize, struct ice_ring **rings,
+		u16 count)
 {
-	struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
 	u16 i;
 
 	for (i = 0; i < count; i++) {
@@ -5758,11 +5758,11 @@ ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi, struct ice_ring **rings,
 
 		ring = READ_ONCE(rings[i]);
 		ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
-		vsi_stats->tx_packets += pkts;
-		vsi_stats->tx_bytes += bytes;
-		vsi->tx_restart += ring->tx_stats.restart_q;
-		vsi->tx_busy += ring->tx_stats.tx_busy;
-		vsi->tx_linearize += ring->tx_stats.tx_linearize;
+		*tx_packets += pkts;
+		*tx_bytes += bytes;
+		*tx_restart += ring->tx_stats.restart_q;
+		*tx_busy += ring->tx_stats.tx_busy;
+		*tx_linearize += ring->tx_stats.tx_linearize;
 	}
 }
 
@@ -5776,41 +5776,54 @@ static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
 	u64 pkts, bytes;
 	int i;
 
-	/* reset netdev stats */
-	vsi_stats->tx_packets = 0;
-	vsi_stats->tx_bytes = 0;
-	vsi_stats->rx_packets = 0;
-	vsi_stats->rx_bytes = 0;
+	u64 tx_packets = 0;
+	u64 tx_bytes = 0;
+	u64 rx_packets = 0;
+	u64 rx_bytes = 0;
 
-	/* reset non-netdev (extended) stats */
-	vsi->tx_restart = 0;
-	vsi->tx_busy = 0;
-	vsi->tx_linearize = 0;
-	vsi->rx_buf_failed = 0;
-	vsi->rx_page_failed = 0;
+	u64 tx_restart = 0;
+	u64 tx_busy = 0;
+	u64 tx_linearize = 0;
+	u64 rx_buf_failed = 0;
+	u64 rx_page_failed = 0;
 
 	rcu_read_lock();
 
 	/* update Tx rings counters */
-	ice_update_vsi_tx_ring_stats(vsi, vsi->tx_rings, vsi->num_txq);
+	ice_update_vsi_tx_ring_stats(&tx_packets, &tx_bytes, &tx_restart,
+			&tx_busy, &tx_linearize, vsi->tx_rings, vsi->num_txq);
 
 	/* update Rx rings counters */
 	ice_for_each_rxq(vsi, i) {
 		struct ice_ring *ring = READ_ONCE(vsi->rx_rings[i]);
 
 		ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
-		vsi_stats->rx_packets += pkts;
-		vsi_stats->rx_bytes += bytes;
-		vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
-		vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
+		rx_packets += pkts;
+		rx_bytes += bytes;
+		rx_buf_failed += ring->rx_stats.alloc_buf_failed;
+		rx_page_failed += ring->rx_stats.alloc_page_failed;
 	}
 
 	/* update XDP Tx rings counters */
 	if (ice_is_xdp_ena_vsi(vsi))
-		ice_update_vsi_tx_ring_stats(vsi, vsi->xdp_rings,
-					     vsi->num_xdp_txq);
+		ice_update_vsi_tx_ring_stats(&tx_packets, &tx_bytes,
+				&tx_restart, &tx_busy, &tx_linearize,
+				vsi->xdp_rings, vsi->num_xdp_txq);
 
 	rcu_read_unlock();
+
+	/* reset netdev stats */
+	vsi_stats->tx_packets = tx_packets;
+	vsi_stats->tx_bytes = tx_bytes;
+	vsi_stats->rx_packets = rx_packets;
+	vsi_stats->rx_bytes = rx_bytes;
+
+	/* reset non-netdev (extended) stats */
+	vsi->tx_restart = tx_restart;
+	vsi->tx_busy = tx_busy;
+	vsi->tx_linearize = tx_linearize;
+	vsi->rx_buf_failed = rx_buf_failed;
+	vsi->rx_page_failed = rx_page_failed;
 }
 
 /**

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

end of thread, other threads:[~2025-07-04 11:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-21  3:12 [Intel-wired-lan] The ice driver may rarely return incorrect statistics counter values Masakazu Asama
2025-02-24 11:21 ` Przemek Kitszel
2025-07-02  8:01   ` Masakazu Asama
2025-07-04 11:25     ` Przemek Kitszel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.