net: axienet: free outstanding TX buffers in axienet_dma_bd_release()
PATCH v3 1/1 net: axienet: free outstanding TX buffers in axienet_dma_bd_release()
axienet_dma_bd_release() walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring with dma_free_coherent() alone. Any descriptor that axienet_free_tx_chain() had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
axienet_stop() disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up to lp->tx_bd_num skbs and mappings each time.
Walk the TX ring the way axienet_dma_err_handler() already does: unmap every descriptor whose cntrl is still set - axienet_free_tx_chain() clears it on reclaim - and free any skb still attached, as a drop. This relies on axienet_stop() having stopped the DMA engine first, as the RX walk in the same function already does.
The walk must not run on a ring that is not there. axienet_open() does not check the result of the reset that runs axienet_dma_bd_init(), so when that reset fails tx_bd_v is either still NULL or, after an earlier close, points at the ring that close freed. Clear tx_bd_v and rx_bd_v once their rings are freed, and skip the walk when tx_bd_v is NULL. That also ends the second dma_free_coherent() of a stale ring which the same path already did. On the axienet_dma_bd_init() error path the TX ring has just been allocated zeroed, so the walk does nothing.
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, and after each of ten down/up cycles and five module reloads, all made with traffic running and each running axienet_dma_bd_release(), traffic resumes and nothing is logged. The leak itself was not measured, and the failed-reset paths were not exercised.
---
Notes:
Changes in v3:
- Clear tx_bd_v and rx_bd_v after freeing the rings. v2 only caught a NULL tx_bd_v from a first open; after a close followed by a failed reset the walk would have read the freed ring (Sashiko).
- Reword the comment on the skb free: a descriptor can complete after TX NAPI was disabled, so "never transmitted" was not always true (Sashiko).
- Say in the commit message which hardware the test ran on.
- Kept Jacob's Reviewed-by, as the changes are small; please say if that is not OK.
- The hardware test is v1's. The changes since only affect the failed-reset paths, which it did not exercise, and how the freed skbs are accounted.
- v2: https://lore.kernel.org/netdev/[email protected]/
Changes in v2:
- Skip the TX walk when tx_bd_v is NULL (Sashiko).
- Free the skbs with dev_kfree_skb_any(), so they count as drops as in axienet_dma_err_handler() (Sashiko).
- v1: https://lore.kernel.org/netdev/[email protected]/
.../net/ethernet/xilinx/xilinx_axienet_main.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +25 -1
@@ -186,11 +186,34 @@ static void axienet_dma_bd_release(struct net_device *ndev)int i;struct axienet_local *lp =netdev_priv (ndev); -/* If we end up here, tx_bd_v must have been DMA allocated. */ +/* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as +* allocating it, and is cleared below once the ring is freed; +* dma_free_coherent() accepts NULL. +*/ +for (i =0 ; lp->tx_bd_v && i < lp->tx_bd_num; i++) { +struct axidma_bd *cur_p = &lp->tx_bd_v[i]; + +/* axienet_free_tx_chain() clears cntrl when it reclaims a +* descriptor, so a non-zero value means the mapping is live. +*/ +if (cur_p->cntrl) { +dma_addr_t addr =desc_get_phys_addr (lp, cur_p); + +dma_unmap_single (lp->dev, addr, + (cur_p->cntrl & +XAXIDMA_BD_CTRL_LENGTH_MASK ), +DMA_TO_DEVICE ); + } +/* not reclaimed by axienet_free_tx_chain(), so a drop */ +if (cur_p->skb) +dev_kfree_skb_any (cur_p->skb); + } +dma_free_coherent (lp->dev,sizeof (*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v =NULL ;if (!lp->rx_bd_v)return ;
@@ -221,6 +244,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }static u64 axienet_dma_rate (struct axienet_local *lp)
base-commit: 6dc989ea46b96ce170840174b4a38c4a387fb005
Signature · 1 line
2.47.0
Quoted 16 lines · Sagi Maimon
axienet_dma_bd_release()walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring withdma_free_coherent()alone. Any descriptor thataxienet_free_tx_chain()had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
axienet_stop()disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up tolp->tx_bd_numskbs and mappings each time.Walk the TX ring the way
axienet_dma_err_handler()already does: unmap every descriptor whose cntrl is still set -axienet_free_tx_chain()clears it on reclaim - and free any skb still attached, as a drop. This relies onaxienet_stop()having stopped the DMA engine first, as the RX walk in the same function already does.
[...]
Quoted 21 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")Reviewed-by Jacob Keller <[email protected]>Assisted-by LLM sparseSigned-off-by Sagi Maimon <[email protected]>---
Notes:
Changes in v3:
- Cleartx_bd_vandrx_bd_vafter freeing the rings. v2 only caught a NULLtx_bd_vfrom a first open; after a close followed by a failed reset the walk would have read the freed ring (Sashiko).
- Reword the comment on the skb free: a descriptor can complete after TX NAPI was disabled, so "never transmitted" was not always true (Sashiko).
- Say in the commit message which hardware the test ran on.
- Kept Jacob's Reviewed-by, as the changes are small; please say if that is not OK.
- The hardware test is v1's. The changes since only affect the failed-reset paths, which it did not exercise, and how the freed skbs are accounted.
- v2: https://lore.kernel.org/netdev/[email protected]/
[...]
Quoted 9 lines
.../net/ethernet/xilinx/xilinx_axienet_main.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0@@ -186,11 +186,34 @@ static void axienet_dma_bd_release(struct net_device *ndev)
[...]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 248
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2
-0+ lp->tx_bd_v =NULL ;if (!lp->rx_bd_v)return ;@@ -221,6 +244,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }
The added null writes makes me think that centralizing this code and using it from both axienet_dma_err_handler and axienet_dma_bd_release (instead of repeating it) is a good idea like I mentioned in the last post.
The code seems right tho even tho I don't like duplicating the logic.
Quoted 72 lines · Joe Damato
Quoted 16 lines · Sagi Maimon
axienet_dma_bd_release()walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring withdma_free_coherent()alone. Any descriptor thataxienet_free_tx_chain()had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
axienet_stop()disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up tolp->tx_bd_numskbs and mappings each time.Walk the TX ring the way
axienet_dma_err_handler()already does: unmap every descriptor whose cntrl is still set -axienet_free_tx_chain()clears it on reclaim - and free any skb still attached, as a drop. This relies onaxienet_stop()having stopped the DMA engine first, as the RX walk in the same function already does.[...]
Quoted 21 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")Reviewed-by Jacob Keller <[email protected]>Assisted-by LLM sparseSigned-off-by Sagi Maimon <[email protected]>---
Notes:
Changes in v3:
- Cleartx_bd_vandrx_bd_vafter freeing the rings. v2 only caught a NULLtx_bd_vfrom a first open; after a close followed by a failed reset the walk would have read the freed ring (Sashiko).
- Reword the comment on the skb free: a descriptor can complete after TX NAPI was disabled, so "never transmitted" was not always true (Sashiko).
- Say in the commit message which hardware the test ran on.
- Kept Jacob's Reviewed-by, as the changes are small; please say if that is not OK.
- The hardware test is v1's. The changes since only affect the failed-reset paths, which it did not exercise, and how the freed skbs are accounted.
- v2: https://lore.kernel.org/netdev/[email protected]/[...]
Quoted 9 lines
.../net/ethernet/xilinx/xilinx_axienet_main.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0@@ -186,11 +186,34 @@ static void axienet_dma_bd_release(struct net_device *ndev)[...]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 248
Quoted 10 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2
-0+ lp->tx_bd_v =NULL ;if (!lp->rx_bd_v)return ;@@ -221,6 +244,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }The added null writes makes me think that centralizing this code and using it from both
axienet_dma_err_handlerandaxienet_dma_bd_release(instead of repeating it) is a good idea like I mentioned in the last post.
Quoted 3 lines
The code seems right tho even tho I don't like duplicating the logic.
Reviewed-by Joe Damato <[email protected]>
Thanks for the review, Joe.
Agreed on the helper. As on v2, I kept the fix minimal for net, and will send the helper to net-next once this has reached it, with both axienet_dma_bd_release() and axienet_dma_err_handler() using it. Thanks,
Sagi
Jakub Kicinski
maintainerQuoted 3 lines · On Tue, 6 Oct 2026 06:44:55 +0300 Sagi Maimon wrote:
Agreed on the helper. As on v2, I kept the fix minimal for net, and will send the helper to net-next once this has reached it, with both
axienet_dma_bd_release()andaxienet_dma_err_handler()using it.
Let's do this now, trying to keep fixes small is a bit of an anti-pattern
Quoted 7 lines · On Tue, 6 Oct 2026 06:44:55 +0300 Sagi Maimon wrote:
Quoted 3 lines
Agreed on the helper. As on v2, I kept the fix minimal for net, and will send the helper to net-next once this has reached it, with both
axienet_dma_bd_release()andaxienet_dma_err_handler()using it.Let's do this now, trying to keep fixes small is a bit of an anti-pattern
Out of curiosity, why is that an anti-pattern?
I'd think that small fixes are, in general, easier to backport to stable. Is this more of procedural question - if the whole fix gets into net, it will get merged into net-next by the end of the week anyway?
/Daniel
Paolo Abeni
maintainerQuoted 5 lines · Daniel Machon
Quoted 5 lines · On Tue, 6 Oct 2026 06:44:55 +0300 Sagi Maimon wrote:
Quoted 3 lines
Agreed on the helper. As on v2, I kept the fix minimal for net, and will send the helper to net-next once this has reached it, with both
axienet_dma_bd_release()andaxienet_dma_err_handler()using it.
Quoted 8 lines
Quoted 2 lines
Let's do this now, trying to keep fixes small is a bit of an anti-pattern
Out of curiosity, why is that an anti-pattern?
I'd think that small fixes are, in general, easier to backport to stable. Is this more of procedural question - if the whole fix gets into net, it will get merged into net-next by the end of the week anyway?
I'm answering here because I can only guess how scarefully long is Jakub's email backlog, and possibly this could get lost.
I think the key here is the context. This revision is incorrect because in order to be minimal intentionally adds a significant chunk of duplicate code, but such duplication must be avoided, the 'keep is small' is not a good argument to allow that.
I guess a one-line alternative implementing a different solution (if existing) could have been ok.
/P
Quoted 9 lines · Daniel Machon
Quoted 8 lines
Quoted 7 lines · On Tue, 6 Oct 2026 06:44:55 +0300 Sagi Maimon wrote:
Quoted 3 lines
Agreed on the helper. As on v2, I kept the fix minimal for net, and will send the helper to net-next once this has reached it, with both
axienet_dma_bd_release()andaxienet_dma_err_handler()using it.Let's do this now, trying to keep fixes small is a bit of an anti-pattern
Quoted 7 lines
Quoted 5 lines
Out of curiosity, why is that an anti-pattern?
I'd think that small fixes are, in general, easier to backport to stable. Is this more of procedural question - if the whole fix gets into net, it will get merged into net-next by the end of the week anyway?
I'm answering here because I can only guess how scarefully long is Jakub's email backlog, and possibly this could get lost.
I appreciate that.
Quoted 11 lines
I think the key here is the context. This revision is incorrect because in order to be minimal intentionally adds a significant chunk of duplicate code, but such duplication must be avoided, the 'keep is small' is not a good argument to allow that.
I guess a one-line alternative implementing a different solution (if existing) could have been ok.
/P
Thanks for the clarification.
/Daniel
PATCH v4 1/1 net: axienet: free outstanding TX buffers in axienet_dma_bd_release()
In reply to Sagi Maimonaxienet_dma_bd_release() walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring with dma_free_coherent() alone. Any descriptor that axienet_free_tx_chain() had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
axienet_stop() disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up to lp->tx_bd_num skbs and mappings each time.
axienet_dma_err_handler() already walks the TX ring this way before it restarts the DMA engine: it unmaps every descriptor whose cntrl is still set - axienet_free_tx_chain() clears it on reclaim - frees any skb still attached, and clears the descriptor. Move that loop into a helper, axienet_free_tx_bufs(), and call it from axienet_dma_bd_release() too. This relies on axienet_stop() having stopped the DMA engine first, as the RX walk in the same function already does. The helper frees the skbs with dev_kfree_skb_any(), as drops: in the error handler, which runs from a workqueue, that frees them directly rather than deferring them to softirq as dev_kfree_skb_irq() did.
The walk must not run on a ring that is not there. axienet_open() does not check the result of the reset that runs axienet_dma_bd_init(), so when that reset fails tx_bd_v is either still NULL or, after an earlier close, points at the ring that close freed. Clear tx_bd_v and rx_bd_v once their rings are freed, and skip the walk when tx_bd_v is NULL. That also ends the second dma_free_coherent() of a stale ring which the same path already did. On the axienet_dma_bd_init() error path the TX ring has just been allocated zeroed, so the walk does nothing.
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, and after each of ten down/up cycles and five module reloads, all made with traffic running and each running axienet_dma_bd_release(), traffic resumes and nothing is logged. The leak itself was not measured, and neither the failed-reset paths nor axienet_dma_err_handler() were exercised.
---
Notes:
Changes in v4:
- Move the TX ring walk of axienet_dma_err_handler() into a helper, axienet_free_tx_bufs(), and use it from axienet_dma_bd_release() instead of a second copy (Joe, Jakub). The error handler now frees the skbs with dev_kfree_skb_any() instead of dev_kfree_skb_irq().
- Kept Joe's Reviewed-by, as the helper is what he asked for; dropped Jacob's, as the error handler changes too. Jacob, Joe: please take another look and say if either tag should change.
- v3: https://lore.kernel.org/netdev/[email protected]/
Changes in v3:
- Clear tx_bd_v and rx_bd_v after freeing the rings. v2 only caught a NULL tx_bd_v from a first open; after a close followed by a failed reset the walk would have read the freed ring (Sashiko).
- Reword the comment on the skb free: a descriptor can complete after TX NAPI was disabled, so "never transmitted" was not always true (Sashiko).
- Say in the commit message which hardware the test ran on.
- v2: https://lore.kernel.org/netdev/[email protected]/
Changes in v2:
- Skip the TX walk when tx_bd_v is NULL (Sashiko).
- Free the skbs with dev_kfree_skb_any(), so they count as drops as in axienet_dma_err_handler() (Sashiko).
- v1: https://lore.kernel.org/netdev/[email protected]/
.../net/ethernet/xilinx/xilinx_axienet_main.c | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +50 -24
@@ -173,6 +173,46 @@ static dma_addr_t desc_get_phys_addr(struct axienet_local *lp,return ret; } +/** +* axienet_free_tx_bufs - Release the buffers still held by the TX ring +* @lp: Pointer to the axienet_local structure +* +* Unmap every descriptor whose mapping is still live, free any skb still +* attached, and clear the descriptor for reuse. axienet_free_tx_chain() +* clears cntrl when it reclaims a descriptor, so a non-zero value means +* the mapping is live. The DMA engine must be stopped. +*/ +static void axienet_free_tx_bufs (struct axienet_local *lp) +{ +struct axidma_bd *cur_p; +u32 i; + +for (i =0 ; i < lp->tx_bd_num; i++) { + cur_p = &lp->tx_bd_v[i]; +if (cur_p->cntrl) { +dma_addr_t addr =desc_get_phys_addr (lp, cur_p); + +dma_unmap_single (lp->dev, addr, + (cur_p->cntrl & +XAXIDMA_BD_CTRL_LENGTH_MASK ), +DMA_TO_DEVICE ); + } +/* not reclaimed by axienet_free_tx_chain(), so a drop */ +if (cur_p->skb) +dev_kfree_skb_any (cur_p->skb); + cur_p->phys =0 ; + cur_p->phys_msb =0 ; + cur_p->cntrl =0 ; + cur_p->status =0 ; + cur_p->app0 =0 ; + cur_p->app1 =0 ; + cur_p->app2 =0 ; + cur_p->app3 =0 ; + cur_p->app4 =0 ; + cur_p->skb =NULL ; + } +} +/** * axienet_dma_bd_release - Release buffer descriptor rings * @ndev: Pointer to the net_device structure
@@ -186,11 +226,18 @@ static void axienet_dma_bd_release(struct net_device *ndev)int i;struct axienet_local *lp =netdev_priv (ndev); -/* If we end up here, tx_bd_v must have been DMA allocated. */ +/* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as +* allocating it, and is cleared below once the ring is freed; +* dma_free_coherent() accepts NULL. +*/ +if (lp->tx_bd_v) +axienet_free_tx_bufs (lp); +dma_free_coherent (lp->dev,sizeof (*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v =NULL ;if (!lp->rx_bd_v)return ;
@@ -221,6 +268,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }static u64 axienet_dma_rate (struct axienet_local *lp)
@@ -2749,29 +2797,7 @@ static void axienet_dma_err_handler(struct work_struct *work)axienet_dma_stop (lp);netdev_reset_queue (ndev); -for (i =0 ; i < lp->tx_bd_num; i++) { - cur_p = &lp->tx_bd_v[i]; -if (cur_p->cntrl) { -dma_addr_t addr =desc_get_phys_addr (lp, cur_p); - -dma_unmap_single (lp->dev, addr, - (cur_p->cntrl & -XAXIDMA_BD_CTRL_LENGTH_MASK ), -DMA_TO_DEVICE ); - } -if (cur_p->skb) -dev_kfree_skb_irq (cur_p->skb); - cur_p->phys =0 ; - cur_p->phys_msb =0 ; - cur_p->cntrl =0 ; - cur_p->status =0 ; - cur_p->app0 =0 ; - cur_p->app1 =0 ; - cur_p->app2 =0 ; - cur_p->app3 =0 ; - cur_p->app4 =0 ; - cur_p->skb =NULL ; - } +axienet_free_tx_bufs (lp);for (i =0 ; i < lp->rx_bd_num; i++) { cur_p = &lp->rx_bd_v[i];
base-commit: 23609bce9e1de525d1d0e73fc68c6e7971d0b49e
Signature · 1 line
2.47.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 1 (3) · Medium: 1 (3) · Low: 2
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] net: axienet: RX buffer leak in axienet_dma_bd_release
- [Medium] axienet_free_tx_bufs() loops over the current lp->tx_bd_num entries of lp->tx_bd_v, reading cntrl/skb and storing zeros into every…
- [Low] axienet_free_tx_bufs() walks the TX ring in index order 0..tx_bd_num-1 and, at each descriptor that has an skb attached, frees…
- [Low] axienet_dma_stop() ignores both the timeouts of its HALT polls and the return value of __axienet_device_reset(), which is -ETIMEDOUT…
Pre-existing issues:
- [High] axienet_open() ignores the result of axienet_device_reset().
- [High] In the RX walk of axienet_dma_bd_release(), each RX skb is freed with dev_kfree_skb() (line 254) before its DMA_FROM_DEVICE streaming…
- [High] axienet_dma_err_handler() runs from a workqueue and does not stop or lock the TX queue: there is no netif_tx_disable(),…
- [Medium] In the sibling Xilinx driver ll_temac, temac_dma_bd_release() unmaps and frees the RX skbs but frees the TX descriptor ring with…
- [Medium] The RX walk in axienet_dma_bd_release() stops (break) at the first descriptor with a NULL skb, on the assumption in its comment…
- [Medium] If phylink_of_phy_connect() or axienet_init_legacy_dma() fails after axienet_device_reset() has succeeded, axienet_open() returns…
--
net: axienet: free outstanding TX buffers in axienet_dma_bd_release()
This patch moves the TX ring walk out of axienet_dma_err_handler() into a new helper, axienet_free_tx_bufs(). axienet_dma_bd_release() now calls it, so TX skbs still in flight and their DMA mappings are freed when the interface goes down. The patch also clears tx_bd_v and rx_bd_v once their rings are freed, skips the TX walk when tx_bd_v is NULL, and frees skbs with dev_kfree_skb_any() instead of dev_kfree_skb_irq().
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0@@ -173,6 +173,46 @@ static dma_addr_t desc_get_phys_addr(struct axienet_local *lp,
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static dma_addr_t desc_get_phys_addr(struct axienet_local *lp, · line 191
Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7
-0+static void axienet_free_tx_bufs (struct axienet_local *lp) +{ +struct axidma_bd *cur_p; +u32 i; + +for (i =0 ; i < lp->tx_bd_num; i++) { + cur_p = &lp->tx_bd_v[i];
[Severity: Medium]
Can this loop run past the end of the allocated ring? The loop bound is the current lp->tx_bd_num. The only guard in axienet_dma_bd_release() is the NULL check on lp->tx_bd_v, and that says nothing about how many entries the ring was allocated with.
This sequence seems to reach that state:
axienet_open()
axienet_device_reset() succeeds, axienet_dma_bd_init() allocates N entries phylink_of_phy_connect() or axienet_init_legacy_dma() fails returns without axienet_dma_bd_release(), so tx_bd_v stays non-NULL
axienet_ethtools_set_ringparam()
the interface is down, so lp->tx_bd_num = M with M > N is accepted
axienet_open()
__axienet_device_reset() times out and axienet_dma_bd_init() is skipped the failure is ignored and open returns 0
axienet_stop()->axienet_dma_bd_release()->axienet_free_tx_bufs()
walks M entries of an N-entry ring
For i >= N, the loop reads cntrl and skb from beyond the coherent buffer. It may call dma_unmap_single() or dev_kfree_skb_any() on garbage values, and it writes zeros past the end of the allocation.
On this path the following dma_free_coherent() already passes the wrong size, so the path itself isn't new. The walk adds out-of-bounds writes to it. Fixing the unchecked reset and the missing unwind in axienet_open() would cover this too.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static dma_addr_t desc_get_phys_addr(struct axienet_local *lp, · line 202
Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +11
-0+if (cur_p->cntrl) { +dma_addr_t addr =desc_get_phys_addr (lp, cur_p); + +dma_unmap_single (lp->dev, addr, + (cur_p->cntrl & +XAXIDMA_BD_CTRL_LENGTH_MASK ), +DMA_TO_DEVICE ); + } +/* not reclaimed by axienet_free_tx_chain(), so a drop */ +if (cur_p->skb) +dev_kfree_skb_any (cur_p->skb);
[Severity: Low]
Is the skb freed here before all of its mappings have been unmapped?
axienet_start_xmit() puts the head at orig_tail_ptr and the fragments at the following indices, wrapping to 0. Only the last descriptor gets cur_p->skb:
for (ii = 0; ii < num_frag; ii++) {
if (++new_tail_ptr >= lp->tx_bd_num)
new_tail_ptr = 0;
...
cur_p->skb = skb;Take an in-flight packet whose head is at tx_bd_num - 1 and whose last fragment wrapped to index 0. This loop frees the skb at index 0. It only calls dma_unmap_single() on the head and fragment descriptors at the top of the ring later in the walk.
With DMA_TO_DEVICE and the engine stopped there may be no visible effect. Would unmapping every descriptor first and then freeing the skbs, or walking from tx_bd_ci in chain order, keep the usual unmap-before-free order? The error handler loop had the same order, and this patch adds it to normal teardown.
Quoted 1 line
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1
-0+ cur_p->phys =0 ;
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 234
Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-1@@ -186,11 +226,18 @@ static void axienet_dma_bd_release(struct net_device *ndev)int i;struct axienet_local *lp =netdev_priv (ndev); -/* If we end up here, tx_bd_v must have been DMA allocated. */ +/* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as +* allocating it, and is cleared below once the ring is freed; +* dma_free_coherent() accepts NULL. +*/ +if (lp->tx_bd_v) +axienet_free_tx_bufs (lp);
[Severity: Low]
This code assumes the DMA engine has stopped. axienet_dma_stop() ignores the HALT poll timeouts and also the return value of the reset:
/* Do a reset to ensure DMA is really stopped */ axienet_lock_mii(lp); __axienet_device_reset(lp); axienet_unlock_mii(lp);
Suppose __axienet_device_reset() returns -ETIMEDOUT ("DMA reset timeout!") while an AXI read is still outstanding. Could the device then read TX buffers after they were unmapped and freed here, for example causing an IOMMU fault?
axienet_stop() clears TXEN before this point, so freed data shouldn't reach the wire, and teardown has to proceed anyway. This is more a hardening question about faulty hardware.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 240
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2
-0+dma_free_coherent (lp->dev,sizeof (*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v =NULL ;
[Severity: High]
This isn't a bug introduced by this patch. The commit message notes that axienet_open() does not check the reset result, and the transmit path still uses the ring when the reset fails:
axienet_open() {
...
ret = axienet_device_reset(ndev);
axienet_unlock_mii(lp);
ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0);
...
}The reset can fail in two ways: __axienet_device_reset() times out, or axienet_dma_bd_init() fails with -ENOMEM and calls axienet_dma_bd_release(). Either way, open still runs axienet_init_legacy_dma() and returns 0 with no TX or RX ring.
The first transmit then does this:
axienet_start_xmit()
cur_p = &lp->tx_bd_v[orig_tail_ptr]; ... axienet_check_tx_bd_space() cur_p = &lp->tx_bd_v[(READ_ONCE(lp->tx_bd_tail) + num_frag) % lp->tx_bd_num]; if (cur_p->cntrl)
Now that this patch clears tx_bd_v, that is a NULL pointer dereference. Before the patch, after an earlier close, it was a write into the freed coherent ring.
axienet_dma_err_handler() also calls axienet_free_tx_bufs() and walks rx_bd_v, without the NULL check that axienet_dma_bd_release() now has.
Should axienet_open() check the result of axienet_device_reset() and unwind on failure?
[Severity: Medium]
This is a pre-existing issue. The axienet_open() error exits that come after a successful reset never release the rings or stop the DMA engine:
ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0);
if (ret) {
dev_err(lp->dev, "phylink_of_phy_connect() failed: %d\n", ret);
return ret;
}The err_phy path, taken when axienet_init_legacy_dma() fails, does the same.
By that point axienet_dma_bd_init() has allocated both coherent rings, allocated and mapped rx_bd_num RX skbs, and started the DMA engine. Do these leak, with the DMA engine still running?
The next open's axienet_dma_bd_init() then overwrites tx_bd_v and rx_bd_v without freeing the old allocations.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 243
Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0if (!lp->rx_bd_v)return ;
[Severity: High]
This isn't a bug introduced by this patch, but the RX walk just below leaks in the same way the TX side did. It stops at the first descriptor with a NULL skb:
if (!lp->rx_bd_v[i].skb) break;
That only works if the populated descriptors form a prefix of the ring. That holds on the axienet_dma_bd_init() error path, but not once the ring has been running.
axienet_rx_poll() takes the skb from a completed descriptor and sets cur_p->skb to NULL before refilling it. If napi_alloc_skb() or dma_map_single() then fails, the poll loop breaks. That leaves a NULL slot at rx_bd_ci in the middle of an otherwise populated ring.
If the interface is closed before a later poll refills that slot, axienet_stop()->axienet_dma_bd_release() stops there. The skb and DMA_FROM_DEVICE mapping of every descriptor after it are then leaked. Depending on where rx_bd_ci sits, that can be most of the ring. A system under memory pressure is the one most likely to hit this.
It also contradicts the commit message, which says this walk frees every receive buffer.
Would continue instead of break be enough? A slot emptied by axienet_rx_poll() still has a non-zero cntrl, and its phys points at the buffer that was already unmapped. So the skip has to cover the unmap as well, which a continue at that point does. The zeroed, never-filled slots on the axienet_dma_bd_init() error path would be skipped the same way.
This patch is about making axienet_dma_bd_release() release everything the rings still hold. Could the RX side be fixed here as well, or in a separate patch?
[Severity: High]
This isn't a bug introduced by this patch. The RX walk below frees each skb before it unmaps the skb's DMA_FROM_DEVICE mapping:
dev_kfree_skb(lp->rx_bd_v[i].skb);
...
if (lp->rx_bd_v[i].cntrl) {
phys = desc_get_phys_addr(lp, &lp->rx_bd_v[i]);
dma_unmap_single(lp->dev, phys,
lp->max_frm_size, DMA_FROM_DEVICE);
}With swiotlb bouncing, can the unmap copy up to max_frm_size bytes back into the skb data that was just freed? On non-coherent platforms the unmap also invalidates cache lines of memory that may already belong to a new owner.
Bouncing looks realistic here. Probe uses a 32-bit DMA mask unless 64-bit DMA is detected, so a 32-bit AXI DMA on a host with RAM above 4 GiB would bounce, as could the PCIe card from the commit message.
The new TX helper unmaps before it frees. Would swapping the order in this loop make the two walks consistent?
[Severity: Medium]
This is also pre-existing. The same RX walk stops at the first NULL skb:
/* A NULL skb means this descriptor has not been initialised * at all. */ if (!lp->rx_bd_v[i].skb) break;
axienet_rx_poll() sets cur_p->skb = NULL and exits its loop if napi_alloc_skb() or dma_map_single() fails. That leaves a NULL slot at rx_bd_ci in the middle of a populated ring.
Would a close after such a refill failure leak every RX skb and mapping after that slot? That would also contradict the commit message, which says the RX walk frees "every receive buffer".
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 272
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1
-0@@ -221,6 +268,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }
[Severity: Medium]
This isn't a bug introduced by this patch, but the sibling ll_temac driver seems to have the same TX leak. temac_dma_bd_release() in drivers/net/ethernet/xilinx/ll_temac_main.c frees only the TX ring:
if (lp->tx_bd_v) dma_free_coherent(ndev->dev.parent, sizeof(*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p);
temac_start_xmit() attaches the skb to the last TX BD via ptr_to_txbd(), and only temac_start_xmit_done() reclaims it.
Does temac_stop()->temac_dma_bd_release() leak in-flight TX skbs and their DMA_TO_DEVICE mappings? It may be worth a separate fix.
[ ... ]
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-1@@ -2749,29 +2797,7 @@ static void axienet_dma_err_handler(struct work_struct *work)axienet_dma_stop (lp);netdev_reset_queue (ndev); -for (i =0 ; i < lp->tx_bd_num; i++) {
[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c
Quoted 2 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1
-1- } +axienet_free_tx_bufs (lp);
[Severity: High]
This is a pre-existing issue, since the loop was moved rather than newly written. What stops axienet_start_xmit() from running at the same time as this code?
axienet_dma_err_handler() runs from a workqueue. It disables NAPI, the MAC TX/RX enables and the DMA engine, but it never calls netif_tx_disable(), netif_tx_lock() or netif_stop_queue(). The TX queue stays awake for the up to ~250 ms spent in axienet_dma_stop().
Meanwhile, on another CPU:
axienet_start_xmit()
cur_p->skb = skb; ... WRITE_ONCE(lp->tx_bd_tail, new_tail_ptr); netdev_sent_queue(ndev, skb->len);
If axienet_free_tx_bufs() frees that skb between the store and the read of skb->len, can start_xmit read a freed skb?
The two paths also race on tx_bd_tail, which the handler later resets to 0, on BQL state (netdev_reset_queue() against netdev_sent_queue()), and on descriptor contents. The restarted DMA could therefore fetch zeroed descriptors.
dev_kfree_skb_irq() deferred the free to NET_TX softirq. With dev_kfree_skb_any(), this process-context worker now frees the skb immediately, so the freed memory can be reused sooner.
The helper's kernel-doc lists only "The DMA engine must be stopped" as a precondition. Should it also require the TX queue to be quiesced?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261007034620.1360542-1-maimon.sagi%40gmail.com
Quoted 6 lines · On Thu, Oct 8, 2026 at 6:47 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 1 (3) · Medium: 1 (3) · Low: 2
Quoted 7 lines
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] net: axienet: RX buffer leak in
axienet_dma_bd_release
Real, but not introduced here: the RX walk is unchanged by this patch. It stops at the first descriptor with a NULL skb, so after a failed refill in axienet_rx_poll() the buffers behind that slot leak, and it frees each skb before unmapping it. The commit message overstates it when it says the RX walk frees every receive buffer. I will send a separate fix for the RX walk once I can test it on hardware.
Quoted 2 lines
- [Medium]
axienet_free_tx_bufs()loops over the currentlp->tx_bd_numentries oflp->tx_bd_v, reading cntrl/skb and storing zeros into every…
This needs axienet_open() to ignore a failed reset after the ring was resized, a path on which dma_free_coherent() already uses the wrong size. The fix is for axienet_open() to check the reset result and unwind, which is a separate, pre-existing problem.
The remaining pre-existing items (the unchecked reset in axienet_open(), the error handler not stopping the TX queue, the open error paths, ll_temac) are outside this patch. For the error handler, the loop is moved unchanged; dev_kfree_skb_any() in its process context frees at once instead of at the next softirq on the same CPU, which neither opens nor closes that race.
Quoted 366 lines
- [Low]
axienet_free_tx_bufs()walks the TX ring in index order 0..tx_bd_num-1 and, at each descriptor that has an skb attached, frees…
- [Low]axienet_dma_stop()ignores both the timeouts of its HALT polls and the return value of__axienet_device_reset(), which is -ETIMEDOUT…Pre-existing issues:
- [High]axienet_open()ignores the result ofaxienet_device_reset().
- [High] In the RX walk ofaxienet_dma_bd_release(), each RX skb is freed withdev_kfree_skb()(line 254) before itsDMA_FROM_DEVICEstreaming…
- [High]axienet_dma_err_handler()runs from a workqueue and does not stop or lock the TX queue: there is no netif_tx_disable(),…
- [Medium] In the sibling Xilinx driverll_temac,temac_dma_bd_release()unmaps and frees the RX skbs but frees the TX descriptor ring with…
- [Medium] The RX walk inaxienet_dma_bd_release()stops (break) at the first descriptor with a NULL skb, on the assumption in its comment…
- [Medium] Ifphylink_of_phy_connect()oraxienet_init_legacy_dma()fails afteraxienet_device_reset()has succeeded,axienet_open()returns…--
net: axienet: free outstanding TX buffers in
axienet_dma_bd_release()This patch moves the TX ring walk out of
axienet_dma_err_handler()into a new helper,axienet_free_tx_bufs().axienet_dma_bd_release()now calls it, so TX skbs still in flight and their DMA mappings are freed when the interface goes down. The patch also clearstx_bd_vandrx_bd_vonce their rings are freed, skips the TX walk whentx_bd_vis NULL, and frees skbs withdev_kfree_skb_any()instead ofdev_kfree_skb_irq().Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0@@ -173,6 +173,46 @@ static dma_addr_t desc_get_phys_addr(struct axienet_local *lp,[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static dma_addr_t desc_get_phys_addr(struct axienet_local *lp, · line 191
Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +7
-0+static void axienet_free_tx_bufs (struct axienet_local *lp) +{ +struct axidma_bd *cur_p; +u32 i; + +for (i =0 ; i < lp->tx_bd_num; i++) { + cur_p = &lp->tx_bd_v[i];[Severity: Medium]
Can this loop run past the end of the allocated ring? The loop bound is the currentlp->tx_bd_num. The only guard inaxienet_dma_bd_release()is the NULL check onlp->tx_bd_v, and that says nothing about how many entries the ring was allocated with.This sequence seems to reach that state:
axienet_open()
axienet_device_reset()succeeds,axienet_dma_bd_init()allocates N entriesphylink_of_phy_connect()oraxienet_init_legacy_dma()fails returns withoutaxienet_dma_bd_release(), sotx_bd_vstays non-NULL
axienet_ethtools_set_ringparam()
the interface is down, solp->tx_bd_num= M with M > N is accepted
axienet_open()
__axienet_device_reset()times out andaxienet_dma_bd_init()is skipped the failure is ignored and open returns 0axienet_stop()->axienet_dma_bd_release()->axienet_free_tx_bufs()
walks M entries of an N-entry ringFor i >= N, the loop reads cntrl and skb from beyond the coherent buffer. It may call
dma_unmap_single()ordev_kfree_skb_any()on garbage values, and it writes zeros past the end of the allocation.On this path the following
dma_free_coherent()already passes the wrong size, so the path itself isn't new. The walk adds out-of-bounds writes to it. Fixing the unchecked reset and the missing unwind inaxienet_open()would cover this too.drivers/net/ethernet/xilinx/xilinx_axienet_main.c static dma_addr_t desc_get_phys_addr(struct axienet_local *lp, · line 202
Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +11
-0+if (cur_p->cntrl) { +dma_addr_t addr =desc_get_phys_addr (lp, cur_p); + +dma_unmap_single (lp->dev, addr, + (cur_p->cntrl & +XAXIDMA_BD_CTRL_LENGTH_MASK ), +DMA_TO_DEVICE ); + } +/* not reclaimed by axienet_free_tx_chain(), so a drop */ +if (cur_p->skb) +dev_kfree_skb_any (cur_p->skb);[Severity: Low]
Is the skb freed here before all of its mappings have been unmapped?
axienet_start_xmit()puts the head atorig_tail_ptrand the fragments at the following indices, wrapping to 0. Only the last descriptor getscur_p->skb:for (ii = 0; ii < num_frag; ii++) { if (++new_tail_ptr >= lp->tx_bd_num) new_tail_ptr = 0; ... cur_p->skb = skb;Take an in-flight packet whose head is at
tx_bd_num- 1 and whose last fragment wrapped to index 0. This loop frees the skb at index 0. It only callsdma_unmap_single()on the head and fragment descriptors at the top of the ring later in the walk.With
DMA_TO_DEVICEand the engine stopped there may be no visible effect. Would unmapping every descriptor first and then freeing the skbs, or walking fromtx_bd_ciin chain order, keep the usual unmap-before-free order? The error handler loop had the same order, and this patch adds it to normal teardown.Quoted 1 line
+
cur_p->phys= 0;[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 234
Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-1@@ -186,11 +226,18 @@ static void axienet_dma_bd_release(struct net_device *ndev)int i;struct axienet_local *lp =netdev_priv (ndev); -/* If we end up here, tx_bd_v must have been DMA allocated. */ +/* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as +* allocating it, and is cleared below once the ring is freed; +* dma_free_coherent() accepts NULL. +*/ +if (lp->tx_bd_v) +axienet_free_tx_bufs (lp);[Severity: Low]
This code assumes the DMA engine has stopped.axienet_dma_stop()ignores the HALT poll timeouts and also the return value of the reset:/* Do a reset to ensure DMA is really stopped */ axienet_lock_mii(lp); __axienet_device_reset(lp); axienet_unlock_mii(lp);Suppose
__axienet_device_reset()returns-ETIMEDOUT("DMA reset timeout!") while an AXI read is still outstanding. Could the device then read TX buffers after they were unmapped and freed here, for example causing an IOMMU fault?
axienet_stop()clears TXEN before this point, so freed data shouldn't reach the wire, and teardown has to proceed anyway. This is more a hardening question about faulty hardware.drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 240
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2
-0+dma_free_coherent (lp->dev,sizeof (*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v =NULL ;[Severity: High]
This isn't a bug introduced by this patch. The commit message notes thataxienet_open()does not check the reset result, and the transmit path still uses the ring when the reset fails:axienet_open() { ... ret = axienet_device_reset(ndev); axienet_unlock_mii(lp); ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0); ... }The reset can fail in two ways:
__axienet_device_reset()times out, oraxienet_dma_bd_init()fails with-ENOMEMand callsaxienet_dma_bd_release(). Either way, open still runsaxienet_init_legacy_dma()and returns 0 with no TX or RX ring.The first transmit then does this:
axienet_start_xmit()cur_p = &lp->tx_bd_v[orig_tail_ptr]; ... axienet_check_tx_bd_space() cur_p = &lp->tx_bd_v[(READ_ONCE(lp->tx_bd_tail) + num_frag) % lp->tx_bd_num]; if (cur_p->cntrl)Now that this patch clears
tx_bd_v, that is a NULL pointer dereference. Before the patch, after an earlier close, it was a write into the freed coherent ring.
axienet_dma_err_handler()also callsaxienet_free_tx_bufs()and walksrx_bd_v, without the NULL check thataxienet_dma_bd_release()now has.Should
axienet_open()check the result ofaxienet_device_reset()and unwind on failure?[Severity: Medium]
This is a pre-existing issue. Theaxienet_open()error exits that come after a successful reset never release the rings or stop the DMA engine:ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0); if (ret) { dev_err(lp->dev, "phylink_of_phy_connect() failed: %d\n", ret); return ret; }The
err_phypath, taken whenaxienet_init_legacy_dma()fails, does the same.By that point
axienet_dma_bd_init()has allocated both coherent rings, allocated and mappedrx_bd_numRX skbs, and started the DMA engine. Do these leak, with the DMA engine still running?The next open's
axienet_dma_bd_init()then overwritestx_bd_vandrx_bd_vwithout freeing the old allocations.drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 243
Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0if (!lp->rx_bd_v)return ;[Severity: High]
This isn't a bug introduced by this patch, but the RX walk just below leaks in the same way the TX side did. It stops at the first descriptor with a NULL skb:if (!lp->rx_bd_v[i].skb) break;That only works if the populated descriptors form a prefix of the ring. That holds on the
axienet_dma_bd_init()error path, but not once the ring has been running.
axienet_rx_poll()takes the skb from a completed descriptor and setscur_p->skbto NULL before refilling it. Ifnapi_alloc_skb()ordma_map_single()then fails, the poll loop breaks. That leaves a NULL slot atrx_bd_ciin the middle of an otherwise populated ring.If the interface is closed before a later poll refills that slot, axienet_stop()->axienet_dma_bd_release() stops there. The skb and
DMA_FROM_DEVICEmapping of every descriptor after it are then leaked. Depending on whererx_bd_cisits, that can be most of the ring. A system under memory pressure is the one most likely to hit this.It also contradicts the commit message, which says this walk frees every receive buffer.
Would continue instead of break be enough? A slot emptied by
axienet_rx_poll()still has a non-zero cntrl, and its phys points at the buffer that was already unmapped. So the skip has to cover the unmap as well, which a continue at that point does. The zeroed, never-filled slots on theaxienet_dma_bd_init()error path would be skipped the same way.This patch is about making
axienet_dma_bd_release()release everything the rings still hold. Could the RX side be fixed here as well, or in a separate patch?[Severity: High]
This isn't a bug introduced by this patch. The RX walk below frees each skb before it unmaps the skb'sDMA_FROM_DEVICEmapping:dev_kfree_skb(lp->rx_bd_v[i].skb); ... if (lp->rx_bd_v[i].cntrl) { phys = desc_get_phys_addr(lp, &lp->rx_bd_v[i]); dma_unmap_single(lp->dev, phys, lp->max_frm_size, DMA_FROM_DEVICE); }With swiotlb bouncing, can the unmap copy up to
max_frm_sizebytes back into the skb data that was just freed? On non-coherent platforms the unmap also invalidates cache lines of memory that may already belong to a new owner.Bouncing looks realistic here. Probe uses a 32-bit DMA mask unless 64-bit DMA is detected, so a 32-bit AXI DMA on a host with RAM above 4 GiB would bounce, as could the PCIe card from the commit message.
The new TX helper unmaps before it frees. Would swapping the order in this loop make the two walks consistent?
[Severity: Medium]
This is also pre-existing. The same RX walk stops at the first NULL skb:/* A NULL skb means this descriptor has not been initialised * at all. */ if (!lp->rx_bd_v[i].skb) break;
axienet_rx_poll()setscur_p->skb= NULL and exits its loop ifnapi_alloc_skb()ordma_map_single()fails. That leaves a NULL slot atrx_bd_ciin the middle of a populated ring.Would a close after such a refill failure leak every RX skb and mapping after that slot? That would also contradict the commit message, which says the RX walk frees "every receive buffer".
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_bd_release(struct net_device *ndev) · line 272
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1
-0@@ -221,6 +268,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }[Severity: Medium]
This isn't a bug introduced by this patch, but the siblingll_temacdriver seems to have the same TX leak.temac_dma_bd_release()indrivers/net/ethernet/xilinx/ll_temac_main.cfrees only the TX ring:if (lp->tx_bd_v) dma_free_coherent(ndev->dev.parent, sizeof(*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p);
temac_start_xmit()attaches the skb to the last TX BD viaptr_to_txbd(), and onlytemac_start_xmit_done()reclaims it.Does temac_stop()->temac_dma_bd_release() leak in-flight TX skbs and their
DMA_TO_DEVICEmappings? It may be worth a separate fix.[ ... ]
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-1@@ -2749,29 +2797,7 @@ static void axienet_dma_err_handler(struct work_struct *work)axienet_dma_stop (lp);netdev_reset_queue (ndev); -for (i =0 ; i < lp->tx_bd_num; i++) {[ ... ]
drivers/net/ethernet/xilinx/xilinx_axienet_main.c
Quoted 2 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1
-1- } +axienet_free_tx_bufs (lp);[Severity: High]
This is a pre-existing issue, since the loop was moved rather than newly written. What stopsaxienet_start_xmit()from running at the same time as this code?
axienet_dma_err_handler()runs from a workqueue. It disables NAPI, the MAC TX/RX enables and the DMA engine, but it never callsnetif_tx_disable(),netif_tx_lock()ornetif_stop_queue(). The TX queue stays awake for the up to ~250 ms spent inaxienet_dma_stop().Meanwhile, on another CPU:
axienet_start_xmit()cur_p->skb = skb; ... WRITE_ONCE(lp->tx_bd_tail, new_tail_ptr); netdev_sent_queue(ndev, skb->len);If
axienet_free_tx_bufs()frees that skb between the store and the read ofskb->len, canstart_xmitread a freed skb?The two paths also race on
tx_bd_tail, which the handler later resets to 0, on BQL state (netdev_reset_queue()againstnetdev_sent_queue()), and on descriptor contents. The restarted DMA could therefore fetch zeroed descriptors.
dev_kfree_skb_irq()deferred the free toNET_TXsoftirq. Withdev_kfree_skb_any(), this process-context worker now frees the skb immediately, so the freed memory can be reused sooner.The helper's kernel-doc lists only "The DMA engine must be stopped" as a precondition. Should it also require the TX queue to be quiesced?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261007034620.1360542-1-maimon.sagi%40gmail.com
Quoted 40 lines · Sagi Maimon
axienet_dma_bd_release()walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring withdma_free_coherent()alone. Any descriptor thataxienet_free_tx_chain()had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
axienet_stop()disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up tolp->tx_bd_numskbs and mappings each time.
axienet_dma_err_handler()already walks the TX ring this way before it restarts the DMA engine: it unmaps every descriptor whose cntrl is still set -axienet_free_tx_chain()clears it on reclaim - frees any skb still attached, and clears the descriptor. Move that loop into a helper,axienet_free_tx_bufs(), and call it fromaxienet_dma_bd_release()too. This relies onaxienet_stop()having stopped the DMA engine first, as the RX walk in the same function already does. The helper frees the skbs withdev_kfree_skb_any(), as drops: in the error handler, which runs from a workqueue, that frees them directly rather than deferring them to softirq asdev_kfree_skb_irq()did.The walk must not run on a ring that is not there.
axienet_open()does not check the result of the reset that runsaxienet_dma_bd_init(), so when that reset failstx_bd_vis either still NULL or, after an earlier close, points at the ring that close freed. Cleartx_bd_vandrx_bd_vonce their rings are freed, and skip the walk whentx_bd_vis NULL. That also ends the seconddma_free_coherent()of a stale ring which the same path already did. On theaxienet_dma_bd_init()error path the TX ring has just been allocated zeroed, so the walk does nothing.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, and after each of ten down/up cycles and five module reloads, all made with traffic running and each running
axienet_dma_bd_release(), traffic resumes and nothing is logged. The leak itself was not measured, and neither the failed-reset paths noraxienet_dma_err_handler()were exercised.
Quoted 4 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")Reviewed-by Joe Damato <[email protected]>Assisted-by LLM sparseSigned-off-by Sagi Maimon <[email protected]>
In future please post new patch revisions as new email threads, not as a reply to an earlier revision.
Thanks!
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Wed, 7 Oct 2026 06:46:20 +0300 you wrote:
axienet_dma_bd_release()walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring withdma_free_coherent()alone. Any descriptor thataxienet_free_tx_chain()had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
Quoted 6 lines
axienet_stop()disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up tolp->tx_bd_numskbs and mappings each time.[...]
Here is the summary with links:
- [net,v4] net: axienet: free outstanding TX buffers in axienet_dma_bd_release()
https://git.kernel.org/netdev/net-next/c/0c20cb4cfb40
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html