🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27508

[PATCH net-next v10 01/14] net: ethernet: cortina: Keep shared free queue parent-owned

#27508
From: Linus Walleij
Date: Sat, 05 Dec 2026 21:46
130 lines
12231 bytes
The software free queue is shared by both Ethernet ports, but teardown is
not ordered around that ownership. On parent unbind or module unload, the
parent remove callback runs before devres depopulates the child devices. It
therefore destroys the queue while both child netdevs are still registered
and can be doing DMA. Devres then removes each child, and both child remove
callbacks destroy the same queue again, resulting in up to three cleanup
attempts.

Removal before the first interface has been opened is broken as well. The
shared block initialization assigns a nonzero queue order, but allocation
is deferred until open. Cleanup consequently derives a nonzero page count
and dereferences the NULL queue ring.

Depopulate both port devices before cleaning up the queue, and perform that
cleanup only from the parent. Disable the free-queue interrupt after the
managed handlers have drained, since its threaded handler can re-enable it.
Guard cleanup for paths where no queue was allocated.

Hold parent-managed enables on the port clocks across child removal, IRQ
draining and shared queue cleanup, so teardown never relies on clocks
already released by the children.

Port 1 owns the shared refill interrupt, so prevent the children from being
unbound independently. Unregister each netdev before detaching its PHY so
ndo_stop can still access netdev->phydev.

Reported-by: Myeonghun Pak <mhun512@gmail.com>
Closes: https://lore.kernel.org/netdev/20260917192835.58126-1-mhun512@gmail.com/
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 41 ++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 29d94be68701..8f65097e284c 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1004,6 +1004,9 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	unsigned int pages = len >> fpp_order;
 	unsigned int pn;
 
