🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19897

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

#19897
From: Linus Walleij
Date: Fri, 20 Nov 2026 17:29
86 lines
11196 bytes
The free queue read pointer is owned by hardware and can retain a
position from the previous ring when the queue is rebuilt at a smaller
order. Using an unmasked pointer to index the replacement page table can
then access it out of bounds. A replacement ring which does not contain
the raw retained pointer can also let hardware address past the new
allocation.

Mask software page indices to the active queue order. Keep the
replacement ring large enough for the retained hardware pointer and
initialize the software-owned write pointer from it before filling the
ring. This represents an empty queue without relying on a read-pointer
reset.

Testing on a D-Link DIR-685 with both ports stopped and the free queue
disabled showed that neither a 16-bit zero write to rptr nor a 32-bit
zero write to the pointer register resets rptr. The latter clears only
wptr. Clearing the queue base also leaves rptr unchanged. Networking
recovered after each rebuild, with all ten ping replies received.

A retained pointer can prevent shrinking the descriptor allocation. At
order 15 this is a 512 KiB ring. Buffer allocation initially follows that
order too, approaching 64 MiB; a following patch decouples the RX buffer
budget from descriptor geometry. If allocation fails, retries see the
same floor while DMA is stopped. Keep the queue disabled rather than use
a descriptor ring that cannot contain the retained pointer. Removing
this restriction requires verified pointer-reset or truncation behaviour.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 5e9dd2aea407..66984c78a7cd 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;
 	epn = (rw.bits.rptr >> fpp_order) - 1;
 	epn &= m_pn;
 
@@ -969,6 +970,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	union dma_skb_size skbsz;
 	unsigned int filled;
 	unsigned int pn;
+	u16 rptr;
 
 	geth->freeq_ring = dma_alloc_coherent(geth->dev,
 		sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -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));
+
 	filled = geth_fill_freeq(geth, false);
 	if (!filled)
 		goto err_freeq_alloc;
@@ -1101,6 +1107,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	struct net_device *other_netdev;
 	unsigned int new_size = 0;
 	unsigned int new_order;
+	u16 rptr;
 	int ret;
 
 	ASSERT_RTNL();
@@ -1132,6 +1139,10 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	}
 
 	new_order = min(15, ilog2(new_size - 1) + 1);
+	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
+	if (rptr >= BIT(15))
+		return -EIO;
+	new_order = max_t(unsigned int, new_order, fls(rptr));
 	dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
 		new_size, new_order);
 	if (geth->freeq_ring && geth->freeq_order == new_order)

-- 
2.56.1
Technical Details
Message-ID: <20261120-gemini-ethernet-fixes-3-v9-4-298671d799d5@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368043-linux-kernel-netdev=dewy.ru
References: <20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368043-linux-kernel-netdev=dewy.ru
From: linusw@kernel.org (Linus Walleij)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free
 queue pointers on rebuild
Date: Fri, 20 Nov 2026 18:29:23 +0100
Organization: Usenet Network
Message-ID: <20261120-gemini-ethernet-fixes-3-v9-4-298671d799d5@kernel.org>
References: <20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3219705"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KNTj4AHCGUnlmgTNqHr/IB8LsrM= sha256:9xtNHWyXJOz79Fe4U5Wj4kZrbgYlxn6BWRlJJ2tVsZc=
	sha1:V3yff5YHczRX/ksKuMN9ehiuBSk= sha256:mgLZ5zCnZ9x9wAn0TU5zbi8B/g1MNUcLsRxn7A7yiMU=
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 2DCDF115A22; Fri, 20 Nov 2026 20:30:26 +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 QgRag9ccU7iS;
	Fri, 20 Nov 2026 20:30:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-368043-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 0FCDC1159CA; Fri, 20 Nov 2026 20:30:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id B201AC45B7; Fri, 20 Nov 2026 17:29:52 +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=1795195785;
	b=1WaOC3R91keBHR9aygDt9yKuDUpK2FURU/bl9TnpHtmNLBsvHuOwFosmoXhXGFVUgHAR
	 /AGIDBct1kPSKhutGhJ2VggO9oroa70a9TFPx9ZGlkAeVr9BBGgyONnq/hFFEDrFTG+yY
	 pmJg8NnoD1N8TuD45CDZ/spG2+jpZFzgicdpmWPifdoK9JiS5tSzh2/qWrjkOliQtBAWS
	 ajNQaYau7jipHqUtvHqNdhWgNLrt4/qjd/ii+PduDx3SuwxLTc7uGrPwW/f/Ki4BRuH48
	 Bbva0W6VDsDR57AU8kyUZH56vFOGGfTqYH6kDyo1gQt9qpAHpmZGqD+pMDADVw4mZGA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795195785;
	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=bqrGnmj0r0O9VcnQQWr/AlRBMQf2jlG70xjlsBKgSDw=;
	b=VSz9mx+TcLc4aNx7BsyinS4fvN3caFSxnCfgApseME2/0+p+WtZMp37cWMqQsQSzxsS1
	 5Eg4OUMOPK1xAwrkXCrnjSlN98+9BtLUGM1zFXTmWJWMwJd2fvAijSr7qxq+d/bWeMJOU
	 9NAYnHbcVPC41jgwGfqX+p3DdxY4KCkWFRrfgyVcPihzF63KqHtpbUpT5uzjTAPgEPrxg
	 WubtQWw25BBBajH9eIozy0M6vkBNRkSa0YMgJCfA+64ANbrE3ZZ4C10R4mJEEdBaZBuMA
	 n8s/rcTvOIGjyulKQIoMivEO1St2E3oZrnifioMXIPckkY/2QeYI8yHOVffE4RVj3/w==
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=nTGzyA3I;
	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 7C2BA60A2618;
	Fri, 20 Nov 2026 17:29:45 +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=nTGzyA3I
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=1795195784;
	b=5EgD/sTEO2z7pEfIrdVKm2WOr9p7NvA7Pu8y95HNukHNVZ4+E05ip4NVVPKCfYQ4M4uO
	 vB6icasJ0HSbDy0EErf8zJpjgwQcWxgR7MRcqE73LuD2i3CVRt5EhRvcOs03Hi0q6aJIo
	 CdZyMDY+LKFKZOAgywSo/LxMBSvXcugbMdeVS4TviJAXI+VMNNIeHQ7gnSPVbr44Ak9Gc
	 X3X3Lw51ykn5HiXE5KYGNOS60siRPaeKfufxBX81qtjEujD9K3rxMtohHQcXQnKiMT82N
	 14/k7xt+eJaV1Ts9WmVbo99AaBNKITzK7VsSVgmTmvT57TOPFh9bi2zBBM0B0WEJCPw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795195784;
	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=bqrGnmj0r0O9VcnQQWr/AlRBMQf2jlG70xjlsBKgSDw=;
	b=sA0uh8v//1T0w6cfPJPOd0tu0+d1iw5WzcrCfHBvFeVyYk06uQd2s8F2Ux4bk1Ytigdy
	 b/cRkRnpFyMq0Y4fe39uRq6jT5RUNEiWx8kgMkH/6iR0zosqzBhon+pj9D5FRipDG2gOh
	 mF99HWPavSDATTamEpLso1rKdAGrsZn1SoDpov1tINdpDTAKavl0416FvFvUeRm1lSw5s
	 POsvRZDhuVVDyDDNfvjDXDOQMruRpGdcAGR/6OdAfis7sKLCzfJ2dSuaDjn/40SiXZZPQ
	 3OJs0Y/5ldql8BlTR1dgKy1p4X9lUmzgjH/AaswOv2uWz2LQEZ8Ou9wxmiGe3CjkxdQ==
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=nTGzyA3I;
	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 9DC2E60A260D
	for <netdev@vger.kernel.org>; Fri, 20 Nov 2026 17:29:44 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A338A1F000CA;
	Fri, 20 Nov 2026 17:29:41 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795195783;
	bh=bqrGnmj0r0O9VcnQQWr/AlRBMQf2jlG70xjlsBKgSDw=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=nTGzyA3IeTkM44uUqtWsLEf2l2gMcdlJo7E3fjGZN1sek2biSD5/mAVbaCcUGaqqe
	 7PJH72VBhGHdA2WQtVmxGW3zXz1FIJs6wvevuk8Dfc2dsQq4oz79NeSlV2jwgAxGxI
	 Fh7p69KrQLWjZZTm0dzgEo9EgOtXsViXFCvZlLF+EKmR4rF/h4CMsg03kaaxk9sc5A
	 xuTKJT4Wo8fibPY5AIhrJo6oHYgJdw7bla+tsqWKZLXI3FSoU7ELJEB4JFn7or7WHg
	 5EGsjq4bQooIs5LCaUkDf7iuCooYnMDT9/gGkcAVaNedxrYzVXWhPzObgdaxt0cV9l
	 mnQFexInZjmKw==
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: <20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5@kernel.org>
X-Cc: netdev@vger.kernel.org, Linus Walleij <linusw@kernel.org>
X-Mailer: b4 0.16.0