🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15206

[PATCH net-next v8 18/19] net: ethernet: cortina: Reject TX rings smaller than retained pointers

#15206
From: Linus Walleij
Date: Thu, 12 Nov 2026 13:30
101 lines
11297 bytes
The hardware-owned TX read pointers can retain their positions when the
queues are rebuilt. After shrinking the TX ring with ethtool -G while
the interface is down, gmac_setup_txqs() copies those pointers into the
write and clean pointers without checking the new ring size. A retained
pointer outside the smaller ring can then index past both the skb table
and the coherent descriptor allocation.

Reject a TX ring size that cannot contain every retained read pointer,
before applying any RX ring changes in the same ethtool request. Check
again before allocating and programming the TX rings on open, including
for pointer state inherited from firmware. DMA is stopped at both checks.
Do not just mask the software pointers, which would leave the hardware
read pointer outside the new ring.

Found during Sashiko review and confirmed with a pointer arithmetic
model: a retained pointer of 200 with 16 entries reports 15 free entries
and permits the first TX write at index 200. Checked all 16-bit pointer
values against queue orders 0 through 15 and cross-built the driver for
ARM.

Tested on the D-Link DIR-685 with intense transfers and ping storms.

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 24a66fc34738..899d96420b1b 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -602,6 +602,20 @@ static int gmac_init(struct net_device *netdev)
 	return 0;
 }
 
