netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Nicolai Buchwitz" <nb@tipi-net.de>
Cc: "Conor Dooley" <conor.dooley@microchip.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Russell King" <linux@armlinux.org.uk>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Paolo Valerio" <pvalerio@redhat.com>,
	"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>
Subject: Re: [PATCH net-next v6 1/2] net: macb: implement ethtool_ops.get|set_channels()
Date: Tue, 17 Nov 2026 11:20:24 +0100	[thread overview]
Message-ID: <DMXES9NC6HIW.14FBO92H3XSQQ@bootlin.com> (raw)
In-Reply-To: <0d65e4cc9a68684cd69ffa7feb5b7440@tipi-net.de>

Hello Nicolai,

On Sun Nov 15, 2026 at 8:39 PM CET, Nicolai Buchwitz wrote:
> On 13.11.2026 18:32, Théo Lebrun wrote:
>> @@ -3351,16 +3374,21 @@ static void macb_context_swap_end(struct macb 
>> *bp,
>> 
>>  	lockdep_assert_held(&bp->mac_cfg_lock);
>> 
>> -	/* Swap contexts & give buffer pointers to HW. */
>> +	/* Swap contexts & give buffer pointers to HW.
>> +	 * !new_ctx means that the swap failed and we keep the old context.
>> +	 */
>> +
>> +	if (new_ctx) {
>> +		old_ctx = bp->ctx;
>> +		WRITE_ONCE(bp->ctx, new_ctx);
>> +		wmb(); /* ensure IRQ enabled below read the new context */
>> +	}
>> 
>> -	old_ctx = bp->ctx;
>> -	WRITE_ONCE(bp->ctx, new_ctx);
>> -	wmb(); /* ensure IRQ enabled below read the new context */
>>  	macb_init_buffers(bp);
>
> The NULL case reuses the old rings without mog_init_rings(). The HW
> restarts at descriptor 0 but head/tail don't, so Tx stalls after a
> failed ethtool -L? macb_hresp_error_task() reinits the rings first.

Hum, so you are totally right on that. Both Tx (txq->head + txq->tail)
and Rx (rxq->tail + rxq->prepared_head) cursors are wrong by being out
of sync with the hardware cursors.

But the approach taken by macb_hresp_error_task() is wrong: it resets
the Tx cursors and Tx descriptors in the existing context but by doing
so leak all Tx buffers. Rx buffers aren't leaking because
gem_init_rx_ring() sets RX_USED on all slots then refills.

Sashiko [0] points out the same issue; I'll wait for the end of the
Clashiko [1] embargo period before re-sending, to see what it has to
say.

---

There can be two solutions to this:

 - We don't touch the HW cursors RBQPH/TBQPH/RBQP/TBQP by not calling
   macb_init_buffers() at swap_end. So here the swap operation will
   have been as close as possible to a no-op where we just stopped the
   HW for a small window.

 - We do reset the HW cursors. But that means we need to make sure both
   rings are in a good shape (which they are not with v6).

   It isn't a massive amount of work, but it still is more code (that
   might be buggy). We need to free pending Tx slots or bring them to
   the front of the ring. For Rx we should consume RX_USED slots.

I prefer the first approach. It is simpler and alloc-free (ENOMEM is
probably the reason why the set_channels context swap failed when
calling netif_set_real_num_queues).

[0]: https://sashiko.dev/#/patchset/20261113-macb-set-channels-v6-0-5de59d9e7f02%40bootlin.com?part=1
[1]: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-macb-set-channels-v6-0-5de59d9e7f02%40bootlin.com

Thanks,

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


  reply	other threads:[~2026-11-17 10:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 17:32 [PATCH net-next v6 0/2] net: macb: implement ethtool set channels count operation Théo Lebrun
2026-11-13 17:32 ` [PATCH net-next v6 1/2] net: macb: implement ethtool_ops.get|set_channels() Théo Lebrun
2026-11-15 19:39   ` Nicolai Buchwitz
2026-11-17 10:20     ` Théo Lebrun [this message]
2026-11-13 17:32 ` [PATCH net-next v6 2/2] net: macb: distribute evenly Tx SRAM segments Théo Lebrun
2026-11-13 18:18   ` Théo Lebrun
2026-11-15 19:40   ` Nicolai Buchwitz
2026-11-17 10:23     ` Théo Lebrun

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=DMXES9NC6HIW.14FBO92H3XSQQ@bootlin.com \
    --to=theo.lebrun@bootlin.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=benoit.monin@bootlin.com \
    --cc=conor.dooley@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gregory.clement@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pvalerio@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).