Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Linus Walleij
Fri, 20 Nov 2026 17:29
[PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned
Author: Linus Walleij
Date: Fri, 20 Nov 2026 17:29
Date: Fri, 20 Nov 2026 17:29
130 lines
12212 bytes
12212 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 | 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 3ed8b1ae0bbc..f198e535f1a0 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_obj(dev, *geth);
@@ -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.1
Re: [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned
Author: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 18:29
Date: Tue, 24 Nov 2026 18:29
123 lines
12479 bytes
12479 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message has Reported-by and Closes tags but no Fixes:
tag and no Cc: stable, even though the patch fixes user-triggerable…
- [Low] gemini_ethernet_probe() now gets every available child's PCLK
with devm_get_clk_from_child() and enables it with…
--
net: ethernet: cortina: Keep shared free queue parent-owned
This patch makes the parent gemini-ethernet device the only owner of the
shared software free queue. The parent now depopulates the port devices
before it cleans up the queue, and it keeps the port clocks enabled itself.
Each netdev is now unregistered before its PHY is disconnected.
Closes: https://lore.kernel.org/netdev/20260917192835.58126-1-mhun512@gmail.com/
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 3ed8b1ae0bbc2..f198e535f1a00 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
[ ... ]
> @@ -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);
> }
[Severity: Low]
This isn't a bug, but should the commit message carry Fixes: tags, and
maybe Cc: stable?
The geth_cleanup_freeq() call removed from gemini_port_remove() here goes
back to the original driver. gemini_ethernet_remove() also calls it, so a
single parent unbind or module unload could run the cleanup up to three
times.
geth_cleanup_freeq() never clears freeq_ring. The later runs then call
dma_free_coherent() and kfree() on memory that was already freed. Unbinding
before any interface was opened also dereferenced the NULL freeq_ring.
The phy_disconnect() before unregister_netdev() order was added later. With
the interface up, it makes gmac_stop() call phy_stop(netdev->phydev) with a
NULL phydev.
Something like:
Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
Fixes: 3e813d61401a ("net: gemini: Clean up phy registration")
Without these tags, stable trees that still have these bugs may not pick up
the fix.
[ ... ]
> @@ -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;
[Severity: Low]
Is the commit message accurate about this part? It says:
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.
gemini_ethernet_probe() enables the clocks, and the matching
clk_disable_unprepare() runs as a parent devm action. Both port clocks
therefore stay on for as long as the parent is bound, not only during
teardown.
The patch also adds new ways for the parent probe to fail, and the message
doesn't mention them. Because of the "if (!clocks) return -ENODEV;" check,
a parent with no available port children now fails to probe. Before this
patch that probe succeeded and did nothing.
The parent probe can also fail or defer if devm_get_clk_from_child() cannot
resolve a child's PCLK, since it only does OF lookups. The child's own
devm_clk_get() can fall back to clkdev lookups.
The in-tree gemini.dtsi provides "PCLK" for both ports, so in-tree boards
don't hit these paths. Could the commit message describe these changes?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads