Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: theo.lebrun@bootlin.com
Cc: conor.dooley@microchip.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, linux@armlinux.org.uk, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, nb@tipi-net.de,
	pvalerio@redhat.com, vladimir.kondratiev@mobileye.com,
	gregory.clement@bootlin.com, benoit.monin@bootlin.com,
	tawfik.bayouk@mobileye.com, thomas.petazzoni@bootlin.com
Subject: Re: [PATCH net-next v7 2/3] net: macb: implement ethtool_ops.get|set_channels()
Date: Sun, 22 Nov 2026 20:01:33 +0000	[thread overview]
Message-ID: <179537769318.3135.17791912110495668142@kernel.org> (raw)
In-Reply-To: <20261118-macb-set-channels-v7-2-2dbc00f686af@bootlin.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] When TX queues are disabled, their BQL/DQL state is never
  reset, so they can stall after a later regrow.
- [Medium] The new rollback path in macb_set_channels() restarts TX on
  the old rings without realigning the hardware queue pointer.
- [Low] The new comment in macb_init_buffers() (line 514) says that
  "macb_set_channels(), which is the only way of writing to…

--

net: macb: implement ethtool_ops.get|set_channels()

This commit moves num_queues from struct macb into struct macb_context and
adds bp->max_num_queues and bp->configured_num_queues. It then implements
the ethtool get_channels/set_channels operations, using the existing
context swap window to reallocate rings when the interface is running.
Queues beyond the active count are disabled by writing QUEUE_DISABLE to
their RBQP/TBQP registers.

> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 1e06666921160..180da5d62f09a 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -504,11 +504,25 @@ static void macb_init_buffers(struct macb *bp)
>  		macb_writel(bp, TBQPH, upper_32_bits(txq->ring_dma));
>  	}
>  
> -	for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
> -		rxq = &bp->ctx->rxq[q];
> -		txq = &bp->ctx->txq[q];
> -		queue_writel(queue, RBQP, lower_32_bits(rxq->ring_dma));
> -		queue_writel(queue, TBQP, lower_32_bits(txq->ring_dma));
> +	for (q = 0, queue = bp->queues; q < bp->max_num_queues; ++q, ++queue) {
> +		if (q < bp->ctx->num_queues) {
> +			rxq = &bp->ctx->rxq[q];
> +			txq = &bp->ctx->txq[q];
> +			queue_writel(queue, RBQP, lower_32_bits(rxq->ring_dma));
> +			queue_writel(queue, TBQP, lower_32_bits(txq->ring_dma));
> +		} else {
> +			/* macb_set_channels(), which is the only way of writing
> +			 * to bp->configured_num_queues, is only allowed if
> +			 * MACB_CAPS_QUEUE_DISABLE.
> +			 */

[Severity: Low]
This isn't a bug, but is this comment accurate? macb_probe() also writes
bp->configured_num_queues:

	bp->max_num_queues = num_queues;
	bp->configured_num_queues = num_queues;

The else branch is still only reached on QUEUE_DISABLE hardware, because
macb_set_channels() is the only path that can lower the count below
bp->max_num_queues.

Could the comment say that instead?

[ ... ]

> @@ -3359,10 +3385,6 @@ static void macb_context_swap_start(struct macb *bp)
>  	 */
>  	netif_tx_disable(bp->netdev);
>  
> -	/* Now that everything is stopped, clear DQL. */
> -	for (q = 0; q < bp->num_queues; ++q)
> -		netdev_tx_reset_queue(netdev_get_tx_queue(bp->netdev, q));
> -
>  	/* Safe to call outside bp->lock because bp->irq_quiesced ensures the IRQ

[ ... ]

> @@ -3399,16 +3421,26 @@ 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.
> +	 */
>  
> -	old_ctx = bp->ctx;
> -	WRITE_ONCE(bp->ctx, new_ctx);
> -	wmb(); /* ensure IRQ enabled below read the new context */
> -	macb_init_buffers(bp);
> +	if (new_ctx) {
> +		old_ctx = bp->ctx;
> +		WRITE_ONCE(bp->ctx, new_ctx);
> +		wmb(); /* ensure IRQ enabled below read the new context */
> +
> +		macb_init_buffers(bp);
> +
> +		/* Clear DQL (only on successful context swap). */
> +		for (q = 0; q < bp->ctx->num_queues; ++q)
> +			netdev_tx_reset_queue(netdev_get_tx_queue(bp->netdev,
> +								  q));
> +	}

[Severity: Medium]
This reset runs after bp->ctx has been switched to new_ctx, so it only
covers the new, smaller queue count. Take a running shrink such as
"ethtool -L eth0 combined 2" on a 4-queue GEM. What resets the DQL state
of queues 2 and 3?

macb_free(old_ctx) at the end of this function frees the in-flight skbs on
all 4 old queues. netdev_tx_completed_queue() is never called for those
bytes, so num_queued - num_completed stays non-zero on queues 2-3. If BQL
had already stopped those queues, __QUEUE_STATE_STACK_XOFF also stays set.

macb_close() only resets the active context's queues:

	for (q = 0; q < bp->ctx->num_queues; ++q)
		netdev_tx_reset_queue(netdev_get_tx_queue(netdev, q));

macb_open() has no reset. netif_set_real_num_tx_queues() does nothing
with DQL when queues are re-enabled. So consider this sequence:

  ethtool -L eth0 combined 2   (running, TX in flight on queues 2-3)
  ip link set eth0 down        (resets queues 0-1 only)
  ethtool -L eth0 combined 4   (down, no swap, no reset)
  ip link set eth0 up          (no reset)

Can queues 2-3 come back with stale in-flight bytes and STACK_XOFF still
set? The hardware ring would have nothing to complete, and
macb_tx_timeout()->macb_tx_restart() doesn't touch DQL. Flows hashed to
those queues would stall. Even after a completion, the stale bytes keep
dql_completed() from growing the limit.

Before this patch, macb_context_swap_start() and macb_close() both reset
every hardware queue. Should these resets cover the old context's queue
count, or bp->max_num_queues?

[ ... ]

> @@ -4618,6 +4658,75 @@ static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)

[ ... ]

> +	if (running) {
> +		new_ctx = macb_context_alloc(bp, num_queues, netdev->mtu,
> +					     bp->configured_rx_ring_size,
> +					     bp->configured_tx_ring_size);
> +		if (IS_ERR(new_ctx))
> +			return PTR_ERR(new_ctx);
> +
> +		macb_context_swap_start(bp);
> +	}
> +
> +	ret = netif_set_real_num_queues(bp->netdev, num_queues, num_queues);
> +	if (ret) {
> +		if (running) {
> +			macb_free(new_ctx);
> +			kfree(new_ctx);
> +			macb_context_swap_end(bp, NULL);
> +		}
> +		return ret;
> +	}

[Severity: Medium]
Is it safe to restart TX on the old rings here? By this point
macb_context_swap_start() has already cleared NCR.TE:

	ctrl = macb_readl(bp, NCR);
	macb_writel(bp, NCR, ctrl & ~(MACB_BIT(RE) | MACB_BIT(TE)));

On GEM, clearing TE resets the transmit queue pointer to the TBQP base,
i.e. descriptor 0. Commit 881a0263d502 ("net: macb: Shuffle the tx ring
before enabling tx") relies on this, which is why macb_mac_link_up() calls
gem_shuffle_tx_rings() before it sets TE again.

With new_ctx == NULL, macb_context_swap_end() skips macb_init_buffers()
and doesn't rotate the rings. If bp->link_up is set, it goes straight to:

		ctrl = macb_readl(bp, NCR);
		macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE));

