Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: daniel.machon@microchip.com
Cc: horatiu.vultur@microchip.com, UNGLinuxDriver@microchip.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: lan966x: free the RX pages when the TX allocation fails
Date: Wed, 18 Nov 2026 13:08:14 +0000	[thread overview]
Message-ID: <179500729408.3136.14303184286284983260@kernel.org> (raw)
In-Reply-To: <20261117-lan966x-rx-pages-tx-alloc-fail-v1-1-13f310d66650@microchip.com>

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.

> diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> index 1fbe910c5ec38..586ee648c7741 100644
> --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> @@ -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.

> +				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()?

> +		}
>  	}
>  }

[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?

> @@ -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:

Fixes: 076344a6ad9d ("net: lan966x: fix page pool leak in error paths")

Without the tag, stable trees that picked up 076344a6ad9d would keep
the warning.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-lan966x-rx-pages-tx-alloc-fail-v1-1-13f310d66650%40microchip.com

      parent reply	other threads:[~2026-11-18 13:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:49 [PATCH net-next] net: lan966x: free the RX pages when the TX allocation fails Daniel Machon
2026-11-17 12:53 ` netdev-bot+sinfo
2026-11-17 13:18 ` Nicolai Buchwitz
2026-11-18 13:08 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179500729408.3136.14303184286284983260@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=daniel.machon@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horatiu.vultur@microchip.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox