net: lan966x: free the RX pages when the TX allocation fails
Subsystems (3)
PATCH 1/1 net: lan966x: free the RX pages when the TX allocation fails
lan966x_fdma_init() allocates the RX ring and fills its DCBs with pages from the RX page pool, then allocates the TX ring. If the TX allocation fails, the error path frees the RX ring and destroys the page pool, but does not return the pages to the pool first.
The pool then never finishes its shutdown, and page_pool_release_retry() keeps warning about the pages still in flight.
To let the pool shut down, return the RX pages before destroying it, as lan966x_fdma_deinit() does. lan966x_fdma_rx_alloc() does not check that every DCB got its pages, so skip the entries that are still empty.
--- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +6 -3
@@ -54,9 +54,11 @@ static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx)int i, j;for (i =0 ; i < fdma->n_dcbs; ++i) { -for (j =0 ; j < fdma->n_dbs; ++j) -page_pool_put_full_page (rx->page_pool, - rx->page[i][j], false); +for (j =0 ; j < fdma->n_dbs; ++j) { +if (rx->page[i][j]) +page_pool_put_full_page (rx->page_pool, + rx->page[i][j], false); + } } }
@@ -999,6 +1001,7 @@ int lan966x_fdma_init(struct lan966x *lan966x) err =lan966x_fdma_tx_alloc (&lan966x->tx);if (err) { +lan966x_fdma_rx_free_pages (&lan966x->rx);fdma_free_coherent (lan966x->dma_dev, &lan966x->rx.fdma);page_pool_destroy (lan966x->rx.page_pool);return err;
---
base-commit: 994089a3fa3882f27f4bed9fc5815ee7df502e88
change-id: 20261116-lan966x-rx-pages-tx-alloc-fail-2b8e412f15f2
Best regards,
Signature · 1 line
Daniel Machon <[email protected]>
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 50 lines · Daniel Machon
lan966x_fdma_init()allocates the RX ring and fills its DCBs with pages from the RX page pool, then allocates the TX ring. If the TX allocation fails, the error path frees the RX ring and destroys the page pool, but does not return the pages to the pool first.The pool then never finishes its shutdown, and
page_pool_release_retry()keeps warning about the pages still in flight.To let the pool shut down, return the RX pages before destroying it, as
lan966x_fdma_deinit()does.lan966x_fdma_rx_alloc()does not check that every DCB got its pages, so skip the entries that are still empty.Signed-off-by Daniel Machon <[email protected]>--- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +6
-4@@ -54,9 +54,11 @@ static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx)int i, j;for (i =0 ; i < fdma->n_dcbs; ++i) { -for (j =0 ; j < fdma->n_dbs; ++j) -page_pool_put_full_page (rx->page_pool, - rx->page[i][j], false); +for (j =0 ; j < fdma->n_dbs; ++j) { +if (rx->page[i][j]) +page_pool_put_full_page (rx->page_pool, + rx->page[i][j], false); + } } }@@ -999,6 +1001,7 @@ int lan966x_fdma_init(struct lan966x *lan966x) err =lan966x_fdma_tx_alloc (&lan966x->tx);if (err) { +lan966x_fdma_rx_free_pages (&lan966x->rx);fdma_free_coherent (lan966x->dma_dev, &lan966x->rx.fdma);page_pool_destroy (lan966x->rx.page_pool);return err; ---base-commit:
994089a3fa3882f27f4bed9fc5815ee7df502e88
change-id: 20261116-lan966x-rx-pages-tx-alloc-fail-2b8e412f15f2
Quoted 1 line
Best regards,
Regards
Nicolai
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 (2) · Medium: 1 · Low: 1
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] lan966x_fdma_rx_alloc() ignores the return value of fdma_dcbs_init() (line 137).
- [Low] Missing Fixes:/Cc: stable tags.
Pre-existing issues:
- [High] NULL pointer dereference in the open-coded page-return loop of lan966x_fdma_reload().
- [High] The new if (rx->page[i][j]) check in lan966x_fdma_rx_free_pages() assumes a slot without a page is NULL.
--
net: lan966x: free the RX pages when the TX allocation fails
When lan966x_fdma_tx_alloc() fails in lan966x_fdma_init(), this patch returns the RX pages to the page pool before the pool is destroyed, so the pool can finish shutting down. It also makes lan966x_fdma_rx_free_pages() skip empty entries, because lan966x_fdma_rx_alloc() does not check that every DCB got its pages.
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) · line 58
Quoted 13 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +2
-3@@ -54,9 +54,11 @@ static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx)int i, j;for (i =0 ; i < fdma->n_dcbs; ++i) { -for (j =0 ; j < fdma->n_dbs; ++j) -page_pool_put_full_page (rx->page_pool, - rx->page[i][j], false); +for (j =0 ; j < fdma->n_dbs; ++j) { +if (rx->page[i][j])
[Severity: Medium]
The commit message says "lan966x_fdma_rx_alloc() does not check that every DCB got its pages, so skip the entries that are still empty".
Instead of treating a partly filled ring as normal here, would it be better to check the return value of fdma_dcbs_init() in lan966x_fdma_rx_alloc() and unwind?
lan966x_fdma_rx_alloc() {
...
fdma_dcbs_init(fdma, FDMA_DCB_INFO_DATAL(fdma->db_size),
FDMA_DCB_STATUS_INTR);
lan966x_fdma_llp_configure(lan966x, fdma->dma, fdma->channel_id);
return 0;
}Say page_pool_dev_alloc_pages() fails in lan966x_fdma_rx_dataptr_cb() at DCB k. Then __fdma_dcb_add() returns before it links prev->nextptr. DCB k-1 keeps FDMA_DCB_INVALID_DATA as its next pointer, and DCB k and the ones after it are never linked into the chain. Even so, lan966x_fdma_rx_alloc() still returns 0.
lan966x_fdma_init() and lan966x_fdma_reload() then call lan966x_fdma_rx_start() on the short chain. When NAPI has consumed DCBs 0..k-1, fdma_dcb_advance() moves dcb_index to k. From then on, fdma_has_frames() in lan966x_fdma_napi_poll() polls a DCB that the hardware never completes.
Can CPU RX stall permanently this way?
The PCI variant, lan966x_fdma_pci_rx_alloc(), already checks this call:
err = fdma_dcbs_init(fdma,
FDMA_DCB_INFO_DATAL(fdma->db_size - XDP_PACKET_HEADROOM),
FDMA_DCB_STATUS_INTR);
if (err) {
fdma_free_coherent_and_unmap(lan966x->dma_dev, fdma);
return err;
}lan969x_fdma_rx_alloc() in sparx5 has the same unchecked call, and lan969x_fdma_free_pages() has no NULL guard.
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) · line 60
Quoted 2 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +2
-0+page_pool_put_full_page (rx->page_pool, + rx->page[i][j], false);
[Severity: High]
This is a pre-existing issue, but does the NULL check catch every slot that no longer owns a page?
lan966x_fdma_rx_dataptr_cb() is the only writer of rx->page[dcb][db]. It does not clear the slot on -ENOMEM. Nothing else sets a slot back to NULL after its page has been handed off. That means a slot is only guaranteed to be NULL on the first init, when struct lan966x has just been zeroed.
In lan966x_fdma_napi_poll(), lan966x_fdma_rx_get_frame() hands the page to an skb, or lan966x_fdma_rx_free_page() recycles it, but the slot keeps the pointer either way. The refill then ignores failure:
fdma_dcb_add(fdma, old_dcb, FDMA_DCB_INFO_DATAL(fdma->db_size), FDMA_DCB_STATUS_INTR);
In lan966x_fdma_reload(), lan966x_fdma_rx_alloc() refills rx->page without clearing it first. After a partial fill, the slots that were not refilled still point at pages from the old pool. Those pages are then returned to the old pool and freed by page_pool_destroy(page_pool).
Later, lan966x_fdma_deinit()->lan966x_fdma_rx_free_pages() or the next reload puts these stale pointers into the current rx->page_pool.
Could that put a page twice while an skb still owns it, or put an already freed page into a different pool?
Would it help to clear the slot whenever its page is given away, and also check the return value of fdma_dcbs_init()?
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) · line 63
Quoted 3 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +1
-0+ } } }
[Severity: High]
This isn't a bug introduced by this patch, but if NULL slots are expected here, what about the open-coded copy of this loop in lan966x_fdma_reload()?
lan966x_fdma_reload() {
...
for (i = 0; i < fdma_rx_old.n_dcbs; ++i)
for (j = 0; j < fdma_rx_old.n_dbs; ++j)
page_pool_put_full_page(page_pool,
old_pages[i][j], false);
...
}If the first fdma_dcbs_init() at probe stops partway, the rx->page[] entries from DCB k onward stay NULL, and lan966x_fdma_rx_alloc() still returns 0.
A later MTU change through lan966x_fdma_change_mtu(), or an XDP setup through lan966x_fdma_reload_page_pool(), reaches lan966x_fdma_reload(). That function kmemdup()s those NULL entries into old_pages.
Once the new lan966x_fdma_rx_alloc() succeeds, this loop passes NULL to page_pool_put_full_page(). That leads to page_pool_unref_netmem(), which reads the pp_ref_count of a NULL netmem. Can this oops?
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c int lan966x_fdma_init(struct lan966x *lan966x) · line 1007
Quoted 8 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +1
-0@@ -999,6 +1001,7 @@ int lan966x_fdma_init(struct lan966x *lan966x) err =lan966x_fdma_tx_alloc (&lan966x->tx);if (err) { +lan966x_fdma_rx_free_pages (&lan966x->rx);fdma_free_coherent (lan966x->dma_dev, &lan966x->rx.fdma);page_pool_destroy (lan966x->rx.page_pool);return err;
[Severity: Low]
Should this patch have a Fixes: tag and go to net with Cc: stable?
The page_pool_destroy() call on this error path was added by commit 076344a6ad9d ("net: lan966x: fix page pool leak in error paths"), which is tagged Cc: stable. Since that commit, the pool is destroyed while the RX pages are still in flight. That causes the page_pool_release_retry() warning described in this commit message.
Something like:
Without the tag, stable trees that picked up 076344a6ad9d would keep the warning.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-lan966x-rx-pages-tx-alloc-fail-v1-1-13f310d66650%40microchip.com
Quoted 87 lines
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 (2) · Medium: 1 · Low: 1
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]
lan966x_fdma_rx_alloc()ignores the return value offdma_dcbs_init()(line 137).
- [Low] Missing Fixes:/Cc: stable tags.Pre-existing issues:
- [High] NULL pointer dereference in the open-coded page-return loop oflan966x_fdma_reload().
- [High] The newif (rx->page[i][j])check inlan966x_fdma_rx_free_pages()assumes a slot without a page is NULL.--
net: lan966x: free the RX pages when the TX allocation fails
When
lan966x_fdma_tx_alloc()fails inlan966x_fdma_init(), this patch returns the RX pages to the page pool before the pool is destroyed, so the pool can finish shutting down. It also makeslan966x_fdma_rx_free_pages()skip empty entries, becauselan966x_fdma_rx_alloc()does not check that every DCB got its pages.drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) · line 58
Quoted 13 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +2
-3@@ -54,9 +54,11 @@ static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx)int i, j;for (i =0 ; i < fdma->n_dcbs; ++i) { -for (j =0 ; j < fdma->n_dbs; ++j) -page_pool_put_full_page (rx->page_pool, - rx->page[i][j], false); +for (j =0 ; j < fdma->n_dbs; ++j) { +if (rx->page[i][j])[Severity: Medium]
The commit message says "lan966x_fdma_rx_alloc()does not check that every DCB got its pages, so skip the entries that are still empty".Instead of treating a partly filled ring as normal here, would it be better to check the return value of
fdma_dcbs_init()inlan966x_fdma_rx_alloc()and unwind?lan966x_fdma_rx_alloc() { ... fdma_dcbs_init(fdma, FDMA_DCB_INFO_DATAL(fdma->db_size), FDMA_DCB_STATUS_INTR); lan966x_fdma_llp_configure(lan966x, fdma->dma, fdma->channel_id); return 0; }Say
page_pool_dev_alloc_pages()fails inlan966x_fdma_rx_dataptr_cb()at DCB k. Then__fdma_dcb_add()returns before it linksprev->nextptr. DCB k-1 keepsFDMA_DCB_INVALID_DATAas its next pointer, and DCB k and the ones after it are never linked into the chain. Even so,lan966x_fdma_rx_alloc()still returns 0.
lan966x_fdma_init()andlan966x_fdma_reload()then calllan966x_fdma_rx_start()on the short chain. When NAPI has consumed DCBs 0..k-1,fdma_dcb_advance()movesdcb_indexto k. From then on,fdma_has_frames()inlan966x_fdma_napi_poll()polls a DCB that the hardware never completes.Can CPU RX stall permanently this way?
The PCI variant,
lan966x_fdma_pci_rx_alloc(), already checks this call:err = fdma_dcbs_init(fdma, FDMA_DCB_INFO_DATAL(fdma->db_size - XDP_PACKET_HEADROOM), FDMA_DCB_STATUS_INTR); if (err) { fdma_free_coherent_and_unmap(lan966x->dma_dev, fdma); return err; }
Quoted 5 lines
lan969x_fdma_rx_alloc()in sparx5 has the same unchecked call, andlan969x_fdma_free_pages()has no NULL guard.drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) · line 60
Quoted 2 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +2
-0+page_pool_put_full_page (rx->page_pool, + rx->page[i][j], false);
The concern raised is valid, but for what this patch fixes, out-of-scope.
This patch is scoped to the TX allocation failure path, which before this patch, didn't return the RX pages.
The reason that the ring can be partly filled at all, is because the return value of fdma_dcbs_init() is ignored (not just in rx_alloc, as the bot points out, but also in other places), but that needs its own fix in a separate patch.
Quoted 80 lines
[Severity: High]
This is a pre-existing issue, but does the NULL check catch every slot that no longer owns a page?
lan966x_fdma_rx_dataptr_cb()is the only writer of rx->page[dcb][db]. It does not clear the slot on-ENOMEM. Nothing else sets a slot back to NULL after its page has been handed off. That means a slot is only guaranteed to be NULL on the first init, when struct lan966x has just been zeroed.In
lan966x_fdma_napi_poll(),lan966x_fdma_rx_get_frame()hands the page to an skb, orlan966x_fdma_rx_free_page()recycles it, but the slot keeps the pointer either way. The refill then ignores failure:fdma_dcb_add(fdma, old_dcb, FDMA_DCB_INFO_DATAL(fdma->db_size), FDMA_DCB_STATUS_INTR);In
lan966x_fdma_reload(),lan966x_fdma_rx_alloc()refillsrx->pagewithout clearing it first. After a partial fill, the slots that were not refilled still point at pages from the old pool. Those pages are then returned to the old pool and freed bypage_pool_destroy(page_pool).Later, lan966x_fdma_deinit()->lan966x_fdma_rx_free_pages() or the next reload puts these stale pointers into the current
rx->page_pool.Could that put a page twice while an skb still owns it, or put an already freed page into a different pool?
Would it help to clear the slot whenever its page is given away, and also check the return value of
fdma_dcbs_init()?drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c static void lan966x_fdma_rx_free_pages(struct lan966x_rx *rx) · line 63
Quoted 3 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +1
-0+ } } }[Severity: High]
This isn't a bug introduced by this patch, but if NULL slots are expected here, what about the open-coded copy of this loop inlan966x_fdma_reload()?lan966x_fdma_reload() { ... for (i = 0; i < fdma_rx_old.n_dcbs; ++i) for (j = 0; j < fdma_rx_old.n_dbs; ++j) page_pool_put_full_page(page_pool, old_pages[i][j], false); ... }If the first
fdma_dcbs_init()at probe stops partway, the rx->page[] entries from DCB k onward stay NULL, andlan966x_fdma_rx_alloc()still returns 0.A later MTU change through
lan966x_fdma_change_mtu(), or an XDP setup throughlan966x_fdma_reload_page_pool(), reacheslan966x_fdma_reload(). That function kmemdup()s those NULL entries intoold_pages.Once the new
lan966x_fdma_rx_alloc()succeeds, this loop passes NULL topage_pool_put_full_page(). That leads topage_pool_unref_netmem(), which reads thepp_ref_countof a NULL netmem. Can this oops?drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c int lan966x_fdma_init(struct lan966x *lan966x) · line 1007
Quoted 8 lines
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +1
-0@@ -999,6 +1001,7 @@ int lan966x_fdma_init(struct lan966x *lan966x) err =lan966x_fdma_tx_alloc (&lan966x->tx);if (err) { +lan966x_fdma_rx_free_pages (&lan966x->rx);fdma_free_coherent (lan966x->dma_dev, &lan966x->rx.fdma);page_pool_destroy (lan966x->rx.page_pool);return err;[Severity: Low]
Should this patch have a Fixes: tag and go to net with Cc: stable?The
page_pool_destroy()call on this error path was added by commit076344a6ad9d("net: lan966x: fix page pool leak in error paths"), which is tagged Cc: stable. Since that commit, the pool is destroyed while the RX pages are still in flight. That causes thepage_pool_release_retry()warning described in this commit message.
Quoted 6 lines
Something like:
Fixes 076344a6ad9d ("net: lan966x: fix page pool leak in error paths")Without the tag, stable trees that picked up
076344a6ad9dwould keep the warning.
I routed this to net-next without a fixes tag, because its not a regression, and its an init error path leak.
Quoted 3 lines
Signature · 2 lines
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-lan966x-rx-pages-tx-alloc-fail-v1-1-13f310d66650%40microchip.com
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 9 lines · On Tue, 17 Nov 2026 13:49:50 +0100 you wrote:
lan966x_fdma_init()allocates the RX ring and fills its DCBs with pages from the RX page pool, then allocates the TX ring. If the TX allocation fails, the error path frees the RX ring and destroys the page pool, but does not return the pages to the pool first.The pool then never finishes its shutdown, and
page_pool_release_retry()keeps warning about the pages still in flight.[...]
Here is the summary with links:
- [net-next] net: lan966x: free the RX pages when the TX allocation fails
https://git.kernel.org/netdev/net-next/c/ac9dfaeb9cd9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html