🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15310

Re: [PATCH net 1/7] net: bcm4908_enet: fix the TX ring wrap

#15310
From: netdev-bot+sashiko
Date: Thu, 12 Nov 2026 17:14
188 lines
15183 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · 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] The early ring-full path at the top of
  bcm4908_enet_start_xmit() (`if…
- [Low] The commit message leaves out a second symptom of the same index
  mismatch, which this patch also fixes.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch's
  new stop/wake logic still depends on it working.

--

net: bcm4908_enet: fix the TX ring wrap

The TX ring now uses all descriptors, with WRAP on the last one. Both
read_idx and write_idx wrap at length, and one descriptor is always left
free, so read_idx == write_idx can only mean an empty ring.
bcm4908_enet_start_xmit() now stops the queue once the ring is full.
bcm4908_enet_poll_tx() wakes it again, with smp_mb() on both sides.

> diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> index fd2715f84af97..01a3e1d0192f8 100644
> --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
> +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c

[ ... ]

> @@ -525,20 +535,14 @@ static netdev_tx_t bcm4908_enet_start_xmit(struct sk_buff *skb, struct net_devic

[ ... ]

>  	/* Free transmitted skbs */
>  	if (enet->irq_tx < 0 &&
> -	    !(le32_to_cpu(ring->buf_desc[ring->read_idx].ctl) & DMA_CTL_STATUS_OWN))
> +	    !(le32_to_cpu(ring->buf_desc[READ_ONCE(ring->read_idx)].ctl) & DMA_CTL_STATUS_OWN))
>  		napi_schedule(&enet->tx_ring.napi);

[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but
does the new stop/wake logic work when the optional TX interrupt is
missing?

In Documentation/devicetree/bindings/net/brcm,bcm4908-enet.yaml, both
interrupts and interrupt-names have minItems: 1. A DT node that lists
only "rx" is therefore valid, and probe carries on with
enet->irq_tx < 0.

In that case bcm4908_enet_open() never enables the TX NAPI:

	if (enet->irq_tx > 0) {
		napi_enable(&tx_ring->napi);

The TX NAPI still has NAPI_STATE_SCHED set from netif_napi_add, so
napi_schedule() here always fails in napi_schedule_prep(), and
bcm4908_enet_poll_tx() never runs.

Nothing then advances read_idx, unmaps or frees the TX skbs, or wakes
the queue. After length - 1 frames, the new stop-on-full branch at the
end of bcm4908_enet_start_xmit() stops the queue. Nothing wakes it
again, although the new comment there says "poll_tx() wakes the queue
once there is room".

On ifdown, bcm4908_enet_stop() calls napi_disable(&tx_ring->napi) on
the NAPI that was never enabled. Wouldn't napi_disable_locked() then
spin here forever while holding RTNL and the netdev instance lock?

		while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
			usleep_range(20, 200);
			val = READ_ONCE(n->state);
		}

bcm4908_enet_stop() also calls free_irq(enet->irq_tx, enet) with a
negative IRQ.

This goes back to 12bb508bfe5a ("net: broadcom: bcm4908_enet: support
TX interrupt"). The in-tree bcm4908.dtsi provides both "rx" and "tx",
so only DTs that use the binding's optional-TX form are affected.

>  
> -	/* Don't use the last empty buf descriptor */
> -	if (ring->read_idx <= ring->write_idx)
> -		free_buf_descs = ring->read_idx - ring->write_idx + ring->length;
> -	else
> -		free_buf_descs = ring->read_idx - ring->write_idx;
> -	if (free_buf_descs < 2) {
> +	if (unlikely(bcm4908_enet_tx_free_descs(ring) < 1)) {
>  		netif_stop_queue(netdev);
>  		return NETDEV_TX_BUSY;
>  	}

[Severity: Medium]
Can this early ring-full path in bcm4908_enet_start_xmit() lose a
wakeup?

It stops the queue without the smp_mb() and re-check that the patch
adds at the end of bcm4908_enet_start_xmit(). include/net/netdev_queues.h
says the standard stop/wake pairing does not prevent false wake ups
when the ring is full, and that drivers should check for ring full at
the start of the xmit handler. So this path can be reached.

Here is one way to get a false wake:

  - bcm4908_enet_poll_tx() finds netif_queue_stopped() true and free
    descriptors >= 1.
  - Meanwhile the stop/smp_mb/re-check at the end of start_xmit
    restarts the queue.
  - poll_tx is delayed, for example by a hardirq, before it calls
    netif_wake_queue().
  - start_xmit fills the last free descriptor and stops the queue
    again.
  - poll_tx's late netif_wake_queue() then clears XOFF on a full ring.

There is no read barrier in poll_tx between the XOFF test and the
write_idx load, so load-load reordering is another way to get there.

On the next xmit, the early check reads read_idx and sees a full ring.
Suppose the poll_tx() runs that reap the remaining descriptors finish
inside the window before netif_stop_queue() here:

CPU0 (start_xmit)                    CPU1 (poll_tx)
bcm4908_enet_tx_free_descs() == 0
                                     reap all outstanding descriptors
                                     WRITE_ONCE(tx_ring->read_idx, ...)
                                     smp_mb()
                                     netif_queue_stopped() == false
netif_stop_queue()
return NETDEV_TX_BUSY

No descriptors are outstanding at that point, so no TX interrupt or
NAPI poll follows, and the driver has no ndo_tx_timeout. Wouldn't the
queue then stay stopped until ifdown/ifup? That is the "queue stops for
good with nothing left to wake it" symptom the commit message describes.

The window is narrow. It needs the xmit CPU to be preempted, as on
PREEMPT_RT, or held by a long hardirq.

Could this path use netif_txq_try_stop() instead, or the same
stop/smp_mb/re-check/restart sequence used at the end of
bcm4908_enet_start_xmit()?

[ ... ]

> @@ -572,8 +576,17 @@ static netdev_tx_t bcm4908_enet_start_xmit(struct sk_buff *skb, struct net_devic
>  
>  	bcm4908_enet_dma_tx_ring_enable(enet, &enet->tx_ring);
>  
> -	if (++ring->write_idx == ring->length - 1)
> -		ring->write_idx = 0;
> +	WRITE_ONCE(ring->write_idx,
> +		   ring->write_idx == ring->length - 1 ? 0 : ring->write_idx + 1);

[Severity: Low]
This isn't a bug, but the commit message leaves out a second symptom of
the same index mismatch, and this change fixes it too.

With the old wrap at length - 1, slot length - 1 was never filled.
bcm4908_enet_poll_tx() wrapped read_idx at length. After it reaped
slot length - 2, read_idx became length - 1, which write_idx could
never equal.

The loop then ran on the unused slot, whose descriptor ctl is still
zero, so OWN is clear. Once per ring lap it called dma_unmap_single()
with slot->dma_addr 0 and slot->len 0, then dev_kfree_skb(NULL) and
handled++. This over-counted tx_packets and caused CONFIG_DMA_API_DEBUG
warnings about unmapping memory that was never mapped.

The changelog only says:

    while poll_tx() wraps read_idx at length,

Could it also name this symptom, so stable backporters can see that it
is covered?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109235700.2586821-1-kudzo51%40gmail.com
Technical Details
Message-ID: <179450367847.2199510.5624854630375363280@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.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-362047-linux-kernel-netdev=dewy.ru
References: <20261109235700.2586821-2-kudzo51@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.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-362047-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/7] net: bcm4908_enet: fix the TX ring wrap
Date: Thu, 12 Nov 2026 17:14:38 +0000
Organization: Usenet Network
Message-ID: <179450367847.2199510.5624854630375363280@kernel.org>
References: <20261109235700.2586821-2-kudzo51@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1133838"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dztQz6CLUDNASQaDW2rKE51Cwk4= sha256:1us44TpLrTeM0P5yR7UShL6sDJ6Au5lkvvZkEvXdwco=
	sha1:eR6cNQJBoQ7Ef52G3yGFPn+L8fI= sha256:PkLFISTOrNn3PsZ/dgD9QKzF4RM2YUWsxLWWbdWm3tA=
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 4F637114311; Thu, 12 Nov 2026 20:20:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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]
	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 z0j15qdwJHZR;
	Thu, 12 Nov 2026 20:20:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-362047-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 5756C1142E3; Thu, 12 Nov 2026 20:19:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 40CED6456E9; Thu, 12 Nov 2026 17:15:17 +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=1794503685;
	b=ieI3Daw57lDIXIIZ3s7LOzag+t7HWmJR0Fs8ZS4fRkdPbIe1l95atlld5uykVi71FqeO
	 TH3+jj6YLYtKmRs3LcQDiOJcLZTHVktKtppI746SjbOYXHO6R0Rizk+8UjX47bOQX3O+A
	 88CckxYqLb7LGuV7sv98wK2xzuuhq/Unp567lnM4qWhKz9tONB3c8liuy72mzCPUx5d/9
	 Nz6QCu9BnsB4+Xfm6bHFfL2gisSz6oKuEuHa5W5onPdd9VOSOWcKR/jsujyplnympji+F
	 zZ+Gr1DYhbsKNLaNAqNuSrIolw7aJcl+szB28s+TcwGgNsYUZG/NWLGyURZPnJ3hHmw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794503685;
	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=/TDcQhTa12XtYWxapL+e3sH8uDMDLzi4mZ29QKak43A=;
	b=02MXQvLQrNmqGpXWWTCBzUnIHOH/afQThBZryyxvCwHIHvbwJt2mP4Xno7jAKeIO5vhd
	 QV51iNSY+7N7z5ngK7Zkk4WVmyYfpT1xvxzTqPEzuFXTrY/FZH326021f6Xc+Xb++UiJ2
	 l2r6awzPzJpaczrU5snhqb2AgJDwvVczQJfmFnIy144AmI6mwY5CM0eEH5UUnk37i/N0R
	 gdfMR4EXNIl17CHSLP9WbPw174v3Te/p6MLoHhHY3LoqcIc8NFreeOvjzlGyWzoSaqzwm
	 u1hJviqm3ZJ6aeASHFrQLFiXTNHynr1yZ2b1jufdWfDDOIaWqC9uvogb9GZD2FfGdIQ==
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=l2XvtUl1;
	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 D9B6B606A332;
	Thu, 12 Nov 2026 17:14:45 +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=l2XvtUl1
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=1794503680;
	b=4GXKk9tkxMTXUdJpVJ8S4CP4waJJvdYYO1e2SEM3fXBQhNdGAehzLrB2zuPSSd6QFjx1
	 9p6Oz/1ptN+ddcxj3rLpTXHckYzL5s1k//5VD14ktEmcz/TyZ4iDzdgxVBmMixzYnJbut
	 aTmPPt5YAcaWr1BnXVa84nEWRb4ole+yZ192+CG6AW9LXprgoM9qWHHheuNKB9CwJbIqJ
	 XPzOQK2v5/ArX3jX9H+Nx2ocD2U0gqMb4slRLP5R9jUiKGCwha3eg3ptEPCBChA2TT1mY
	 iMaPlTts5a7wTwsvqR4aNFK8pMgK0BcBvx28ea4cwQzpcLHLkS9uqeMmMeX/qoQ0VAQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794503680;
	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=/TDcQhTa12XtYWxapL+e3sH8uDMDLzi4mZ29QKak43A=;
	b=DWcXIp6V+T0SUm/M7Jt6rRvMpcp/SojJYHY2jyfbacGNehvb0/V4Kt/Q62WAN2XXxH3g
	 WKsHaZlio8lZYVPoXbi5SeDKo/8letpzP3JI1bEkxmiXu5rt70ldMNCgnNMyLSGEKbbCh
	 1zWRG6JuU/1mEhHseb0qG+ykCwLRw5/Cqu+w92e6rB22f/GT87gDSPK+xOymplOXPivLA
	 G9ISLOWhVcahPN5QSHkEzH4dwUOrn2JtAh5bwLuYds4ZhP0iS2bA2lhtKeETU/yH5wDb2
	 ilFqKynF9UwkY5yiy/S0IUPeYo17KmkJ7FKGJq8C6UVA+B890J2Z7se4Pt58diHHjsw==
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=l2XvtUl1;
	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 013FA606A31C;
	Thu, 12 Nov 2026 17:14:39 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0024F1F000C4;
	Thu, 12 Nov 2026 17:14:38 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794503679;
	bh=/TDcQhTa12XtYWxapL+e3sH8uDMDLzi4mZ29QKak43A=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=l2XvtUl1+lKAuKGPvcerkThj5kNyPxpTvfjnCKaaUKGn36RZWOWeCOlC6OJPHw9k/
	 t4uWQdMnE23Vt2u04lU2sJFqzxxvAe+lmvh/9j1kzII2qAJosOdIcMcaRRRKbvJNTq
	 1y+hQ9qL8qfkmgscPD7UDgFI9bcIXQ6cydo+DucogK5lik7MHPXM2mqgA3MD2X8lHE
	 62N8+cbFXwL4Rm3b/ypvyLxnnvPKY2oWyIDmhLhPJuExbgY6LPgG9YcOr5hfHPBtyu
	 COCAkqoBWydfthmDlknVMnoH3SLgqMRirFShdu7wO71mI43LMnh88IcBMJfISMyaGo
	 vpBzHcari0TSQ==
X-Cc: netdev@vger.kernel.org, rafal@milecki.pl,
 bcm-kernel-feedback-list@broadcom.com, andrew+netdev@lunn.ch,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261109235700.2586821-2-kudzo51@gmail.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