🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10550

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

#10550
From: Linus Walleij
Date: Tue, 03 Nov 2026 17:51
72 lines
10335 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 trying to write the
read-only pointer.

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 003108270d06..7ebd62f8a3a4 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -887,6 +887,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;
 
@@ -936,6 +937,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,
@@ -958,6 +960,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;
@@ -1068,6 +1074,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();
@@ -1099,6 +1106,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.0
Technical Details
Message-ID: <20261103-gemini-ethernet-fixes-3-v6-4-c4b5ff8a65d8@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355885-linux-kernel-netdev=dewy.ru
References: <20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355885-linux-kernel-netdev=dewy.ru
From: linusw@kernel.org (Linus Walleij)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v6 04/15] net: ethernet: cortina: Normalize free
 queue pointers on rebuild
Date: Tue, 03 Nov 2026 18:51:15 +0100
Organization: Usenet Network
Message-ID: <20261103-gemini-ethernet-fixes-3-v6-4-c4b5ff8a65d8@kernel.org>
References: <20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3224213"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dEn2LAGjH4yDncaXfNjkQdcAiNI= sha256:5357OM/BYcgjWMjiDQQiV4Irua1bRNd5KzvrpxcJtG0=
	sha1:j7lz7/DLWn4kUVstDQtziODLTz8= sha256:VrMiI9gO97Eavy5lvkRA4oAcjBdRBXsytGXEtlhrlNo=
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 3A88C11297F; Tue,  3 Nov 2026 20:52:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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 augPXOoW2vFe;
	Tue,  3 Nov 2026 20:52:13 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-355885-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id E5751112956; Tue,  3 Nov 2026 20:52:04 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 3FEA8602B4E; Tue,  3 Nov 2026 17:51:32 +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=1793728290;
	b=2ld6fOF/40ysQRXYODnOZK/Kl4uKcDVIVFI3t8MoMmSl/ibSMfu6BjyRHS/1ITAa3r/N
	 jwufO1EqfJdnHLwh/GgcbvPsRcWaLZUF7IqpLv/gdKlkkw1Zx8XbnWBe9bABHSi/AmyiC
	 tUD4W34UsWW4rdriav8l3E/O/yfcKoRhz3khGXvsZQgmJOnWak3Wo9HzpHt9D0RpOd4Iy
	 LUzDeaCsQLb4sGBKalqFJyujDEAX6VXwEo9AWL2gN4O+lqOhsxYMBtwJH3sX8Xbf5qh89
	 mdzx15shl8MQ3H93+FWaO5/4KBR1iRgayQfd9vqEgeYDvkpF6QU7CNBTuXNI00nY6ZQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793728290;
	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=fFABdFdemLSusjZLC23cUbVSsrGcJ7NisgIVtUC/MMY=;
	b=1yrhBTPNChKcQb9Fpcoyk7T3FoomjnIsa6xK2medM1uHNhcmeTzYHG66QETFDny4rBff
	 +YHQKR6kkVqJiwoi2/bbOjLaOV4CJpI+tTLw07f+yjEtD3WC87GtwzOnpT0XXeq5wvXed
	 UWpkU1NM7noC8ueZIRGt5YGN2bIwVZ7BGyQNRcrqPFwKedNniDkuKada6lQatB9jMTo3s
	 QrYAzZrP3Ca04jfCAZC72saDuiB5Fd6SwrD3qwuZ5aHqeoRFP5REcsyZSNSv55I9AwZ25
	 f2U88TIw8FnRoKfOwIh7zfl+l8s6+JBzcvZF9sX40tkdlfe5mbQ/WuncTn8+d7uTAVQ==
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=hgFOxh++;
	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 70798606A334;
	Tue,  3 Nov 2026 17:51:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hgFOxh++
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=1793728289;
	b=PuFj/FkVT+8Sc33kleCl5OeLux2m0y30l/C9+uoTD9Oc4NnKAmkHgooepaVwE3LE1rER
	 XF3hzldVNrxlgn+QOgsPKh4qokaYbDM4JmSl4rkzykUM0dwdUuZnl8pTbJujbKDYL6eXz
	 AAdUHUy0vBu1tfrsCROHg8Rpew5/UougKTFYlJRtyUVyfvicvfV5yH7WpA5I/zHq0GSPi
	 E4dQ3Uco97/mjuxxyCZ4XSRBp6+1Bt5ZmHCp4Pax8o9w8Ix3rZ0hpsKPdDCmEYe5DK74p
	 lgxN+gIq4Fi77yXq7w3Kuk/mqjhZwwn9JvD9YUTQLi/Lvx31dFEFIo/HbuWAJhpTUPQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793728289;
	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=fFABdFdemLSusjZLC23cUbVSsrGcJ7NisgIVtUC/MMY=;
	b=F+F3MkjiYe3B5AY1iimbfegg00LvhSnuyp2TyNlz5XeaW/5DnQ+S6EMyYqHKXArDftZe
	 1vL0zpwYeDM3VBZHthP23KZV5tTZRmKhcUIxeU+z8ScKlSkMgWdU7UCDA6dhOD9VyciQo
	 FLR02MjUwjEucS1FteNNZqX+/Qx74S1Uxl/2YB0IBUoL7EaY+i46XTzO6bohnf/aEYY/I
	 Cy0FGOqLhvwNiCpkkZ0+M2EsrpoCnSrb5eGYNXxdk5dz2k2bytqPav5MQnDf81UXtIjoq
	 triZkyRmKZ3Jujohu6ErTvNgVuf0r3YTEjPlbFJitvFy2R1p4FfymwWibDheYvedHdA==
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=hgFOxh++;
	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 55208606A329
	for <netdev@vger.kernel.org>; Tue,  3 Nov 2026 17:51:29 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF1BB1F0093A;
	Tue,  3 Nov 2026 17:51:26 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793728288;
	bh=fFABdFdemLSusjZLC23cUbVSsrGcJ7NisgIVtUC/MMY=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=hgFOxh++AipcM/1hJuMHNhQDZpNQCsHXCCBWs40+wz0nsG5/x4On09cuK0q2d4RrS
	 4Y0uQzN2+7vHNiOm/6Sp2ccPrf3BfTJzvZnL2fNI2pABRQu4zxS0TPchRQwAJsjJsF
	 3tpn1B/+rA4IUW43Q+LYNOU25R9THWVZlh+X0fYp6WmROkn2InGcZqD5oDCAv7IwVs
	 V6OPxlo09HEDJmh7yrICjyTnm5gzxP1/SDm448Fha5Tu0WJQAwOHfLuXkXqirXJW5D
	 9wfYJzoFgZEgEHwSB7GsD4pBMUs1fnx0YRLeVIWG23caHwlbOGGSayQPLtptXVy5C9
	 sBLZY3erlWSiQ==
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: <20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org>
X-Cc: netdev@vger.kernel.org, Linus Walleij <linusw@kernel.org>
X-Mailer: b4 0.16.0