Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: linusw@kernel.org
Cc: Jakub Kicinski <kuba@kernel.org>,
	ulli.kroll@googlemail.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, pabeni@redhat.com, mirq-linux@rere.qmqm.pl,
	mhun512@gmail.com, edumazet@kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v6 09/15] net: ethernet: cortina: Recycle claimed free queue pages
Date: Mon,  9 Nov 2026 17:16:22 -0800	[thread overview]
Message-ID: <20261110011622.1733542-1-kuba@kernel.org> (raw)
In-Reply-To: <20261103-gemini-ethernet-fixes-3-v6-9-c4b5ff8a65d8@kernel.org>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -964,9 +986,69 @@ static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
>  		xa_erase(&geth->freeq_mappings,
>  			 geth_freeq_mapping_index(geth, mapping));
>  	}
> -	gpage->page = NULL;
> -	gpage->mapping = 0;
> -	__clear_bit(slot, geth->freeq_page_bitmap);
> +	return ret;
> +}
> +
> +static int geth_freeq_add_page(struct gemini_ethernet *geth,
> +			       unsigned int wptr,
> +			       struct page *page, dma_addr_t page_mapping)
> +{
> +	struct gmac_queue_page *gpage;
> +	int ret;
> +	int slot;
> +
> +	lockdep_assert_held(&geth->freeq_lock);
> +
> +	slot = geth_freeq_alloc_slot(geth);
> +	if (slot < 0)
> +		return slot;
> +
> +	gpage = &geth->freeq_pages[slot];
> +	gpage->page = page;
> +	gpage->mapping = page_mapping;
> +	ret = geth_freeq_post_page(geth, wptr, gpage, false);
> +	if (ret) {
> +		gpage->page = NULL;
> +		gpage->mapping = 0;
> +		__clear_bit(slot, geth->freeq_page_bitmap);
> +	}
> +
> +	return ret;
> +}
> +
> +static int geth_freeq_recycle_page(struct gemini_ethernet *geth,
> +				   unsigned int wptr)
> +{
> +	struct gmac_queue_page *gpage;
> +	struct page *page;
> +	int ret;
> +	int slot;
> +
> +	lockdep_assert_held(&geth->freeq_lock);
> +
> +	slot = geth_freeq_recycle_slot(geth);
> +	if (slot < 0)
> +		return slot;
> +
> +	gpage = &geth->freeq_pages[slot];
> +	if (page_ref_count(gpage->page) > 1) {
> +		page = gpage->page;
> +		dma_unmap_single_attrs(geth->dev, gpage->mapping, PAGE_SIZE,
> +				       DMA_FROM_DEVICE,
> +				       DMA_ATTR_SKIP_CPU_SYNC);
> +		gpage->page = NULL;
> +		gpage->mapping = 0;
> +		__clear_bit(slot, geth->freeq_page_bitmap);
> +		put_page(page);
> +		return -EAGAIN;
> +	}
> +
> +	ret = geth_freeq_post_page(geth, wptr, gpage, true);
> +	if (ret) {
> +		__set_bit(slot, geth->freeq_recycle_bitmap);
> +		geth->freeq_recycle_pending++;
> +	}
> +
>  	return ret;
>  }
>  

[Severity: Medium]
geth_freeq_recycle_page() only checks page_ref_count() before handing
the page back to geth_freeq_post_page(). The pages come from
alloc_page(GFP_ATOMIC) in geth_freeq_map_page(). Under memory pressure
that allocation can return a page from the PFMEMALLOC reserves.

When gmac_rx() attaches a fragment with skb_fill_page_desc(), the skb
inherits skb->pfmemalloc. The core then drops it for any socket that
does not have SOCK_MEMALLOC set. That drop happens inside the NAPI
poll, so by the time geth_fill_freeq() runs the refcount is back to
one and the page is reposted to the free queue.

Nothing ever returns that page to the allocator. The reserve page stays
pinned, and every frame that lands in it is dropped, long after the
pressure has gone away.

Before this patch the base reference was dropped on the last claim in
geth_freeq_claim(), so a reserve page was freed once the stack let go
of it. The problem is new with recycling.

Other drivers that recycle RX pages gate reuse on
dev_page_is_reusable(), which also rejects pages from a remote NUMA
node. Could the discard branch here also be taken when
dev_page_is_reusable(gpage->page) is false? Pfmemalloc pages would then
go through the dma_unmap_single_attrs() and put_page() path instead of
being reposted.

  reply	other threads:[~2026-11-10  1:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 17:51 [PATCH net-next v6 00/15] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 01/15] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
2026-11-10  1:16   ` Jakub Kicinski
2026-11-10 10:08     ` Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 02/15] net: ethernet: cortina: Keep PHY-less port bound for shared IRQ Linus Walleij
2026-11-10  1:16   ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 03/15] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 04/15] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
2026-11-10  1:16   ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 05/15] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 06/15] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
2026-11-10  1:16   ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 07/15] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
2026-11-10  1:16   ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 08/15] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 09/15] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
2026-11-10  1:16   ` Jakub Kicinski [this message]
2026-11-03 17:51 ` [PATCH net-next v6 10/15] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 11/15] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 12/15] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 13/15] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
2026-11-03 17:51 ` [PATCH net-next v6 14/15] net: ethernet: cortina: Scope RX statistics updates Linus Walleij
2026-11-10  1:16   ` Jakub Kicinski
2026-11-03 17:51 ` [PATCH net-next v6 15/15] net: ethernet: cortina: Drain RX coalescing timer on stop Linus Walleij

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=20261110011622.1733542-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=linusw@kernel.org \
    --cc=mhun512@gmail.com \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ulli.kroll@googlemail.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