🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20504

Re: [PATCH net-next v7 2/3] net: macb: implement ethtool_ops.get|set_channels()

#20504
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 20:01
206 lines
15977 bytes
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
Technical Details
Message-ID: <179537769318.3135.17791912110495668142@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368801-linux-kernel-netdev=dewy.ru
References: <20261118-macb-set-channels-v7-2-2dbc00f686af@bootlin.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368801-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179537769318.3135.17791912110495668142@kernel.org>
References: <20261118-macb-set-channels-v7-2-2dbc00f686af@bootlin.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3713070"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VRu3PkEkRaLv3mPTYbtDlOM4cUQ= sha256:NBlB9wiGf3VmV/k2OBNYL3Ng4YaSbxxmrR7bgJVVtz8=
	sha1:KYTNHb8S1pdKjVEGLHId2Y3dzG8= sha256:NJbgaugqjGSRQ9KVKWEcrDeUT0qgxzFbW+FvnsRq4vc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 77E98125D83; Sun, 22 Nov 2026 23:02:12 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jcU9sgnwpKxZ;
	Sun, 22 Nov 2026 23:02:08 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-368801-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 8BA73125D7A; Sun, 22 Nov 2026 23:02:00 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id BD8422C52F; Sun, 22 Nov 2026 20:01:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795377700;
	b=jiijN4VR2t/M8PTEUVdQFQebJB+UeJb4jmTFr4RxBa8BYJ8yK/+IlsOipg2rMP5SIlLc
	 CObddmzRo804yYIV3+qROIqh2NWMyGeDEA0bc2E0YQRv6pbl9Lr1S14d4TNJ6mpLDoAEX
	 mdpnKecmHFqNjoWiP5dIGIi2C7kHUP4jGpsG28YbWh3eVUBfyTWnHnLKXWvdWfsYP+7Nu
	 cJeGZkSw7pwe+pzPUfw5OBJDE50WZL0Lnho2O/uKaahe/eK2Wtnc8HWXseAh6wS14lucb
	 tk18eIZJlGSj5QdGq2NTkdU3b6sDR6Im7335ro5lbrcTQ4SAy0kgNWTCAq8KfP08NAA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795377700;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=gU5RHCu+hcTZQvQ0meagwlFAHELPvEe/fPoQ7O8LQ0g=;
	b=bs9dHr2aF5CZV0GkINGMd+VKCt7xWq7lVkH/+6g2ECbo4gkcMUO795p6FsGnu/q5MfLh
	 O5tUatkcMiiaz92Qbe6rBN7jQRjGIXn01yzjN+7YbdT2iBTsr3lm6emNfUFrAyvU+hCsU
	 0wLPrchMVmp1PbdLNXkq2zcpcowOHBySC+87Z8tvwKrBmmWHRKQ/9V1ycEWQ7/fC9No6Y
	 byE9OtHAZQLeBB2aVgmC2ctjEjn+vdv9tHCj+2+vWbcCeFtFnatNB0apz2XXPrwiUJjaX
	 us/mebKwUUVgTiw5pF+ujdVgirl0Uk0Dd4Td3G9F3GOplYG0zKZqAeprjwQFqtlrYjA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k0hEkWXK;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id CBE6B606A69E;
	Sun, 22 Nov 2026 20:01:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k0hEkWXK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795377695;
	b=hmNNP6NcZcfkArjizDArrAdXlv9E8MvRI3LpznImnHrRM8u7yzcbWc3Ste8m+UQlitDw
	 qdsVpAl2KssI6Y47UKduiaak0l717RIgUKe6H7sjlTAAlLe5sTDp4zwKem55stlY/fi5U
	 IucShwASzl+D7oRoDSO0DzH5Huv5vzz3nNjyW3tygGIIU05mkkF8zo3upGJ83CwLCKay3
	 OLD3/IyB+vAJSJST27kjFpsNFw/mS2PH7jUQleDuicTQIF3iuAl+WPIrqf6t9Kca4GPTv
	 EtQegu4A2ha01d+ZHKEopTcxd4jTWlVMdpkVWNEVLOZ+MCCBK5vtdn/7nHmpBb+pewQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795377695;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=gU5RHCu+hcTZQvQ0meagwlFAHELPvEe/fPoQ7O8LQ0g=;
	b=m7GMWo+aJ4qYO/B67hlMqacRq2aDDPYTkHrkqBE2Y3wwjxtohyLL1lrItJlp7VdVa74/
	 qEUWB3bNqhyJ8WXZEI2+P0imWLwQC0pGlfIR63EkcmmKDqgBvI4kmQKJcjP1L7goy0TRq
	 DxE5W/LIz8cMog6PyhjUYTDvQemaWkl8fbdftV88mAxl+8RsHrGQBa2G7a5NjukHMsh2R
	 oH/OTrwPOd99+Nmr9+otgC6OoJSCWo4OrQPk+vAojAq5d75WaxXMhz3V/WUKfsq6LOR6W
	 TGMItb7JWD6lwWlKwLz0yb4Eus3YbmxgQsp4gcQ0G+HsrKsdxmp5KizYE9N/DOYi5sQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k0hEkWXK;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECDF8606A33F;
	Sun, 22 Nov 2026 20:01:34 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A8D61F0093C;
	Sun, 22 Nov 2026 20:01:33 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795377694;
	bh=gU5RHCu+hcTZQvQ0meagwlFAHELPvEe/fPoQ7O8LQ0g=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=k0hEkWXKIq0D1+75dk4hVtio5bah0vV+VCXAos+Cpk5z4XSVsh6yZhuJAnDHXv/ag
	 wNVp5vMtcXnB4tzzsCZnbGWcioQObQyZFptepTKQPesU6VJ2IhdFgDyxnIZexWJQnb
	 p9f6RbBIwqMSwNqNCn9pB2eJvdIq4Rman3UGWoaiO8uBdQu4JkKjH8o9NKQpLe4LrU
	 1RloE6uY7pm556H1TnlYQLTYsj+n2e3/C1XJeian8lMOOfVjXGeC6ayBsDmb0d1624
	 4XU/RhiLxuo8w/GWmhlvx0S0XXtcAeEO0dOy5s4Rh0RB0qW4i+5g8TlODMK14hsNSW
	 Kje8bR3TfVhmA==
X-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
X-In-Reply-To: <20261118-macb-set-channels-v7-2-2dbc00f686af@bootlin.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list