+	if (!geth->freeq_ring)
+		return;
+
 	writew(readw(geth->base + GLOBAL_SWFQ_RWPTR_REG),
 	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
 	writel(0, geth->base + GLOBAL_SW_FREEQ_BASE_SIZE_REG);
@@ -2387,11 +2390,9 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
 static void gemini_port_remove(struct gemini_ethernet_port *port)
 {
 	if (port->netdev) {
-		phy_disconnect(port->netdev->phydev);
 		unregister_netdev(port->netdev);
+		phy_disconnect(port->netdev->phydev);
 	}
-
-	geth_cleanup_freeq(port->geth);
 }
 
 static void gemini_ethernet_init(struct gemini_ethernet *geth)
@@ -2625,17 +2626,25 @@ static struct platform_driver gemini_ethernet_port_driver = {
 	.driver = {
 		.name = "gemini-ethernet-port",
 		.of_match_table = gemini_ethernet_port_of_match,
+		.suppress_bind_attrs = true,
 	},
 	.probe = gemini_ethernet_port_probe,
 	.remove = gemini_ethernet_port_remove,
 };
 
+static void gemini_ethernet_disable_clk(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int gemini_ethernet_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct gemini_ethernet *geth;
 	unsigned int retry = 5;
+	unsigned int clocks = 0;
 	u32 val;
+	int ret;
 
 	/* Global registers */
 	geth = devm_kzalloc_obj(dev, *geth);
@@ -2646,6 +2655,30 @@ static int gemini_ethernet_probe(struct platform_device *pdev)
 		return PTR_ERR(geth->base);
 	geth->dev = dev;
 
+	/* Keep both port clocks enabled until the shared queue is torn down. */
+	for_each_available_child_of_node_scoped(dev->of_node, child) {
+		struct clk *clk;
+
+		if (!of_device_is_compatible(child, "cortina,gemini-ethernet-port"))
+			continue;
+
+		clk = devm_get_clk_from_child(dev, child, "PCLK");
+		if (IS_ERR(clk))
+			return dev_err_probe(dev, PTR_ERR(clk),
+					     "failed to get port clock\n");
+
+		ret = clk_prepare_enable(clk);
+		if (ret)
+			return ret;
+		ret = devm_add_action_or_reset(dev, gemini_ethernet_disable_clk,
+					       clk);
+		if (ret)
+			return ret;
+		clocks++;
+	}
+	if (!clocks)
+		return -ENODEV;
+
 	/* Wait for ports to stabilize */
 	do {
 		udelay(2);
@@ -2673,6 +2706,8 @@ static void gemini_ethernet_remove(struct platform_device *pdev)
 {
 	struct gemini_ethernet *geth = platform_get_drvdata(pdev);
 
+	devm_of_platform_depopulate(&pdev->dev);
+	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
 	geth_cleanup_freeq(geth);
 	geth->initialized = false;
 }

-- 
2.56.1
Technical Details
Message-ID: <20261205-gemini-ethernet-fixes-3-v10-1-9edd2057429c@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378136-linux-kernel-netdev=dewy.ru
References: <20261205-gemini-ethernet-fixes-3-v10-0-9edd2057429c@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378136-linux-kernel-netdev=dewy.ru
From: linusw@kernel.org (Linus Walleij)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v10 01/14] net: ethernet: cortina: Keep shared free queue parent-owned
Date: Sat, 05 Dec 2026 22:46:44 +0100
Organization: Usenet Network
Message-ID: <20261205-gemini-ethernet-fixes-3-v10-1-9edd2057429c@kernel.org>
References: <20261205-gemini-ethernet-fixes-3-v10-0-9edd2057429c@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network; logging-data="3125835"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:+iwmMlDw4xKCxWjUXqjy0lY1nwg= sha256:qR+Uf7XY27Cwq+JT3CHLqZu0pjqsxQ3qUWsCsl5ox48= sha1:TujOxJf8fu6l2qZFJYxQpBUsXG8= sha256:lRWFl8TE3PBY9el00qqJaiOFMm/hP828dLvKOeugpGo=
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 B56FC117EB9; Sun,  6 Dec 2026 00:47:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.54
X-Spam-Status: No, score=-3.54 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, 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 kUT2RFoBwKCz; Sun,  6 Dec 2026 00:47:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-378136-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 2368C117EA4; Sun,  6 Dec 2026 00:46:59 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id C8B482AD60; Sat,  5 Dec 2026 21:46: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=1796507213; b=zo1SIVob4J/oWOVtJwKrfRX0ctcsVoPMKPM7LUOUn2kRRARweq5h7EdSRJOWdi/mi8Ce TfDzEXD6nHDHLvgUa+8mxnoZXdXBNQCJ7z1fOUU5dW3wz4ZGmhFHr5FoaFgDPgaDQ7hCg a8/igOIvS+SvhH+ZvND322cZBAudI+sddlQPfIY+BjuWYNA+CkjR399MpUFGicaN3dFhC AyuyR2zpd9Nu307jOq6bWEdt6F2pPZiv4gd22f5XT4OHqwNhyfG9XLPYi6Twx+u/DeDiK ogVO13GAPi7eXbFxweAyiAROnzxCpbkTHI7ZpSZC1oBc3ilBBr0jqG/yrK73eO+s1XQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796507213; 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=ao6AlFDaZa+i4WXYMCfRaH11ePopyrdYn+hpQLyJUa8=; b=YtF8+9ee5VYctZwigYHamdmtr6m9o2/4qs874HcIXuaG7VBTkS5T7+TWIEbxGFZfeTj8 OovaYmYi/bC3OSQV7laDt8SwQu1GQN9ZUhzkHzIz53BLsSx8qKdvDJkw1eaHbUzgj+kDX Qiok0RkMwyoD/Zx0sb9wj2Kw5u+eFD5gd74yi4FM/h/toGWsoJJctzVB+YpNAUdO1sFfp hCG3a3zD83CUdFLjE8mBpdeng0ypdK6rU7SU2bHLSWZapJaibugw81+MpHx95gkmRw6YT 8H/VnMbW25Hmfw2R3ifZH5nozcotxT7wiF9lrr8prrOFb/3nAo0LrfJfK6iDE74dcsw==
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=F9kZ37w4; 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 387B6606A339; Sat,  5 Dec 2026 21:46: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=F9kZ37w4
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=1796507212; b=ZirSx92a2qGkORxh18zhWC+S0wNKeJvn4XcWNWANJacXMs303v1/5t1i2r5y2Xc0tQVU PBWd8zI59ecFXsshWev5yrF94tMtrQafsk1+odATXBsIlm1BEBb2AyMm/X95URD792k7l OmxP/WsfjglJZ72p7PcVsABnq4idwv+ErgheoBDTbUEQwokp0mEsHDRXR6JawK9PZUoGl 0+Xn55S6ZT12ABmkMFJo+8UidXqJYnnqH3XwA9MBz0c84xe46qsKasn4EO1jGQs80KEqf Ck8FejIL1ZgVeOlS1yicrHoynZ2m9DqMmoDn49dN2yiHAuZ/9HbXEd6UUhWHKE5dArQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796507212; 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=ao6AlFDaZa+i4WXYMCfRaH11ePopyrdYn+hpQLyJUa8=; b=Iqx3149jsZtvQ6ui+wKGydBvWSbPj7+mp2SF9BGLASFnvxaBKa+1+dc/OJNUTiO6xLnV oP9nVixxy3Wha41RXBPrdoMebl9ukphZEj3cnNsQY5sAS1fNwNE+2HTk+KplBAfzxCZBQ d9F8YXNNgMl9mz6lKH4HqsDs404k8yJnZOjoeMlQuhILSj3ac/c9zq4vnqJMOehgDtSXD pM5LiGfyjejHXETO/KNXvlcG7U/w03KLe1F5Y1FA/7vK6QSk7WMT2PDvhPguJiQoh/sVH p62PNQZJxFiNpSWXDE3RrFR0G97tguDYqiqluXtmwMhmbHwovebbA88X6REru/aWGnA==
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=F9kZ37w4; 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 55EED606A335 for <netdev@vger.kernel.org>; Sat,  5 Dec 2026 21:46:52 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94F8A1F00936; Sat,  5 Dec 2026 21:46:49 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796507212; bh=ao6AlFDaZa+i4WXYMCfRaH11ePopyrdYn+hpQLyJUa8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=F9kZ37w4tO+yZM2I5stYD84HAbPW+YC/I/nBFWFpo59nRmpqaLw0w1T0g4tt+lEmE DsfixV8XAgHzbuHe9g6yYtpDVQWoiskXjGq13bCYEdh2Q+UJ2L1RoJaZNmT4oHY8J6 s53eAhCdKZS/+K+En+Q0fYDS93pz32a9yiuX4+XBL2p368zE1OOAV1bJgaN8e7KvfY pxhCkymUuUYA49Z2dY6S7MKv3ujIVvMdN3I29i5ss9lIWGEdHjRAVkflayILDZvfDy hgEkR9Gzln6DeUFWXXaKLh/PXBIAJXVsgC8q7duv5jMK7vJBnQus+tvT1vP8dZDuIC 924POY7296wFA==
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: <20261205-gemini-ethernet-fixes-3-v10-0-9edd2057429c@kernel.org>
X-Cc: netdev@vger.kernel.org, Linus Walleij <linusw@kernel.org>
X-Mailer: b4 0.16.0
X-Received-Bytes: 12034