๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22017

Re: [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild

#22017
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 18:29
151 lines
12857 bytes
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
Technical Details
Message-ID: <179554499156.3135.8516338457129003935@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370673-linux-kernel-netdev=dewy.ru
References: <20261120-gemini-ethernet-fixes-3-v9-4-298671d799d5@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370673-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179554499156.3135.8516338457129003935@kernel.org>
References: <20261120-gemini-ethernet-fixes-3-v9-4-298671d799d5@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="9384"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:M+4Dc453y8wCRqogwbfZyC6UpSQ= sha256:BoeqNy3GEjFW5IYg4B662vOkKnhjbc7MIzEU2tnhdLM=
	sha1:29GcrJnbgp4Aw12KMSHwwPrmHOM= sha256:61e/8ENvVqJcoVXYBmZLdvkQMERZ8FqwLxFUJ8ZDaK4=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 468D0125E2D; Tue, 24 Nov 2026 21:30:14 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id chU3EQc1plj8;
	Tue, 24 Nov 2026 21:30:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370673-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 30E1B125E2E; Tue, 24 Nov 2026 21:30:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id DC81037305; Tue, 24 Nov 2026 18:29:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795544993;
	b=dlUVyD6fuNctugukIoGlYMNbVWUcxiu3G6fSo81x3AUlVJe6m4g+NPAHwiDEiMlOto5b
	 /suXq0p2mmvrXyhlKa/UicFTyzxkomoScipE9CMsHddrX921qeoNCeEcJ8+tdzBfcjP1v
	 C2GNYT92jGQbeHAkYWGv8O5j8So2uI+ZAZnu8MpyDNEqPRIf6w4kEIIEhVYNCHwVvmWvo
	 PA4a9OzmpvixQPMWtQj4sgdnUvDi8WnTJKrbEBc1Ab5ScqSFpKjPK0K4oWLrRrv3g67GZ
	 tvmmjskSKJdGNnI2wpAx8XQLCWU4Py6K/FZ8z6dskcMl3vArDwOs/zKTRGdcwwghhvA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795544993;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=CpDRI2KX2DLDuf63UR7B6P74f5SCQjbk+q32avF+F2A=;
	b=Nl9IcoFJKAkuNuUQrKPmArRBq9WgvoV3PbRRE7HIIgOMg/WIzvdZmv5hqiyx/UVvDMkc
	 eXkQ2Qx0L1CgWIbdfVzZTITRGZA7CjnQ3DsT2JiFJIXx15ufZJDZ6PUcJRO/kxOajUS9f
	 SqWnz3qAdu2W/CBLMp/Lmr4WlUjCLdVtGWKpCeQwbOz97ALIMtVLZlGqsdJczpYFTauz9
	 XoCdU052EVSgpvtC6nPKQICkTWXfbWzYyThprsFtrqg+q1E/qHPpTZ11J2vrnXqaYlsYD
	 RC/a+I/lYv+LuianJ45NhpAFW/+NkGVecvmZz8+M747QMNn32IC6GHU4xn1UMEkpBuQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lr5kZp05;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B28AF606A335;
	Tue, 24 Nov 2026 18:29:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lr5kZp05
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795544992;
	b=Os+b/ho90td/BZtJS8Sl+ylT0ySdGH3jUHUVAjb2KvzR7lo0qpS+P5JtMbINmvtIbTOB
	 AYJ83HaAsFqAIyQhGeV2Afm1hD+wjzFX2wNMbW+TZ5rJnSoSjN+sXKuRD0TR7aLl8/Rwm
	 x8G+hra3iKsysT5m2RsB7q5B/iWeB7gAWmeGiXxAax6H3i79PlYI0jCgudhx+nqM4fqQ9
	 kILzbnW/EnpSzGySDJo+yRd3bmdEykmslh1phUDQR6QF03e5yO24L0iD5Hu0OYiX2Kw/q
	 jj9jybwFnpzH1cs2vRxOKppznM8ppUCsz+MREw4hpwN9nB2OMjCReAQ7w7u4onY679A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795544992;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=CpDRI2KX2DLDuf63UR7B6P74f5SCQjbk+q32avF+F2A=;
	b=zJ2ls61IfAlkTHrvs/3963EKqy9LTA3BpX9PMqe8tooWpeBdFyI2jd6S2sNypiENqE+A
	 pikQWYBPLICTXUtiYSDXnf+jb1KDB7KQOO68cV5tBAzaTgbnUniPY47B6KxIqp6PS6fHb
	 09XFDiMJHKtICdX0KpQcOFeRnnJdYNTicOzoDiz09OkRGXUjrKD4pmOfnKTa1RbEkKiC0
	 mjSj+h401PzxjbAN51GwOjeFjzCOR53crrgvL/AaHSbd4EmtERKVXjUX+GQxks31QCMM5
	 3l958fy1sweWvb6Uep4TI+VURWl2D2SqxTKwVyxQnQ+NjcyTtDef4/LXv6z7dRi6ntw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lr5kZp05;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2437606A332
	for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 18:29:52 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03DF51F000D8;
	Tue, 24 Nov 2026 18:29:51 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795544992;
	bh=CpDRI2KX2DLDuf63UR7B6P74f5SCQjbk+q32avF+F2A=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=lr5kZp05ZMlhF8f4bQmBJDPNtk4XjJA5iSyawvPu4vLKa1YanIsUJrX2x+KfSesxN
	 WuyKxZuyd6ZiQd0laYUCEH7d0bUSfr+xNh3QnYFMCmnKtrlaYhukSgmKKRbMWMGyhl
	 CUHcDQziqumXEamR9udB5jJDiCRcbby/LMyWo34ZIlxrNf53IpMgmAQ3F7IaBN93z+
	 K0keu4XvQ8X/Z9ztDS38+9JQJbTW2iZ+CVg1YLbRxTx+83w0toV8dqhi15lugoSCI7
	 2Yx+uBEsJpb3pAxSO1oJKjViAEoMIs3NpulD8gMS+M+Oy4Ds3pO52DlOKmo1sbXKcL
	 FqTMsEc0wfaIA==
X-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
X-In-Reply-To: <20261120-gemini-ethernet-fixes-3-v9-4-298671d799d5@kernel.org>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list