net: axienet: release every RX buffer in axienet_dma_bd_release()
PATCH 1/1 net: axienet: release every RX buffer in axienet_dma_bd_release()
The RX walk in axienet_dma_bd_release() stops at the first descriptor without an skb, assuming that such a slot and all after it were never filled. That holds on the axienet_dma_bd_init() error path, but not once the ring has been running: when axienet_rx_poll() fails to allocate or map a replacement buffer it leaves the slot it emptied with a NULL skb, in the middle of a populated ring, until a later poll refills it. Closing the interface before then leaks the skb and the streaming DMA mapping of every descriptor after that slot, which can be most of the ring, and is most likely under memory pressure.
The walk also frees each skb before unmapping it. With swiotlb, the DMA_FROM_DEVICE unmap copies the bounce buffer back into the skb data that was just freed, and on non-coherent platforms it invalidates cache lines that may already belong to a new owner.
Skip empty slots instead of stopping at the first one. An emptied slot still has a non-zero cntrl but its buffer is already unmapped, so the skip has to cover the unmap too, which it does by coming before it. Then unmap before freeing, as axienet_rx_poll() does.
This was reported by the Sashiko AI review bot.
Tested on the AXI Ethernet MAC of an ADVA TimeCard X2 (PCIe card, with the built-in AXI DMA): traffic passes after each of ten down/up cycles, each running axienet_dma_bd_release(), so the unmap-then-free order is exercised on every buffer. A failed RX refill was not reproduced, so the skip over an empty slot was not exercised.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7 -5
@@ -247,13 +247,13 @@ static void axienet_dma_bd_release(struct net_device *ndev)for (i =0 ; i < lp->rx_bd_num; i++) {dma_addr_t phys; -/* A NULL skb means this descriptor has not been initialised -* at all. +/* A NULL skb means the descriptor holds no buffer: it was +* never filled, or axienet_rx_poll() took its skb and could +* not refill it, having already unmapped the old buffer. +* Such slots can sit anywhere in a ring that has been running. */ if (!lp->rx_bd_v[i].skb) -break ; - -dev_kfree_skb (lp->rx_bd_v[i].skb); +continue ;/* For each descriptor, we programmed cntrl with the (non-zero) * descriptor size, after it had been successfully allocated.
@@ -264,6 +264,8 @@ static void axienet_dma_bd_release(struct net_device *ndev)dma_unmap_single (lp->dev, phys, lp->max_frm_size,DMA_FROM_DEVICE ); } + +dev_kfree_skb (lp->rx_bd_v[i].skb); } dma_free_coherent(lp->dev,
Signature · 1 line
2.47.0
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Thu, 15 Oct 2026 11:47:43 +0300 you wrote:
The RX walk in
axienet_dma_bd_release()stops at the first descriptor without an skb, assuming that such a slot and all after it were never filled. That holds on theaxienet_dma_bd_init()error path, but not once the ring has been running: whenaxienet_rx_poll()fails to allocate or map a replacement buffer it leaves the slot it emptied with a NULL skb, in the middle of a populated ring, until a later poll refills it. Closing the interface before then leaks the skb and the streaming DMA mapping of every descriptor after that slot, which can be most of the ring, and is most likely under memory pressure.[...]
Here is the summary with links:
- [net-next] net: axienet: release every RX buffer in axienet_dma_bd_release()
https://git.kernel.org/netdev/net-next/c/b59787892d04
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html