* [PATCH net v4 0/2] net: atl1c: fix the RX buffer leak on errored frames
@ 2026-11-17 22:55 Federico Musto
2026-11-17 22:55 ` [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset Federico Musto
2026-11-17 22:55 ` [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error Federico Musto
0 siblings, 2 replies; 5+ messages in thread
From: Federico Musto @ 2026-11-17 22:55 UTC (permalink / raw)
To: Chris Snook, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev
Cc: linux-kernel, Federico Musto
Patch 2 is v4 of the fix for the skb and the DMA mapping leaked by every
RX frame whose descriptor reports an error. The Sashiko review of v3
pointed out that freeing the buffer there trusts the RFD index and count
written by the device. v4 checks them against the driver's own ring state
first and resets on a mismatch, as alx does for the same descriptor
layout.
Patch 1 is new. It closes the race between the RX poll and the ring reset
of the link-down path, which the same review flagged on v2 and on v3 as
pre-existing but made worse by a free in that window.
The per-patch changelogs are below the "---" of each patch.
Both problems were found by code inspection. Build-tested with W=1 and
sparse on netdev/net: no new warnings, three "restricted __le32" sparse
warnings fewer with patch 2.
The candidate was also runtime-tested with diagnostic instrumentation on
a MikroTik CCR2004-1G-2XS-PCIe, which exposes emulated AR8151 functions,
on a 7.0.14-29-pve kernel. More than 1.5 million RRDs passed the count and
index validation in a single traffic run, with no mismatch. The candidate
survived more than 15 MTU-change resets without an RX poll-wait timeout,
deadlock, Oops or warning. The errored-descriptor path itself was not
exercised, and this is not a test on a physical AR8151 controller.
v3: https://lore.kernel.org/netdev/20261103225218.19206-1-federico@rimpianto.com/
v2: https://lore.kernel.org/netdev/20261102215253.68185-1-federico@rimpianto.com/
v1: https://lore.kernel.org/netdev/20261027115156.17128-1-federico@rimpianto.com/
Federico Musto (2):
net: atl1c: wait for in-flight RX polls before the link-down ring
reset
net: atl1c: free the RX buffer when the descriptor reports an error
.../net/ethernet/atheros/atl1c/atl1c_main.c | 118 +++++++++++-------
1 file changed, 73 insertions(+), 45 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset 2026-11-17 22:55 [PATCH net v4 0/2] net: atl1c: fix the RX buffer leak on errored frames Federico Musto @ 2026-11-17 22:55 ` Federico Musto 2026-11-21 23:18 ` netdev-bot+sashiko 2026-11-17 22:55 ` [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error Federico Musto 1 sibling, 1 reply; 5+ messages in thread From: Federico Musto @ 2026-11-17 22:55 UTC (permalink / raw) To: Chris Snook, Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev Cc: linux-kernel, Federico Musto, stable When the PHY reports link down, the work item calls atl1c_check_link_status(), which resets the MAC, frees every RX buffer and zeroes the ring indices through atl1c_reset_dma_ring(), then posts fresh buffers through atl1c_configure(). Nothing keeps the RX poll away while it does so: atl1c_irq_disable() masks the device interrupt and waits for the hard interrupt handler only, and atl1c_clean_rx() tests the carrier only when it is entered. A poll that passed that test before the carrier went off keeps walking the RRD ring on another CPU while the work item frees the same buffers. Both can unmap and free the same skb, or the poll can hand the stack an skb the work item has already freed. Once the carrier is off, wait until no RX poll is in flight before touching the rings. A poll that starts later sees the carrier off and returns without looking at them, so NAPI does not have to be disabled. napi_disable() is not used because it cannot be made safe here without serialising the work item against atl1c_down() first: the two can run concurrently (MTU change, ethtool, suspend), a second napi_disable() on an already disabled NAPI sleeps holding the netdev instance lock, and the napi_enable() of the first caller then blocks on that lock. atl1c_check_link_status() is also called by atl1c_up() before napi_enable(). For the same reason the wait gives up when the interface is down: a disabled NAPI keeps NAPI_STATE_SCHED set, and atl1c_down() has quiesced NAPI on its own. Found by code inspection; the race has not been reproduced. Fixes: 5e5c0964d9b9 ("atl1c: do MAC-reset when PHY link down") Cc: stable@vger.kernel.org Signed-off-by: Federico Musto <federico@rimpianto.com> --- New in v4. The Sashiko review flagged this race on v2 and again on v3 of the next patch: pre-existing, but made worse by a free in the same window. Not addressed, both pre-existing: the TX side of the same reset (atl1c_clean_tx() and atl1c_xmit_frame() against atl1c_clean_tx_ring()), and the missing serialisation between the work item and the callers of atl1c_down(). --- .../net/ethernet/atheros/atl1c/atl1c_main.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c index eddd8406867f..e9baee8fa7e5 100644 --- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c @@ -248,6 +248,26 @@ void atl1c_reinit_locked(struct atl1c_adapter *adapter) clear_bit(__AT_RESETTING, &adapter->flags); } +/* atl1c_clean_rx() looks at the carrier only when it is entered. Once the + * carrier is off, wait for the polls that are already past that test, so + * that the link-down path can reset the RX rings. A poll that starts later + * sees the carrier off and leaves the rings alone. + * + * A disabled NAPI keeps NAPI_STATE_SCHED set, which is why this is not + * napi_synchronize(): stop waiting when the interface is down. atl1c_up() + * gets here before napi_enable(), and atl1c_down() quiesces NAPI itself. + */ +static void atl1c_rx_poll_sync(struct atl1c_adapter *adapter) +{ + int i; + + for (i = 0; i < adapter->rx_queue_count; ++i) + while (test_bit(NAPI_STATE_SCHED, + &adapter->rrd_ring[i].napi.state) && + !test_bit(__AT_DOWN, &adapter->flags)) + usleep_range(1000, 2000); +} + static void atl1c_check_link_status(struct atl1c_adapter *adapter) { struct atl1c_hw *hw = &adapter->hw; @@ -265,6 +285,7 @@ static void atl1c_check_link_status(struct atl1c_adapter *adapter) if (!link) { /* link down */ netif_carrier_off(netdev); + atl1c_rx_poll_sync(adapter); hw->hibernate = true; if (atl1c_reset_mac(hw) != 0) if (netif_msg_hw(adapter)) -- 2.47.3 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset 2026-11-17 22:55 ` [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset Federico Musto @ 2026-11-21 23:18 ` netdev-bot+sashiko 0 siblings, 0 replies; 5+ messages in thread From: netdev-bot+sashiko @ 2026-11-21 23:18 UTC (permalink / raw) To: federico Cc: chris.snook, andrew+netdev, davem, edumazet, kuba, pabeni, netdev, linux-kernel, stable Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 1 (1) · Medium: 1 · 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] This patch does not close the RX race it claims to fix. - [Medium] atl1c_rx_poll_sync() waits with no time limit for NAPI_STATE_SCHED to clear and gives up only when __AT_DOWN is set. Pre-existing issues: - [High] This problem wasn't introduced by this patch, but the same link- down reset still frees TX buffers while TX NAPI and transmit can run. -- net: atl1c: wait for in-flight RX polls before the link-down ring reset This patch adds atl1c_rx_poll_sync(). In the link-down path of atl1c_check_link_status() it is called after netif_carrier_off() and before the MAC and DMA rings are reset. It waits for NAPI_STATE_SCHED to clear on every RX NAPI, and stops waiting once __AT_DOWN is set. > diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c > index eddd8406867f7..e9baee8fa7e5e 100644 > --- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c > +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c > @@ -248,6 +248,26 @@ void atl1c_reinit_locked(struct atl1c_adapter *adapter) > clear_bit(__AT_RESETTING, &adapter->flags); > } > > +/* atl1c_clean_rx() looks at the carrier only when it is entered. Once the > + * carrier is off, wait for the polls that are already past that test, so > + * that the link-down path can reset the RX rings. A poll that starts later > + * sees the carrier off and leaves the rings alone. > + * > + * A disabled NAPI keeps NAPI_STATE_SCHED set, which is why this is not > + * napi_synchronize(): stop waiting when the interface is down. atl1c_up() > + * gets here before napi_enable(), and atl1c_down() quiesces NAPI itself. > + */ > +static void atl1c_rx_poll_sync(struct atl1c_adapter *adapter) > +{ > + int i; > + > + for (i = 0; i < adapter->rx_queue_count; ++i) > + while (test_bit(NAPI_STATE_SCHED, > + &adapter->rrd_ring[i].napi.state) && > + !test_bit(__AT_DOWN, &adapter->flags)) > + usleep_range(1000, 2000); [Severity: High] Does the __AT_DOWN exit leave the RX race open? Both places that set __AT_DOWN do it while the RX NAPI is still live. atl1c_close() sets the bit before cancel_work_sync(). napi_disable() only runs later, in atl1c_down(): atl1c_close() { ... set_bit(__AT_DOWN, &adapter->flags); cancel_work_sync(&adapter->common_task); atl1c_down(adapter); ... } cancel_work_sync() waits for the work item, and the work item is the thread doing the ring reset. So at that point nothing has quiesced NAPI. atl1c_down() is used by suspend, MTU change and ethtool. It sets the bit before its napi_disable() loop: atl1c_down() { ... set_bit(__AT_DOWN, &adapter->flags); netif_carrier_off(netdev); for (i = 0; i < adapter->tx_queue_count; ++i) napi_disable(&adapter->tpd_ring[i].napi); for (i = 0; i < adapter->rx_queue_count; ++i) napi_disable(&adapter->rrd_ring[i].napi); ... } In either case the work item leaves this loop and goes on to atl1c_reset_mac(), atl1c_reset_dma_ring() and atl1c_configure(). If the bit was set after atl1c_common_task() checked it on entry, the work item does not wait at all. Meanwhile, an atl1c_clean_rx() that has already passed this check can still be walking the RRD ring on another CPU: if (!netif_carrier_ok(adapter->netdev)) goto quit_polling; Can atl1c_clean_rx_ring() unmap and free buffer_info->skb while that poll unmaps the same buffer? The poll could then pass the freed skb to napi_gro_receive(), or free it a second time. The code comment says atl1c_down() quiesces NAPI itself, and the commit message says the same: For the same reason the wait gives up when the interface is down: a disabled NAPI keeps NAPI_STATE_SCHED set, and atl1c_down() has quiesced NAPI on its own. That does not seem to hold when the exit fires. On the close path atl1c_down() has not run yet. On the down path napi_disable() has not started or has not finished. This loop also polls another context's state bit, and its exit condition does not synchronise with the poll. Would a fix need real serialisation of the work item against close and down, plus a wait that ends only when the poll has finished? [Severity: Medium] Can this loop wait forever when the RX NAPI is in threaded busy-poll mode? An administrator can set NETDEV_NAPI_THREADED_BUSY_POLL through napi_set_threaded(), and the driver does not need to opt in. In that mode napi_threaded_poll() keeps NAPI_STATE_IN_BUSY_POLL set, and napi_complete_done() returns early without clearing SCHED: net/core/dev.c:napi_complete_done() { ... if (unlikely(n->state & (NAPIF_STATE_NPSVC | NAPIF_STATE_IN_BUSY_POLL))) return false; ... } With the carrier off, atl1c_clean_rx() jumps straight to quit_polling and calls napi_complete_done(), which does nothing. NAPI_STATE_SCHED therefore stays set for as long as the interface is up, and __AT_DOWN stays clear. The work item would then never get past atl1c_rx_poll_sync(), so the atl1c_irq_enable() call in atl1c_common_task() is never reached: atl1c_irq_disable(adapter); atl1c_check_link_status(adapter); atl1c_irq_enable(adapter); Device interrupts stay masked and later LINK_CHANGE and RESET events are not handled. The carrier also stays off after the PHY link comes back, until the interface is brought down. Before this patch the link-down path had no such wait. > +} > + > static void atl1c_check_link_status(struct atl1c_adapter *adapter) > { > struct atl1c_hw *hw = &adapter->hw; > @@ -265,6 +285,7 @@ static void atl1c_check_link_status(struct atl1c_adapter *adapter) > if (!link) { > /* link down */ > netif_carrier_off(netdev); > + atl1c_rx_poll_sync(adapter); > hw->hibernate = true; > if (atl1c_reset_mac(hw) != 0) > if (netif_msg_hw(adapter)) [Severity: High] This is a pre-existing issue, not introduced by this patch, and the patch notes list it as not addressed. The same link-down reset also tears down the TX rings without quiescing TX: atl1c_check_link_status() atl1c_reset_dma_ring() atl1c_clean_tx_ring() atl1c_clean_buffer() on every tpd_ring->buffer_info[] entry memset(tpd_ring->desc, ...) next_to_clean = 0, next_to_use = 0 atl1c_clean_tx() checks neither the carrier nor __AT_DOWN. It walks next_to_clean up to the hardware consumer index and calls atl1c_clean_buffer() on the same entries. atl1c_xmit_frame() checks only __AT_DOWN, which the link-down path does not set. netif_carrier_off() does not stop the TX queue right away; that happens later through linkwatch. Can both contexts unmap and free the same TX skb here? Can atl1c_xmit_frame() keep queuing TPDs, or touch an skb that atl1c_clean_tx_ring() has just freed, while the ring indices and BQL state are being reset? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117225521.19689-1-federico%40rimpianto.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error 2026-11-17 22:55 [PATCH net v4 0/2] net: atl1c: fix the RX buffer leak on errored frames Federico Musto 2026-11-17 22:55 ` [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset Federico Musto @ 2026-11-17 22:55 ` Federico Musto 2026-11-21 23:18 ` netdev-bot+sashiko 1 sibling, 1 reply; 5+ messages in thread From: Federico Musto @ 2026-11-17 22:55 UTC (permalink / raw) To: Chris Snook, Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev Cc: linux-kernel, Federico Musto, stable atl1c_clean_rx() drops a frame whose return descriptor (RRD) carries RRS_RX_ERR_SUM or RRS_802_3_LEN_ERR by calling atl1c_clean_rfd(), which only marks the RFD free and clears the skb pointer. Nothing unmaps the DMA mapping and nothing frees the skb, so every errored frame - CRC, alignment, truncation, runt - leaks one skb and one DMA mapping. The driver uses a 32-bit DMA mask, so on a host without an IOMMU each of those mappings also pins a swiotlb slot. Unmap the buffer and free the skb before the RFD is recycled. Freeing makes the RFD index and count found in the RRD matter more than they did. Both are written by the device and neither is checked: the index field is 12 bits wide for a ring of 512 entries, and the count can be 0 to 15 while one RFD per frame is all the driver handles. A wrong index used to leak a buffer; it would now unmap and free one the device still owns, or one outside the ring. So validate the RRD first, the way alx_clean_rx_irq() does for the same descriptor layout: the count must be 1, the index must be the one the driver expects back next (rfd_ring->next_to_clean) and that slot must hold a buffer. Otherwise touch no buffer and schedule a reset through ATL1C_WORK_EVENT_RESET, as the interrupt handler does on ISR_ERROR. After the check the slot is addressed through the driver's own index, in the good receive path too, which took the unchecked index from the descriptor in the same way. The check also covers two cases the count was left to cause. An RRD with a count of 0 was never consumed and RX stalled on it, in an endless loop inside the poll when it also had an error bit set. A good RRD with a count above 1 was consumed without recycling its RFDs. Count an errored descriptor as work, so that the refill runs when a poll sees no good frame. Clear the RRD ring on reset: the RRD and RFD rings advance in step, so an RRD left over from before a reset would pass the check above and release a freshly posted buffer the device still owns. The hardware already counts these frames in its own error counters, which atl1c_get_stats() reports, so no software counter is added here. Found by code inspection; the error path has not been exercised on hardware. Fixes: 43250ddd75a3 ("atl1c: Atheros L1C Gigabit Ethernet driver") Cc: stable@vger.kernel.org Signed-off-by: Federico Musto <federico@rimpianto.com> --- v3 -> v4, after the Sashiko AI review of v3: - validate the RFD count and index of the RRD against rfd_ring->next_to_clean, and that the slot holds a buffer, before any buffer is touched; reset on a mismatch, as alx_clean_rx_irq() does; - address the buffer through the driver's own index in the error path and in the good path; atl1c_clean_rfd() takes nothing from the descriptor any more; - drop the multi-RFD loop added in v3: a count other than 1 resets; - a count of 0 no longer leaves the RRD unconsumed; - new patch 1/2 for the link-down reset race. Pre-existing and left to separate patches: there is no dma_rmb() between the test of the RRD valid bit (word3) and the read of word0, and word3 is __le32 but is read without conversion. v3: https://lore.kernel.org/netdev/20261103225218.19206-1-federico@rimpianto.com/ v2: https://lore.kernel.org/netdev/20261102215253.68185-1-federico@rimpianto.com/ v1: https://lore.kernel.org/netdev/20261027115156.17128-1-federico@rimpianto.com/ --- .../net/ethernet/atheros/atl1c/atl1c_main.c | 97 ++++++++++--------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c index e9baee8fa7e5..5d00f2489d15 100644 --- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c @@ -933,8 +933,9 @@ static void atl1c_clean_rx_ring(struct atl1c_adapter *adapter, u32 queue) buffer_info = &rfd_ring->buffer_info[j]; atl1c_clean_buffer(pdev, buffer_info, 0); } - /* zero out the descriptor ring */ + /* zero out the descriptor rings */ memset(rfd_ring->desc, 0, rfd_ring->size); + memset(rrd_ring->desc, 0, rrd_ring->size); rfd_ring->next_to_clean = 0; rfd_ring->next_to_use = 0; rrd_ring->next_to_use = 0; @@ -1866,23 +1867,16 @@ static void atl1c_clean_rrd(struct atl1c_rrd_ring *rrd_ring, } } -static void atl1c_clean_rfd(struct atl1c_rfd_ring *rfd_ring, - struct atl1c_recv_ret_status *rrs, u16 num) +/* Recycle the RFD the driver expects back next. The caller owns the skb. */ +static void atl1c_clean_rfd(struct atl1c_rfd_ring *rfd_ring) { - u16 i; - u16 rfd_index; - struct atl1c_buffer *buffer_info = rfd_ring->buffer_info; + struct atl1c_buffer *buffer_info; - rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) & - RRS_RX_RFD_INDEX_MASK; - for (i = 0; i < num; i++) { - buffer_info[rfd_index].skb = NULL; - ATL1C_SET_BUFFER_STATE(&buffer_info[rfd_index], - ATL1C_BUFFER_FREE); - if (++rfd_index == rfd_ring->count) - rfd_index = 0; - } - rfd_ring->next_to_clean = rfd_index; + buffer_info = &rfd_ring->buffer_info[rfd_ring->next_to_clean]; + buffer_info->skb = NULL; + ATL1C_SET_BUFFER_STATE(buffer_info, ATL1C_BUFFER_FREE); + if (++rfd_ring->next_to_clean == rfd_ring->count) + rfd_ring->next_to_clean = 0; } /** @@ -1896,6 +1890,7 @@ static int atl1c_clean_rx(struct napi_struct *napi, int budget) container_of(napi, struct atl1c_rrd_ring, napi); struct atl1c_adapter *adapter = rrd_ring->adapter; u16 rfd_num, rfd_index; + u32 rrs_word0; u16 length; struct pci_dev *pdev = adapter->pdev; struct net_device *netdev = adapter->netdev; @@ -1914,47 +1909,59 @@ static int atl1c_clean_rx(struct napi_struct *napi, int budget) if (work_done >= budget) break; rrs = ATL1C_RRD_DESC(rrd_ring, rrd_ring->next_to_clean); - if (likely(RRS_RXD_IS_VALID(rrs->word3))) { - rfd_num = (rrs->word0 >> RRS_RX_RFD_CNT_SHIFT) & - RRS_RX_RFD_CNT_MASK; - if (unlikely(rfd_num != 1)) - /* TODO support mul rfd*/ - if (netif_msg_rx_err(adapter)) - dev_warn(&pdev->dev, - "Multi rfd not support yet!\n"); - goto rrs_checked; - } else { + if (!RRS_RXD_IS_VALID(rrs->word3)) + break; + + rrs_word0 = le32_to_cpu(rrs->word0); + rfd_num = (rrs_word0 >> RRS_RX_RFD_CNT_SHIFT) & + RRS_RX_RFD_CNT_MASK; + rfd_index = (rrs_word0 >> RRS_RX_RFD_INDEX_SHIFT) & + RRS_RX_RFD_INDEX_MASK; + buffer_info = &rfd_ring->buffer_info[rfd_ring->next_to_clean]; + + /* The RRD is written by the device. Its RFD index field is + * wider than the ring, and only one RFD per frame is + * supported. Check both against the driver's own ring state, + * and that the slot holds a buffer, before anything is + * unmapped or freed. When they disagree there is no telling + * which buffers the device still owns: leave them all alone + * and reset. + */ + if (unlikely(rfd_num != 1 || + rfd_index != rfd_ring->next_to_clean || + !buffer_info->skb)) { + dev_err_ratelimited(&pdev->dev, + "RRD out of sync: RFD count %u index %u, expected index %u%s; resetting\n", + rfd_num, rfd_index, + rfd_ring->next_to_clean, + buffer_info->skb ? "" : " (no buffer)"); + set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event); + schedule_work(&adapter->common_task); break; } -rrs_checked: - atl1c_clean_rrd(rrd_ring, rrs, rfd_num); + + atl1c_clean_rrd(rrd_ring, rrs, 1); + dma_unmap_single(&pdev->dev, buffer_info->dma, + buffer_info->length, DMA_FROM_DEVICE); + skb = buffer_info->skb; + atl1c_clean_rfd(rfd_ring); + if (rrs->word3 & (RRS_RX_ERR_SUM | RRS_802_3_LEN_ERR)) { - atl1c_clean_rfd(rfd_ring, rrs, rfd_num); if (netif_msg_rx_err(adapter)) dev_warn(&pdev->dev, "wrong packet! rrs word3 is %x\n", rrs->word3); + kfree_skb_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED); + /* The RFD has been recycled, so count the drop as + * work: the refill after the loop only runs when + * some was done. + */ + work_done++; continue; } length = le16_to_cpu((rrs->word3 >> RRS_PKT_SIZE_SHIFT) & RRS_PKT_SIZE_MASK); - /* Good Receive */ - if (likely(rfd_num == 1)) { - rfd_index = (rrs->word0 >> RRS_RX_RFD_INDEX_SHIFT) & - RRS_RX_RFD_INDEX_MASK; - buffer_info = &rfd_ring->buffer_info[rfd_index]; - dma_unmap_single(&pdev->dev, buffer_info->dma, - buffer_info->length, DMA_FROM_DEVICE); - skb = buffer_info->skb; - } else { - /* TODO */ - if (netif_msg_rx_err(adapter)) - dev_warn(&pdev->dev, - "Multi rfd not support yet!\n"); - break; - } - atl1c_clean_rfd(rfd_ring, rrs, rfd_num); /* A link partner whose l2mtu is larger than ours can hand us a * frame that does not fit the buffer the hardware was given: -- 2.47.3 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error 2026-11-17 22:55 ` [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error Federico Musto @ 2026-11-21 23:18 ` netdev-bot+sashiko 0 siblings, 0 replies; 5+ messages in thread From: netdev-bot+sashiko @ 2026-11-21 23:18 UTC (permalink / raw) To: federico Cc: chris.snook, andrew+netdev, davem, edumazet, kuba, pabeni, netdev, linux-kernel, stable Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 (2) · Medium: 1 · 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). - [Medium] In atl1c_clean_rx() (drivers/net/ethernet/atheros/atl1c/atl1c_main.c), the RRD valid bit… Pre-existing issues: - [High] This patch adds a new schedule_work(&adapter->common_task) call (atl1c_clean_rx(), line 1939) in NAPI context. - [High] The reset branch of atl1c_common_task() (lines 363-367) calls atl1c_down()/atl1c_up() without rtnl_lock and without taking… -- net: atl1c: free the RX buffer when the descriptor reports an error With this patch, atl1c_clean_rx() unmaps and frees the skb for RRDs that report RRS_RX_ERR_SUM or RRS_802_3_LEN_ERR. Before, those buffers leaked. Each RRD's RFD count and index are now checked against rfd_ring->next_to_clean, and a mismatch schedules an adapter reset. The RRD ring is also zeroed in atl1c_clean_rx_ring(). > diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c > index e9baee8fa7e5e..5d00f2489d154 100644 > --- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c > +++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c > @@ -933,8 +933,9 @@ static void atl1c_clean_rx_ring(struct atl1c_adapter *adapter, u32 queue) > buffer_info = &rfd_ring->buffer_info[j]; > atl1c_clean_buffer(pdev, buffer_info, 0); > } > - /* zero out the descriptor ring */ > + /* zero out the descriptor rings */ > memset(rfd_ring->desc, 0, rfd_ring->size); > + memset(rrd_ring->desc, 0, rrd_ring->size); > rfd_ring->next_to_clean = 0; > rfd_ring->next_to_use = 0; > rrd_ring->next_to_use = 0; [ ... ] > @@ -1914,47 +1909,59 @@ static int atl1c_clean_rx(struct napi_struct *napi, int budget) > if (work_done >= budget) > break; > rrs = ATL1C_RRD_DESC(rrd_ring, rrd_ring->next_to_clean); > - if (likely(RRS_RXD_IS_VALID(rrs->word3))) { > - rfd_num = (rrs->word0 >> RRS_RX_RFD_CNT_SHIFT) & > - RRS_RX_RFD_CNT_MASK; > - if (unlikely(rfd_num != 1)) > - /* TODO support mul rfd*/ > - if (netif_msg_rx_err(adapter)) > - dev_warn(&pdev->dev, > - "Multi rfd not support yet!\n"); > - goto rrs_checked; > - } else { > + if (!RRS_RXD_IS_VALID(rrs->word3)) > + break; > + > + rrs_word0 = le32_to_cpu(rrs->word0); [Severity: Medium] Should there be a dma_rmb() between the RRS_RXD_IS_VALID() test on word3 and the read of word0 here? The notes after the commit message say the missing barrier is pre-existing and will be fixed in a separate patch. Before this patch, a stale word0 only made one poll stop early. Now the RFD count and index taken from word0 decide whether ATL1C_WORK_EVENT_RESET is scheduled, and that runs atl1c_down()/atl1c_up() from atl1c_common_task(). On weakly ordered CPUs such as arm64 and powerpc, the control dependency on the word3 test does not order the later word0 load. So word0 can be read before the device's RRD write is visible. The RRD ring is zero after open, because dma_alloc_coherent() zeroes it. With the memset added to atl1c_clean_rx_ring() above, it is also zero after every reset. On the first lap after open or reset, a stale word0 would then be 0 and give rfd_num == 0, which hits: if (unlikely(rfd_num != 1 || rfd_index != rfd_ring->next_to_clean || !buffer_info->skb)) { ... set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event); schedule_work(&adapter->common_task); Could this produce a spurious "RRD out of sync" message and a full MAC reset that drops the link? The reset zeroes the ring again, so the next lap is exposed in the same way. Without the memset, a stale word0 at slot k would still hold the previous lap's value (count 1, index k) and pass the check. Would a dma_rmb() right after the RRS_RXD_IS_VALID() test close this window? > + rfd_num = (rrs_word0 >> RRS_RX_RFD_CNT_SHIFT) & > + RRS_RX_RFD_CNT_MASK; > + rfd_index = (rrs_word0 >> RRS_RX_RFD_INDEX_SHIFT) & > + RRS_RX_RFD_INDEX_MASK; > + buffer_info = &rfd_ring->buffer_info[rfd_ring->next_to_clean]; [ ... ] > + if (unlikely(rfd_num != 1 || > + rfd_index != rfd_ring->next_to_clean || > + !buffer_info->skb)) { > + dev_err_ratelimited(&pdev->dev, > + "RRD out of sync: RFD count %u index %u, expected index %u%s; resetting\n", > + rfd_num, rfd_index, > + rfd_ring->next_to_clean, > + buffer_info->skb ? "" : " (no buffer)"); > + set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event); > + schedule_work(&adapter->common_task); [Severity: High] This isn't a bug introduced by this patch, but this schedule_work() is a new producer for common_task that only napi_disable() can quiesce. Can common_task be queued again after it has been cancelled, and then outlive the adapter? atl1c_close() cancels the work before atl1c_down() quiesces NAPI and the IRQ: atl1c_close() { set_bit(__AT_DOWN, &adapter->flags); cancel_work_sync(&adapter->common_task); atl1c_down(adapter); ... } atl1c_down() { atl1c_del_timer(adapter); adapter->work_event = 0; /* clear all event */ ... napi_disable(&adapter->rrd_ring[i].napi); atl1c_irq_disable(adapter); atl1c_free_irq(adapter); ... } An RX poll still running in this window that hits an out-of-sync RRD sets ATL1C_WORK_EVENT_RESET and calls schedule_work() again. The existing ISR_ERROR path in the interrupt handler and atl1c_link_chg_event() can do the same. atl1c_remove() then does: unregister_netdev(netdev); ... free_netdev(netdev); There is no cancel_work_sync() or flush_work() between the two. If the worker has not run by then, the queued work_struct sits in freed netdev_priv() memory. atl1c_common_task() would then run container_of() and test_bit(__AT_DOWN, &adapter->flags) on freed memory. Would a cancel_work_sync() once NAPI and the IRQ are quiesced avoid this? That could go at the end of atl1c_close(), or in atl1c_remove() after unregister_netdev(). [Severity: High] This is a pre-existing issue, but this patch adds a new trigger (an out-of-sync RRD) for the reset in atl1c_common_task(). The existing triggers are tx_timeout and ISR_ERROR. Is that reset path serialized against other callers of atl1c_down()/atl1c_up()? atl1c_common_task() { if (test_bit(__AT_DOWN, &adapter->flags)) return; if (test_and_clear_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event)) { netif_device_detach(netdev); atl1c_down(adapter); atl1c_up(adapter); netif_device_attach(netdev); } ... } It takes neither rtnl_lock nor __AT_RESETTING. atl1c_change_mtu() runs under rtnl and takes __AT_RESETTING before its own atl1c_down() and atl1c_up(). Nothing keeps the two apart. Suppose atl1c_change_mtu()'s atl1c_down() runs while common_task is between napi_disable() and napi_enable(). The second napi_disable() takes netdev_lock() and waits on NAPI_STATE_SCHED, which is already set. common_task's napi_enable() then blocks on netdev_lock(). Can this deadlock while atl1c_change_mtu() holds rtnl? Other interleavings look like they could unmap and free the same RX buffers twice through atl1c_reset_dma_ring(). They could also call free_irq()/request_irq() twice. The previous patch in this series, "net: atl1c: wait for in-flight RX polls before the link-down ring reset", describes the same napi_disable()/netdev_lock() deadlock for the link-change work. > break; > } [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117225521.19689-1-federico%40rimpianto.com ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-21 23:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-17 22:55 [PATCH net v4 0/2] net: atl1c: fix the RX buffer leak on errored frames Federico Musto 2026-11-17 22:55 ` [PATCH net v4 1/2] net: atl1c: wait for in-flight RX polls before the link-down ring reset Federico Musto 2026-11-21 23:18 ` netdev-bot+sashiko 2026-11-17 22:55 ` [PATCH net v4 2/2] net: atl1c: free the RX buffer when the descriptor reports an error Federico Musto 2026-11-21 23:18 ` netdev-bot+sashiko
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®