πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15319

Re: [PATCH net 6/7] net: bcm4908_enet: publish the buffer address before OWN

#15319
From: netdev-bot+sashiko
Date: Thu, 12 Nov 2026 17:14
144 lines
13119 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The comment this patch adds in bcm4908_enet_dma_alloc_rx_buf()
  (drivers/net/ethernet/broadcom/bcm4908_enet.c, lines 292-295) says the…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is in the
  function the patch edits and is still present at the end of the series.

--

net: bcm4908_enet: publish the buffer address before OWN

This patch changes the RX refill in bcm4908_enet_dma_alloc_rx_buf() so the
buffer address is written before the control word that carries
DMA_CTL_STATUS_OWN. It adds a dma_wmb() between the two stores on both the
RX refill path and the TX path. It also adds a dma_rmb() in
bcm4908_enet_poll_rx() after DMA_CTL_STATUS_OWN is seen clear.

> diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> index c0aca68010c3b..ea4a9eb98097c 100644
> --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c
> +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c
> @@ -289,8 +289,13 @@ static int bcm4908_enet_dma_alloc_rx_buf(struct bcm4908_enet *enet, unsigned int
>  	tmp |= DMA_CTL_STATUS_OWN;
>  	if (idx == enet->rx_ring.length - 1)
>  		tmp |= DMA_CTL_STATUS_WRAP;
> -	buf_desc->ctl = cpu_to_le32(tmp);
> +	/* The DMA must not see OWN before the new buffer address: with a full
> +	 * ring it waits on this very descriptor and would fill the old buffer,
> +	 * which is on its way up the stack as an skb.
> +	 */

[Severity: Low]
This isn't a bug, but does this comment match what the rest of the driver
assumes about a full ring? The commit message makes the same claim:

  "which is where the DMA waits once the ring is full"

The end of bcm4908_enet_poll_rx() assumes the opposite for the same case:

	/* Hardware could disable ring if it run out of descriptors */
	bcm4908_enet_dma_rx_ring_enable(enet, &enet->rx_ring);

If the channel is disabled when it runs out of descriptors, it only
restarts through the writel() in bcm4908_enet_dma_rx_ring_enable(). That
write comes after the descriptor stores, so the window described here
would not open.

The new addr -> dma_wmb() -> ctl ordering looks correct under either
model. Could the new comment and the commit message be brought in line
with the existing comment, or hedged, so a reader can tell which hardware
behaviour applies?

>  	buf_desc->addr = cpu_to_le32(slot->dma_addr);
> +	dma_wmb();
> +	buf_desc->ctl = cpu_to_le32(tmp);
>  
>  	return 0;
>  }

[ ... ]

> @@ -638,6 +645,8 @@ static int bcm4908_enet_poll_rx(struct napi_struct *napi, int weight)
>  		ctl = le32_to_cpu(buf_desc->ctl);
>  		if (ctl & DMA_CTL_STATUS_OWN)
>  			break;
> +		/* Nothing the DMA wrote may be read before it gave the descriptor back */
> +		dma_rmb();
>  
>  		slot = enet->rx_ring.slots[enet->rx_ring.read_idx];
>  

