🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26278

Re: [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the refill fails

#26278
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 10:48
178 lines
14341 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0

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).

- [High] bcm4908_enet_open() discards the return value of
  bcm4908_enet_dma_init()…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  bcm4908_enet_dma_alloc_rx_buf() allocates with napi_alloc_frag(), and…

--

net: bcm4908_enet: keep the RX buffer when the refill fails

With this patch, bcm4908_enet_dma_alloc_rx_buf() allocates and maps the
RX buffer into local variables. It updates the ring slot only after both
steps succeed. When a refill fails, bcm4908_enet_poll_rx() now drops the
frame and re-arms the descriptor with its old buffer, so the ring keeps
going.

> diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> index 8bc620de2ef0d..d6cbb771b88ac 100644
> --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
> +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> @@ -265,36 +265,50 @@ static void bcm4908_enet_dma_reset(struct bcm4908_enet *enet)

[ ... ]

> +static int bcm4908_enet_dma_alloc_rx_buf(struct bcm4908_enet *enet,
> +					 unsigned int idx)
> +{
> +	struct bcm4908_enet_dma_ring_slot *slot = &enet->rx_ring.slots[idx];
> +	struct device *dev = enet->dev;
> +	dma_addr_t dma_addr;
> +	void *buf;
>  	int err;
>  
> -	slot->buf = napi_alloc_frag(ENET_RX_SKB_BUF_ALLOC_SIZE);
> -	if (!slot->buf)
> +	buf = napi_alloc_frag(ENET_RX_SKB_BUF_ALLOC_SIZE);
> +	if (!buf)
>  		return -ENOMEM;

[Severity: High]
This isn't a bug introduced by this patch, but is napi_alloc_frag() safe
here? This helper is also called from process context with BH enabled.

The open path calls it once for each RX slot:

bcm4908_enet_open()
  bcm4908_enet_dma_init()
    bcm4908_enet_dma_alloc_rx_buf(enet, i)
      napi_alloc_frag()
        __napi_alloc_frag_align()

__napi_alloc_frag_align() uses the per-CPU napi_alloc_cache:

net/core/skbuff.c:__napi_alloc_frag_align() {
	struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
	...
	local_lock_nested_bh(&napi_alloc_cache.bh_lock);
	data = __page_frag_alloc_align(&nc->page, fragsz,
				       GFP_ATOMIC | __GFP_NOWARN, align_mask);
	...
}

On !PREEMPT_RT, local_lock_nested_bh() only asserts softirq context. It
disables neither BH nor preemption. The core's own process-context wrapper
disables BH explicitly:

net/core/skbuff.c:__netdev_alloc_frag_align() {
	...
		local_bh_disable();
		data = __napi_alloc_frag_align(fragsz, align_mask);
		local_bh_enable();
	...
}

Could a NET_RX softirq for another device on the same CPU interrupt
__page_frag_alloc_align() while it is updating nc->page? Could the open
loop also be migrated after this_cpu_ptr() and race with the NAPI of
another CPU?

Either case could hand out overlapping frags or unbalance page
references. With CONFIG_PROVE_LOCKING, lockdep_assert_in_softirq() would
also warn on every open.

Would netdev_alloc_frag() work better on the open path? Wrapping the init
loop in local_bh_disable()/local_bh_enable() would also work.

[ ... ]

> @@ -662,8 +676,16 @@ static int bcm4908_enet_poll_rx(struct napi_struct *napi, int weight)
>  
>  		/* Provide new buffer before unpinning the old one */
>  		err = bcm4908_enet_dma_alloc_rx_buf(enet, enet->rx_ring.read_idx);
> -		if (err)
> -			break;
> +		if (err) {
> +			/* Drop the frame and give its buffer back to the DMA */
> +			bcm4908_enet_dma_rx_desc_arm(enet,
> +						     enet->rx_ring.read_idx);

[Severity: High]
This drop path assumes every slot holds a valid mapped buffer. Can that
assumption break when the refill fails at open time?

bcm4908_enet_open() ignores the return value of bcm4908_enet_dma_init():

	bcm4908_enet_gmac_init(enet);
	bcm4908_enet_dma_reset(enet);
	bcm4908_enet_dma_init(enet);

	enet_umac_set(enet, UMAC_CMD, CMD_TX_EN | CMD_RX_EN);

Suppose bcm4908_enet_dma_alloc_rx_buf() fails for slot i during init.
bcm4908_enet_dma_init() then calls bcm4908_enet_dma_uninit() and returns
before bcm4908_enet_dma_ring_init() runs:

	for (i = 0; i < rx_ring->length; i++) {
		err = bcm4908_enet_dma_alloc_rx_buf(enet, i);
		if (err) {
			dev_err(dev, "Failed to alloc RX buffer: %d\n", err);
			bcm4908_enet_dma_uninit(enet);
			return err;
		}
	}

bcm4908_enet_dma_uninit() unmaps and frees the buffers of slots 0..i-1
and sets slot->buf = NULL. It leaves those descriptors armed with the old
bus addresses, and slot->dma_addr keeps its stale value. On a first open,
slots i..N-1 still have dma_addr == 0 from the zeroed allocation.

Open still sets ENET_DMA_CTRL_CFG_MASTER_EN, enables the RX channel and
NAPI, and unmasks the RX interrupts. The STATE_RAM_BASE_DESC_PTR
registers keep the 0 that bcm4908_enet_dma_reset() wrote. read_idx and
write_idx are never reset.

Now suppose a later refill in bcm4908_enet_poll_rx() fails in this state.
The new code re-arms the descriptor with slot->dma_addr. That value is
either 0 or the bus address of a buffer that was already unmapped and
freed.

Can the device then write packet data into memory the driver no longer
owns?

If the refill succeeds instead, slot.buf is NULL. Take i == 0 on a first
open: descriptor 0 has ctl == 0, so len < ETH_ZLEN and the code reaches:

			dma_unmap_single(dev, slot.dma_addr,
					 ENET_RX_BUF_DMA_SIZE, DMA_FROM_DEVICE);
			skb_free_frag(slot.buf);

With other ctl values the NULL reaches build_skb() instead. Isn't this
the outcome the commit message says the patch removes?

    hands the NULL buffer to build_skb(), or to skb_free_frag() on the
    bad-frame path.

Should bcm4908_enet_open() check the return value of
bcm4908_enet_dma_init() and unwind, calling free_irq() for both IRQs and
returning the error?

The ignored return value dates back to commit 9d61d138ab30. The second
patch of the series ("keep the RX buffers when the RX channel does not
stop") does not change it.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202095611.156840-1-kudzo51%40gmail.com
Technical Details
Message-ID: <179629488517.3146.16278518529618524423@kernel.org>
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!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-376484-linux-kernel-netdev=dewy.ru
References: <20261202095611.156840-2-kudzo51@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!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-376484-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the
 refill fails
Date: Thu, 03 Dec 2026 10:48:05 +0000
Organization: Usenet Network
Message-ID: <179629488517.3146.16278518529618524423@kernel.org>
References: <20261202095611.156840-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="2463212"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:6RGnU2jFoMcM0nncmKo6Oqr+UFQ= sha256:mC2Ib80q3Ll/uSU0uhxeFWFMnl9ngQsbVbsDJLHE0BU=
	sha1:5XaE3aGN6rR3dpoOkrYcxwP7bd8= sha256:pa2vj9pQJUlAW/W+lff5ImGSqYFxpxO/5R21CKBqVpM=
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 5C9AD1178D2; Thu,  3 Dec 2026 13:48:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.74
X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.24, 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 bMjCreDf4YiS;
	Thu,  3 Dec 2026 13:48:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-376484-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 92E981178A3; Thu,  3 Dec 2026 13:48:13 +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 25E9260228C; Thu,  3 Dec 2026 10:48:13 +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=1796294892;
	b=F7QbrCcc9iyBTymem5zfSe14zPNiGZKACQJ+LeMHZ8wr92LKzkih0+ONbA8fls12uBPj
	 sXP7FvwhjFxRqtsjgKD1bMYLamS/jxZJ/ddYWuTBNcFysQWaWRWawr7QThVMQZVnLmx5W
	 5e4uRpo+1VxGnOIbpNrp1BaoPJR76UdFc2UGLHFHivcQWxPWYZtjxhI2XagQCQovaXpND
	 c7sUDQtZvBNiTDfO17G1gUzpk5Yy0ZoeXJjN8jHuy+i1dXLgR/C/50VARo9NZrjwAVyVU
	 yJDSax1OXfeWFKX3lbGWXGzqDKhiKb6h/Oke7mP7K3I0lWgPFISDjTt5z8p51eYyz0A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796294892;
	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=adbv6X0fRigtXLtS6jGXZMWq5SlHsXhOqnzYbsIa77M=;
	b=VXDf3RDN7QC9h/ilpzI4vZijxwi8r/a+LK/6DqpDFVh9l5obUq4n06mNFz5bVvf3Dm1G
	 jkt+Jj2FdTEa6k0kDi9lzfQMGUW8xA2fS6owL29Brfg9AqMrtn0bShl1MeRH3r5tOCEPK
	 l9vRjZyat+sWydGwjTgAelKNmjKuI4cR0zPyFTMAKDDQDrAlMukHrBhXAX3NidDcqMKl9
	 +pl8tGkXeWL1y5Dy7HmrGs8nuJyxJMxjz0GLwgwQhV/v7SBmXD+HvzdD6i5kv2FFtpJcK
	 kXBA6QeXhsTST+11yPkPmkIeZnbamq+cjLbkrvEuCIh3kvx3WPHMWZmKYrt/T4Gx1yw==
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=DDPxJhI2;
	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 795B0606A332;
	Thu,  3 Dec 2026 10:48:12 +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=DDPxJhI2
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=1796294886;
	b=N0YiU5GRLnlMa4NBg4IsEC4AuS1BDZY+Mo49NHSqzATe/UDBEcSOYpuSQRhEH1QQBvyt
	 7wOfE6BrV5cbFFwCb0kwGtUimzyyB4b5eJsqcIpIoggZzyH23nGfwmwrsIuB+qaH9qPnm
	 LoBp9z4VUPVcLLyVnKW4BREP3XWQzvA8TuTvy0UhFXeHmH/TRgiWhfRVg2HdwSPmny5WV
	 Su7BK7oLS1L28reexNGRzSr9W3Xyzw7r2qU/5hIUfcu8eSbcc33xJ/SSZE4jiNlZQ4zBg
	 uUpj/jhuPWLuxmICTxG3RTbdFS0xOu4vJpD2ob6ebHnYAuXLHk9K6sgDVA41L/9RewA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796294886;
	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=adbv6X0fRigtXLtS6jGXZMWq5SlHsXhOqnzYbsIa77M=;
	b=Y4gZ6E5D7YSkoFiChaa1oYkCBjMC/nKbTgjAs+7zZx73IFQBx+Og2RlgyYtP6Sz+hW/u
	 JjeSBH3p1xVqOp795/OinzgIUdzyGlzGhNPHVZL5tyr7omPHqFu6vIHCSZ2G38FM84HgS
	 ZCdi8W08XzgSoICTDxGXGVvRuec+ikM++fZS5E5HiywrPOGCdBZK6b4ZqmJolGCELA2AW
	 y1KhqnoI6MEw8P6K+Y3YvQDSFXwVy5ow+1a5zm8H5CIjRUkavVSKN5ifdAthUqV+sOny9
	 gsRQmPmXpzfxUh99N9dJ3RvNC/lTeqfDlPLtyj2h4WuNdMSgGgwlPO48yD+Q7NWrikg==
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=DDPxJhI2;
	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 96067606A322;
	Thu,  3 Dec 2026 10:48:06 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A0831F00896;
	Thu,  3 Dec 2026 10:48:05 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796294886;
	bh=adbv6X0fRigtXLtS6jGXZMWq5SlHsXhOqnzYbsIa77M=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=DDPxJhI2JXJrW5g0riE16UfiD+9DZaCvaP2HJfJjMdWv9c+1Pp06I2RU5SH018Kql
	 qiEn17l8PNMkmIoqNPgZ7Rk8XaYpTdJrK7jvDXeDzTJvdIxwO3s8PhvEug33OdBiUD
	 DmaBDruCBTLTZv8TXVXAApDmleCbGbRNEtxR6Xs7mPFb+6CMDjxLGJvv4+jbaOGMlN
	 IcrmYDS5a/f//NuI6dMEzM4YVenOBs5lfc4x7BgDhyyFWm+FaR8/DITuhJVZsjXOc/
	 oQ20trl5IoSrMl7HWh6uPlImcl7EAk20twofeGGdshbfl+866FSQ3B3k/MfH2Qk9Cr
	 rLzKjQ9EeXDDQ==
X-Cc: netdev@vger.kernel.org, f.fainelli@gmail.com,
 florian.fainelli@broadcom.com, 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: <20261202095611.156840-2-kudzo51@gmail.com>
X-sashiko-severity: High
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