🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15167

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

#15167
From: Linus Walleij
Date: Thu, 12 Nov 2026 13:30
131 lines
12379 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/
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 | 40 +++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 2fe7fd0202d2..0b05a1552983 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,10 @@ 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);
 	}
 	clk_disable_unprepare(port->pclk);
-	geth_cleanup_freeq(port->geth);
 }
 
 static void gemini_ethernet_init(struct gemini_ethernet *geth)
@@ -2635,17 +2637,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(dev, sizeof(*geth), GFP_KERNEL);
@@ -2656,6 +2666,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);
@@ -2683,6 +2717,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.0
Technical Details
Message-ID: <20261112-gemini-ethernet-fixes-3-v8-1-f55bd43e02d3@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361863-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!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361863-linux-kernel-netdev=dewy.ru
From: linusw@kernel.org (Linus Walleij)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v8 01/19] net: ethernet: cortina: Keep shared free
 queue parent-owned
Date: Thu, 12 Nov 2026 14:30:16 +0100
Organization: Usenet Network
Message-ID: <20261112-gemini-ethernet-fixes-3-v8-1-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="1095820"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:h5M1eRBvfUgQffEov+ckMHlFxBw= sha256:BQxly7p1HqwblSwK/avtjfQhxkyJCZZTW7QoJ1UGsW0=
	sha1:mRqlVZW9/lQ28pAjCFKKgumBO9I= sha256:60YPB2GtJFb0DCC3HyDdz591aPhmK+b2fIyzz0FkFNE=
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 1332411425D; Thu, 12 Nov 2026 16:36:56 +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 oX6E6PhFA_yo;
	Thu, 12 Nov 2026 16:36:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-361863-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 587BD114257; Thu, 12 Nov 2026 16:36:37 +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 832DDE30CD; Thu, 12 Nov 2026 13:30:27 +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=1794490225;
	b=Kr2mxbu6xsCJEKwagkrM794/ZAN50FPpTFg3xd1MR20/OW5utpF/rJ9+36nE2xfGt5Eq
	 7Wadm3xKk4n8FQQBdN5J8lB3BPk6OOHxLo0WBT/asIl4LpJjv40lfJSut4Z/zIeoXbGhh
	 79yV0rT/2CG8JrhBBE8QEGuPF/qP7pjRtshYLl9IZUo+FaFcIU6filKAGPPw2JIemOE6D
	 UDrFvlLcGN/E8L6m3qAf72/TKxLkFD9SQCCAS061WpJwInN2R731Bjcilwtyrs2HXMH2+
	 mEkMx43gmUDkr1kGWG0s7FyAqPKYOJ2riHm8rsf093rGAI05aXt6z6fqKR1b1lbj5cA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794490225;
	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=M2hUWOgCedLe37XpMNsh1vER96Y5dhQC8IWrrxybGBw=;
	b=F1PiE3yClTCrsi5CwTNfNbCMEIY5LsVJTwrxBWUjMgWMk/KqS0xe6o9e3j1BM6ETOxhX
	 NfJx2hSKzGiSFMOILhWLjp7Guq1p1mQB2e1bcg8pFiiEQTfMLZVub+pvt1gxs7x1yzGwu
	 ADDWtnzV7lQ5dbcrYmVIIe1YEJ2D8efTDUl06zZOfIkD4jQ3tzKcZ5yrZ+xn3Ye1sLZMx
	 jrVsJCzFsF6mB9+zV3A2hrpaIFCoMm4B3Plp1w+JoWyJGGt2B7TiEagoWOrogHqblJMaN
	 0/xEtL11mzvvbI3K+ut9tuprUlsmkvgAOYO3P6Bxg3JPQ0AeGmWOl5bgmfYDrggTfhg==
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=ml1c40iY;
	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 6F94F606A331;
	Thu, 12 Nov 2026 13:30:25 +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=ml1c40iY
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=1794490224;
	b=XtTHK6oflx62Yj0YlC6Y29JZC7d1lCnKeo/pODJmmtpA+waoxg+FDpWFmtrHmR32tT5A
	 uUDje4avzmchCNHgZe+eB9f+9M6hVefdCFozhKTDq5OBtbt+OPzvebW9Ku3bqbkuWp00F
	 TkM3JLBlLBt++H7oaK6C/5KLm4ITt4J7kULYhXH++LLdtdWh303zsmk7PDE4A8w5EPB0g
	 2/1uITBjABZ/iF07jSEenifDzfXv+z3TLZoAj2Jxb/aA1/eG7SrP0lTwrz6PDwN8llRVc
	 ny6OaFCu6tP4dRAw1ml8j1VhcMzHmG1+dLNA0jCj574ZHEHQ6p/Vayrnj1pkE5FFw8A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794490224;
	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=M2hUWOgCedLe37XpMNsh1vER96Y5dhQC8IWrrxybGBw=;
	b=xcDrQOchWoduyG6AK62XWubgVTCkIDP8Lu2eE+WWCI3P+vSgY02RzEZk9opxTc70+7Fa
	 D/i6RacVrM2lHweqiRzWVZFbfAxyIkQa3unIHTgLwNewEPF+OsFAlz3E7FbHkK0A3QJk9
	 M3MoCQBXt78iiocc+CfZk9mFqjCDmcnnut3J1WpzDIDUvKCRJOa8FoAr6/w+3BpAYvyA/
	 p0CUkPS7f7iLPnDHhhoVT+ZefWZSjz45KX+aWPi82TohTzXYhJjblCQgvWkAPsgapdz78
	 Py7AzknWoKpCYkjJcNVbpbL3ymFPBd7gVYK35tpLtCt6toVVQK31ZJf9cUpp5CYWY/Q==
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=ml1c40iY;
	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 8E47F606A32E
	for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 13:30:24 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5BD91F00A05;
	Thu, 12 Nov 2026 13:30:21 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794490224;
	bh=M2hUWOgCedLe37XpMNsh1vER96Y5dhQC8IWrrxybGBw=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=ml1c40iYCPymSkXdJNIPv2G1L3+KINqRIeMy/SeYHAk+THmn1Rlhhl8uZMwzKrwv1
	 m6xDLUC20b39QsSJ1cFBvSsFn4Xan4PTcQ5qpTg4ngmcvsYPdEuI2Rwc6X37vRsyQC
	 OtOMPkUT+hzT7fEswJ+wKoxABzZ9xc5r3I2i6FKBjW17EsaWe45UF8Ho5wZjS3K1U2
	 p6poebqap26DAvvrfDb97aah1aInPJUrP9lfWEWU5/w1LbSAHJs4QBcdd/Yu5mm5h7
	 SDV809N/6+VaKeTSCIQQ8D8r4mfUCHBpsVdrOBtCFwP8PuZay3JJne4Cu7GsX9+7en
	 oqDyJnCNHfQaw==
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