public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Jakub Kicinski" <kuba@kernel.org>
Cc: "Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Haavard Skinnemoen" <hskinnemoen@atmel.com>,
	"Jeff Garzik" <jeff@garzik.org>,
	"Paolo Valerio" <pvalerio@redhat.com>,
	"Conor Dooley" <conor@kernel.org>,
	"Nicolai Buchwitz" <nb@tipi-net.de>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
	"Gregory CLEMENT" <gregory.clement@bootlin.com>,
	"Benoît Monin" <benoit.monin@bootlin.com>,
	"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH net v2 2/4] net: macb: drop in-flight Tx SKBs on close
Date: Thu, 30 Apr 2026 18:20:01 +0200	[thread overview]
Message-ID: <DI6MK3PFX8EE.1R1567RYTUVNL@bootlin.com> (raw)
In-Reply-To: <20260429193446.5985abea@kernel.org>

Hello Jakub,

On Thu Apr 30, 2026 at 4:34 AM CEST, Jakub Kicinski wrote:
> On Tue, 28 Apr 2026 18:32:58 +0200 Théo Lebrun wrote:
>>  	for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
>> -		kfree(queue->tx_skb);
>> -		queue->tx_skb = NULL;
>> +		if (queue->tx_skb) {
>> +			unsigned int dropped = 0, tail;
>> +
>> +			for (tail = queue->tx_tail; tail != queue->tx_head;
>> +			     tail++) {
>> +				if (macb_tx_skb(queue, tail)->skb)
>> +					dropped++;
>> +				macb_tx_unmap(bp, macb_tx_skb(queue, tail), 0,
>> +					      SKB_DROP_REASON_NOT_SPECIFIED);
>> +			}
>> +
>> +			queue->stats.tx_dropped += dropped;
>> +			bp->dev->stats.tx_dropped += dropped;
>
> I'm slightly baffled by the stats in this driver.
>
> Incrementing of both device and queue stats is highly unusual.
> The driver seems to already have the values for the per-queue drops
> but currently never increments it (did I miss it?) It does for Rx
> stats but not for Tx stats.
>
> As sashiko correctly points out incrementing dev stats will lead
> to races and lass of increments for multi-queue devices.
>
> Since there are no increments for tx_dropped stat today - could you
> please delete it from ethtool -S, migrate the only existing
> dev->stats.tx_dropped++; to increment the per-queue stat and make 
> macb_get_stats() collect the tx_dropped from all queues, instead
> of relying on the device-level stat?
>
> This should be patch 2 in this series, and then subsequent patches
> don't have to do this double-counting dance.
>
> I suppose you may want to migrate the byte and packet counters
> while at it, and add a u64 sync...

Agreed. Here is the plan for next revision. It goes further than your
proposal on some aspects and less so on others.

 - Stop using `netdev->stats`. Not even on MACB (single queue) or from
   at91 code (single queue, custom functions for a lot of things). This
   will drop all the double-counting; I added some in this series but
   there is lot in the driver to drop.

   sed 's/netdev->stats/queue->stats/' **/macb_main.c  # -ish

 - All stats that used to land in netdev->stats will instead land in
   queue->stats. For that we need to add two fields:
    - multicast, incremented by at91ether_rx()
    - tx_errors, incremented by at91ether_interrupt()

 - Make queue->stats u64 values (getting inspiration from nstat).

 - In macb_get_stats(), replace:

      netdev_stats_to_stats64(nstat, &bp->dev->stats);

   by:

      for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
         u64_stats_fetch_begin(...);
         nstat->rx_packets += queue->stats.rx_packets;
         nstat->tx_packets += queue->stats.tx_packets;
         // ... same for all stats ...
      }

 - Also the struct name (struct queue_stats) deserves a driver prefix.

Notice we don't drop tx_dropped from `ethtool -S`. It might be useful to
get per-queue stats and it doesn't cost much. We need per-queue
counters anyway, let's keep exposing them.

I don't have time to test enough, next revision will wait next week.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  parent reply	other threads:[~2026-04-30 16:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28 16:32 [PATCH net v2 0/4] Drop in-flight Tx SKBs on MACB close Théo Lebrun
2026-04-28 16:32 ` [PATCH net v2 1/4] net: macb: give reasons for Tx SKB kfree Théo Lebrun
2026-04-28 21:21   ` Nicolai Buchwitz
2026-04-28 16:32 ` [PATCH net v2 2/4] net: macb: drop in-flight Tx SKBs on close Théo Lebrun
2026-04-28 21:30   ` Nicolai Buchwitz
2026-04-29  9:26     ` Théo Lebrun
2026-04-29 22:14       ` Nicolai Buchwitz
2026-04-30  2:34   ` Jakub Kicinski
2026-04-30  7:14     ` Nicolai Buchwitz
2026-04-30 16:20     ` Théo Lebrun [this message]
2026-04-30 23:54       ` Jakub Kicinski
2026-04-28 16:32 ` [PATCH net v2 3/4] net: macb: increment stats.tx_dropped on tx error Théo Lebrun
2026-04-28 21:25   ` Nicolai Buchwitz
2026-04-28 16:33 ` [PATCH net v2 4/4] net: macb: increment stats.tx_dropped on DMA map error Théo Lebrun
2026-04-28 21:26   ` Nicolai Buchwitz

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=DI6MK3PFX8EE.1R1567RYTUVNL@bootlin.com \
    --to=theo.lebrun@bootlin.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=benoit.monin@bootlin.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=conor@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregory.clement@bootlin.com \
    --cc=hskinnemoen@atmel.com \
    --cc=jeff@garzik.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=pabeni@redhat.com \
    --cc=pvalerio@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tawfik.bayouk@mobileye.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vladimir.kondratiev@mobileye.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