From: Jakub Kicinski <kuba@kernel.org>
To: linusw@kernel.org
Cc: Jakub Kicinski <kuba@kernel.org>,
ulli.kroll@googlemail.com, andrew+netdev@lunn.ch,
davem@davemloft.net, pabeni@redhat.com, mirq-linux@rere.qmqm.pl,
mhun512@gmail.com, edumazet@kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v6 14/15] net: ethernet: cortina: Scope RX statistics updates
Date: Mon, 9 Nov 2026 17:16:23 -0800 [thread overview]
Message-ID: <20261110011623.1733622-1-kuba@kernel.org> (raw)
In-Reply-To: <20261103-gemini-ethernet-fixes-3-v6-14-c4b5ff8a65d8@kernel.org>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: ethernet: cortina: Scope RX statistics updates
This patch narrows the rx_stats_syncp writer sections in gmac_napi_poll()
so they no longer span gmac_rx(). The writer sections now wrap only the
individual counter updates in gmac_skb_if_good_frame() and gmac_rx(). It
also adds u64_stats_init() calls for the tx, rx and ir syncp objects in
gemini_ethernet_port_probe().
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 5e89057bb2fb6..c32e9574c8c95 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
[ ... ]
> @@ -2863,6 +2872,9 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
> }
>
> port = netdev_priv(netdev);
> + u64_stats_init(&port->tx_stats_syncp);
> + u64_stats_init(&port->rx_stats_syncp);
> + u64_stats_init(&port->ir_stats_syncp);
[Severity: High]
This patch didn't introduce this, but since it touches tx_stats_syncp:
can the TX reader loop in gmac_get_ethtool_stats() write past the end of
the ethtool stats buffer?
drivers/net/ethernet/cortina/gemini.c:gmac_get_ethtool_stats() {
...
/* Racing with TX start_xmit */
do {
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;
} while (u64_stats_fetch_retry(&port->tx_stats_syncp, start));
}
The loop resets p at the top of each pass, but the body writes through
values++ and never uses p. After the first pass, values points at the end
of the GMAC_STATS_NUM u64 array.
ethtool_get_stats() allocates that array with
vzalloc(n_stats * sizeof(u64)). If u64_stats_fetch_retry() forces a
retry, the next pass writes another TX_MAX_FRAGS + 2 u64 values (144
bytes) past the end. Each further retry writes another 144 bytes, and
nothing bounds the number of retries.
Gemini is 32-bit, so the seqcount is real there. A transmit that runs
during the read can bump tx_stats_syncp and trigger the retry, for
example:
gmac_start_xmit()->gmac_clean_txq()
u64_stats_update_begin(&port->tx_stats_syncp);
port->tx_frag_stats[nfrags]++;
u64_stats_update_end(&port->tx_stats_syncp);
ETHTOOL_GSTATS is one of the commands that does not need privileges.
This loop has two more problems. port->tx_hw_csummed is read under
tx_stats_syncp, but gmac_clean_txq() writes it under ir_stats_syncp:
u64_stats_update_begin(&port->ir_stats_syncp);
...
port->tx_hw_csummed += hwchksum;
u64_stats_update_end(&port->ir_stats_syncp);
So this reader has no protection against torn reads of that counter.
Also, the reader clears port->tx_frag_stats[i] = 0 outside any writer
section. That races with the tx_frag_stats[nfrags]++ in gmac_clean_txq()
and can lose increments. It also resets the counters on every read.
Should the loop write through *p++ like the RX and MIB loops above it,
read tx_hw_csummed under ir_stats_syncp, and stop zeroing tx_frag_stats
from the reader?
> SET_NETDEV_DEV(netdev, dev);
> port->netdev = netdev;
> port->id = id;
next prev parent reply other threads:[~2026-11-10 1:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 17:51 [PATCH net-next v6 00/15] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 01/15] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
2026-11-10 1:16 ` Jakub Kicinski
2026-11-10 10:08 ` Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 02/15] net: ethernet: cortina: Keep PHY-less port bound for shared IRQ Linus Walleij
2026-11-10 1:16 ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 03/15] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 04/15] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
2026-11-10 1:16 ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 05/15] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 06/15] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
2026-11-10 1:16 ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 07/15] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
2026-11-10 1:16 ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 08/15] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 09/15] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
2026-11-10 1:16 ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 10/15] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 11/15] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 12/15] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 13/15] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 14/15] net: ethernet: cortina: Scope RX statistics updates Linus Walleij
2026-11-10 1:16 ` Jakub Kicinski [this message]
2026-11-03 17:51 ` [PATCH net-next v6 15/15] net: ethernet: cortina: Drain RX coalescing timer on stop Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110011623.1733622-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=linusw@kernel.org \
--cc=mhun512@gmail.com \
--cc=mirq-linux@rere.qmqm.pl \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ulli.kroll@googlemail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox