Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Linus Walleij
Thu, 12 Nov 2026 13:30
[PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics
Author: Linus Walleij
Date: Thu, 12 Nov 2026 13:30
Date: Thu, 12 Nov 2026 13:30
66 lines
10330 bytes
10330 bytes
gmac_clean_txq() updates ir_stats_syncp with hard interrupts enabled,
while the MIB and RX overrun interrupt paths update the same seqcount.
Initializing its lockdep key exposes the incompatible IRQ contexts on
32-bit debug kernels. The writer sections also lack mutual exclusion.
Take the existing IRQ-safe irq_lock around the TX completion statistics
update, matching the other ir_stats_syncp writers. Acquire it before
opening the seqcount writer section so PREEMPT_RT does not acquire a
potentially sleeping spinlock with preemption disabled.
The TX fragment counter also uses tx_stats_syncp from both start_xmit()
and process-context teardown. Use IRQ-safe writer helpers around that
increment so a statistics reader cannot interrupt the writer and spin on
an odd sequence. Keep this protection local to the counter update rather
than covering the entire TX cleanup.
Found during Sashiko review and confirmed by tracing the IRQ, transmit and
stop paths. Cross-built gemini.o for ARM with W=1. No hardware lockdep or
PREEMPT_RT runtime testing was performed for this change.
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 | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 5a87d88607cd..cc26ff16a0a3 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -671,6 +671,7 @@ static void gmac_clean_txq(struct net_device *netdev, struct gmac_txq *txq,
union gmac_txdesc_1 word1;
unsigned int hwchksum = 0;
unsigned long bytes = 0;
+ unsigned long flags;
struct gmac_txdesc *txd;
unsigned short nfrags;
unsigned int errs = 0;
@@ -716,18 +717,21 @@ static void gmac_clean_txq(struct net_device *netdev, struct gmac_txq *txq,
if (nfrags >= TX_MAX_FRAGS)
nfrags = TX_MAX_FRAGS - 1;
- u64_stats_update_begin(&port->tx_stats_syncp);
+ flags = u64_stats_update_begin_irqsave(&port->tx_stats_syncp);
port->tx_frag_stats[nfrags]++;
- u64_stats_update_end(&port->tx_stats_syncp);
+ u64_stats_update_end_irqrestore(&port->tx_stats_syncp,
+ flags);
}
}
+ spin_lock_irqsave(&geth->irq_lock, flags);
u64_stats_update_begin(&port->ir_stats_syncp);
port->stats.tx_errors += errs;
port->stats.tx_packets += pkts;
port->stats.tx_bytes += bytes;
port->tx_hw_csummed += hwchksum;
u64_stats_update_end(&port->ir_stats_syncp);
+ spin_unlock_irqrestore(&geth->irq_lock, flags);
txq->cptr = c;
}
--
2.56.0
Re: [PATCH net-next v8 15/19] net: ethernet: cortina: Serialize TX completion statistics
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 14:45
Date: Mon, 16 Nov 2026 14:45
66 lines
10244 bytes
10244 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] The comment on geth->irq_lock still describes it as a lock for
IRQ-related registers.
--
net: ethernet: cortina: Serialize TX completion statistics
This commit takes geth->irq_lock around the ir_stats_syncp writer section
in gmac_clean_txq(), so the TX completion counters are serialized against
the MIB and RX overrun writers. It also switches the tx_frag_stats update
to the irqsave variants of the u64_stats writer helpers.
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 5a87d88607cdb..cc26ff16a0a36 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
[ ... ]
> @@ -716,18 +717,21 @@ static void gmac_clean_txq(struct net_device *netdev, struct gmac_txq *txq,
[ ... ]
> + spin_lock_irqsave(&geth->irq_lock, flags);
> u64_stats_update_begin(&port->ir_stats_syncp);
> port->stats.tx_errors += errs;
> port->stats.tx_packets += pkts;
> port->stats.tx_bytes += bytes;
> port->tx_hw_csummed += hwchksum;
> u64_stats_update_end(&port->ir_stats_syncp);
> + spin_unlock_irqrestore(&geth->irq_lock, flags);
[Severity: Low]
This isn't a bug, but should the comment on irq_lock in struct
gemini_ethernet be updated as well? It still says:
spinlock_t irq_lock; /* Locks IRQ-related registers */
This new critical section in gmac_clean_txq() does not touch any registers.
It only serializes the software counters under ir_stats_syncp against the
writers in gmac_update_hw_stats() and gmac_irq(). After this patch, irq_lock
is also the lock every ir_stats_syncp writer has to hold, and the struct
comment does not mention that.
A related issue predates this patch and was not introduced by it. The
reader in gmac_get_stats64() says:
/* Racing with MIB and TX completion interrupts */
gmac_clean_txq() is only called from gmac_start_xmit() and
gmac_cleanup_txqs(), never from an interrupt handler. Could that comment be
corrected at the same time?
>
> txq->cptr = c;
> }
--
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 15/19] net: ethernet: cortina: Serialize TX completion statistics
Author: Linus Walleij
Date: Tue, 17 Nov 2026 08:08
Date: Tue, 17 Nov 2026 08:08
17 lines
9310 bytes
9310 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 on irq_lock in struct > gemini_ethernet be updated as well? It still says: > > spinlock_t irq_lock; /* Locks IRQ-related registers */ > > This new critical section in gmac_clean_txq() does not touch any registers. No big deal, that is the main purpose. 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