From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A0831F00896; Thu, 3 Dec 2026 10:48:05 +0000 (UTC) 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== Subject: Re: [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the refill fails From: netdev-bot+sashiko@kernel.org To: kudzo51@gmail.com 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 Date: Thu, 03 Dec 2026 10:48:05 +0000 Message-ID: <179629488517.3146.16278518529618524423@kernel.org> In-Reply-To: <20261202095611.156840-2-kudzo51@gmail.com> References: <20261202095611.156840-2-kudzo51@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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