* [PATCH net 0/2] net: bcm4908_enet: RX buffer fixes
@ 2026-12-02 9:56 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-02 9:56 ` [PATCH net 2/2] net: bcm4908_enet: keep the RX buffers when the RX channel does not stop Kordian Chmielewski
0 siblings, 2 replies; 7+ messages in thread
From: Kordian Chmielewski @ 2026-12-02 9:56 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Florian Fainelli, Rafał Miłecki,
bcm-kernel-feedback-list, Andrew Lunn, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel
Two follow-ups to the TX ring series that is now in net [1]. Both are
about RX buffers, and Sashiko's reviews of that series pointed out both.
Patch 1 keeps the old buffer in its slot when the RX refill fails, so
that a failed allocation drops one frame instead of leaving the slot
without a buffer.
Patch 2 makes stop() leave the RX buffers to the DMA when the RX channel
does not stop in time, as that series did for the TX buffers. It also
waits for the channel with read_poll_timeout(), because the 2 ms
deadline in jiffies can pass after a single read at HZ=100 or 250.
Tested on an Archer AX6000 with OpenWrt and Linux 6.18.55, with the LAN
going through this driver, whose code differs from net with this series
only in one tree-wide change, two test-only module parameters and two
comments. TX and RX ran at line rate (941 Mbit/s TCP). With every 50th
RX buffer allocation made to fail, RX averaged 787 Mbit/s over 30 s and
dropped 41579 of 2079029 frames (2.0%), with no errors in the counters
or in the kernel log. With the RX stop made to report a timeout after
the channel had stopped, each of 45 down/up cycles of the conduit
logged the "Timeout waiting for DMA RX stop" warning once. Five of them
were made while the router was receiving at line rate, and RX came back
after each. 45 cycles without that parameter did not log it. I have not
seen the RX channel time out for real, and the parameter does not make
the DMA keep writing.
Fixes for some other points from those reviews will follow separately:
open() ignores a failure to fill the RX ring and calls napi_alloc_frag()
outside NAPI, the driver does not work without its optional TX
interrupt, and a TX completion can still be missed.
[1] https://lore.kernel.org/netdev/20261113235847.517308-1-kudzo51@gmail.com/
Kordian Chmielewski (2):
net: bcm4908_enet: keep the RX buffer when the refill fails
net: bcm4908_enet: keep the RX buffers when the RX channel does not
stop
drivers/net/ethernet/broadcom/bcm4908_enet.c | 114 +++++++++++++------
1 file changed, 81 insertions(+), 33 deletions(-)
base-commit: 4d67cf2fd2352f130c42494a933ba9158b925c65
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the refill fails 2026-12-02 9:56 [PATCH net 0/2] net: bcm4908_enet: RX buffer fixes Kordian Chmielewski @ 2026-12-02 9:56 ` Kordian Chmielewski 2026-12-03 4:36 ` Florian Fainelli 2026-12-03 10:48 ` netdev-bot+sashiko 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 1 sibling, 2 replies; 7+ messages in thread From: Kordian Chmielewski @ 2026-12-02 9:56 UTC (permalink / raw) To: netdev Cc: Florian Fainelli, Florian Fainelli, Rafał Miłecki, bcm-kernel-feedback-list, Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel poll_rx() refills a descriptor before it passes the old buffer up the stack, but bcm4908_enet_dma_alloc_rx_buf() writes the results of the allocation and of the mapping into the ring slot before it checks them. When either fails, the slot is left with buf == NULL, the old buffer is lost while still mapped, and read_idx stays on a descriptor the DMA has already completed. A later poll takes that descriptor again and, once its refill works, hands the NULL buffer to build_skb(), or to skb_free_frag() on the bad-frame path. Allocate and map into local variables and update the slot only once both have worked. When either fails, drop the frame and give its buffer back to the DMA, so that the ring keeps going. Sashiko's reviews of the TX ring series pointed this out. I have not seen a refill fail on its own on the hardware. Fixes: 4feffeadbcb2 ("net: broadcom: bcm4908enet: add BCM4908 controller driver") Signed-off-by: Kordian Chmielewski <kudzo51@gmail.com> --- drivers/net/ethernet/broadcom/bcm4908_enet.c | 60 +++++++++++++------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c index 8bc620de2ef0..d6cbb771b88a 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) +/* Give the descriptor, with the buffer of its slot, to the DMA */ +static void bcm4908_enet_dma_rx_desc_arm(struct bcm4908_enet *enet, + unsigned int idx) { struct bcm4908_enet_dma_ring_bd *buf_desc = &enet->rx_ring.buf_desc[idx]; struct bcm4908_enet_dma_ring_slot *slot = &enet->rx_ring.slots[idx]; - struct device *dev = enet->dev; u32 tmp; + + tmp = ENET_RX_BUF_DMA_SIZE << DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT; + tmp |= DMA_CTL_STATUS_OWN; + if (idx == enet->rx_ring.length - 1) + tmp |= DMA_CTL_STATUS_WRAP; + buf_desc->addr = cpu_to_le32(slot->dma_addr); + /* Hand the descriptor to the DMA only once it holds the address */ + dma_wmb(); + buf_desc->ctl = cpu_to_le32(tmp); +} + +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; - slot->dma_addr = dma_map_single(dev, slot->buf + ENET_RX_BUF_DMA_OFFSET, - ENET_RX_BUF_DMA_SIZE, DMA_FROM_DEVICE); - err = dma_mapping_error(dev, slot->dma_addr); + dma_addr = dma_map_single(dev, buf + ENET_RX_BUF_DMA_OFFSET, + ENET_RX_BUF_DMA_SIZE, DMA_FROM_DEVICE); + err = dma_mapping_error(dev, dma_addr); if (err) { dev_err(dev, "Failed to map DMA buffer: %d\n", err); - skb_free_frag(slot->buf); - slot->buf = NULL; + skb_free_frag(buf); return err; } - tmp = ENET_RX_BUF_DMA_SIZE << DMA_CTL_LEN_DESC_BUFLENGTH_SHIFT; - tmp |= DMA_CTL_STATUS_OWN; - if (idx == enet->rx_ring.length - 1) - tmp |= DMA_CTL_STATUS_WRAP; - buf_desc->addr = cpu_to_le32(slot->dma_addr); - /* Hand the descriptor to the DMA only once it holds the new buffer */ - dma_wmb(); - buf_desc->ctl = cpu_to_le32(tmp); + /* The slot changes only now, so a failure above leaves it as it was */ + slot->buf = buf; + slot->dma_addr = dma_addr; + bcm4908_enet_dma_rx_desc_arm(enet, idx); return 0; } @@ -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); + if (++enet->rx_ring.read_idx == enet->rx_ring.length) + enet->rx_ring.read_idx = 0; + enet->netdev->stats.rx_dropped++; + handled++; + continue; + } if (++enet->rx_ring.read_idx == enet->rx_ring.length) enet->rx_ring.read_idx = 0; -- 2.56.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the refill fails 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 1 sibling, 0 replies; 7+ messages in thread From: Florian Fainelli @ 2026-12-03 4:36 UTC (permalink / raw) To: Kordian Chmielewski, netdev Cc: Florian Fainelli, Rafał Miłecki, bcm-kernel-feedback-list, Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel On 12/2/2026 1:56 AM, Kordian Chmielewski wrote: > poll_rx() refills a descriptor before it passes the old buffer up the > stack, but bcm4908_enet_dma_alloc_rx_buf() writes the results of the > allocation and of the mapping into the ring slot before it checks them. > When either fails, the slot is left with buf == NULL, the old buffer is > lost while still mapped, and read_idx stays on a descriptor the DMA has > already completed. A later poll takes that descriptor again and, once > its refill works, hands the NULL buffer to build_skb(), or to > skb_free_frag() on the bad-frame path. > > Allocate and map into local variables and update the slot only once > both have worked. When either fails, drop the frame and give its buffer > back to the DMA, so that the ring keeps going. > > Sashiko's reviews of the TX ring series pointed this out. I have not > seen a refill fail on its own on the hardware. > > Fixes: 4feffeadbcb2 ("net: broadcom: bcm4908enet: add BCM4908 controller driver") > Signed-off-by: Kordian Chmielewski <kudzo51@gmail.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> -- Florian ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the refill fails 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 2026-12-03 12:33 ` Kordian Chmielewski 1 sibling, 1 reply; 7+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 10:48 UTC (permalink / raw) To: kudzo51 Cc: netdev, f.fainelli, florian.fainelli, rafal, bcm-kernel-feedback-list, andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net 1/2] net: bcm4908_enet: keep the RX buffer when the refill fails 2026-12-03 10:48 ` netdev-bot+sashiko @ 2026-12-03 12:33 ` Kordian Chmielewski 0 siblings, 0 replies; 7+ messages in thread From: Kordian Chmielewski @ 2026-12-03 12:33 UTC (permalink / raw) To: netdev Cc: f.fainelli, florian.fainelli, rafal, bcm-kernel-feedback-list, andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel > [Severity: High] > This drop path assumes every slot holds a valid mapped buffer. Can that > assumption break when the refill fails at open time? [ ... ] > 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? Yes. open() ignoring that error is older than this patch, and it is the first of the follow-ups listed in the cover letter. When open() carries on after bcm4908_enet_dma_init() failed, the RX ring is left in a broken state with or without this patch. The descriptors before the failed slot still carry OWN and the bus addresses of buffers that the error path has unmapped and freed. bcm4908_enet_dma_ring_init() has not run, so the RX channel is enabled with the descriptor base that bcm4908_enet_dma_reset() set to 0. And a refill that works still passes the slot's NULL buffer to build_skb() or skb_free_frag(), as the review describes. The commit message is about a slot that a failed refill in poll_rx() leaves empty, which this patch stops; here the slots are empty because open() went on after the error. What this patch changes in that state is a refill that fails: the descriptor is now re-armed with the stale or zero address of the slot and the loop moves on, where the old code stopped without writing the descriptor. > Can the device then write packet data into memory the driver no longer > owns? In that state the drop path can hand the DMA a freed or zero address, as the error path already does for the descriptors before the failed slot. The fix is for open() to fail and unwind. I will send it next, together with a fix for the napi_alloc_frag() point, which the cover letter lists as well. If the maintainers would rather have the open() fix in this series, before this patch, I will send a v2 with it. Kordian ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net 2/2] net: bcm4908_enet: keep the RX buffers when the RX channel does not stop 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-02 9:56 ` Kordian Chmielewski 2026-12-03 4:38 ` Florian Fainelli 1 sibling, 1 reply; 7+ messages in thread From: Kordian Chmielewski @ 2026-12-02 9:56 UTC (permalink / raw) To: netdev Cc: Florian Fainelli, Florian Fainelli, Rafał Miłecki, bcm-kernel-feedback-list, Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel bcm4908_enet_stop() frees the RX buffers even when bcm4908_enet_dma_rx_ring_disable() timed out, so the DMA may still write a frame into a buffer that has been freed. Do for RX what commit e2785f0ff0a2 ("net: bcm4908_enet: release the TX ring on stop") did for TX: return the timeout and, when the channel did not stop, leave the buffers to the DMA. They are leaked: the slots forget them, so that nothing frees them later, not even the error path of the next open(). The wait itself can also give up too early. Its 2 ms deadline is counted in jiffies, which is a single tick at HZ=100 or HZ=250, so it can pass after the first read of the channel config. With the change above, such an early timeout would leak all the RX buffers. Wait with read_poll_timeout() instead, and still clear ENABLE on every read that finds it set, as the loop did. Sashiko's reviews of the TX ring series pointed out both problems, the second one in a TX copy of this loop in v2 of that series. I have not seen the RX channel time out on the hardware. bcm4908_enet_remove() still frees the descriptor ring, which the DMA may also write to, after a stop() that timed out. This patch does not change that. Fixes: 4feffeadbcb2 ("net: broadcom: bcm4908enet: add BCM4908 controller driver") Signed-off-by: Kordian Chmielewski <kudzo51@gmail.com> --- drivers/net/ethernet/broadcom/bcm4908_enet.c | 54 +++++++++++++++----- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcm4908_enet.c b/drivers/net/ethernet/broadcom/bcm4908_enet.c index d6cbb771b88a..f42ad45a47ea 100644 --- a/drivers/net/ethernet/broadcom/bcm4908_enet.c +++ b/drivers/net/ethernet/broadcom/bcm4908_enet.c @@ -357,6 +357,18 @@ static void bcm4908_enet_dma_uninit(struct bcm4908_enet *enet) } } +/* Let go of the RX buffers without unmapping or freeing them, for when the + * DMA may still write to them: they are leaked, and nothing frees them later + */ +static void bcm4908_enet_dma_rx_leak(struct bcm4908_enet *enet) +{ + struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring; + int i; + + for (i = 0; i < rx_ring->length; i++) + rx_ring->slots[i].buf = NULL; +} + static int bcm4908_enet_dma_init(struct bcm4908_enet *enet) { struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring; @@ -409,24 +421,32 @@ static void bcm4908_enet_dma_rx_ring_enable(struct bcm4908_enet *enet, enet_set(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE); } -static void bcm4908_enet_dma_rx_ring_disable(struct bcm4908_enet *enet, - struct bcm4908_enet_dma_ring *ring) +/* Read the RX channel config and clear ENABLE again while it is still set */ +static u32 bcm4908_enet_dma_rx_ring_stop(struct bcm4908_enet *enet, u16 offset) +{ + u32 tmp = enet_read(enet, offset); + + if (tmp & ENET_DMA_CH_CFG_ENABLE) + enet_maskset(enet, offset, ENET_DMA_CH_CFG_ENABLE, 0); + + return tmp; +} + +static int bcm4908_enet_dma_rx_ring_disable(struct bcm4908_enet *enet, + struct bcm4908_enet_dma_ring *ring) { - unsigned long deadline; u32 tmp; + int err; enet_maskset(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE, 0); - deadline = jiffies + usecs_to_jiffies(2000); - do { - tmp = enet_read(enet, ring->cfg_block + ENET_DMA_CH_CFG); - if (!(tmp & ENET_DMA_CH_CFG_ENABLE)) - return; - enet_maskset(enet, ring->cfg_block + ENET_DMA_CH_CFG, ENET_DMA_CH_CFG_ENABLE, 0); - usleep_range(10, 30); - } while (!time_after_eq(jiffies, deadline)); + err = read_poll_timeout(bcm4908_enet_dma_rx_ring_stop, tmp, + !(tmp & ENET_DMA_CH_CFG_ENABLE), 10, 2000, + false, enet, ring->cfg_block + ENET_DMA_CH_CFG); + if (err) + dev_warn(enet->dev, "Timeout waiting for DMA RX stop\n"); - dev_warn(enet->dev, "Timeout waiting for DMA RX stop\n"); + return err; } /*** @@ -555,6 +575,7 @@ static int bcm4908_enet_stop(struct net_device *netdev) struct bcm4908_enet *enet = netdev_priv(netdev); struct bcm4908_enet_dma_ring *tx_ring = &enet->tx_ring; struct bcm4908_enet_dma_ring *rx_ring = &enet->rx_ring; + int rx_err; netif_stop_queue(netdev); netif_carrier_off(netdev); @@ -562,12 +583,17 @@ static int bcm4908_enet_stop(struct net_device *netdev) napi_disable(&tx_ring->napi); netdev_reset_queue(netdev); - bcm4908_enet_dma_rx_ring_disable(enet, &enet->rx_ring); + rx_err = bcm4908_enet_dma_rx_ring_disable(enet, &enet->rx_ring); /* Leave the TX buffers alone if the channel may still read them */ if (!bcm4908_enet_dma_tx_ring_disable(enet, &enet->tx_ring)) bcm4908_enet_tx_ring_clean(enet); - bcm4908_enet_dma_uninit(enet); + + /* Likewise for the RX buffers, which the channel may still write to */ + if (rx_err) + bcm4908_enet_dma_rx_leak(enet); + else + bcm4908_enet_dma_uninit(enet); free_irq(enet->irq_tx, enet); free_irq(enet->netdev->irq, enet); -- 2.56.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net 2/2] net: bcm4908_enet: keep the RX buffers when the RX channel does not stop 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 0 siblings, 0 replies; 7+ messages in thread From: Florian Fainelli @ 2026-12-03 4:38 UTC (permalink / raw) To: Kordian Chmielewski, netdev Cc: Florian Fainelli, Rafał Miłecki, bcm-kernel-feedback-list, Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel On 12/2/2026 1:56 AM, Kordian Chmielewski wrote: > bcm4908_enet_stop() frees the RX buffers even when > bcm4908_enet_dma_rx_ring_disable() timed out, so the DMA may still > write a frame into a buffer that has been freed. > > Do for RX what commit e2785f0ff0a2 ("net: bcm4908_enet: release the TX > ring on stop") did for TX: return the timeout and, when the channel did > not stop, leave the buffers to the DMA. They are leaked: the slots > forget them, so that nothing frees them later, not even the error path > of the next open(). > > The wait itself can also give up too early. Its 2 ms deadline is counted > in jiffies, which is a single tick at HZ=100 or HZ=250, so it can pass > after the first read of the channel config. With the change above, such > an early timeout would leak all the RX buffers. Wait with > read_poll_timeout() instead, and still clear ENABLE on every read that > finds it set, as the loop did. > > Sashiko's reviews of the TX ring series pointed out both problems, the > second one in a TX copy of this loop in v2 of that series. I have not > seen the RX channel time out on the hardware. > > bcm4908_enet_remove() still frees the descriptor ring, which the DMA may > also write to, after a stop() that timed out. This patch does not > change that. > > Fixes: 4feffeadbcb2 ("net: broadcom: bcm4908enet: add BCM4908 controller driver") > Signed-off-by: Kordian Chmielewski <kudzo51@gmail.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> -- Florian ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-03 12:35 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox