Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: linusw@kernel.org
Cc: ulli.kroll@googlemail.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	mirq-linux@rere.qmqm.pl, mhun512@gmail.com, edumazet@kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild
Date: Tue, 24 Nov 2026 18:29:51 +0000	[thread overview]
Message-ID: <179554499156.3135.8516338457129003935@kernel.org> (raw)
In-Reply-To: <20261120-gemini-ethernet-fixes-3-v9-4-298671d799d5@kernel.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit has no Fixes: tag, but it fixes a memory-safety bug.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch's
  own premise exposes it.

--

net: ethernet: cortina: Normalize free queue pointers on rebuild

The hardware keeps the free queue read pointer when the queue is rebuilt
at a smaller order. This patch masks the page indices in
geth_fill_freeq() to the active order and sets the software write
pointer from the retained read pointer in geth_setup_freeq(). It also
stops geth_resize_freeq() from shrinking the ring below the size needed
to hold the retained pointer.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 5e9dd2aea4077..66984c78a7cd4 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -920,6 +920,7 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth, bool refill)
>  
>  	rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
>  	pn = (refill ? rw.bits.wptr : rw.bits.rptr) >> fpp_order;
> +	pn &= m_pn;

[Severity: Low]
Should this patch have a Fixes: tag?

Before this change, geth_fill_freeq() used the unmasked pn to index
geth->freeq_pages[pn], and then dereferenced gpage->page through
page_ref_count() and page_ref_add(). If the free queue was rebuilt at a
smaller order, for example via ethtool -G (gmac_set_ringparam() ->
geth_resize_freeq()), pn could be >= num_freeq_pages.

The unmasked code seems to date back to:

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

The commit message also says that a following patch, which decouples
the RX buffer budget from descriptor geometry, is needed to avoid an
allocation approaching 64 MiB. Would it help to add a note about that
dependency for stable backporters?

>  	epn = (rw.bits.rptr >> fpp_order) - 1;
>  	epn &= m_pn;
>  

[ ... ]

> @@ -991,6 +993,10 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
>  		if (!geth_freeq_alloc_map_page(geth, pn))
>  			goto err_freeq_alloc;
>  
> +	/* Match the software pointer to the retained hardware pointer. */
> +	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
> +	SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, rptr & (len - 1));
> +

[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but the
premise here seems to apply to the per-port SW TX queue too. gemini.h
describes the SW TX queues as the same TOE DMA queue type as the SW
free queue.

gmac_setup_txqs() copies the retained hardware read pointer into the
write pointer and cptr without masking it to the new txq_order:

drivers/net/ethernet/cortina/gemini.c:gmac_setup_txqs() {
    ...
		r = readw(rwptr_reg);
		rwptr_reg += 2;
		writew(r, rwptr_reg);
		rwptr_reg += 2;
		txq->cptr = r;
    ...
}

gmac_set_ringparam() lets the user shrink txq_order while the interface
is down. After the next gmac_open(), the ring and skb_tab hold only
1 << txq_order entries, but r can still be any value from the old,
larger ring.

On the first transmit, gmac_map_tx_bufs() uses the raw w before its
first mask:

drivers/net/ethernet/cortina/gemini.c:gmac_map_tx_bufs() {
    ...
		if (frag == last_frag) {
			word3 |= EOF_BIT;
			txq->skb[w] = skb;
		}
    ...
		txd = txq->ring + w;
		txd->word0.bits32 = buflen;
    ...
		w++;
		w &= m;
    ...
}

Can this write past the kzalloc'd skb_tab and past the coherent
descriptor ring?

gmac_clean_txq() has the same pattern with the unmasked cptr:

	while (c != r) {
		txd = txq->ring + c;
		...
		if (word3 & EOF_BIT)
			dev_kfree_skb(txq->skb[c]);

		c++;
		c &= m;

One possible trigger is ethtool -G <if> tx 64 while the port is down,
after the TX rptr has moved past 64 at the default order of 8. Bringing
the interface up and sending a packet would then hit this path.

The RX default queue may have a similar problem. gmac_setup_rxq() still
treats writel(0, port->rxq_rwptr) as a pointer reset. The testing
described in this commit shows that a 32-bit zero write does not clear
the hardware-owned half. gmac_rx() also compares the masked software r
with the unmasked hardware w:

	r = rw.bits.rptr;
	w = rw.bits.wptr;

	while (budget && consumed < desc_limit && w != r) {

If the retained w is >= 1 << rxq_order, could r never reach it? Could
the hardware also DMA RX descriptors past the new rxq_ring?

Were the TX and RX default queues considered along with the free queue?

>  	filled = geth_fill_freeq(geth, false);
>  	if (!filled)
>  		goto err_freeq_alloc;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

  reply	other threads:[~2026-11-24 18:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 02/14] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 03/14] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko [this message]
2026-11-20 17:29 ` [PATCH net-next v9 05/14] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 06/14] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 07/14] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 08/14] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 09/14] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 10/14] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 12/14] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 13/14] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 14/14] net: ethernet: cortina: Scale Gemini RX queues to system memory 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=179554499156.3135.8516338457129003935@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@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