[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but it is
in the refill path this patch touches. What happens to the old RX buffer
when bcm4908_enet_dma_alloc_rx_buf() fails?

The refill writes into the live slot before it knows the refill will
succeed:

bcm4908_enet_dma_alloc_rx_buf() {
	slot->buf = napi_alloc_frag(ENET_RX_SKB_BUF_ALLOC_SIZE);
	if (!slot->buf)
		return -ENOMEM;
	...
	if (err) {
		...
		skb_free_frag(slot->buf);
		slot->buf = NULL;
		return err;
	}
	...
}

bcm4908_enet_poll_rx() keeps the old buffer only in its local copy:

	slot = enet->rx_ring.slots[enet->rx_ring.read_idx];

	/* Provide new buffer before unpinning the old one */
	err = bcm4908_enet_dma_alloc_rx_buf(enet, enet->rx_ring.read_idx);
	if (err)
		break;

After that break, slots[read_idx].buf is NULL. Its dma_addr holds either
the old mapping or the mapping error cookie. The filled, still-mapped old
buffer is leaked, and read_idx does not move. The descriptor still has
DMA_CTL_STATUS_OWN clear, and ctl still holds the old length and
SOP/EOP bits.

The next poll stops on the same index, now with slot.buf == NULL. The
refill succeeds this time, and the length and SOP/EOP check passes on the
stale ctl, so we get:

bcm4908_enet_poll_rx()
  dma_unmap_single(dev, slot.dma_addr, ...)   <- stale or error dma_addr
  build_skb(NULL, ENET_RX_SKB_BUF_ALLOC_SIZE)
    __build_skb_around()
      __finalize_skb_around()                 <- writes shinfo at NULL + size

The bad-frame path calls skb_free_frag(slot.buf) on NULL instead. Could
this oops in NAPI softirq context when GFP_ATOMIC allocations fail or DMA
mappings run out?

bcm4908_enet_dma_uninit() also skips slots with buf == NULL:

	if (!slot->buf)
		continue;

so the leaked frag and its mapping are never freed. The code looks the
same at the end of the series.

Would it work to allocate and map into local variables, and only write
them to the slot and the descriptor once both steps succeed? On failure,
poll_rx() could give the old buffer back to the hardware, or drop the
frame and keep the slot intact.

-- 
Sashiko AI review Β· https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109235700.2586821-1-kudzo51%40gmail.com
Technical Details
Message-ID: <179450368092.2199510.12272271322711865382@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-362050-linux-kernel-netdev=dewy.ru
References: <20261109235700.2586821-7-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-362050-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 6/7] net: bcm4908_enet: publish the buffer address before OWN
Date: Thu, 12 Nov 2026 17:14:40 +0000
Organization: Usenet Network
Message-ID: <179450368092.2199510.12272271322711865382@kernel.org>
References: <20261109235700.2586821-7-kudzo51@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1135336"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:roq2Uzt0RhtQhHEfDeBUKNACg3k= sha256:1LS/IUuNX8HdnYm7zsQO/hop2RTpIzlZr10VjXquX0Y=
	sha1:cc9fEcc88rEu8AjZSu38oCN0LXs= sha256:4WDX2CMQ6tepnSqNU9BbGNxnrrraccmVT4PHHHHsk4k=
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 6862C114318; Thu, 12 Nov 2026 20:27:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 e4H7c4NAhHxJ;
	Thu, 12 Nov 2026 20:27:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-362050-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 7EBDF114316; Thu, 12 Nov 2026 20:27:15 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 662B7149EC3; Thu, 12 Nov 2026 17:14:59 +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=1794503683;
	b=1ElEHX71gJZrAwV6H7GzH+uct4MmYz4+gbz3LXiHvaRb/Tpxpsqad2hJ/E8foCHsBOr4
	 A5vaT/y4Fc2ytBhqJ499RKDhJ0rNTL5FtLpf3g7vf7Vmrz1sY2ZX/NZSmcrqFjBlcHZxJ
	 QGZr2HB5OYE1bs8weE12ZZbtz6pOPg5T38OVX+Hi1z0OTEGJkD56ebo+e2yiZ+PRfDJJ1
	 gr2885S4IxtnlmVFKZNCOyBdS/VpOWveyBNV4bj613iBwsCWam/Ur2Zh+5OSWp79pQsyd
	 U2zSzPZG/0X0bPwnYuFRn27/3BPWZGPBVKeecdHZNjjLwc+z8jWvbMktZdADY/YalCw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794503683;
	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=qMWqzOwgjhj/riKmv4SFNzHAl3QB/o2M98LqJqz9cVk=;
	b=N4OCgLWaCfdzrmv+RicchTMoujNlvXJeOaqUOJz9grqbqyVXziZfHPRlUjby10Mo59Rg
	 Tf21XXIcrxwp5HRsUEOmcL/Eu/PmUoLUFT/knqc3mMLpU2H/XxncMtaz9WqMBbeBPkmEE
	 LCHnwcAOTBPxKLpnjNPZlvuiMPOKGrcYa+S5UcODo+KOo3clKBeLFSxab0qFUjjMBoerH
	 YUVsB8ZIEHf7I2qD6ygVo2J6j7bliz+rS3DV+rxjd5t+95RKO4riB+9Mo4QG2JWa5hyHS
	 z5d+gOqJC5sxFBZkEuVHwSyWHtAWUmTYRjoZhZTgOrgfsUMoWBcakDH1A/lxUzIDlVQ==
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=g2HPiEve;
	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 171EF606A8A6;
	Thu, 12 Nov 2026 17:14:43 +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=g2HPiEve
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=1794503682;
	b=XNTkF4rJbT88lvekKns725v9N25t7neM/+Ed2ZoZA8sf+ZW6DKQ1nhMlGMDG3yBqdBqI
	 KyS3+KTswgMWvAFdrvJJF8s+q6e3+N1QlY86aYYE1xEj3j0imi0cmlRKjMDBTARovNNXv
	 TZoMGMsAP6tgBigoCk/pDgTkoJ5ji5/8LsxX3gu7LCg7OQix3BGu2hdauCc7x3XoTeXDF
	 shwMtPFa7kJJiTRjkmFFi89N3XCdfmc2XHNHhh2POhL9y74eqaPDFKIS87f68sNzohAge
	 iuBOfGEsqGd8c9NAQtoJkgOrEtsg+6zzW5LlQP/i6ez/2WBstdcfGs2LNvjdWyfyCGA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794503682;
	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=qMWqzOwgjhj/riKmv4SFNzHAl3QB/o2M98LqJqz9cVk=;
	b=ygJs/VaYw9Ix1bUBwA8Y5j//E2pA+4Bej4UXZDj0u4RhEvxyB4WyYlkv/kBNcuO4FOPq
	 NKmKcqzahH0J7SF0PoJZCmySnl1tq8LVIWRx186KU9LnfvaD/wWCmNHeP91r4QMySUxBD
	 uElnAv6+nW1Tnt1fuw7tPT1sx1Jf1FbyfeHyxWB608QXDZZidn4agHE/v2AO48sJoqcch
	 kgZSW4ohxNts2gA5RJrjGT12ED6LghJ+ybNoog3/SF67fDYM3vgR0jcZRpgM5cq61qAJP
	 dcEc3yXQEfbY25Y1AK6uuQYTcd6RbMlgigYfF9RQD0Xm3U5cpjkwVOBCotuz6n1GiAA==
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=g2HPiEve;
	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 350DC606A88C;
	Thu, 12 Nov 2026 17:14:42 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D2E01F000C7;
	Thu, 12 Nov 2026 17:14:41 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794503681;
	bh=qMWqzOwgjhj/riKmv4SFNzHAl3QB/o2M98LqJqz9cVk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=g2HPiEveQ9Hk3FTbbNbslgV94gxCizewq8sxOurtaZH7DSuKMBNaNP7/+ekEJkeyS
	 Nmr0mw/CeAiOUdEV4lNaTiyMC5l5/btuSmz4b8ygW46KgH5dF4wEelBQfUYSS3Gn39
	 BwZ2SGffDvwfqlOJb8/vRpFb2jLR7aoelTia+rn4jOl+6+XTfSfVIiCTjBkgWio+AN
	 joBDuoPqLB62PG04abyklNLgsF2FqxvOmVDDuizzaeUIBtV5n6+zu8QYSiEdq5/qPs
	 2TT6istSarz0eUe6annYpg2KCO/Qxg6SDR2JehJnjq1sXpCIKYETeLhHTiJHcgQ9Pq
	 aLZnsyFxEtxhw==
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-7-kudzo51@gmail.com>
X-sashiko-severity: Low
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