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
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 [thread overview]
Message-ID: <179629488517.3146.16278518529618524423@kernel.org> (raw)
In-Reply-To: <20261202095611.156840-2-kudzo51@gmail.com>
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
next prev parent reply other threads:[~2026-12-03 10:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:56 [PATCH net 0/2] net: bcm4908_enet: RX buffer fixes Kordian Chmielewski
2026-12-02 9:56 ` [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the refill fails Kordian Chmielewski
2026-12-03 4:36 ` Florian Fainelli
2026-12-03 10:48 ` netdev-bot+sashiko [this message]
2026-12-03 12:33 ` Kordian Chmielewski
2026-12-02 9:56 ` [PATCH net 2/2] net: bcm4908_enet: keep the RX buffers when the RX channel does not stop Kordian Chmielewski
2026-12-03 4:38 ` Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179629488517.3146.16278518529618524423@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=f.fainelli@gmail.com \
--cc=florian.fainelli@broadcom.com \
--cc=kuba@kernel.org \
--cc=kudzo51@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rafal@milecki.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®