The link never went down, so macb_mac_link_up() and its shuffle don't run.

Would the hardware then restart at descriptor 0 while txq->tail points
somewhere else?

If descriptor 0 has TX_USED set, TX stops with TXUBR. macb_tx_restart()
then keeps issuing TSTART because TBQP != head, and TX stalls for good.

If descriptor 0 is a middle descriptor of an earlier multi-descriptor
(SG/TSO) frame, TX_USED is clear. The DMA would then fetch a buffer that
macb_tx_unmap() has already unmapped.

This path is reached when channels are grown on a running, link-up
interface and netif_set_real_num_queues() fails with -ENOMEM while
allocating the queue kobjects. Does the !new_ctx path in
macb_context_swap_end() need the same gem_shuffle_tx_rings() handling as
macb_mac_link_up()?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-macb-set-channels-v7-0-2dbc00f686af%40bootlin.com

  parent reply	other threads:[~2026-11-22 20:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 20:53 [PATCH net-next v7 0/3] net: macb: implement ethtool set channels count operation Théo Lebrun
2026-11-18 20:53 ` [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up Théo Lebrun
2026-11-19 11:49   ` Nicolai Buchwitz
2026-11-19 12:36   ` Vineeth Karumanchi
2026-11-19 15:40     ` Théo Lebrun
2026-11-19 16:10       ` Théo Lebrun
2026-11-20  6:44       ` Vineeth Karumanchi
2026-11-22 20:01   ` netdev-bot+sashiko
2026-11-18 20:53 ` [PATCH net-next v7 2/3] net: macb: implement ethtool_ops.get|set_channels() Théo Lebrun
2026-11-19 11:54   ` Nicolai Buchwitz
2026-11-19 16:19     ` Théo Lebrun
2026-11-22 20:01   ` netdev-bot+sashiko [this message]
2026-11-18 20:53 ` [PATCH net-next v7 3/3] net: macb: distribute evenly Tx SRAM segments Théo Lebrun
2026-11-19 11:45   ` Nicolai Buchwitz
2026-11-22 20:01   ` netdev-bot+sashiko

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=179537769318.3135.17791912110495668142@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --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=theo.lebrun@bootlin.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