+static bool gmac_txq_size_valid(struct net_device *netdev, unsigned int entries)
+{
+	struct gemini_ethernet_port *port = netdev_priv(netdev);
+	unsigned int i;
+
+	/* DMA is stopped, so the hardware read pointers cannot advance. */
+	for (i = 0; i < netdev->num_tx_queues; i++)
+		if (GET_RPTR(port->dma_base + GMAC_SW_TX_QUEUE_PTR_REG(i)) >=
+		    entries)
+			return false;
+
+	return true;
+}
+
 static int gmac_setup_txqs(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
@@ -616,6 +630,12 @@ static int gmac_setup_txqs(struct net_device *netdev)
 	unsigned int r;
 	int i;
 
+	if (!gmac_txq_size_valid(netdev, entries)) {
+		netdev_err(netdev,
+			   "TX ring is too small for the retained read pointer\n");
+		return -EINVAL;
+	}
+
 	rwptr_reg = port->dma_base + GMAC_SW_TX_QUEUE0_PTR_REG;
 
 	skb_tab = kzalloc_objs(*skb_tab, len);
@@ -2623,11 +2643,21 @@ static int gmac_set_ringparam(struct net_device *netdev,
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	unsigned int old_rxq_order;
+	unsigned int txq_order = port->txq_order;
 	int err = 0;
 
 	if (netif_running(netdev))
 		return -EBUSY;
 
+	if (rp->tx_pending) {
+		txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
+		if (!gmac_txq_size_valid(netdev, BIT(txq_order))) {
+			NL_SET_ERR_MSG(extack,
+				       "TX ring is too small for the retained read pointer");
+			return -EINVAL;
+		}
+	}
+
 	if (rp->rx_pending) {
 		old_rxq_order = port->rxq_order;
 		port->rxq_order = min(15, ilog2(rp->rx_pending - 1) + 1);
@@ -2638,7 +2668,7 @@ static int gmac_set_ringparam(struct net_device *netdev,
 		}
 	}
 	if (rp->tx_pending) {
-		port->txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
+		port->txq_order = txq_order;
 		port->irq_every_tx_packets = 1 << (port->txq_order - 2);
 	}
 

-- 
2.56.0
Technical Details
Message-ID: <20261112-gemini-ethernet-fixes-3-v8-18-f55bd43e02d3@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361880-linux-kernel-netdev=dewy.ru
References: <20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361880-linux-kernel-netdev=dewy.ru
From: linusw@kernel.org (Linus Walleij)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v8 18/19] net: ethernet: cortina: Reject TX rings
 smaller than retained pointers
Date: Thu, 12 Nov 2026 14:30:33 +0100
Organization: Usenet Network
Message-ID: <20261112-gemini-ethernet-fixes-3-v8-18-f55bd43e02d3@kernel.org>
References: <20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="1104824"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ia4tys64X8D/EHhEqGKTCiuwb0U= sha256:oD+rETaoSCzaQ4OzHyvEdhvW2tnm9bvvsWtXVvk5OHs=
	sha1:yJbcpltWHxIbAcnlc5COCiMnulQ= sha256:pRykLs0OtrFMPJMMBlHIomiSxbooJ6ZIeim10ssCfDc=
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 2334411428F; Thu, 12 Nov 2026 17:19:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 udCe9FNIGgDj;
	Thu, 12 Nov 2026 17:19:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-361880-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 BE0D011420C; Thu, 12 Nov 2026 17:19:07 +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 14A7A1A799F; Thu, 12 Nov 2026 13:31:49 +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=1794490271;
	b=bK07ziMhyPePsvpmIzi4Vq8/ZO7mJQyFXOUPXKFwZ+Vt0b+NVRAiFXySSITWte9NQuGg
	 s6QQ7TRAdBOGCx8cdqto3kmotR2V7U/oWP9zrHjQv6vvQqtcn05SaRBFDdW+tC2DKo772
	 cnBtnf9nlLXq165g9zlslr9GXTGQnJDQqpSmr7m2GTyeEzht3izpWhR7awse22cxRCEmZ
	 clvGR/MWHd7oZXl+jXGRqXtqpV98/+WaQfr56ASF95H18O7RhOJEfKn8KnmQHDusEeqkQ
	 gVVZHM9AHTVCq8Nr5oWuHWUJaoxmSMGXUS9nYUbtz/GGZw7Plpni4viYB/uDE+6Vvsw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794490271;
	h=X-Original-To:Received:Received:DKIM-Signature:From:Date:Subject:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer;
	bh=stWeNmOFxIgHe2Lsk2Jd+hY/Hny7hRBVyzbKd7me1rs=;
	b=CfCnuca+u5RQe1GenlT2OO3app56L5wt5Z8M7jQQjrvOSxN2lttCsoC9/7b/xmOy18wd
	 vsI213+h+mSkWA7JCg7AEwqN9hyw1kYNZ9WewdkalvzML3e8+Y5oCJCtYkjGmgAS+Tr4n
	 6ipKJkNOXTUMV55OXH5+jHCCaNkEVt8rd22ncsDRpMQ5NQTRxL2kFxfJ+ekD3LDJex+uC
	 SrzA/+qWXv7iNhuOnnXfGnM/DDHZnBHLjpwVdXF+rj93ful/IUJdkkEa6IpANtMUZna8Y
	 40rB44roxx9w/Pq54PWHuEatPJYhbyVMpGiVZsfcA0dZUuM/UVS72eCNQmLHVnQGtew==
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="U/Y9Uv8Z";
	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 26E8C606A898;
	Thu, 12 Nov 2026 13:31:11 +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=U/Y9Uv8Z
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=1794490270;
	b=erSmPbLx0jiPEw5bMS8ysN77R3BaYyCrQbr4iJHM6/+XXwo/f8Dpq2+CxSlZoiBECDL+
	 L8NGyb8zkQQwP8pRrEeDqjTeH8hQA4Il0P7h25pO10KIt2PGewHHMr1KjQ2u47/0wWvJz
	 wYS9HK9IbLrXvYlf+1UVtyv847zLZSgBy3XUTlYVn3/FOhPp5licH1j07NK/TZPSuicdM
	 V0E+le9swg33rCgvofp/Gd2BU6Kg9azKeW2DXcBP5985bPvcOkqxYK7YkfO8XVuDuBfe8
	 ijyM01jgidAIJ6HjKaH0uQvtcOhVrtFegzwJMr7g7GSRpmSo+6Kond1B2FOsRb+BbPg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794490270;
	h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer;
	bh=stWeNmOFxIgHe2Lsk2Jd+hY/Hny7hRBVyzbKd7me1rs=;
	b=Gm+F/gzkszWbFh7utZd/nyeBTBmE177ctnH77TVi+WZj9Dv5wIUnOdU+2G1L81Ncm/Hw
	 ELN7IqThWCXjKHGKziN+tHV76s1h4RaszaN2vl95GpODpXX78yM3fsVwm96p7yDrPSayx
	 iA6M6vfJ2aCW0Q0Rfa6OeH/AoXyCgswd7yZNJ9DdQyxXkH4ge7Ap+mSlTrQin5R/9JOce
	 h/9qOG7rZpj3uM6T2jABhMtBEp/k0OzaCQBUt5JdpL5tPwr6TVeMduCH2o+FiiaPvetT0
	 IHNQNwFrew+ZEuB/FSi9/gyuMMSglTvowaedQxWElM9TkXLgdPguSnVTpSWtkT8Jjsw==
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="U/Y9Uv8Z";
	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 44ABA606A899
	for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 13:31:10 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E8831F00A09;
	Thu, 12 Nov 2026 13:31:07 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794490269;
	bh=stWeNmOFxIgHe2Lsk2Jd+hY/Hny7hRBVyzbKd7me1rs=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=U/Y9Uv8ZeU8atuHJxvtKqJvAHialLZcgvHu3mIm/B4ueiC6OEj+KXqc2jALxPKhVS
	 UVlOM+TBHDiCOKp23FIqUsaxdlH2rzYkbq2flx3FBFEdmv5qQGHkD9cSSzdTVpwrDt
	 QsBoG2joOsRufCr45opLm7ZXL5Mex1oa4Pymr19EGa/zHIlc3sWJM6+Ma+zk5XC3HO
	 2vzn+uabdSYHpU5fv5YG66izpZqdbzspfuEFvgcV90M4VFeLr8wQJq+OQEDC/PqOh6
	 3vdm5uPiWx4wXB5c2WiY9PbMIsMYdl3wdUDWEYg4jHTs0cp9gQo1gRgHEz1GojRRzH
	 rfYk7ktJKw4Kg==
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
X-In-Reply-To: <20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3@kernel.org>
X-Cc: netdev@vger.kernel.org, Linus Walleij <linusw@kernel.org>
X-Mailer: b4 0.16.0