🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Linus Walleij Thu, 12 Nov 2026 13:30
[PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads
#15169
Author: Linus Walleij
Date: Thu, 12 Nov 2026 13:30
65 lines
10058 bytes
The TX statistics reader resets p on a seqcount retry but writes through
values instead. A retry on 32-bit systems therefore writes another 18
counters past the end of the ethtool statistics array. ETHTOOL_GSTATS
does not require privileges.

Write through p so each retry overwrites the same output slots. Stop
clearing the fragment counters from the reader, which races with TX
updates and resets the counters on each read. Snapshot tx_hw_csummed
under ir_stats_syncp, matching its writer, and retain its output position.

Found during Sashiko review and checked with an extracted-reader host
harness that forces seqcount retries. The old reader overwrote guard
entries and cleared counters; the fixed reader stays within the output
array and preserves counters.

Tested on the D-Link DIR-685 with intense transfers and ping storms,
reading out stats with ethtool at the same time.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 899d96420b1b..d4aa283ccb7b 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2520,6 +2520,7 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	unsigned int start;
+	u64 tx_hw_csummed;
 	u64 *p;
 	int i;
 
@@ -2532,6 +2533,7 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
 
 		for (i = 0; i < RX_STATS_NUM; i++)
 			*p++ = port->hw_stats[i];
+		tx_hw_csummed = port->tx_hw_csummed;
 
 	} while (u64_stats_fetch_retry(&port->ir_stats_syncp, start));
 	values = p;
@@ -2555,12 +2557,10 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
 		p = values;
 		start = u64_stats_fetch_begin(&port->tx_stats_syncp);
 
-		for (i = 0; i < TX_MAX_FRAGS; i++) {
-			*values++ = port->tx_frag_stats[i];
-			port->tx_frag_stats[i] = 0;
-		}
-		*values++ = port->tx_frags_linearized;
-		*values++ = port->tx_hw_csummed;
+		for (i = 0; i < TX_MAX_FRAGS; i++)
+			*p++ = port->tx_frag_stats[i];
+		*p++ = port->tx_frags_linearized;
+		*p++ = tx_hw_csummed;
 
 	} while (u64_stats_fetch_retry(&port->tx_stats_syncp, start));
 }

-- 
2.56.0
Re: [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads
#17275
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 14:45
72 lines
10219 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In gmac_get_ethtool_stats()
  (drivers/net/ethernet/cortina/gemini.c), the patch adds `tx_hw_csummed…

--

net: ethernet: cortina: Fix ethtool statistics reads

This fixes the TX statistics retry loop in gmac_get_ethtool_stats(). The
loop wrote through values instead of p, so a seqcount retry could write
past the end of the ethtool stats array. It also stops clearing
tx_frag_stats[] from the reader, and now snapshots tx_hw_csummed under
ir_stats_syncp to match its writer.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 899d96420b1b8..d4aa283ccb7b7 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -2532,6 +2533,7 @@ static void gmac_get_ethtool_stats(struct net_device *netdev,
>  
>  		for (i = 0; i < RX_STATS_NUM; i++)
>  			*p++ = port->hw_stats[i];
> +		tx_hw_csummed = port->tx_hw_csummed;
>  
>  	} while (u64_stats_fetch_retry(&port->ir_stats_syncp, start));
>  	values = p;

[Severity: Low]
This isn't a bug, but should the comment above this loop be updated as
well? It still says only:

	/* Racing with MIB interrupt */
	do {
		p = values;
		start = u64_stats_fetch_begin(&port->ir_stats_syncp);

The MIB path, gmac_update_hw_stats(), never writes tx_hw_csummed. The
only writer is gmac_clean_txq(), which is reached from gmac_start_xmit()
and gmac_cleanup_txqs():

drivers/net/ethernet/cortina/gemini.c:gmac_clean_txq() {
    ...
	spin_lock_irqsave(&geth->irq_lock, flags);
	u64_stats_update_begin(&port->ir_stats_syncp);
	...
	port->tx_hw_csummed += hwchksum;
	u64_stats_update_end(&port->ir_stats_syncp);
    ...
}

Before this patch the loop only read hw_stats[], so the comment was
accurate. The other ir_stats_syncp reader, gmac_get_stats64(), already
lists both writers:

	/* Racing with MIB and TX completion interrupts */

Could this loop's comment name the TX completion writer too, so the two
readers describe the same seqcount the same way?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3%40kernel.org
Re: [PATCH net-next v8 19/19] net: ethernet: cortina: Fix ethtool statistics reads
#17664
Author: Linus Walleij
Date: Tue, 17 Nov 2026 08:09
12 lines
9129 bytes
On Mon, Nov 16, 2026 at 3:45 PM <netdev-bot+sashiko@kernel.org> wrote:

> [Severity: Low]
> This isn't a bug, but should the comment above this loop be updated as
> well? It still says only:

That's overzealous, no big deal.

Yours,
Linus Walleij
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads