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

From: netdev-bot+sashiko

Date: Thu Dec 03 2026 - 05:48:11 EST


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