Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management
@ 2026-11-20 17:29 Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
                   ` (13 more replies)
  0 siblings, 14 replies; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The Gemini ethernet uses a custom software free queue shared by both
ports. Its page metadata, DMA mappings and fragment references are not
managed consistently as pages move through the free queue and RX queues.

Correct the DMA address bookkeeping and synchronization.

Track exact fragment mappings with an XArray and keep
in-flight page metadata in bitmap-allocated slots until all hardware
references have been claimed.

Serialize queue resize against the refill interrupt, harden fragment
validation and teardown, then scale the default queue sizes for systems
with 32 or 64 MiB of RAM.

This series now stops at the RX queue memory sizing changes. Statistics,
RX coalescing timer lifetime and retained TX pointer handling are split
out into gemini-ethernet-fixes-4.

This series wasn't so complex to begin with but Sashiko and the other
LLMs just find more and more corner cases. It's for the better I
guess.

Before these patches the network driver would crash under strong load
but it does not happen any more after. Tested on the D-Link DIR-685
playing back media and transfering new media using ksmbd while
issuing ping storms.

Target this series at net-next. I will backport these changes to OpenWrt.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
Changes in v9:
- Rebased on net-next.
- Drop all Fixes: tags.
- Move statistics and other follow-ups out of the series.
- Chop off patches to force the series down to 14 patches, save other concerns for later
- Link to v8: https://patch.msgid.link/20261112-gemini-ethernet-fixes-3-v8-0-f55bd43e02d3@kernel.org

Changes in v8:
- Protect TX fragment statistics updates during process-context teardown.
- Rebuild idle shared free queues on reopen to reclaim unclaimed fragments.
- Separate RX buffer capacity from retained-pointer descriptor ring sizing.
- Preserve PHY probe deferral and clean up fixed links on probe failure or removal.
- Link to v7: https://patch.msgid.link/20261110-gemini-ethernet-fixes-3-v7-0-9c32a1a46aec@kernel.org

Changes in v7:
- Bound free queue refill work and release surplus metadata on downsizing.
- Serialize TX completion statistics with the IRQ-side writers.
- Fix ethtool statistics retry bounds and counter synchronization.
- Reject pfmemalloc pages when recycling RX buffers.
- Document XArray dependency for lifetime and recycling backports.
- Reject TX rings smaller than retained hardware pointers, so now the
  series has also started to fix things on the TX path.
- Document the retained SWFQ pointer shrink and allocation limits.
- Keep ports IRQ-only after PHY setup or netdev registration failure.
- Keep parent-held port clocks enabled through IRQ draining and queue teardown.
- Link to v6: https://patch.msgid.link/20261103-gemini-ethernet-fixes-3-v6-0-c4b5ff8a65d8@kernel.org

Changes in v6:
- Initialize statistics synchronization objects for lockdep.
- Post free queue pages from the exact retained descriptor pointer.
- Document replacement-page lookup failures and tag the DMA mapping fix.
- Initialize and drain the RX coalescing timer around its IRQ lifetime.
- Rebased on v7.4-rc1
- Link to v5: https://patch.msgid.link/20261015-gemini-ethernet-fixes-3-v5-0-b5c9e2f7b8a3@kernel.org

Changes in v5:
- Preserve complete frames terminated by an empty EOF descriptor.
- Recheck concurrently retired pages before consuming fresh metadata slots.
- Fold RX ring metadata sizing and resize rollback into the page lifetime
  fix.
- Match free queue teardown unmaps to the saved full-page DMA mapping.
- Preserve the hardware-owned free queue read pointer across rebuilds and
  keep replacement rings large enough for its retained position.
- Keep shared initialization parent-owned, quiesce inherited IRQ state
  before child handlers register and force first queue setup from ring
  state.
- Link to v4: https://patch.msgid.link/20261011-gemini-ethernet-fixes-3-v4-0-4b1631b08f5d@kernel.org

Changes in v4:
- Protect stop-path RX statistics updates against preemption on 32-bit systems.
- Validate final RX lengths against the Ethernet minimum and descriptor
  transfer size so malformed chains cannot pass short skbs to GRO.
- Charge the full posted RX fragment size in skb truesize accounting.
- Reject free queue geometries that cannot post one complete page and
  document the changed refill and recycling behavior.
- Reset the free queue allocation cursor with its bitmap during teardown.
- Bound recycler IRQ latency and release retained mappings for stack-owned
  pages before allocating replacements.
- Rebuild oversized free queues while both ports are down so RX ring
  downsizing releases the surplus pages.
- Scope RX statistics writer sections to counter updates for PREEMPT_RT.
- Restrict shared free queue handling to port 1 so IRQ draining covers
  every registered handler path.
- Reset and mask free queue pointers when rebuilding the queue.
- Reorder the shared queue ownership fix before the port lifetime fix.
- Publish ports only after setup, serialize their lifetime with RTNL and
  suppress independent child unbind while port 1 owns the shared IRQ.
- Move child-unbind suppression and PHY teardown ordering into the
  parent-ownership patch.
- Link to v3: https://patch.msgid.link/20261002-gemini-ethernet-fixes-3-v3-0-3e1f25890ae8@kernel.org

Changes in v3:
- Add Fixes tags throughout the series, using the original driver commit
  where no more specific offending commit exists, and replace Resolves with
  Closes on the lifetime fix. I did not retarget the series to net
  because there are dependencies in net-next and we are getting closer
  to the merge window.
- Keep PHY-less port 1 bound as the shared free queue IRQ owner and clear
  stale parent port pointers.
- Disable the port 1 Linux IRQ throughout free queue resizing so no newly
  woken threaded handler can race queue teardown or setup.
- Keep failed queue rebuilds quiescent in the IRQ-drain patch.
- Serialize linear DMA lookups before converting them to an XArray.
- Keep all XArray mutation under the IRQ-safe free queue lock.
- Defer page unmapping until fragment lifetime is tracked, and fold DMA
  synchronization into that fix.
- Check free queue space before allocating and mapping a candidate page.
- Rebuild free queue metadata when RX rings grow and roll back rejected
  ring changes.
- Recycle released pages with explicit DMA synchronization using the
  existing free queue allocator.
- Account inconsistent RX descriptor lengths as drops rather than wire
  length errors.
- Count partial RX frames discarded during stop as dropped.
- Drop the cleanup guard conversion because it is not recommended for
  network drivers.
- Link to v2: https://patch.msgid.link/20260928-gemini-ethernet-fixes-3-v2-0-758a795d7a78@kernel.org

Changes in v2:
- Replace the page_pool conversion with several smaller fixes using the
  existing free queue page allocator.
- Split DMA bookkeeping, XArray lookup, bitmap allocation, cursor rotation,
  synchronization, validation and teardown into individual patches.
- Drain the threaded free queue interrupt before resizing the shared queue.
- Allocate and DMA-map refill pages outside the IRQ-disabled free queue
  lock.
- Reject and unwind partial initial free queue fills, reset their hardware
  pointers and leave the refill interrupt masked so setup can be retried.
- Avoid full-page CPU synchronization after fragments enter the network
  stack.
- Bound RX lengths to the posted fragment and account rejected lengths as
  receive errors.
- Keep the fixes, and keep the add-on RAM sizing patch.
- Link to v1: https://patch.msgid.link/20260920-gemini-ethernet-fixes-3-v1-0-3a2a50a83d89@kernel.org

---
Linus Walleij (14):
      net: ethernet: cortina: Keep shared free queue parent-owned
      net: ethernet: cortina: Keep ports bound for shared IRQ
      net: ethernet: cortina: Drain free queue IRQ before resize
      net: ethernet: cortina: Normalize free queue pointers on rebuild
      net: ethernet: cortina: Correct free queue DMA mappings
      net: ethernet: cortina: Index free queue fragments with XArray
      net: ethernet: cortina: Preserve in-flight free queue pages
      net: ethernet: cortina: Rotate free queue page allocation
      net: ethernet: cortina: Recycle claimed free queue pages
      net: ethernet: cortina: Separate RX buffer capacity from free queue size
      net: ethernet: cortina: Validate RX fragment lengths
      net: ethernet: cortina: Account RX buffer size in truesize
      net: ethernet: cortina: Release partial RX frames on stop
      net: ethernet: cortina: Scale Gemini RX queues to system memory

 drivers/net/ethernet/cortina/gemini.c | 923 +++++++++++++++++++++++++---------
 drivers/net/ethernet/cortina/gemini.h |   2 +-
 2 files changed, 699 insertions(+), 226 deletions(-)
---
base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
change-id: 20260919-gemini-ethernet-fixes-3-f0403653f23a

Best regards,
--  
Linus Walleij <linusw@kernel.org>


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 02/14] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

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


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 02/14] net: ethernet: cortina: Keep ports bound for shared IRQ
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 03/14] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The software free queue interrupt is routed through port 1 even on
boards which only connect a PHY to port 0. Since PHY setup was moved
into probe, the PHY-less port fails to bind and releases the threaded
handler needed by the shared queue.

Publishing the port before PHY setup also leaves a dangling parent pointer
when probe fails and devres frees the netdev private data. Opening the
sibling can then dereference freed memory.

Keep children bound as IRQ-only ports when no PHY is described or when PHY
setup or netdev registration fails permanently, so an unusable interface
does not disable its sibling. Disconnect any attached PHY after
registration failure. Continue to propagate deferred-probe and mandatory
resource errors.

Resolve referenced PHYs explicitly and defer probe until they register.
Preserve fixed-link registration and PHY connection errors, and release
fixed links on probe failure or removal. This avoids permanently binding
a port IRQ-only just because its MDIO bus has not probed yet.

Publish a port to the parent only after its IRQ and optional netdev are
ready, and protect port lifetime with RTNL. Refuse shared queue setup
until both ports have completed initialization.

Keep shared hardware initialization parent-owned across individual child
removal so recreating one child cannot reset a live sibling. Mask
firmware interrupt state before child IRQ handlers are registered, and
use the allocated ring rather than an order sentinel to decide whether
the queue still needs initial setup.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index f198e535f1a0..4f27a48908b1 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -25,6 +25,7 @@
 #include <linux/interrupt.h>
 #include <linux/reset.h>
 #include <linux/clk.h>
+#include <linux/rtnetlink.h>
 #include <linux/of.h>
 #include <linux/of_mdio.h>
 #include <linux/of_net.h>
@@ -155,6 +156,7 @@ struct gemini_ethernet_port {
 struct gemini_ethernet {
 	struct device *dev;
 	void __iomem *base;
+	/* Protected by RTNL. */
 	struct gemini_ethernet_port *port0;
 	struct gemini_ethernet_port *port1;
 	bool initialized;
@@ -359,18 +361,51 @@ static void gmac_adjust_link(struct net_device *netdev)
 	gmac_enable_tx_rx(netdev);
 }
 
+static void gmac_deregister_fixed_link(void *data)
+{
+	of_phy_deregister_fixed_link(data);
+}
+
 static int gmac_setup_phy(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	union gmac_status status = { .bits32 = 0 };
 	struct device *dev = port->dev;
+	struct device_node *phy_np;
+	phy_interface_t interface;
 	struct phy_device *phy;
+	int ret;
+
+	ret = of_get_phy_mode(dev->of_node, &interface);
+	if (ret)
+		return ret;
+
+	if (of_phy_is_fixed_link(dev->of_node)) {
+		ret = of_phy_register_fixed_link(dev->of_node);
+		if (ret)
+			return ret;
 
-	phy = of_phy_get_and_connect(netdev,
-				     dev->of_node,
-				     gmac_adjust_link);
+		ret = devm_add_action_or_reset(dev, gmac_deregister_fixed_link,
+					       dev->of_node);
+		if (ret)
+			return ret;
+
+		phy_np = of_node_get(dev->of_node);
+	} else {
+		phy_np = of_parse_phandle(dev->of_node, "phy-handle", 0);
+		if (!phy_np)
+			return -ENODEV;
+	}
+
+	phy = of_phy_find_device(phy_np);
+	of_node_put(phy_np);
 	if (!phy)
-		return -ENODEV;
+		return -EPROBE_DEFER;
+
+	ret = phy_connect_direct(netdev, phy, gmac_adjust_link, interface);
+	put_device(&phy->mdio.dev);
+	if (ret)
+		return ret;
 	netdev->phydev = phy;
 
 	phy_set_max_speed(phy, SPEED_1000);
@@ -1051,10 +1086,17 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	u32 en;
 	int ret;
 
+	ASSERT_RTNL();
+
+	/* The software free queue interrupt is routed through port 1. */
+	if (!geth->initialized || !geth->port0 || !geth->port1)
+		return -ENODEV;
+
 	if (netdev->dev_id == 0)
-		other_netdev = geth->port1->netdev;
+		other_port = geth->port1;
 	else
-		other_netdev = geth->port0->netdev;
+		other_port = geth->port0;
+	other_netdev = other_port ? other_port->netdev : NULL;
 
 	if (other_netdev && netif_running(other_netdev))
 		return -EBUSY;
@@ -1065,7 +1107,6 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 		   new_size,
 		   port->rxq_order);
 	if (other_netdev) {
-		other_port = netdev_priv(other_netdev);
 		new_size += 1 << (other_port->rxq_order + 1);
 		netdev_dbg(other_netdev, "port %d size: %d order %d\n",
 			   other_netdev->dev_id,
@@ -1076,7 +1117,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	new_order = min(15, ilog2(new_size - 1) + 1);
 	dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
 		new_size, new_order);
-	if (geth->freeq_order == new_order)
+	if (geth->freeq_ring && geth->freeq_order == new_order)
 		return 0;
 
 	spin_lock_irqsave(&geth->irq_lock, flags);
@@ -2387,8 +2428,35 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
 	return ret;
 }
 
+static void gemini_port_clear(struct gemini_ethernet_port *port)
+{
+	struct gemini_ethernet *geth = port->geth;
+
+	ASSERT_RTNL();
+
+	if (!port->id && geth->port0 == port)
+		geth->port0 = NULL;
+	else if (port->id && geth->port1 == port)
+		geth->port1 = NULL;
+	else
+		return;
+}
+
+static void gemini_ethernet_disable_irqs(struct gemini_ethernet *geth)
+{
+	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_0_REG);
+	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_1_REG);
+	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_2_REG);
+	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_3_REG);
+	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+}
+
 static void gemini_port_remove(struct gemini_ethernet_port *port)
 {
+	rtnl_lock();
+	gemini_port_clear(port);
+	rtnl_unlock();
+
 	if (port->netdev) {
 		unregister_netdev(port->netdev);
 		phy_disconnect(port->netdev->phydev);
@@ -2398,19 +2466,15 @@ static void gemini_port_remove(struct gemini_ethernet_port *port)
 
 static void gemini_ethernet_init(struct gemini_ethernet *geth)
 {
+	ASSERT_RTNL();
+
 	/* Only do this once both ports are online */
 	if (geth->initialized)
 		return;
-	if (geth->port0 && geth->port1)
-		geth->initialized = true;
-	else
+	if (!geth->port0 || !geth->port1)
 		return;
 
-	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_0_REG);
-	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_1_REG);
-	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_2_REG);
-	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_3_REG);
-	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+	gemini_ethernet_disable_irqs(geth);
 
 	/* Interrupt config:
 	 *
@@ -2442,10 +2506,20 @@ static void gemini_ethernet_init(struct gemini_ethernet *geth)
 	writel(0, geth->base + GLOBAL_HWFQ_RWPTR_REG);
 
 	geth->freeq_frag_order = DEFAULT_RX_BUF_ORDER;
-	/* This makes the queue resize on probe() so that we
-	 * set up and enable the queue IRQ. FIXME: fragile.
-	 */
-	geth->freeq_order = 1;
+	geth->initialized = true;
+}
+
+static void gemini_port_publish(struct gemini_ethernet_port *port)
+{
+	struct gemini_ethernet *geth = port->geth;
+
+	ASSERT_RTNL();
+
+	if (!port->id)
+		geth->port0 = port;
+	else
+		geth->port1 = port;
+	gemini_ethernet_init(geth);
 }
 
 static void gemini_port_save_mac_addr(struct gemini_ethernet_port *port)
@@ -2541,15 +2615,6 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	reset_control_reset(port->reset);
 	usleep_range(100, 500);
 
-	/* Assign pointer in the main state container */
-	if (!id)
-		geth->port0 = port;
-	else
-		geth->port1 = port;
-
-	/* This will just be done once both ports are up and reset */
-	gemini_ethernet_init(geth);
-
 	platform_set_drvdata(pdev, port);
 
 	/* Set up and register the netdev */
@@ -2600,17 +2665,39 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
 	if (ret)
 		goto unprepare;
 
+	if (!of_property_present(np, "phy-handle") &&
+	    !of_phy_is_fixed_link(np)) {
+		dev_info(dev, "no PHY\n");
+		goto irq_only;
+	}
+
 	ret = gmac_setup_phy(netdev);
 	if (ret) {
-		netdev_err(netdev,
-			   "PHY init failed\n");
-		goto unprepare;
+		dev_err_probe(dev, ret, "PHY init failed\n");
+		if (ret == -EPROBE_DEFER)
+			goto unprepare;
+		goto irq_only;
 	}
 
-	ret = register_netdev(netdev);
-	if (ret)
-		goto unprepare;
+	rtnl_lock();
+	ret = register_netdevice(netdev);
+	if (!ret)
+		gemini_port_publish(port);
+	rtnl_unlock();
+	if (ret) {
+		phy_disconnect(netdev->phydev);
+		dev_err(dev, "netdev registration failed: %d\n", ret);
+		goto irq_only;
+	}
+
+	return 0;
 
+irq_only:
+	dev_info(dev, "keeping port for shared IRQ\n");
+	port->netdev = NULL;
+	rtnl_lock();
+	gemini_port_publish(port);
+	rtnl_unlock();
 	return 0;
 
 unprepare:
@@ -2706,6 +2793,9 @@ static int gemini_ethernet_probe(struct platform_device *pdev)
 	spin_lock_init(&geth->irq_lock);
 	spin_lock_init(&geth->freeq_lock);
 
+	/* Quiesce firmware state before child IRQ handlers are registered. */
+	gemini_ethernet_disable_irqs(geth);
+
 	/* The children will use this */
 	platform_set_drvdata(pdev, geth);
 
@@ -2717,10 +2807,13 @@ static void gemini_ethernet_remove(struct platform_device *pdev)
 {
 	struct gemini_ethernet *geth = platform_get_drvdata(pdev);
 
+	rtnl_lock();
+	geth->initialized = false;
+	rtnl_unlock();
+
 	devm_of_platform_depopulate(&pdev->dev);
 	writel(0, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
 	geth_cleanup_freeq(geth);
-	geth->initialized = false;
 }
 
 static const struct of_device_id gemini_ethernet_of_match[] = {

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 03/14] net: ethernet: cortina: Drain free queue IRQ before resize
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 02/14] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The software free queue interrupt remains registered while both netdevs
are down. Merely masking the device source does not stop a threaded
handler which was already woken. That handler can refill the queue while
resize frees its ring and page metadata, or re-enable the source after
teardown.

The free queue interrupt is routed through port 1, but both port IRQs
register the global handler. Ignore the source on port 0, then disable the
port 1 Linux IRQ for the entire resize. disable_irq() drains hard and
threaded handlers and prevents a new thread from being woken.

After the drain, mask the device source and rebuild the queue. If setup
succeeds, re-enable the source before the Linux IRQ. On failure, keep the
source masked, clear freed queue state and restore the Linux IRQ so a later
open retries setup safely.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 4f27a48908b1..5e9dd2aea407 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1019,6 +1019,8 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	}
 
 	kfree(geth->freeq_pages);
+	geth->freeq_pages = NULL;
+	geth->num_freeq_pages = 0;
 err_freeq:
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -1059,20 +1061,37 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	}
 
 	kfree(geth->freeq_pages);
+	geth->freeq_pages = NULL;
+	geth->num_freeq_pages = 0;
 
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,
 			  geth->freeq_ring, geth->freeq_dma_base);
+	geth->freeq_ring = NULL;
+}
+
+static void geth_set_freeq_irq(struct gemini_ethernet *geth, bool enable)
+{
+	unsigned long flags;
+	u32 val;
+
+	spin_lock_irqsave(&geth->irq_lock, flags);
+	val = readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+	if (enable)
+		val |= SWFQ_EMPTY_INT_BIT;
+	else
+		val &= ~SWFQ_EMPTY_INT_BIT;
+	writel(val, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
+	spin_unlock_irqrestore(&geth->irq_lock, flags);
 }
 
 /**
  * geth_resize_freeq() - resize the software queue depth
  * @port: the port requesting the change
  *
- * This gets called at least once during probe() so the device queue gets
- * "resized" from the hardware defaults. Since both ports/net devices share
- * the same hardware queue, some synchronization between the ports is
- * needed.
+ * This is called when a port is opened or its RX ring size changes. Since
+ * both ports/net devices share the same hardware queue, some synchronization
+ * between the ports is needed.
  */
 static int geth_resize_freeq(struct gemini_ethernet_port *port)
 {
@@ -1082,8 +1101,6 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	struct net_device *other_netdev;
 	unsigned int new_size = 0;
 	unsigned int new_order;
-	unsigned long flags;
-	u32 en;
 	int ret;
 
 	ASSERT_RTNL();
@@ -1120,13 +1137,8 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	if (geth->freeq_ring && geth->freeq_order == new_order)
 		return 0;
 
-	spin_lock_irqsave(&geth->irq_lock, flags);
-
-	/* Disable the software queue IRQs */
-	en = readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
-	en &= ~SWFQ_EMPTY_INT_BIT;
-	writel(en, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
-	spin_unlock_irqrestore(&geth->irq_lock, flags);
+	disable_irq(geth->port1->irq);
+	geth_set_freeq_irq(geth, false);
 
 	/* Drop the old queue */
 	if (geth->freeq_ring)
@@ -1136,14 +1148,10 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	geth->freeq_order = new_order;
 	ret = geth_setup_freeq(geth);
 
-	/* Restart the interrupts - NOTE if this is the first resize
-	 * after probe(), this is where the interrupts get turned on
-	 * in the first place.
-	 */
-	spin_lock_irqsave(&geth->irq_lock, flags);
-	en |= SWFQ_EMPTY_INT_BIT;
-	writel(en, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
-	spin_unlock_irqrestore(&geth->irq_lock, flags);
+	/* Enable the queue interrupt only after successful setup. */
+	if (!ret)
+		geth_set_freeq_irq(geth, true);
+	enable_irq(geth->port1->irq);
 
 	return ret;
 }
@@ -2406,6 +2414,9 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
 	irqreturn_t ret = IRQ_NONE;
 	u32 val, en;
 
+	if (!port->id)
+		return IRQ_NONE;
+
 	geth = port->geth;
 	spin_lock(&geth->irq_lock);
 

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (2 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 03/14] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 05/14] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

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


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 05/14] net: ethernet: cortina: Correct free queue DMA mappings
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (3 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 06/14] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The free queue maps complete pages and splits each mapping between its
fragment descriptors. The mapping variable is advanced while filling the
descriptors and that advanced address is then saved as the page mapping.

Replacement also reads the old address after overwriting the descriptor
with the new mapping, so it unmaps the new buffer while leaving the old
mapping live.

The same reassignment leaves replacement metadata holding the new page
base while gmac_rx() still adds PAGE_SIZE before lookup. Once a page is
replaced under RX load, lookup therefore normally fails with "could not
find mapping" and drops the frame. If the resulting key matches another
page, RX can instead attach that page to the skb and drop the wrong page
reference.

Keep the page DMA base separate from the fragment iterator and remove the
invalid replacement unmap. The replaced mapping cannot be released until
its in-flight fragments have been claimed, which is handled with their
lifetime later in the series. Use the saved DMA base and PAGE_SIZE when
unwinding setup and tearing down the current queue.

Reject mappings that cannot fit in the 32-bit hardware descriptors and
derive fragment offsets from the saved DMA base instead of assuming
page-aligned DMA addresses. Snapshot the page, DMA base and offset under
the free queue lock so refill cannot replace them between lookup and use.

The locked linear scan is temporary: the following "Index free queue
fragments with XArray" patch removes it. Backport this change together
with that patch, "Preserve in-flight free queue pages" and "Recycle
claimed free queue pages", which complete the mapping lifetime and DMA
synchronization fixes.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 66984c78a7cd..5fbdd6d2cbd0 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -759,32 +759,43 @@ static int gmac_setup_rxq(struct net_device *netdev)
 	return 0;
 }
 
-static struct gmac_queue_page *
-gmac_get_queue_page(struct gemini_ethernet *geth,
-		    struct gemini_ethernet_port *port,
-		    dma_addr_t addr)
+static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
+				      dma_addr_t mapping,
+				      unsigned int *page_offs)
 {
+	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	struct gmac_queue_page *gpage;
-	dma_addr_t mapping;
+	unsigned long flags;
+	dma_addr_t page_mapping;
+	struct page *page = NULL;
 	int i;
 
-	/* Only look for even pages */
-	mapping = addr & PAGE_MASK;
-
+	spin_lock_irqsave(&geth->freeq_lock, flags);
 	if (!geth->freeq_pages) {
 		dev_err_ratelimited(geth->dev,
 				    "try to get page with no page list\n");
-		return NULL;
+		goto unlock;
 	}
 
 	/* Look up a ring buffer page from virtual mapping */
 	for (i = 0; i < geth->num_freeq_pages; i++) {
 		gpage = &geth->freeq_pages[i];
-		if (gpage->mapping == mapping)
-			return gpage;
+		if (!gpage->page || mapping < gpage->mapping)
+			continue;
+
+		page_mapping = gpage->mapping;
+		if (mapping - page_mapping > PAGE_SIZE - frag_len ||
+		    ((mapping - page_mapping) & (frag_len - 1)))
+			continue;
+
+		page = gpage->page;
+		*page_offs = mapping - page_mapping;
+		break;
 	}
 
-	return NULL;
+unlock:
+	spin_unlock_irqrestore(&geth->freeq_lock, flags);
+	return page;
 }
 
 static void gmac_cleanup_rxq(struct net_device *netdev)
@@ -792,11 +803,12 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	struct gemini_ethernet *geth = port->geth;
 	struct gmac_rxdesc *rxd = port->rxq_ring;
-	static struct gmac_queue_page *gpage;
 	struct nontoe_qhdr __iomem *qhdr;
 	void __iomem *dma_reg;
 	void __iomem *ptr_reg;
+	unsigned int page_offs;
 	dma_addr_t mapping;
+	struct page *page;
 	union dma_rwptr rw;
 	unsigned int r, w;
 
@@ -823,14 +835,13 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 		if (!mapping)
 			continue;
 
-		/* Freeq pointers are one page off */
-		gpage = gmac_get_queue_page(geth, port, mapping + PAGE_SIZE);
-		if (!gpage) {
+		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		if (!page) {
 			dev_err(geth->dev, "could not find page\n");
 			continue;
 		}
 		/* Release the RX queue reference to the page */
-		put_page(gpage->page);
+		put_page(page);
 	}
 
 	dma_free_coherent(geth->dev, sizeof(*port->rxq_ring) << port->rxq_order,
@@ -844,6 +855,7 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	struct gmac_queue_page *gpage;
 	unsigned int fpp_order;
 	unsigned int frag_len;
+	dma_addr_t page_mapping;
 	dma_addr_t mapping;
 	struct page *page;
 	int i;
@@ -853,9 +865,17 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	if (!page)
 		return NULL;
 
-	mapping = dma_map_single(geth->dev, page_address(page),
-				 PAGE_SIZE, DMA_FROM_DEVICE);
-	if (dma_mapping_error(geth->dev, mapping)) {
+	page_mapping = dma_map_single(geth->dev, page_address(page),
+				      PAGE_SIZE, DMA_FROM_DEVICE);
+	if (dma_mapping_error(geth->dev, page_mapping)) {
+		put_page(page);
+		return NULL;
+	}
+	if (page_mapping > U32_MAX - (PAGE_SIZE - 1)) {
+		dev_err_ratelimited(geth->dev,
+				    "freeq DMA mapping exceeds 32 bits\n");
+		dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
+				 DMA_FROM_DEVICE);
 		put_page(page);
 		return NULL;
 	}
@@ -868,31 +888,25 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	 */
 	frag_len = 1 << geth->freeq_frag_order; /* Usually 2048 */
 	fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	gpage = &geth->freeq_pages[pn];
+	if (gpage->page)
+		put_page(gpage->page);
+
+	/* Then put our new mapping into the page table */
+	gpage->mapping = page_mapping;
+	gpage->page = page;
+
 	freeq_entry = geth->freeq_ring + (pn << fpp_order);
 	dev_dbg(geth->dev, "allocate page %d fragment length %d fragments per page %d, freeq entry %p\n",
-		 pn, frag_len, (1 << fpp_order), freeq_entry);
+		pn, frag_len, (1 << fpp_order), freeq_entry);
+	mapping = page_mapping;
 	for (i = (1 << fpp_order); i > 0; i--) {
 		freeq_entry->word2.buf_adr = mapping;
 		freeq_entry++;
 		mapping += frag_len;
 	}
-
-	/* If the freeq entry already has a page mapped, then unmap it. */
-	gpage = &geth->freeq_pages[pn];
-	if (gpage->page) {
-		mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
-		dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
-		/* This should be the last reference to the page so it gets
-		 * released
-		 */
-		put_page(gpage->page);
-	}
-
-	/* Then put our new mapping into the page table */
-	dev_dbg(geth->dev, "page %d, DMA addr: %08x, page %p\n",
-		pn, (unsigned int)mapping, page);
-	gpage->mapping = mapping;
-	gpage->page = page;
+	dev_dbg(geth->dev, "page %d, DMA addr: %pad, page %p\n",
+		pn, &page_mapping, page);
 
 	return page;
 }
@@ -963,7 +977,6 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth, bool refill)
 static int geth_setup_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	unsigned int len = 1 << geth->freeq_order;
 	unsigned int pages = len >> fpp_order;
 	union queue_threshold qt;
@@ -1015,12 +1028,11 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 err_freeq_alloc:
 	while (pn > 0) {
 		struct gmac_queue_page *gpage;
-		dma_addr_t mapping;
 
 		--pn;
-		mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
-		dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
 		gpage = &geth->freeq_pages[pn];
+		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
+				 DMA_FROM_DEVICE);
 		put_page(gpage->page);
 	}
 
@@ -1042,7 +1054,6 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	unsigned int len = 1 << geth->freeq_order;
 	unsigned int pages = len >> fpp_order;
 	unsigned int pn;
@@ -1056,12 +1067,10 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 
 	for (pn = 0; pn < pages; pn++) {
 		struct gmac_queue_page *gpage;
-		dma_addr_t mapping;
-
-		mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
-		dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
 
 		gpage = &geth->freeq_pages[pn];
+		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
+				 DMA_FROM_DEVICE);
 		while (page_ref_count(gpage->page) > 0)
 			put_page(gpage->page);
 	}
@@ -1519,7 +1528,6 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 	unsigned int consumed = 0;
 	unsigned int frame_len, frag_len;
 	struct gmac_rxdesc *rx = NULL;
-	struct gmac_queue_page *gpage;
 	unsigned int received = 0;
 	bool dropping = port->rx_dropping;
 	union gmac_rxdesc_0 word0;
@@ -1556,8 +1564,6 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 
 		frag_len = word0.bits.buffer_size;
 		frame_len = word1.bits.byte_count;
-		page_offs = mapping & ~PAGE_MASK;
-
 		if (word3.bits32 & SOF_BIT) {
 			if (skb) {
 				napi_free_frags(&port->napi);
@@ -1576,14 +1582,12 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			goto err_drop;
 		}
 
-		/* Freeq pointers are one page off */
-		gpage = gmac_get_queue_page(geth, port, mapping + PAGE_SIZE);
-		if (!gpage) {
+		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		if (!page) {
 			dev_err_ratelimited(geth->dev,
 					    "could not find mapping\n");
 			goto err_drop;
 		}
-		page = gpage->page;
 
 		if (word3.bits32 & SOF_BIT) {
 			skb = gmac_skb_if_good_frame(port, word0, frame_len);

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 06/14] net: ethernet: cortina: Index free queue fragments with XArray
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (4 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 05/14] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 07/14] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

RX descriptors return the DMA address of the free queue fragment used by
the hardware. The driver currently recovers its page by scanning every
free queue page and comparing address ranges.

This isn't very efficient...

Instead index each fragment in an XArray using its DMA address in
fragment units.

Populate and erase the fragment index under the free queue lock. The
lookup remains serialized with refill and validates the exact fragment
address before returning the page and offset snapshot.

The per-fragment index is a prerequisite for the following
"Preserve in-flight free queue pages" fix, which keeps each mapping until
its RX descriptor is claimed. Include this patch when backporting that
fix and its subsequent recycling changes.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 5fbdd6d2cbd0..fdf8c0e2f29e 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -38,6 +38,7 @@
 #include <linux/ethtool.h>
 #include <linux/tcp.h>
 #include <linux/u64_stats_sync.h>
+#include <linux/xarray.h>
 
 #include <linux/in.h>
 #include <linux/ip.h>
@@ -167,6 +168,7 @@ struct gemini_ethernet {
 	struct gmac_rxdesc *freeq_ring;
 	dma_addr_t	freeq_dma_base;
 	struct gmac_queue_page	*freeq_pages;
+	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
@@ -759,43 +761,47 @@ static int gmac_setup_rxq(struct net_device *netdev)
 	return 0;
 }
 
+static unsigned long
+geth_freeq_mapping_index(const struct gemini_ethernet *geth,
+			 dma_addr_t mapping)
+{
+	return (unsigned long)(mapping >> geth->freeq_frag_order);
+}
+
 static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
 				      dma_addr_t mapping,
 				      unsigned int *page_offs)
 {
 	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	struct gmac_queue_page *gpage;
+	unsigned long index;
 	unsigned long flags;
 	dma_addr_t page_mapping;
-	struct page *page = NULL;
-	int i;
-
-	spin_lock_irqsave(&geth->freeq_lock, flags);
-	if (!geth->freeq_pages) {
-		dev_err_ratelimited(geth->dev,
-				    "try to get page with no page list\n");
-		goto unlock;
-	}
-
-	/* Look up a ring buffer page from virtual mapping */
-	for (i = 0; i < geth->num_freeq_pages; i++) {
-		gpage = &geth->freeq_pages[i];
-		if (!gpage->page || mapping < gpage->mapping)
-			continue;
-
-		page_mapping = gpage->mapping;
-		if (mapping - page_mapping > PAGE_SIZE - frag_len ||
-		    ((mapping - page_mapping) & (frag_len - 1)))
-			continue;
+	struct page *page;
+	bool valid;
 
-		page = gpage->page;
-		*page_offs = mapping - page_mapping;
-		break;
-	}
+	index = geth_freeq_mapping_index(geth, mapping);
 
-unlock:
+	spin_lock_irqsave(&geth->freeq_lock, flags);
+	gpage = xa_load(&geth->freeq_mappings, index);
+	if (!gpage || !gpage->page)
+		goto err_unlock;
+
+	page = gpage->page;
+	page_mapping = gpage->mapping;
+	valid = mapping >= page_mapping &&
+		mapping - page_mapping <= PAGE_SIZE - frag_len &&
+		!((mapping - page_mapping) & (frag_len - 1));
+	if (!valid)
+		goto err_unlock;
+
+	*page_offs = mapping - page_mapping;
 	spin_unlock_irqrestore(&geth->freeq_lock, flags);
 	return page;
+
+err_unlock:
+	spin_unlock_irqrestore(&geth->freeq_lock, flags);
+	return NULL;
 }
 
 static void gmac_cleanup_rxq(struct net_device *netdev)
@@ -854,12 +860,16 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	struct gmac_rxdesc *freeq_entry;
 	struct gmac_queue_page *gpage;
 	unsigned int fpp_order;
+	unsigned int fragments;
 	unsigned int frag_len;
 	dma_addr_t page_mapping;
 	dma_addr_t mapping;
 	struct page *page;
+	int ret;
 	int i;
 
+	lockdep_assert_held(&geth->freeq_lock);
+
 	/* First allocate and DMA map a single page */
 	page = alloc_page(GFP_ATOMIC);
 	if (!page)
@@ -888,9 +898,26 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	 */
 	frag_len = 1 << geth->freeq_frag_order; /* Usually 2048 */
 	fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	fragments = 1 << fpp_order;
+
 	gpage = &geth->freeq_pages[pn];
-	if (gpage->page)
+	for (i = 0; i < fragments; i++) {
+		mapping = page_mapping + i * frag_len;
+		ret = xa_insert(&geth->freeq_mappings,
+				geth_freeq_mapping_index(geth, mapping),
+				gpage, GFP_ATOMIC);
+		if (ret)
+			goto err_mappings;
+	}
+
+	if (gpage->page) {
+		for (i = 0; i < fragments; i++) {
+			mapping = gpage->mapping + i * frag_len;
+			xa_erase(&geth->freeq_mappings,
+				 geth_freeq_mapping_index(geth, mapping));
+		}
 		put_page(gpage->page);
+	}
 
 	/* Then put our new mapping into the page table */
 	gpage->mapping = page_mapping;
@@ -909,6 +936,17 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		pn, &page_mapping, page);
 
 	return page;
+
+err_mappings:
+	while (i--) {
+		mapping = page_mapping + i * frag_len;
+		xa_erase(&geth->freeq_mappings,
+			 geth_freeq_mapping_index(geth, mapping));
+	}
+	dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
+			 DMA_FROM_DEVICE);
+	put_page(page);
+	return NULL;
 }
 
 /**
@@ -981,6 +1019,8 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	unsigned int pages = len >> fpp_order;
 	union queue_threshold qt;
 	union dma_skb_size skbsz;
+	unsigned long flags;
+	struct page *page;
 	unsigned int filled;
 	unsigned int pn;
 	u16 rptr;
@@ -995,16 +1035,20 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 		goto err_freeq;
 	}
 
-	/* Allocate a mapping to page look-up index */
+	/* Allocate page metadata referenced by the mapping index */
 	geth->freeq_pages = kzalloc_objs(*geth->freeq_pages, pages);
 	if (!geth->freeq_pages)
 		goto err_freeq;
 	geth->num_freeq_pages = pages;
 
 	dev_info(geth->dev, "allocate %d pages for queue\n", pages);
-	for (pn = 0; pn < pages; pn++)
-		if (!geth_freeq_alloc_map_page(geth, pn))
+	for (pn = 0; pn < pages; pn++) {
+		spin_lock_irqsave(&geth->freeq_lock, flags);
+		page = geth_freeq_alloc_map_page(geth, pn);
+		spin_unlock_irqrestore(&geth->freeq_lock, flags);
+		if (!page)
 			goto err_freeq_alloc;
+	}
 
 	/* Match the software pointer to the retained hardware pointer. */
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
@@ -1035,6 +1079,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 				 DMA_FROM_DEVICE);
 		put_page(gpage->page);
 	}
+	xa_destroy(&geth->freeq_mappings);
 
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
@@ -1074,6 +1119,7 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 		while (page_ref_count(gpage->page) > 0)
 			put_page(gpage->page);
 	}
+	xa_destroy(&geth->freeq_mappings);
 
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
@@ -2818,6 +2864,7 @@ static int gemini_ethernet_probe(struct platform_device *pdev)
 
 	spin_lock_init(&geth->irq_lock);
 	spin_lock_init(&geth->freeq_lock);
+	xa_init(&geth->freeq_mappings);
 
 	/* Quiesce firmware state before child IRQ handlers are registered. */
 	gemini_ethernet_disable_irqs(geth);

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 07/14] net: ethernet: cortina: Preserve in-flight free queue pages
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (5 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 06/14] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 08/14] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The software free queue and the two per-port RX queues have independent
lifetimes. A free queue ring position becomes reusable once hardware has
taken its buffer address, but the resulting RX descriptor can remain
unprocessed for longer.

With the default 2K fragments, the sequence is:

1. Free queue entries 2n and 2n + 1 contain the first and second halves
   of page A.
2. Hardware consumes those entries and copies their DMA addresses into RX
   descriptors, potentially in the RX queues of different ports.
3. The free queue read pointer advances, making entries 2n and 2n + 1
   available for refill.
4. NAPI may not yet have processed the RX descriptors referring to page A,
   so their DMA-to-page association must remain valid.
5. Refilling the same free queue positions with page B must therefore not
   replace the metadata describing page A.

The driver currently indexes page metadata by free queue position. Step 5
therefore overwrites page A's association with page B. When NAPI later
processes an old descriptor containing page A's DMA address, the driver can
no longer find the mapping. This may explain long-standing reports of the
driver failing to find RX mappings.

This is not just caused by splitting a 4K page into two 2K
fragments: the metadata would also have to outlive its free queue
position with one full-page buffer per entry, but the 2K split makes
the lifetime more involved because the two halves of one page are
independently consumed and may be waiting in different port RX queues.
The page cannot be unmapped until both fragment references have been
claimed.

Keep free queue positions in descriptor units when posting pages. The
retained hardware pointer need not be aligned to the number of fragments
per page; rounding it down would place one fragment behind the hardware
read pointer and retain its mapping and reference until teardown. Wrap
individual descriptor entries instead.

Allocate page metadata slots independently of free queue positions and
track occupied slots with a bitmap. Keep each exact fragment DMA address in
the XArray until software claims its descriptor.

The pages use streaming DMA_FROM_DEVICE mappings. Synchronize each
fragment when claimed and unmap the page with DMA_ATTR_SKIP_CPU_SYNC after
both are claimed. This has no known visible effect on Gemini's FA526,
where CPU sync is currently a no-op, but follows the DMA API and avoids
resynchronizing a sibling on other implementations. During teardown,
synchronize only fragments still owned by hardware.

Give each posted fragment its own page reference. Queue and error cleanup
can then release precisely the outstanding hardware references without
dropping references held by delivered skbs.

Allocate and DMA-map each candidate page before taking the free queue
lock, then re-read the hardware pointers and publish one complete page at
a time. The old refill path reused pages by queue position and only
allocated replacements once the queued fill fell to 64 descriptors or
fewer. This change allocates replacements to fill the ring, but limits
each call to one usable ring's worth of fragments and a finite number of
iterations.
The iteration allowance covers the metadata slots and one ring of pages,
so later recycling retries remain bounded too, independently of hardware
progress.

The following "Recycle claimed free queue pages" patch restores recycling
independently of queue position. Backport both changes together with
their prerequisites, including "Index free queue fragments with XArray".

Size the metadata pool for the shared free queue and both registered RX
rings. Include that capacity in resize decisions and reuse the queue only
while the peer is running and the existing capacity is sufficient. Rebuild
with the peer down even if the geometry is unchanged, so taking both ports
down and reopening can reclaim fragments that never returned a usable RX
address. This does not reclaim unclaimed fragments while the peer runs.
Roll back rejected RX ring changes to prevent same-order ring growth from
exhausting page slots and let downsizing release surplus pages.

Reject queue geometries that cannot post one complete page before tearing
down the existing queue. Require the initial fill to populate every usable
queue entry. If mapping or metadata allocation stops the fill early,
rewind the hardware write pointer, release the partial population and fail
setup.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index fdf8c0e2f29e..1693a136d734 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -14,6 +14,7 @@
  * Gary Chen & Ch Hsu Storlink Semiconductor
  */
 #include <linux/kernel.h>
+#include <linux/bitmap.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/net.h>
@@ -21,6 +22,7 @@
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
+#include <linux/circ_buf.h>
 #include <linux/cache.h>
 #include <linux/interrupt.h>
 #include <linux/reset.h>
@@ -89,11 +91,13 @@ MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
 /**
  * struct gmac_queue_page - page buffer per-page info
  * @page: the page struct
- * @mapping: the dma address handle
+ * @mapping: DMA address of the first fragment
+ * @fragments: number of fragments not yet claimed from the hardware
  */
 struct gmac_queue_page {
 	struct page *page;
 	dma_addr_t mapping;
+	unsigned int fragments;
 };
 
 struct gmac_txq {
@@ -170,6 +174,7 @@ struct gemini_ethernet {
 	struct gmac_queue_page	*freeq_pages;
 	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
+	unsigned long	*freeq_page_bitmap;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
 
@@ -768,15 +773,32 @@ geth_freeq_mapping_index(const struct gemini_ethernet *geth,
 	return (unsigned long)(mapping >> geth->freeq_frag_order);
 }
 
-static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
-				      dma_addr_t mapping,
-				      unsigned int *page_offs)
+static int geth_freeq_alloc_slot(struct gemini_ethernet *geth)
+{
+	unsigned int slot;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = find_first_zero_bit(geth->freeq_page_bitmap,
+				   geth->num_freeq_pages);
+	if (slot == geth->num_freeq_pages)
+		return -ENOSPC;
+
+	__set_bit(slot, geth->freeq_page_bitmap);
+
+	return slot;
+}
+
+static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
+				     dma_addr_t mapping,
+				     unsigned int *page_offs)
 {
 	unsigned int frag_len = 1 << geth->freeq_frag_order;
 	struct gmac_queue_page *gpage;
 	unsigned long index;
 	unsigned long flags;
 	dma_addr_t page_mapping;
+	unsigned int slot;
 	struct page *page;
 	bool valid;
 
@@ -784,7 +806,7 @@ static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
 
 	spin_lock_irqsave(&geth->freeq_lock, flags);
 	gpage = xa_load(&geth->freeq_mappings, index);
-	if (!gpage || !gpage->page)
+	if (!gpage || !gpage->page || !gpage->fragments)
 		goto err_unlock;
 
 	page = gpage->page;
@@ -795,6 +817,21 @@ static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
 	if (!valid)
 		goto err_unlock;
 
+	dma_sync_single_range_for_cpu(geth->dev, page_mapping,
+				      mapping - page_mapping, frag_len,
+				      DMA_FROM_DEVICE);
+	xa_erase(&geth->freeq_mappings, index);
+	if (!--gpage->fragments) {
+		slot = gpage - geth->freeq_pages;
+		dma_unmap_single_attrs(geth->dev, page_mapping, PAGE_SIZE,
+				       DMA_FROM_DEVICE,
+				       DMA_ATTR_SKIP_CPU_SYNC);
+		gpage->page = NULL;
+		gpage->mapping = 0;
+		__clear_bit(slot, geth->freeq_page_bitmap);
+		put_page(page);
+	}
+
 	*page_offs = mapping - page_mapping;
 	spin_unlock_irqrestore(&geth->freeq_lock, flags);
 	return page;
@@ -841,7 +878,7 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 		if (!mapping)
 			continue;
 
-		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		page = geth_freeq_claim(geth, mapping, &page_offs);
 		if (!page) {
 			dev_err(geth->dev, "could not find page\n");
 			continue;
@@ -854,32 +891,22 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
 			  port->rxq_ring, port->rxq_dma_base);
 }
 
-static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
-					      int pn)
+static int geth_freeq_map_page(struct gemini_ethernet *geth,
+			       struct page **pagep,
+			       dma_addr_t *page_mappingp)
 {
-	struct gmac_rxdesc *freeq_entry;
-	struct gmac_queue_page *gpage;
-	unsigned int fpp_order;
-	unsigned int fragments;
-	unsigned int frag_len;
 	dma_addr_t page_mapping;
-	dma_addr_t mapping;
 	struct page *page;
-	int ret;
-	int i;
 
-	lockdep_assert_held(&geth->freeq_lock);
-
-	/* First allocate and DMA map a single page */
 	page = alloc_page(GFP_ATOMIC);
 	if (!page)
-		return NULL;
+		return -ENOMEM;
 
 	page_mapping = dma_map_single(geth->dev, page_address(page),
 				      PAGE_SIZE, DMA_FROM_DEVICE);
 	if (dma_mapping_error(geth->dev, page_mapping)) {
 		put_page(page);
-		return NULL;
+		return -ENOMEM;
 	}
 	if (page_mapping > U32_MAX - (PAGE_SIZE - 1)) {
 		dev_err_ratelimited(geth->dev,
@@ -887,9 +914,35 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
 				 DMA_FROM_DEVICE);
 		put_page(page);
-		return NULL;
+		return -EOVERFLOW;
 	}
 
+	*pagep = page;
+	*page_mappingp = page_mapping;
+
+	return 0;
+}
+
+static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
+			       struct page *page, dma_addr_t page_mapping)
+{
+	struct gmac_rxdesc *freeq_entry;
+	struct gmac_queue_page *gpage;
+	unsigned int ring_mask;
+	unsigned int fpp_order;
+	unsigned int fragments;
+	unsigned int frag_len;
+	dma_addr_t mapping;
+	int ret;
+	int slot;
+	int i;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = geth_freeq_alloc_slot(geth);
+	if (slot < 0)
+		return slot;
+
 	/* The assign the page mapping (physical address) to the buffer address
 	 * in the hardware queue. PAGE_SHIFT on ARM is 12 (1 page is 4096 bytes,
 	 * 4k), and the default RX frag order is 11 (fragments are up 20 2048
@@ -899,8 +952,11 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 	frag_len = 1 << geth->freeq_frag_order; /* Usually 2048 */
 	fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
 	fragments = 1 << fpp_order;
+	ring_mask = (1 << geth->freeq_order) - 1;
 
-	gpage = &geth->freeq_pages[pn];
+	gpage = &geth->freeq_pages[slot];
+	gpage->page = page;
+	gpage->mapping = page_mapping;
 	for (i = 0; i < fragments; i++) {
 		mapping = page_mapping + i * frag_len;
 		ret = xa_insert(&geth->freeq_mappings,
@@ -909,33 +965,22 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		if (ret)
 			goto err_mappings;
 	}
+	gpage->fragments = fragments;
+	page_ref_add(page, fragments);
 
-	if (gpage->page) {
-		for (i = 0; i < fragments; i++) {
-			mapping = gpage->mapping + i * frag_len;
-			xa_erase(&geth->freeq_mappings,
-				 geth_freeq_mapping_index(geth, mapping));
-		}
-		put_page(gpage->page);
-	}
-
-	/* Then put our new mapping into the page table */
-	gpage->mapping = page_mapping;
-	gpage->page = page;
-
-	freeq_entry = geth->freeq_ring + (pn << fpp_order);
-	dev_dbg(geth->dev, "allocate page %d fragment length %d fragments per page %d, freeq entry %p\n",
-		pn, frag_len, (1 << fpp_order), freeq_entry);
+	dev_dbg(geth->dev,
+		"post page at entry %u fragment length %u fragments per page %u\n",
+		wptr, frag_len, fragments);
 	mapping = page_mapping;
-	for (i = (1 << fpp_order); i > 0; i--) {
+	for (i = 0; i < fragments; i++) {
+		freeq_entry = geth->freeq_ring + ((wptr + i) & ring_mask);
 		freeq_entry->word2.buf_adr = mapping;
-		freeq_entry++;
 		mapping += frag_len;
 	}
-	dev_dbg(geth->dev, "page %d, DMA addr: %pad, page %p\n",
-		pn, &page_mapping, page);
+	dev_dbg(geth->dev, "DMA addr: %pad, page %p\n",
+		&page_mapping, page);
 
-	return page;
+	return 0;
 
 err_mappings:
 	while (i--) {
@@ -943,88 +988,147 @@ static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
 		xa_erase(&geth->freeq_mappings,
 			 geth_freeq_mapping_index(geth, mapping));
 	}
-	dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
-			 DMA_FROM_DEVICE);
-	put_page(page);
-	return NULL;
+	gpage->page = NULL;
+	gpage->mapping = 0;
+	__clear_bit(slot, geth->freeq_page_bitmap);
+	return ret;
 }
 
 /**
  * geth_fill_freeq() - Fill the freeq with empty fragments to use
  * @geth: the ethernet adapter
- * @refill: whether to reset the queue by filling in all freeq entries or
- * just refill it, usually the interrupt to refill the queue happens when
- * the queue is half empty.
+ *
+ * Usually the interrupt to refill the queue happens when the queue is half
+ * empty.
  */
-static unsigned int geth_fill_freeq(struct gemini_ethernet *geth, bool refill)
+static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	unsigned int fragments = 1 << fpp_order;
+	unsigned int len = 1 << geth->freeq_order;
+	unsigned int ring_mask = len - 1;
+	unsigned int remaining = geth->num_freeq_pages + (len >> fpp_order);
 	unsigned int count = 0;
-	unsigned int pn, epn;
+	unsigned int rptr, wptr;
 	unsigned long flags;
 	union dma_rwptr rw;
-	unsigned int m_pn;
+	bool space;
 
-	/* Mask for page */
-	m_pn = (1 << (geth->freeq_order - fpp_order)) - 1;
+	/* Bound retries and post at most one ring's worth of fragments. */
+	while (remaining-- && count < len - fragments) {
+		dma_addr_t page_mapping;
+		struct page *page;
+		int ret;
 
-	spin_lock_irqsave(&geth->freeq_lock, flags);
+		spin_lock_irqsave(&geth->freeq_lock, flags);
+		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
+		rptr = rw.bits.rptr & ring_mask;
+		wptr = rw.bits.wptr & ring_mask;
+		space = CIRC_SPACE(wptr, rptr, len) >= fragments;
+		spin_unlock_irqrestore(&geth->freeq_lock, flags);
+		if (!space)
+			break;
+
+		ret = geth_freeq_map_page(geth, &page, &page_mapping);
+		if (ret)
+			break;
+
+		spin_lock_irqsave(&geth->freeq_lock, flags);
+
+		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
+		rptr = rw.bits.rptr & ring_mask;
+		wptr = rw.bits.wptr & ring_mask;
+		if (CIRC_SPACE(wptr, rptr, len) < fragments) {
+			ret = -ENOSPC;
+		} else {
+			ret = geth_freeq_add_page(geth, wptr, page,
+						  page_mapping);
+			if (!ret) {
+				count += fragments;
+				wptr = (wptr + fragments) & ring_mask;
+				SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, wptr);
+			}
+		}
+
+		spin_unlock_irqrestore(&geth->freeq_lock, flags);
+
+		if (ret) {
+			dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
+					 DMA_FROM_DEVICE);
+			put_page(page);
+			break;
+		}
+	}
 
-	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;
+	return count;
+}
 
-	/* Loop over the freeq ring buffer entries */
-	while (pn != epn) {
+static void geth_freeq_release_pages(struct gemini_ethernet *geth)
+{
+	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	unsigned int frag_len = 1 << geth->freeq_frag_order;
+	unsigned int pn;
+
+	for (pn = 0; pn < geth->num_freeq_pages; pn++) {
 		struct gmac_queue_page *gpage;
+		dma_addr_t mapping;
 		struct page *page;
+		unsigned int i;
 
 		gpage = &geth->freeq_pages[pn];
-		page = gpage->page;
-
-		dev_dbg(geth->dev, "fill entry %d page ref count %d add %d refs\n",
-			pn, page_ref_count(page), 1 << fpp_order);
-
-		if (page_ref_count(page) > 1) {
-			unsigned int fl = (pn - epn) & m_pn;
+		if (!gpage->page)
+			continue;
 
-			if (fl > 64 >> fpp_order)
-				break;
+		page = gpage->page;
+		for (i = 0; i < (1 << fpp_order); i++) {
+			mapping = gpage->mapping + i * frag_len;
+			if (xa_load(&geth->freeq_mappings,
+				    geth_freeq_mapping_index(geth, mapping)) != gpage)
+				continue;
 
-			page = geth_freeq_alloc_map_page(geth, pn);
-			if (!page)
-				break;
+			dma_sync_single_range_for_cpu(geth->dev, gpage->mapping,
+						      i * frag_len, frag_len,
+						      DMA_FROM_DEVICE);
 		}
-
-		/* Add one reference per fragment in the page */
-		page_ref_add(page, 1 << fpp_order);
-		count += 1 << fpp_order;
-		pn++;
-		pn &= m_pn;
+		dma_unmap_single_attrs(geth->dev, gpage->mapping, PAGE_SIZE,
+				       DMA_FROM_DEVICE,
+				       DMA_ATTR_SKIP_CPU_SYNC);
+		while (gpage->fragments) {
+			put_page(page);
+			gpage->fragments--;
+		}
+		put_page(page);
 	}
+	xa_destroy(&geth->freeq_mappings);
+}
 
-	writew(pn << fpp_order, geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
+static unsigned int
+geth_freeq_page_slots(struct gemini_ethernet *geth, unsigned int order)
+{
+	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
+	unsigned int slots = 1 << (order - fpp_order);
 
-	spin_unlock_irqrestore(&geth->freeq_lock, flags);
+	if (geth->port0 && geth->port0->netdev)
+		slots += 1 << geth->port0->rxq_order;
+	if (geth->port1 && geth->port1->netdev)
+		slots += 1 << geth->port1->rxq_order;
 
-	return count;
+	return slots;
 }
 
 static int geth_setup_freeq(struct gemini_ethernet *geth)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
 	unsigned int len = 1 << geth->freeq_order;
-	unsigned int pages = len >> fpp_order;
+	unsigned int page_slots;
+	unsigned int expected;
 	union queue_threshold qt;
 	union dma_skb_size skbsz;
-	unsigned long flags;
-	struct page *page;
 	unsigned int filled;
-	unsigned int pn;
 	u16 rptr;
 
+	page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+
 	geth->freeq_ring = dma_alloc_coherent(geth->dev,
 		sizeof(*geth->freeq_ring) << geth->freeq_order,
 		&geth->freeq_dma_base, GFP_KERNEL);
@@ -1036,27 +1140,22 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	}
 
 	/* Allocate page metadata referenced by the mapping index */
-	geth->freeq_pages = kzalloc_objs(*geth->freeq_pages, pages);
+	geth->freeq_pages = kzalloc_objs(*geth->freeq_pages, page_slots);
 	if (!geth->freeq_pages)
 		goto err_freeq;
-	geth->num_freeq_pages = pages;
-
-	dev_info(geth->dev, "allocate %d pages for queue\n", pages);
-	for (pn = 0; pn < pages; pn++) {
-		spin_lock_irqsave(&geth->freeq_lock, flags);
-		page = geth_freeq_alloc_map_page(geth, pn);
-		spin_unlock_irqrestore(&geth->freeq_lock, flags);
-		if (!page)
-			goto err_freeq_alloc;
-	}
+	geth->freeq_page_bitmap = bitmap_zalloc(page_slots, GFP_KERNEL);
+	if (!geth->freeq_page_bitmap)
+		goto err_freeq_pages;
+	geth->num_freeq_pages = page_slots;
 
 	/* 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;
+	expected = len - (1 << fpp_order);
+	filled = geth_fill_freeq(geth);
+	if (filled != expected)
+		goto err_freeq_bitmap;
 
 	qt.bits32 = readl(geth->base + GLOBAL_QUEUE_THRESHOLD_REG);
 	qt.bits.swfq_empty = 32;
@@ -1069,18 +1168,13 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 
 	return 0;
 
-err_freeq_alloc:
-	while (pn > 0) {
-		struct gmac_queue_page *gpage;
-
-		--pn;
-		gpage = &geth->freeq_pages[pn];
-		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
-				 DMA_FROM_DEVICE);
-		put_page(gpage->page);
-	}
-	xa_destroy(&geth->freeq_mappings);
-
+err_freeq_bitmap:
+	writew(readw(geth->base + GLOBAL_SWFQ_RWPTR_REG),
+	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
+	geth_freeq_release_pages(geth);
+	bitmap_free(geth->freeq_page_bitmap);
+	geth->freeq_page_bitmap = NULL;
+err_freeq_pages:
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
@@ -1098,11 +1192,6 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
  */
 static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 {
-	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int len = 1 << geth->freeq_order;
-	unsigned int pages = len >> fpp_order;
-	unsigned int pn;
-
 	if (!geth->freeq_ring)
 		return;
 
@@ -1110,17 +1199,10 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
 	writel(0, geth->base + GLOBAL_SW_FREEQ_BASE_SIZE_REG);
 
-	for (pn = 0; pn < pages; pn++) {
-		struct gmac_queue_page *gpage;
-
-		gpage = &geth->freeq_pages[pn];
-		dma_unmap_single(geth->dev, gpage->mapping, PAGE_SIZE,
-				 DMA_FROM_DEVICE);
-		while (page_ref_count(gpage->page) > 0)
-			put_page(gpage->page);
-	}
-	xa_destroy(&geth->freeq_mappings);
+	geth_freeq_release_pages(geth);
 
+	bitmap_free(geth->freeq_page_bitmap);
+	geth->freeq_page_bitmap = NULL;
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
@@ -1160,7 +1242,9 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	struct net_device *netdev = port->netdev;
 	struct gemini_ethernet_port *other_port;
 	struct net_device *other_netdev;
+	bool other_running;
 	unsigned int new_size = 0;
+	unsigned int page_slots;
 	unsigned int new_order;
 	u16 rptr;
 	int ret;
@@ -1176,9 +1260,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	else
 		other_port = geth->port0;
 	other_netdev = other_port ? other_port->netdev : NULL;
-
-	if (other_netdev && netif_running(other_netdev))
-		return -EBUSY;
+	other_running = other_netdev && netif_running(other_netdev);
 
 	new_size = 1 << (port->rxq_order + 1);
 	netdev_dbg(netdev, "port %d size: %d order %d\n",
@@ -1200,8 +1282,19 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	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)
-		return 0;
+	if (new_order <= PAGE_SHIFT - geth->freeq_frag_order)
+		return -EINVAL;
+
+	/* Rebuild an idle queue to reclaim fragments which were never claimed. */
+	if (geth->freeq_ring && other_running) {
+		page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+		if (geth->freeq_order >= new_order &&
+		    geth->num_freeq_pages >= page_slots)
+			return 0;
+	}
+
+	if (other_running)
+		return -EBUSY;
 
 	disable_irq(geth->port1->irq);
 	geth_set_freeq_irq(geth, false);
@@ -1628,7 +1721,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			goto err_drop;
 		}
 
-		page = geth_freeq_lookup(geth, mapping, &page_offs);
+		page = geth_freeq_claim(geth, mapping, &page_offs);
 		if (!page) {
 			dev_err_ratelimited(geth->dev,
 					    "could not find mapping\n");
@@ -1725,7 +1818,7 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)
 	port->freeq_refill += freeq_consumed;
 	if (port->freeq_refill > freeq_threshold) {
 		port->freeq_refill -= freeq_threshold;
-		geth_fill_freeq(geth, true);
+		geth_fill_freeq(geth);
 	}
 
 	if (!reschedule && received < budget &&
@@ -1980,10 +2073,7 @@ static int gmac_open(struct net_device *netdev)
 	phy_start(netdev->phydev);
 
 	err = geth_resize_freeq(port);
-	/* It's fine if it's just busy, the other port has set up
-	 * the freeq in that case.
-	 */
-	if (err && (err != -EBUSY)) {
+	if (err) {
 		netdev_err(netdev, "could not resize freeq\n");
 		goto err_stop_phy;
 	}
@@ -2342,14 +2432,20 @@ static int gmac_set_ringparam(struct net_device *netdev,
 			      struct netlink_ext_ack *extack)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
+	unsigned int old_rxq_order;
 	int err = 0;
 
 	if (netif_running(netdev))
 		return -EBUSY;
 
 	if (rp->rx_pending) {
+		old_rxq_order = port->rxq_order;
 		port->rxq_order = min(15, ilog2(rp->rx_pending - 1) + 1);
 		err = geth_resize_freeq(port);
+		if (err) {
+			port->rxq_order = old_rxq_order;
+			return err;
+		}
 	}
 	if (rp->tx_pending) {
 		port->txq_order = min(15, ilog2(rp->tx_pending - 1) + 1);
@@ -2455,7 +2551,7 @@ static irqreturn_t gemini_port_irq_thread(int irq, void *data)
 
 	geth = port->geth;
 	/* The queue is half empty so refill it */
-	geth_fill_freeq(geth, true);
+	geth_fill_freeq(geth);
 
 	spin_lock_irqsave(&geth->irq_lock, flags);
 	/* ACK queue interrupt */

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 08/14] net: ethernet: cortina: Rotate free queue page allocation
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (6 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 07/14] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 09/14] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The free queue metadata bitmap currently searches for a free slot from
zero for every page allocation. Under sustained traffic this repeatedly
scans occupied low-numbered slots.

Remember the position after the most recently allocated slot and wrap the
bitmap search at its end. Reset the cursor when the bitmap is released so
the two remain consistent across failed setup and teardown. This keeps
allocation cost distributed across the metadata table.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 1693a136d734..9323e3d7af6d 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -175,6 +175,7 @@ struct gemini_ethernet {
 	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
 	unsigned long	*freeq_page_bitmap;
+	unsigned int	freeq_page_cursor;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
 
@@ -779,12 +780,20 @@ static int geth_freeq_alloc_slot(struct gemini_ethernet *geth)
 
 	lockdep_assert_held(&geth->freeq_lock);
 
-	slot = find_first_zero_bit(geth->freeq_page_bitmap,
-				   geth->num_freeq_pages);
-	if (slot == geth->num_freeq_pages)
-		return -ENOSPC;
+	slot = find_next_zero_bit(geth->freeq_page_bitmap,
+				  geth->num_freeq_pages,
+				  geth->freeq_page_cursor);
+	if (slot == geth->num_freeq_pages) {
+		slot = find_first_zero_bit(geth->freeq_page_bitmap,
+					   geth->freeq_page_cursor);
+		if (slot == geth->freeq_page_cursor)
+			return -ENOSPC;
+	}
 
 	__set_bit(slot, geth->freeq_page_bitmap);
+	geth->freeq_page_cursor = slot + 1;
+	if (geth->freeq_page_cursor == geth->num_freeq_pages)
+		geth->freeq_page_cursor = 0;
 
 	return slot;
 }
@@ -1147,6 +1156,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	if (!geth->freeq_page_bitmap)
 		goto err_freeq_pages;
 	geth->num_freeq_pages = page_slots;
+	geth->freeq_page_cursor = 0;
 
 	/* Match the software pointer to the retained hardware pointer. */
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
@@ -1178,6 +1188,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
+	geth->freeq_page_cursor = 0;
 err_freeq:
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -1206,6 +1217,7 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 	kfree(geth->freeq_pages);
 	geth->freeq_pages = NULL;
 	geth->num_freeq_pages = 0;
+	geth->freeq_page_cursor = 0;
 
 	dma_free_coherent(geth->dev,
 			  sizeof(*geth->freeq_ring) << geth->freeq_order,

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 09/14] net: ethernet: cortina: Recycle claimed free queue pages
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (7 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 08/14] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 10/14] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The preceding "Preserve in-flight free queue pages" fix releases each
mapping after its last descriptor is claimed. Refilling therefore
allocates and maps a fresh page at line rate even after the network stack
has released all references to an old page.

Keep the free queue base reference and streaming mapping after the
fragments are claimed. Track fully claimed slots in a separate bitmap and
inspect one at a time during refill. Recycle a page once its reference
count returns to one. If the stack still owns fragments, unmap the page
and relinquish the base reference before allocating its replacement.

Reject pfmemalloc pages when recycling so emergency-reserve pages return
to the allocator instead of remaining pinned in the free queue.

This prevents retained pages from exhausting the finite metadata table
and bounds the IRQ-disabled search to a bitmap lookup and one reference
count check. It retains the existing free queue allocator without
introducing a page pool.

Recheck the recycle bitmap on each refill iteration and again after mapping
a candidate page. If another RX path retires a page concurrently, release
the candidate and return to the recycler before consuming another metadata
slot. Retry recycling immediately when a retained page is discarded so
other pending entries are examined before allocating a replacement. This
avoids stopping refill while recyclable slots are pending.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 9323e3d7af6d..2613f09a8f71 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -175,7 +175,9 @@ struct gemini_ethernet {
 	struct xarray	freeq_mappings;
 	unsigned int	num_freeq_pages;
 	unsigned long	*freeq_page_bitmap;
+	unsigned long	*freeq_recycle_bitmap;
 	unsigned int	freeq_page_cursor;
+	unsigned int	freeq_recycle_pending;
 	spinlock_t	freeq_lock; /* Locks queue from reentrance */
 };
 
@@ -798,6 +800,34 @@ static int geth_freeq_alloc_slot(struct gemini_ethernet *geth)
 	return slot;
 }
 
+static int geth_freeq_recycle_slot(struct gemini_ethernet *geth)
+{
+	unsigned int slot = geth->freeq_page_cursor;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	if (!geth->freeq_recycle_pending)
+		return -ENOSPC;
+
+	slot = find_next_bit(geth->freeq_recycle_bitmap,
+			     geth->num_freeq_pages,
+			     geth->freeq_page_cursor);
+	if (slot == geth->num_freeq_pages) {
+		slot = find_first_bit(geth->freeq_recycle_bitmap,
+				      geth->freeq_page_cursor);
+		if (slot == geth->freeq_page_cursor)
+			return -ENOSPC;
+	}
+
+	__clear_bit(slot, geth->freeq_recycle_bitmap);
+	geth->freeq_page_cursor = slot + 1;
+	if (geth->freeq_page_cursor == geth->num_freeq_pages)
+		geth->freeq_page_cursor = 0;
+	geth->freeq_recycle_pending--;
+
+	return slot;
+}
+
 static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
 				     dma_addr_t mapping,
 				     unsigned int *page_offs)
@@ -807,8 +837,8 @@ static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
 	unsigned long index;
 	unsigned long flags;
 	dma_addr_t page_mapping;
-	unsigned int slot;
 	struct page *page;
+	unsigned int slot;
 	bool valid;
 
 	index = geth_freeq_mapping_index(geth, mapping);
@@ -832,13 +862,8 @@ static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
 	xa_erase(&geth->freeq_mappings, index);
 	if (!--gpage->fragments) {
 		slot = gpage - geth->freeq_pages;
-		dma_unmap_single_attrs(geth->dev, page_mapping, PAGE_SIZE,
-				       DMA_FROM_DEVICE,
-				       DMA_ATTR_SKIP_CPU_SYNC);
-		gpage->page = NULL;
-		gpage->mapping = 0;
-		__clear_bit(slot, geth->freeq_page_bitmap);
-		put_page(page);
+		__set_bit(slot, geth->freeq_recycle_bitmap);
+		geth->freeq_recycle_pending++;
 	}
 
 	*page_offs = mapping - page_mapping;
@@ -932,26 +957,23 @@ static int geth_freeq_map_page(struct gemini_ethernet *geth,
 	return 0;
 }
 
-static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
-			       struct page *page, dma_addr_t page_mapping)
+static int geth_freeq_post_page(struct gemini_ethernet *geth,
+				unsigned int wptr,
+				struct gmac_queue_page *gpage, bool recycle)
 {
 	struct gmac_rxdesc *freeq_entry;
-	struct gmac_queue_page *gpage;
 	unsigned int ring_mask;
 	unsigned int fpp_order;
 	unsigned int fragments;
 	unsigned int frag_len;
+	dma_addr_t page_mapping = gpage->mapping;
 	dma_addr_t mapping;
+	struct page *page = gpage->page;
 	int ret;
-	int slot;
 	int i;
 
 	lockdep_assert_held(&geth->freeq_lock);
 
-	slot = geth_freeq_alloc_slot(geth);
-	if (slot < 0)
-		return slot;
-
 	/* The assign the page mapping (physical address) to the buffer address
 	 * in the hardware queue. PAGE_SHIFT on ARM is 12 (1 page is 4096 bytes,
 	 * 4k), and the default RX frag order is 11 (fragments are up 20 2048
@@ -963,9 +985,6 @@ static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
 	fragments = 1 << fpp_order;
 	ring_mask = (1 << geth->freeq_order) - 1;
 
-	gpage = &geth->freeq_pages[slot];
-	gpage->page = page;
-	gpage->mapping = page_mapping;
 	for (i = 0; i < fragments; i++) {
 		mapping = page_mapping + i * frag_len;
 		ret = xa_insert(&geth->freeq_mappings,
@@ -974,6 +993,9 @@ static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
 		if (ret)
 			goto err_mappings;
 	}
+	if (recycle)
+		dma_sync_single_for_device(geth->dev, page_mapping, PAGE_SIZE,
+					   DMA_FROM_DEVICE);
 	gpage->fragments = fragments;
 	page_ref_add(page, fragments);
 
@@ -997,9 +1019,70 @@ static int geth_freeq_add_page(struct gemini_ethernet *geth, unsigned int wptr,
 		xa_erase(&geth->freeq_mappings,
 			 geth_freeq_mapping_index(geth, mapping));
 	}
-	gpage->page = NULL;
-	gpage->mapping = 0;
-	__clear_bit(slot, geth->freeq_page_bitmap);
+	return ret;
+}
+
+static int geth_freeq_add_page(struct gemini_ethernet *geth,
+			       unsigned int wptr,
+			       struct page *page, dma_addr_t page_mapping)
+{
+	struct gmac_queue_page *gpage;
+	int ret;
+	int slot;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = geth_freeq_alloc_slot(geth);
+	if (slot < 0)
+		return slot;
+
+	gpage = &geth->freeq_pages[slot];
+	gpage->page = page;
+	gpage->mapping = page_mapping;
+	ret = geth_freeq_post_page(geth, wptr, gpage, false);
+	if (ret) {
+		gpage->page = NULL;
+		gpage->mapping = 0;
+		__clear_bit(slot, geth->freeq_page_bitmap);
+	}
+
+	return ret;
+}
+
+static int geth_freeq_recycle_page(struct gemini_ethernet *geth,
+				   unsigned int wptr)
+{
+	struct gmac_queue_page *gpage;
+	struct page *page;
+	int ret;
+	int slot;
+
+	lockdep_assert_held(&geth->freeq_lock);
+
+	slot = geth_freeq_recycle_slot(geth);
+	if (slot < 0)
+		return slot;
+
+	gpage = &geth->freeq_pages[slot];
+	if (page_ref_count(gpage->page) > 1 ||
+	    !dev_page_is_reusable(gpage->page)) {
+		page = gpage->page;
+		dma_unmap_single_attrs(geth->dev, gpage->mapping, PAGE_SIZE,
+				       DMA_FROM_DEVICE,
+				       DMA_ATTR_SKIP_CPU_SYNC);
+		gpage->page = NULL;
+		gpage->mapping = 0;
+		__clear_bit(slot, geth->freeq_page_bitmap);
+		put_page(page);
+		return -EAGAIN;
+	}
+
+	ret = geth_freeq_post_page(geth, wptr, gpage, true);
+	if (ret) {
+		__set_bit(slot, geth->freeq_recycle_bitmap);
+		geth->freeq_recycle_pending++;
+	}
+
 	return ret;
 }
 
@@ -1034,9 +1117,22 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		rptr = rw.bits.rptr & ring_mask;
 		wptr = rw.bits.wptr & ring_mask;
 		space = CIRC_SPACE(wptr, rptr, len) >= fragments;
+		ret = -ENOSPC;
+		if (space && geth->freeq_recycle_pending) {
+			ret = geth_freeq_recycle_page(geth, wptr);
+			if (!ret) {
+				count += fragments;
+				wptr = (wptr + fragments) & ring_mask;
+				SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, wptr);
+			}
+		}
 		spin_unlock_irqrestore(&geth->freeq_lock, flags);
 		if (!space)
 			break;
+		if (!ret || ret == -EAGAIN)
+			continue;
+		if (ret != -ENOSPC)
+			break;
 
 		ret = geth_freeq_map_page(geth, &page, &page_mapping);
 		if (ret)
@@ -1049,6 +1145,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		wptr = rw.bits.wptr & ring_mask;
 		if (CIRC_SPACE(wptr, rptr, len) < fragments) {
 			ret = -ENOSPC;
+		} else if (geth->freeq_recycle_pending) {
+			ret = -EAGAIN;
 		} else {
 			ret = geth_freeq_add_page(geth, wptr, page,
 						  page_mapping);
@@ -1065,6 +1163,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 			dma_unmap_single(geth->dev, page_mapping, PAGE_SIZE,
 					 DMA_FROM_DEVICE);
 			put_page(page);
+			if (ret == -EAGAIN)
+				continue;
 			break;
 		}
 	}
@@ -1109,6 +1209,7 @@ static void geth_freeq_release_pages(struct gemini_ethernet *geth)
 		put_page(page);
 	}
 	xa_destroy(&geth->freeq_mappings);
+	geth->freeq_recycle_pending = 0;
 }
 
 static unsigned int
@@ -1155,6 +1256,9 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	geth->freeq_page_bitmap = bitmap_zalloc(page_slots, GFP_KERNEL);
 	if (!geth->freeq_page_bitmap)
 		goto err_freeq_pages;
+	geth->freeq_recycle_bitmap = bitmap_zalloc(page_slots, GFP_KERNEL);
+	if (!geth->freeq_recycle_bitmap)
+		goto err_freeq_page_bitmap;
 	geth->num_freeq_pages = page_slots;
 	geth->freeq_page_cursor = 0;
 
@@ -1182,6 +1286,9 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	writew(readw(geth->base + GLOBAL_SWFQ_RWPTR_REG),
 	       geth->base + GLOBAL_SWFQ_RWPTR_REG + 2);
 	geth_freeq_release_pages(geth);
+	bitmap_free(geth->freeq_recycle_bitmap);
+	geth->freeq_recycle_bitmap = NULL;
+err_freeq_page_bitmap:
 	bitmap_free(geth->freeq_page_bitmap);
 	geth->freeq_page_bitmap = NULL;
 err_freeq_pages:
@@ -1212,6 +1319,8 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
 
 	geth_freeq_release_pages(geth);
 
+	bitmap_free(geth->freeq_recycle_bitmap);
+	geth->freeq_recycle_bitmap = NULL;
 	bitmap_free(geth->freeq_page_bitmap);
 	geth->freeq_page_bitmap = NULL;
 	kfree(geth->freeq_pages);

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 10/14] net: ethernet: cortina: Separate RX buffer capacity from free queue size
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (8 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 09/14] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

Containing a retained hardware read pointer can force an order-15 free
queue even when the configured RX rings need far fewer buffers. Filling
that descriptor ring requires nearly 64 MiB of pages on systems with
32 to 128 MiB of RAM. Allocation failure persists across retries because
the stopped DMA engine cannot advance the pointer.

Keep the descriptor geometry required by the retained pointer, but size
the RX buffer budget from the configured port rings. Bound the posted
occupancy and refill work by that budget, including after dropping the
free queue lock to allocate a page. Size page metadata and the NAPI refill
threshold from the same budget.

For a retained pointer of 16384 and a requested buffer order of 10, this
keeps the 512 KiB descriptor ring but posts 2044 KiB of RX pages instead
of 65532 KiB. No hardware pointer-reset behaviour is assumed.

Found by review and checked with a ring-geometry model covering every
supported retained pointer and buffer order.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 2613f09a8f71..8431f0a2e34a 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -168,6 +168,7 @@ struct gemini_ethernet {
 
 	spinlock_t	irq_lock; /* Locks IRQ-related registers */
 	unsigned int	freeq_order;
+	unsigned int	freeq_buf_order; /* RX buffer budget, independent of ring size */
 	unsigned int	freeq_frag_order;
 	struct gmac_rxdesc *freeq_ring;
 	dma_addr_t	freeq_dma_base;
@@ -1099,15 +1100,17 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 	unsigned int fragments = 1 << fpp_order;
 	unsigned int len = 1 << geth->freeq_order;
 	unsigned int ring_mask = len - 1;
-	unsigned int remaining = geth->num_freeq_pages + (len >> fpp_order);
+	unsigned int buf_len = 1 << geth->freeq_buf_order;
+	unsigned int capacity = buf_len - fragments;
+	unsigned int remaining = geth->num_freeq_pages + (buf_len >> fpp_order);
 	unsigned int count = 0;
 	unsigned int rptr, wptr;
 	unsigned long flags;
 	union dma_rwptr rw;
 	bool space;
 
-	/* Bound retries and post at most one ring's worth of fragments. */
-	while (remaining-- && count < len - fragments) {
+	/* Bound retries and post at most one buffer budget per refill. */
+	while (remaining-- && count < capacity) {
 		dma_addr_t page_mapping;
 		struct page *page;
 		int ret;
@@ -1116,7 +1119,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 		rptr = rw.bits.rptr & ring_mask;
 		wptr = rw.bits.wptr & ring_mask;
-		space = CIRC_SPACE(wptr, rptr, len) >= fragments;
+		space = CIRC_SPACE(wptr, rptr, len) >= fragments &&
+			CIRC_CNT(wptr, rptr, len) <= capacity - fragments;
 		ret = -ENOSPC;
 		if (space && geth->freeq_recycle_pending) {
 			ret = geth_freeq_recycle_page(geth, wptr);
@@ -1143,7 +1147,8 @@ static unsigned int geth_fill_freeq(struct gemini_ethernet *geth)
 		rw.bits32 = readl(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 		rptr = rw.bits.rptr & ring_mask;
 		wptr = rw.bits.wptr & ring_mask;
-		if (CIRC_SPACE(wptr, rptr, len) < fragments) {
+		if (CIRC_SPACE(wptr, rptr, len) < fragments ||
+		    CIRC_CNT(wptr, rptr, len) > capacity - fragments) {
 			ret = -ENOSPC;
 		} else if (geth->freeq_recycle_pending) {
 			ret = -EAGAIN;
@@ -1213,10 +1218,10 @@ static void geth_freeq_release_pages(struct gemini_ethernet *geth)
 }
 
 static unsigned int
-geth_freeq_page_slots(struct gemini_ethernet *geth, unsigned int order)
+geth_freeq_page_slots(struct gemini_ethernet *geth, unsigned int buf_order)
 {
 	unsigned int fpp_order = PAGE_SHIFT - geth->freeq_frag_order;
-	unsigned int slots = 1 << (order - fpp_order);
+	unsigned int slots = 1 << (buf_order - fpp_order);
 
 	if (geth->port0 && geth->port0->netdev)
 		slots += 1 << geth->port0->rxq_order;
@@ -1237,7 +1242,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	unsigned int filled;
 	u16 rptr;
 
-	page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+	page_slots = geth_freeq_page_slots(geth, geth->freeq_buf_order);
 
 	geth->freeq_ring = dma_alloc_coherent(geth->dev,
 		sizeof(*geth->freeq_ring) << geth->freeq_order,
@@ -1266,7 +1271,7 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
 	rptr = GET_RPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG);
 	SET_WPTR(geth->base + GLOBAL_SWFQ_RWPTR_REG, rptr & (len - 1));
 
-	expected = len - (1 << fpp_order);
+	expected = (1 << geth->freeq_buf_order) - (1 << fpp_order);
 	filled = geth_fill_freeq(geth);
 	if (filled != expected)
 		goto err_freeq_bitmap;
@@ -1367,6 +1372,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 	unsigned int new_size = 0;
 	unsigned int page_slots;
 	unsigned int new_order;
+	unsigned int buf_order;
 	u16 rptr;
 	int ret;
 
@@ -1396,20 +1402,23 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 			   other_port->rxq_order);
 	}
 
-	new_order = min(15, ilog2(new_size - 1) + 1);
+	buf_order = min(15, ilog2(new_size - 1) + 1);
+	if (buf_order <= PAGE_SHIFT - geth->freeq_frag_order)
+		return -EINVAL;
+
 	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));
+	/* Contain the retained pointer without increasing RX buffer memory. */
+	new_order = max_t(unsigned int, buf_order, fls(rptr));
 	dev_dbg(geth->dev, "set shared queue to size %d order %d\n",
 		new_size, new_order);
-	if (new_order <= PAGE_SHIFT - geth->freeq_frag_order)
-		return -EINVAL;
 
 	/* Rebuild an idle queue to reclaim fragments which were never claimed. */
 	if (geth->freeq_ring && other_running) {
-		page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
+		page_slots = geth_freeq_page_slots(geth, buf_order);
 		if (geth->freeq_order >= new_order &&
+		    geth->freeq_buf_order >= buf_order &&
 		    geth->num_freeq_pages >= page_slots)
 			return 0;
 	}
@@ -1426,6 +1435,7 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
 
 	/* Allocate a new queue with the desired order */
 	geth->freeq_order = new_order;
+	geth->freeq_buf_order = buf_order;
 	ret = geth_setup_freeq(geth);
 
 	/* Enable the queue interrupt only after successful setup. */
@@ -1927,7 +1937,7 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)
 	unsigned int received;
 	bool reschedule;
 
-	freeq_threshold = 1 << (geth->freeq_order - 1);
+	freeq_threshold = 1 << (geth->freeq_buf_order - 1);
 	u64_stats_update_begin(&port->rx_stats_syncp);
 
 	received = gmac_rx(napi->dev, budget, &freeq_consumed, &reschedule);

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (9 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 10/14] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 12/14] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

RX descriptor lengths are used to adjust the page offset and populate skb
fragments without checking that the resulting range remains inside the
posted free queue fragment. A zero-length descriptor is logged but is still
appended.

The backing page is larger than the default 2 KiB DMA fragment, so checking
only the page boundary would allow a malformed descriptor for the first
half of a page to consume data from the sibling fragment. That fragment may
still be owned by the device.

Reject a short initial fragment before applying NET_IP_ALIGN. Validate the
final fragment length derived from the total frame byte count, rejecting
underflow and ranges extending beyond either the DMA fragment or the page.

Drop zero-length non-final descriptors. If an EOF descriptor carries no new
data after earlier descriptors completed the frame, release its unused page
reference and pass the assembled skb to GRO. Check this case before the
fragment limit so an empty EOF can terminate a full fragment array.

Correct the copied buffer_size comment to match the Gemini manual, which
defines it as the transfer buffer size associated with the descriptor.
Require the final frame length to cover an Ethernet frame so a malformed
chain cannot pass a short skb to GRO. Account descriptor inconsistencies as
drops rather than wire length errors.

The issue was found by inspecting the descriptor arithmetic and validated
against the Gemini receive descriptor definitions. The series was tested on
a D-Link DIR-685 with media playback and ksmbd transfers under ping load.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/net/ethernet/cortina/gemini.c | 42 +++++++++++++++++++++++++++--------
 drivers/net/ethernet/cortina/gemini.h |  2 +-
 2 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 8431f0a2e34a..fe23ef8be9e5 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1790,6 +1790,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
 	unsigned short m = (1 << port->rxq_order) - 1;
 	struct gemini_ethernet *geth = port->geth;
+	unsigned int freeq_frag_len = 1 << geth->freeq_frag_order;
 	void __iomem *ptr_reg = port->rxq_rwptr;
 	unsigned int frag_nr = port->rx_frag_nr;
 	struct sk_buff *skb = port->rx_skb;
@@ -1864,6 +1865,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			if (!skb)
 				goto err_drop;
 
+			if (frag_len < NET_IP_ALIGN)
+				goto err_drop;
+
 			page_offs += NET_IP_ALIGN;
 			frag_len -= NET_IP_ALIGN;
 			frag_nr = 0;
@@ -1872,15 +1876,33 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 			goto err_drop;
 		}
 
-		if (word3.bits32 & EOF_BIT)
+		if (word3.bits32 & EOF_BIT) {
+			if (frame_len < ETH_ZLEN ||
+			    frame_len < skb->len)
+				goto err_drop;
 			frag_len = frame_len - skb->len;
+		}
+
+		if (!frag_len) {
+			if (word3.bits32 & EOF_BIT) {
+				put_page(page);
+				page = NULL;
+				goto complete_frame;
+			}
+
+			if (net_ratelimit())
+				netdev_err(netdev,
+					   "Received fragment with len = 0\n");
+			goto err_drop;
+		}
 
 		/* append page frag to skb */
 		if (frag_nr == MAX_SKB_FRAGS)
 			goto err_drop;
-
-		if (frag_len == 0 && net_ratelimit())
-			netdev_err(netdev, "Received fragment with len = 0\n");
+		if (frag_len > freeq_frag_len -
+			       (page_offs & (freeq_frag_len - 1)) ||
+		    frag_len > PAGE_SIZE - page_offs)
+			goto err_drop;
 
 		skb_fill_page_desc(skb, frag_nr, page, page_offs, frag_len);
 		skb->len += frag_len;
@@ -1888,11 +1910,13 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 		skb->truesize += frag_len;
 		frag_nr++;
 
-		if (word3.bits32 & EOF_BIT) {
-			napi_gro_frags(&port->napi);
-			skb = NULL;
-			frag_nr = 0;
-		}
+		if (!(word3.bits32 & EOF_BIT))
+			goto next_desc;
+
+complete_frame:
+		napi_gro_frags(&port->napi);
+		skb = NULL;
+		frag_nr = 0;
 		goto next_desc;
 
 err_drop:
diff --git a/drivers/net/ethernet/cortina/gemini.h b/drivers/net/ethernet/cortina/gemini.h
index d359c633c5de..43006fe44c9f 100644
--- a/drivers/net/ethernet/cortina/gemini.h
+++ b/drivers/net/ethernet/cortina/gemini.h
@@ -519,7 +519,7 @@ struct gmac_txdesc {
 union gmac_rxdesc_0 {
 	unsigned int bits32;
 	struct bit_8060 {
-		/* bit 15:0 number of descriptors used for the current frame */
+		/* bit 15:0 transfer buffer size for this descriptor */
 		unsigned int buffer_size:16;
 		/* bit 21:16 number of descriptors used for the current frame */
 		unsigned int desc_count:6;

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 12/14] net: ethernet: cortina: Account RX buffer size in truesize
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (10 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 13/14] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
  2026-11-20 17:29 ` [PATCH net-next v9 14/14] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

gmac_rx() charges only the received payload length for each page fragment
attached to an skb. Each fragment pins a complete free queue DMA buffer, so
short packets understate their memory use to GRO and socket accounting.

Charge the full posted fragment size for every attached fragment. The skb
already accounts for its own head separately.

The issue was found by reviewing the RX fragment accounting. The series was
tested on a D-Link DIR-685 with media playback and ksmbd transfers under
ping load.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index fe23ef8be9e5..5f8f220ad9d7 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -1907,7 +1907,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
 		skb_fill_page_desc(skb, frag_nr, page, page_offs, frag_len);
 		skb->len += frag_len;
 		skb->data_len += frag_len;
-		skb->truesize += frag_len;
+		skb->truesize += freeq_frag_len;
 		frag_nr++;
 
 		if (!(word3.bits32 & EOF_BIT))

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 13/14] net: ethernet: cortina: Release partial RX frames on stop
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (11 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 12/14] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  2026-11-24 18:29   ` netdev-bot+sashiko
  2026-11-20 17:29 ` [PATCH net-next v9 14/14] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
  13 siblings, 1 reply; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

A NAPI poll can retain a partially assembled frame across invocations. The
stop path clears port->rx_skb without freeing the skb retained in
napi->skb. If the interface is reopened, napi_get_frags() returns that
stale skb. The next frame overwrites its fragment array from index zero
while len and data_len still include the partial frame.

This can lose page references belonging to the old fragments or pass an
skb with inconsistent fragment accounting to GRO. If the interface is
removed without reopening, NAPI teardown eventually frees the stale skb.

Free a pending fragment skb after disabling NAPI and before clearing the
saved RX state. Count the discarded frame as dropped under the RX
statistics sequence counter. Use the irqsave update helpers because
ndo_stop runs in preemptible process context while 32-bit statistics
writers must not be preempted.

The issue was found by inspecting the partial frame lifetime and statistics
writer contexts. The series was tested on a D-Link DIR-685 with media
playback and ksmbd transfers under ping load.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 5f8f220ad9d7..3d121eec8873 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -2269,12 +2269,19 @@ static int gmac_open(struct net_device *netdev)
 static int gmac_stop(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
+	unsigned long flags;
 
 	hrtimer_cancel(&port->rx_coalesce_timer);
 	netif_tx_stop_all_queues(netdev);
 	gmac_disable_tx_rx(netdev);
 	gmac_stop_dma(port);
 	napi_disable(&port->napi);
+	if (port->rx_skb) {
+		napi_free_frags(&port->napi);
+		flags = u64_stats_update_begin_irqsave(&port->rx_stats_syncp);
+		port->stats.rx_dropped++;
+		u64_stats_update_end_irqrestore(&port->rx_stats_syncp, flags);
+	}
 	port->rx_skb = NULL;
 	port->rx_frag_nr = 0;
 	port->rx_dropping = false;

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH net-next v9 14/14] net: ethernet: cortina: Scale Gemini RX queues to system memory
  2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
                   ` (12 preceding siblings ...)
  2026-11-20 17:29 ` [PATCH net-next v9 13/14] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
@ 2026-11-20 17:29 ` Linus Walleij
  13 siblings, 0 replies; 24+ messages in thread
From: Linus Walleij @ 2026-11-20 17:29 UTC (permalink / raw)
  To: Hans Ulli Kroll, Andrew Lunn, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Michał Mirosław, Myeonghun Pak,
	Eric Dumazet
  Cc: netdev, Linus Walleij

The default RX queues contain 512 descriptors per port. The shared
software free queue is sized at twice their combined capacity, requiring
4 MiB of page fragments even on Gemini systems with only 32 or 64 MiB of
RAM.

Choose smaller default RX queues on memory-constrained systems. Use 256
descriptors per port and a 2 MiB free queue with at most 64 MiB of RAM,
and 128 descriptors per port with a 1 MiB free queue with at most 32 MiB.
Keep the existing defaults on systems with more memory.

This preserves the existing relationship between RX descriptor capacity
and the free queue. Users can still override the defaults with ethtool.

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

diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
index 3d121eec8873..ae59970e0f82 100644
--- a/drivers/net/ethernet/cortina/gemini.c
+++ b/drivers/net/ethernet/cortina/gemini.c
@@ -16,6 +16,7 @@
 #include <linux/kernel.h>
 #include <linux/bitmap.h>
 #include <linux/init.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/net.h>
 #include <linux/platform_device.h>
@@ -37,6 +38,7 @@
 #include <linux/skbuff.h>
 #include <linux/phy.h>
 #include <linux/crc32.h>
+#include <linux/sizes.h>
 #include <linux/ethtool.h>
 #include <linux/tcp.h>
 #include <linux/u64_stats_sync.h>
@@ -509,6 +511,17 @@ static int gmac_pick_rx_max_len(unsigned int max_l3_len)
 	return -1;
 }
 
+static unsigned int gmac_pick_rxq_order(void)
+{
+	if (totalram_pages() <= (SZ_32M >> PAGE_SHIFT))
+		return DEFAULT_GMAC_RXQ_ORDER - 2;
+
+	if (totalram_pages() <= (SZ_64M >> PAGE_SHIFT))
+		return DEFAULT_GMAC_RXQ_ORDER - 1;
+
+	return DEFAULT_GMAC_RXQ_ORDER;
+}
+
 static int gmac_init(struct net_device *netdev)
 {
 	struct gemini_ethernet_port *port = netdev_priv(netdev);
@@ -577,7 +590,7 @@ static int gmac_init(struct net_device *netdev)
 	writel(sw_weigh.bits32,
 	       port->dma_base + GMAC_TX_WEIGHTING_CTRL_1_REG);
 
-	port->rxq_order = DEFAULT_GMAC_RXQ_ORDER;
+	port->rxq_order = gmac_pick_rxq_order();
 	port->txq_order = DEFAULT_GMAC_TXQ_ORDER;
 	port->rx_coalesce_nsecs = DEFAULT_RX_COALESCE_NSECS;
 

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned
  2026-11-20 17:29 ` [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

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

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 02/14] net: ethernet: cortina: Keep ports bound for shared IRQ
  2026-11-20 17:29 ` [PATCH net-next v9 02/14] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In the commit "net: ethernet: cortina: Keep ports bound for
  shared IRQ", gmac_setup_phy()…
- [Low] The commit "net: ethernet: cortina: Keep ports bound for shared
  IRQ" fixes user-visible bugs on in-tree boards but has no Fixes: tag…

--

net: ethernet: cortina: Keep ports bound for shared IRQ

This patch keeps Gemini ethernet child ports bound as IRQ-only ports when
no PHY is described or PHY setup fails. That keeps the shared free queue
interrupt routed through port 1 available. Probe is deferred until
referenced PHYs register, and ports are published to the parent under
RTNL only once their setup is complete.

> The software free queue interrupt is routed through port 1 even on
> boards which only connect a PHY to port 0. Since PHY setup was moved
> into probe, the PHY-less port fails to bind and releases the threaded
> handler needed by the shared queue.
>
> Publishing the port before PHY setup also leaves a dangling parent pointer
> when probe fails and devres frees the netdev private data. Opening the
> sibling can then dereference freed memory.

[Severity: Low]
This describes a use-after-free and a lost SWFQ interrupt handler. Both
can happen on in-tree boards such as gemini-verbatim-s08v1901-d1.dts,
where ethernet-port@1 has no phy-mode and no phy-handle.

Before this patch, gemini_ethernet_port_probe() set geth->port1 before
gmac_setup_phy() failed with -ENODEV. Devres then freed the port, and
opening eth0 dereferenced the stale pointer in geth_resize_freeq():

    other_netdev = geth->port1->netdev;

Should this have a Fixes: tag and Cc: stable so stable backporters pick
it up?

The change behind "Since PHY setup was moved into probe" looks like
3e813d61401a ("net: gemini: Clean up phy registration"). The ordering
that leaves the dangling pointer goes back to 4d5ae32f5e1e ("net:
ethernet: Add a driver for Gemini gigabit ethernet").

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index f198e535f1a00..4f27a48908b1a 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -359,18 +361,51 @@ static void gmac_adjust_link(struct net_device *netdev)

[ ... ]

> +	} else {
> +		phy_np = of_parse_phandle(dev->of_node, "phy-handle", 0);
> +		if (!phy_np)
> +			return -ENODEV;
> +	}
> +
> +	phy = of_phy_find_device(phy_np);
> +	of_node_put(phy_np);
>  	if (!phy)
> -		return -ENODEV;
> +		return -EPROBE_DEFER;

[Severity: Medium]
Can this defer forever when the phy-handle target never gets a
phy_device? of_phy_find_device() returns NULL both for a PHY that is
slow to appear and for one that never will. Some examples of the second
case:

  - the PHY node referenced by phy-handle has status = "disabled", and
    of_mdiobus_register() only walks available children
  - the PHY does not answer at its address, so of_mdiobus_register()
    logs "MDIO device at address %d is missing." and skips it
  - the MDIO bus driver (such as mdio-gpio) is not built

In gemini_ethernet_port_probe(), a deferral skips the IRQ-only fallback:

	ret = gmac_setup_phy(netdev);
	if (ret) {
		dev_err_probe(dev, ret, "PHY init failed\n");
		if (ret == -EPROBE_DEFER)
			goto unprepare;
		goto irq_only;
	}

so gemini_port_publish() never runs for this port. fw_devlink does not
parse phy-handle, and the deferred probe timeout does not override a
driver's own -EPROBE_DEFER. The port is therefore retried indefinitely.

Opening the sibling then fails every time:

gmac_open()
  geth_resize_freeq()
    if (!geth->initialized || !geth->port0 || !geth->port1)
        return -ENODEV;

gmac_open() treats this as fatal ("could not resize freeq", goto
err_stop_phy), so the sibling interface never comes up.

The commit message says ports stay bound when PHY setup "fails
permanently, so an unusable interface does not disable its sibling".
Isn't a PHY that never registers that kind of permanent failure? In
this case the unusable port still disables its sibling.

Could something like driver_deferred_probe_check_state(), or a fallback
to irq_only after the deferred probe timeout, handle the permanent case
here? The behaviour looks the same at the end of the series:
gmac_setup_phy() still returns -EPROBE_DEFER and the probe still takes
goto unprepare.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 03/14] net: ethernet: cortina: Drain free queue IRQ before resize
  2026-11-20 17:29 ` [PATCH net-next v9 03/14] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

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] This patch fixes a real memory-safety race but has no Fixes: tag
  and no Cc: stable.
- [Low] This patch makes gemini_port_irq() return IRQ_NONE
  unconditionally when !port->id (line 2417).

Pre-existing issues:
- [High] At the target revision, geth_cleanup_freeq() runs `while
  (page_ref_count(gpage->page) > 0) put_page(gpage->page);` (lines…
- [High] At the target revision, geth_cleanup_freeq() only sets wptr =
  rptr and zeroes GLOBAL_SW_FREEQ_BASE_SIZE_REG (lines 1047-1049).
- [Medium] At the target revision, geth_freeq_alloc_map_page() maps each
  page with dma_map_single(..., PAGE_SIZE, ...) at line 856.
- [Medium] gmac_enable_irq() enables GMAC0_IRQ4_8 << (dev_id * 8) in
  GLOBAL_INTERRUPT_ENABLE_4_REG (line 1430), which includes…

--

net: ethernet: cortina: Drain free queue IRQ before resize

This patch disables the port 1 Linux IRQ for the whole of
geth_resize_freeq(). An already woken free queue IRQ thread is therefore
drained before the ring and page metadata are freed. The free queue source
is re-enabled only after a successful setup, freed queue state is cleared,
and gemini_port_irq() now ignores the interrupt on port 0.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 4f27a48908b1a..5e9dd2aea4077 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -1019,6 +1019,8 @@ static int geth_setup_freeq(struct gemini_ethernet *geth)
>  	}
>  
>  	kfree(geth->freeq_pages);
> +	geth->freeq_pages = NULL;
> +	geth->num_freeq_pages = 0;
>  err_freeq:

[Severity: Medium]
This isn't a bug introduced by this patch, but the error path just above
unmaps each page using frag_len as the size:

geth_setup_freeq() {
    ...
	mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
	dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
    ...
}

geth_freeq_alloc_map_page(), however, maps the whole page with PAGE_SIZE.
geth_cleanup_freeq() has the same frag_len size mismatch.

There is a related problem in the replacement branch of
geth_freeq_alloc_map_page(). By the time the old mapping is read back, the
descriptors have already been overwritten with the new mapping:

geth_freeq_alloc_map_page() {
    ...
	gpage = &geth->freeq_pages[pn];
	if (gpage->page) {
		mapping = geth->freeq_ring[pn << fpp_order].word2.buf_adr;
		dma_unmap_single(geth->dev, mapping, frag_len, DMA_FROM_DEVICE);
    ...
}

Doesn't this unmap the new buffer that was just posted to the hardware,
and leak the old page's mapping? geth_fill_freeq() takes this branch
whenever page_ref_count(page) > 1.

This looks to be resolved later in the series by "net: ethernet: cortina:
Correct free queue DMA mappings". After that patch, every unmap site uses
gpage->mapping with PAGE_SIZE.

> @@ -1059,20 +1061,37 @@ static void geth_cleanup_freeq(struct gemini_ethernet *geth)
>  	}
>  
>  	kfree(geth->freeq_pages);
> +	geth->freeq_pages = NULL;
> +	geth->num_freeq_pages = 0;

[Severity: High]
This is a pre-existing issue, but the loop just before this kfree() in
geth_cleanup_freeq() keeps dropping page references until the count
reaches zero:

geth_cleanup_freeq() {
    ...
	gpage = &geth->freeq_pages[pn];
	while (page_ref_count(gpage->page) > 0)
		put_page(gpage->page);
    ...
}

Can this drop references owned by RX skbs that were already delivered to
the stack? After the final put_page(), the loop also reads the refcount of
a page that has already been freed.

The path is gmac_open() or gmac_set_ringparam() -> geth_resize_freeq() ->
geth_cleanup_freeq(). It runs when the peer netdev is down and the order
changes, which can happen while skbs that reference free queue pages are
still queued in sockets.

This looks to be fixed later in the series by "net: ethernet: cortina:
Preserve in-flight free queue pages". After that patch,
geth_freeq_release_pages() drops only the driver-owned references.

>  
>  	dma_free_coherent(geth->dev,
>  			  sizeof(*geth->freeq_ring) << geth->freeq_order,
>  			  geth->freeq_ring, geth->freeq_dma_base);
> +	geth->freeq_ring = NULL;
> +}
> +
> +static void geth_set_freeq_irq(struct gemini_ethernet *geth, bool enable)
> +{
> +	unsigned long flags;
> +	u32 val;
> +
> +	spin_lock_irqsave(&geth->irq_lock, flags);
> +	val = readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
> +	if (enable)
> +		val |= SWFQ_EMPTY_INT_BIT;

[Severity: Medium]
This isn't a bug introduced by this patch, but when SWFQ_EMPTY fires,
gemini_port_irq() clears the RX overrun enables for both GMACs:

gemini_port_irq() {
    ...
		en &= ~(SWFQ_EMPTY_INT_BIT | GMAC0_RX_OVERRUN_INT_BIT
					   | GMAC1_RX_OVERRUN_INT_BIT);
		writel(en, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
    ...
}

gemini_port_irq_thread() restores only SWFQ_EMPTY_INT_BIT, and so does
geth_set_freeq_irq(geth, true) here. Only gmac_enable_irq() enables the
overrun sources again, and it runs only on open.

Won't RX overrun interrupts for both ports stay masked after the first
free queue refill, so that rx_fifo_errors stops counting? This still seems
to be present at the end of the series.

> +	else
> +		val &= ~SWFQ_EMPTY_INT_BIT;
> +	writel(val, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
> +	spin_unlock_irqrestore(&geth->irq_lock, flags);
>  }

[ ... ]

> @@ -1120,13 +1137,8 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
>  	if (geth->freeq_ring && geth->freeq_order == new_order)
>  		return 0;
>  
> -	spin_lock_irqsave(&geth->irq_lock, flags);
> -
> -	/* Disable the software queue IRQs */
> -	en = readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
> -	en &= ~SWFQ_EMPTY_INT_BIT;
> -	writel(en, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
> -	spin_unlock_irqrestore(&geth->irq_lock, flags);
> +	disable_irq(geth->port1->irq);
> +	geth_set_freeq_irq(geth, false);

[Severity: Low]
This change closes a use-after-free. Before it, gemini_port_irq_thread()
could run geth_fill_freeq() on freeq_pages and freeq_ring while
geth_cleanup_freeq() was freeing them. It could also set
SWFQ_EMPTY_INT_BIT again after teardown.

Should the patch carry a Fixes: tag and Cc: stable so it can be
backported? The mask-only sequence in geth_resize_freeq() and the
unconditional re-enable in gemini_port_irq_thread() both appear to come
from the original driver:

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

>  
>  	/* Drop the old queue */
>  	if (geth->freeq_ring)
> @@ -1136,14 +1148,10 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
>  	geth->freeq_order = new_order;
>  	ret = geth_setup_freeq(geth);

[Severity: High]
This is a pre-existing issue, but geth_cleanup_freeq() only copies rptr
into wptr and zeroes GLOBAL_SW_FREEQ_BASE_SIZE_REG. The hardware rptr
therefore still holds an index from the old ring geometry.

geth_setup_freeq() then calls geth_fill_freeq(geth, false) with the new
freeq_order, and the rptr it uses is not masked:

geth_fill_freeq() {
    ...
	pn = (refill ? rw.bits.wptr : rw.bits.rptr) >> fpp_order;
	epn = (rw.bits.rptr >> fpp_order) - 1;
	epn &= m_pn;
    ...
}

Suppose ethtool -G shrinks the ring, or an open picks a smaller order,
while the hardware rptr is at or above the new ring length. Can
freeq_pages[pn] and freeq_ring[pn << fpp_order] then be indexed out of
bounds? The hardware rptr would also point past the end of the new
descriptor ring.

This looks to be fixed later in the series by "net: ethernet: cortina:
Normalize free queue pointers on rebuild". That patch masks rptr and wptr
with the ring mask, and resize rejects rings that cannot contain the
retained rptr.

[ ... ]

> @@ -2406,6 +2414,9 @@ static irqreturn_t gemini_port_irq(int irq, void *data)
>  	irqreturn_t ret = IRQ_NONE;
>  	u32 val, en;
>  
> +	if (!port->id)
> +		return IRQ_NONE;
> +

[Severity: Low]
gemini_ethernet_port_probe() still registers the free queue handler and
thread for both ports:

gemini_ethernet_port_probe() {
    ...
	ret = devm_request_threaded_irq(port->dev,
					port->irq,
					gemini_port_irq,
					gemini_port_irq_thread,
					IRQF_SHARED,
					port_names[port->id],
					port);
    ...
}

With this check, the port 0 handler never claims an interrupt and its
thread can never be woken. It is still called on every interrupt on the
shared port 0 line, and it still shows up as an "ethernet0" handler.

gemini_ethernet_init() routes SWFQ_EMPTY to int1 through
GLOBAL_INTERRUPT_SELECT_4_REG, so this isn't a functional bug. Would it
be cleaner to skip registering the free queue handler for port 0 rather
than register one that does nothing?

>  	geth = port->geth;
>  	spin_lock(&geth->irq_lock);
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild
  2026-11-20 17:29 ` [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

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 has no Fixes: tag, but it fixes a memory-safety bug.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch's
  own premise exposes it.

--

net: ethernet: cortina: Normalize free queue pointers on rebuild

The hardware keeps the free queue read pointer when the queue is rebuilt
at a smaller order. This patch masks the page indices in
geth_fill_freeq() to the active order and sets the software write
pointer from the retained read pointer in geth_setup_freeq(). It also
stops geth_resize_freeq() from shrinking the ring below the size needed
to hold the retained pointer.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 5e9dd2aea4077..66984c78a7cd4 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;

[Severity: Low]
Should this patch have a Fixes: tag?

Before this change, geth_fill_freeq() used the unmasked pn to index
geth->freeq_pages[pn], and then dereferenced gpage->page through
page_ref_count() and page_ref_add(). If the free queue was rebuilt at a
smaller order, for example via ethtool -G (gmac_set_ringparam() ->
geth_resize_freeq()), pn could be >= num_freeq_pages.

The unmasked code seems to date back to:

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

The commit message also says that a following patch, which decouples
the RX buffer budget from descriptor geometry, is needed to avoid an
allocation approaching 64 MiB. Would it help to add a note about that
dependency for stable backporters?

>  	epn = (rw.bits.rptr >> fpp_order) - 1;
>  	epn &= m_pn;
>  

[ ... ]

> @@ -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));
> +

[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but the
premise here seems to apply to the per-port SW TX queue too. gemini.h
describes the SW TX queues as the same TOE DMA queue type as the SW
free queue.

gmac_setup_txqs() copies the retained hardware read pointer into the
write pointer and cptr without masking it to the new txq_order:

drivers/net/ethernet/cortina/gemini.c:gmac_setup_txqs() {
    ...
		r = readw(rwptr_reg);
		rwptr_reg += 2;
		writew(r, rwptr_reg);
		rwptr_reg += 2;
		txq->cptr = r;
    ...
}

gmac_set_ringparam() lets the user shrink txq_order while the interface
is down. After the next gmac_open(), the ring and skb_tab hold only
1 << txq_order entries, but r can still be any value from the old,
larger ring.

On the first transmit, gmac_map_tx_bufs() uses the raw w before its
first mask:

drivers/net/ethernet/cortina/gemini.c:gmac_map_tx_bufs() {
    ...
		if (frag == last_frag) {
			word3 |= EOF_BIT;
			txq->skb[w] = skb;
		}
    ...
		txd = txq->ring + w;
		txd->word0.bits32 = buflen;
    ...
		w++;
		w &= m;
    ...
}

Can this write past the kzalloc'd skb_tab and past the coherent
descriptor ring?

gmac_clean_txq() has the same pattern with the unmasked cptr:

	while (c != r) {
		txd = txq->ring + c;
		...
		if (word3 & EOF_BIT)
			dev_kfree_skb(txq->skb[c]);

		c++;
		c &= m;

One possible trigger is ethtool -G <if> tx 64 while the port is down,
after the TX rptr has moved past 64 at the default order of 8. Bringing
the interface up and sending a packet would then hit this path.

The RX default queue may have a similar problem. gmac_setup_rxq() still
treats writel(0, port->rxq_rwptr) as a pointer reset. The testing
described in this commit shows that a 32-bit zero write does not clear
the hardware-owned half. gmac_rx() also compares the masked software r
with the unmasked hardware w:

	r = rw.bits.rptr;
	w = rw.bits.wptr;

	while (budget && consumed < desc_limit && w != r) {

If the retained w is >= 1 << rxq_order, could r never reach it? Could
the hardware also DMA RX descriptors past the new rxq_ring?

Were the TX and RX default queues considered along with the free queue?

>  	filled = geth_fill_freeq(geth, false);
>  	if (!filled)
>  		goto err_freeq_alloc;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 05/14] net: ethernet: cortina: Correct free queue DMA mappings
  2026-11-20 17:29 ` [PATCH net-next v9 05/14] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

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] Commit "net: ethernet: cortina: Correct free queue DMA mappings"
  fixes a user-visible RX bug but has no Fixes: tag and no Cc: stable.

--

net: ethernet: cortina: Correct free queue DMA mappings

This patch keeps each free queue page's DMA base separate from the
fragment iterator in geth_freeq_alloc_map_page(). It also removes the
replacement unmap, which hit the wrong buffer. The page lookup is
reworked to derive fragment offsets from the saved DMA base under
freeq_lock, and mappings that do not fit in the 32-bit hardware
descriptors are now rejected.

> The locked linear scan is temporary: the following "Index free queue
> fragments with XArray" patch removes it. Backport this change together
> with that patch, "Preserve in-flight free queue pages" and "Recycle
> claimed free queue pages", which complete the mapping lifetime and DMA
> synchronization fixes.
>
> Signed-off-by: Linus Walleij <linusw@kernel.org>

[Severity: Low]
Should this patch carry a Fixes: tag and Cc: stable?

The commit message describes a user-visible RX regression: frames dropped
with "could not find mapping", or the wrong page attached to the skb and
the wrong page reference dropped.

Blame on the baseline puts the whole block in the original driver
submission:

  - the dma_map_single() result being advanced by the fragment loop
  - the replacement dma_unmap_single() reading back the new buf_adr
  - the "gpage->mapping = mapping" assignment

That submission is:

  4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

The backport request is only in the prose above. Stable and AUTOSEL
tooling relies on Fixes: and Cc: stable trailers to pick up patches. As
things stand, this fix and the three follow-up patches it depends on might
not get picked up at all, or only some of them might.

Would it make sense to add this?

  Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

It could also help to state the dependency on the follow-up patches in a
form stable tooling can use. Another option is to give the related
patches in the series matching tags.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 07/14] net: ethernet: cortina: Preserve in-flight free queue pages
  2026-11-20 17:29 ` [PATCH net-next v9 07/14] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] After this patch, a page metadata slot is freed at runtime
  only from geth_freeq_claim(), and only once every fragment of the page…
- [Medium] geth_resize_freeq() used to return early when the free queue
  already existed with the same order (`if (geth->freeq_ring &&…
- [Medium] The patch now rebuilds the shared free queue on every open
  with the peer down, and says the purpose is to reclaim fragments that…
- [Low] This patch fixes an RX mapping-lifetime bug that has been user-
  visible since the driver was first added, and its commit message…

--

net: ethernet: cortina: Preserve in-flight free queue pages

This patch stops indexing free queue page metadata by ring position.
Metadata slots now come from a pool tracked by a bitmap, and each
fragment's DMA address stays in the XArray until an RX descriptor claims
it. Pages are now allocated and mapped outside the free queue lock, and
the shared free queue is rebuilt on every open while the peer port is
down.

> The following "Recycle claimed free queue pages" patch restores recycling
> independently of queue position. Backport both changes together with
> their prerequisites, including "Index free queue fragments with XArray".

[Severity: Low]
The commit message asks for a backport, but neither this patch nor any
other patch in the series has a Fixes: tag or a Cc: stable. Should one be
added?

This patch replaces the refill logic that was indexed by queue position.
In that code, geth_fill_freeq() called geth_freeq_alloc_map_page(geth, pn)
once page_ref_count(page) > 1, which erased the old page's XArray entries.
That logic appears to go back to:

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index fdf8c0e2f29e6..1693a136d7343 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -768,15 +773,32 @@ geth_freeq_mapping_index(const struct gemini_ethernet *geth,
>  	return (unsigned long)(mapping >> geth->freeq_frag_order);
>  }
>  
> -static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
> -				      dma_addr_t mapping,
> -				      unsigned int *page_offs)
> +static int geth_freeq_alloc_slot(struct gemini_ethernet *geth)
> +{
> +	unsigned int slot;
> +
> +	lockdep_assert_held(&geth->freeq_lock);
> +
> +	slot = find_first_zero_bit(geth->freeq_page_bitmap,
> +				   geth->num_freeq_pages);
> +	if (slot == geth->num_freeq_pages)
> +		return -ENOSPC;
> +
> +	__set_bit(slot, geth->freeq_page_bitmap);
> +
> +	return slot;
> +}

[ ... ]

> @@ -795,6 +817,21 @@ static struct page *geth_freeq_lookup(struct gemini_ethernet *geth,
>  	if (!valid)
>  		goto err_unlock;
>  
> +	dma_sync_single_range_for_cpu(geth->dev, page_mapping,
> +				      mapping - page_mapping, frag_len,
> +				      DMA_FROM_DEVICE);
> +	xa_erase(&geth->freeq_mappings, index);
> +	if (!--gpage->fragments) {
> +		slot = gpage - geth->freeq_pages;
> +		dma_unmap_single_attrs(geth->dev, page_mapping, PAGE_SIZE,
> +				       DMA_FROM_DEVICE,
> +				       DMA_ATTR_SKIP_CPU_SYNC);
> +		gpage->page = NULL;
> +		gpage->mapping = 0;
> +		__clear_bit(slot, geth->freeq_page_bitmap);
> +		put_page(page);
> +	}

[Severity: Medium]
Is geth_freeq_claim() the only place that clears a bit in
freeq_page_bitmap at runtime? It does so only after every fragment of the
page has been claimed through an RX descriptor.

The hardware can take a fragment from the free queue and never return it
with a valid buf_adr. Such a fragment is never claimed, and the commit
message itself refers to "fragments that never returned a usable RX
address". In gmac_rx(), the zero mapping path and the "could not find
mapping" path both go to err_drop without claiming anything:

gmac_rx() {
    ...
		if (!mapping) {
			if (net_ratelimit())
				netdev_err(netdev,
					   "rxq[%u]: HW BUG: zero DMA desc\n",
					   r);
			goto err_drop;
		}
    ...
}

Each lost fragment keeps its slot bit set, along with its DMA mapping, its
page references and its XArray entry.

geth_freeq_page_slots() sizes the pool as the ring's pages plus
1 << rxq_order for each port, so there is no headroom for lost
fragments. The only reclaim is geth_cleanup_freeq() during a rebuild, and
geth_resize_freeq() skips the rebuild whenever the peer port is running.

Once leaked slots fill the bitmap, won't geth_freeq_alloc_slot() return
-ENOSPC every time? geth_fill_freeq() would then map a page, unmap and
free it, and break without posting anything. The shared free queue would
drain, and RX would stop on both ports until both interfaces are taken
down.

gemini_port_irq_thread() also ACKs and re-enables SWFQ_EMPTY whether or
not the refill posted anything:

gemini_port_irq_thread() {
	geth_fill_freeq(geth);
	...
	writel(irqmask, geth->base + GLOBAL_INTERRUPT_STATUS_4_REG);
	irqmask |= readl(geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
	writel(irqmask, geth->base + GLOBAL_INTERRUPT_ENABLE_4_REG);
	...
}

Could that become an interrupt loop that makes no progress?

The old refill could not stall like this, because it always replaced the
page at a given position. The problem also remains at the end of the
series, since "Recycle claimed free queue pages" only recycles slots whose
fragments have all been claimed.

[ ... ]

> @@ -854,32 +891,22 @@ static void gmac_cleanup_rxq(struct net_device *netdev)
>  			  port->rxq_ring, port->rxq_dma_base);
>  }
>  
> -static struct page *geth_freeq_alloc_map_page(struct gemini_ethernet *geth,
> -					      int pn)
> +static int geth_freeq_map_page(struct gemini_ethernet *geth,
> +			       struct page **pagep,
> +			       dma_addr_t *page_mappingp)
>  {

[ ... ]

> -	lockdep_assert_held(&geth->freeq_lock);
> -
> -	/* First allocate and DMA map a single page */
>  	page = alloc_page(GFP_ATOMIC);
>  	if (!page)
> -		return NULL;
> +		return -ENOMEM;

[Severity: Medium]
geth_freeq_map_page() now runs outside freeq_lock. Does the setup path
still need GFP_ATOMIC here?

geth_resize_freeq() no longer returns early when the queue already exists
with the same order. With the peer down, every open and every rx
ethtool -G now tears down and rebuilds the free queue. On single-port
boards other_running is always false, so this happens on every ifup:

gmac_open()
  geth_resize_freeq()
    geth_cleanup_freeq()
    geth_setup_freeq()
      geth_fill_freeq()
        geth_freeq_map_page()
          alloc_page(GFP_ATOMIC)

geth_setup_freeq() now fails unless every usable entry is filled:

	expected = len - (1 << fpp_order);
	filled = geth_fill_freeq(geth);
	if (filled != expected)
		goto err_freeq_bitmap;

With the default rings, a down/up that used to reuse the existing pages
now allocates about 1023 pages (4 MiB) without direct reclaim, taking them
from atomic reserves. Under memory pressure on a small Gemini system,
could the fill fall short and make gmac_open() fail where it used to
succeed?

This path runs in sleepable process context under RTNL, so could the
setup fill use GFP_KERNEL instead? The final state of the series still
uses GFP_ATOMIC here, and still rebuilds on every open with the peer down.

[ ... ]

> @@ -1200,8 +1282,19 @@ static int geth_resize_freeq(struct gemini_ethernet_port *port)
>  	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)
> -		return 0;
> +	if (new_order <= PAGE_SHIFT - geth->freeq_frag_order)
> +		return -EINVAL;
> +
> +	/* Rebuild an idle queue to reclaim fragments which were never claimed. */
> +	if (geth->freeq_ring && other_running) {
> +		page_slots = geth_freeq_page_slots(geth, geth->freeq_order);
> +		if (geth->freeq_order >= new_order &&
> +		    geth->num_freeq_pages >= page_slots)
> +			return 0;
> +	}
> +
> +	if (other_running)
> +		return -EBUSY;

[Severity: Medium]
Is it safe to free the fragments that were never claimed during this
rebuild? The hardware consumed these fragments (rptr moved past them) but
never wrote them into an RX descriptor, so we don't know whether it still
holds their addresses.

geth_cleanup_freeq()->geth_freeq_release_pages() unmaps each such page and
drops all of its outstanding references, so the page goes back to the
page allocator:

geth_freeq_release_pages() {
    ...
		dma_unmap_single_attrs(geth->dev, gpage->mapping, PAGE_SIZE,
				       DMA_FROM_DEVICE,
				       DMA_ATTR_SKIP_CPU_SYNC);
		while (gpage->fragments) {
			put_page(page);
			gpage->fragments--;
		}
		put_page(page);
    ...
}

Nothing in the teardown appears to reset the per-port RX DMA engines:

  - gmac_stop_dma() only clears rd_enable and td_enable.
  - geth_cleanup_freeq() only sets wptr to rptr and writes 0 to
    GLOBAL_SW_FREEQ_BASE_SIZE_REG.
  - The hardware rptr is deliberately kept across the rebuild.

Suppose the GMAC RX DMA keeps a free queue buffer address it has already
fetched, which could explain why those fragments never come back. Would
it then write the next received frame to that address once gmac_open()
calls gmac_start_dma() and gmac_enable_tx_rx()?

That page may already belong to someone else by then, and Gemini has no
IOMMU to catch the write.

Before this patch the queue was only rebuilt when its order changed. A
plain close and reopen kept those pages owned by the driver.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths
  2026-11-20 17:29 ` [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch treats two descriptor layouts inconsistently.
- [Low] The patch fixes descriptor-length bugs that date back to the
  driver's initial commit, but it has no Fixes: tag and no Cc: stable.
- [Low] net: ethernet: cortina: double-counted RX stats on err_drop in
  gmac_rx()

--

net: ethernet: cortina: Validate RX fragment lengths

This patch adds bounds checks on RX descriptor lengths in gmac_rx(), so a
fragment can no longer underflow or run past the posted free queue
fragment or the page. Zero-length non-final descriptors are now dropped.
An EOF descriptor that carries no new data now completes the frame that
has already been assembled.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 8431f0a2e34a4..fe23ef8be9e51 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -1864,6 +1865,9 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
>  			if (!skb)
>  				goto err_drop;
>  
> +			if (frag_len < NET_IP_ALIGN)
> +				goto err_drop;
> +
>  			page_offs += NET_IP_ALIGN;
>  			frag_len -= NET_IP_ALIGN;
>  			frag_nr = 0;

[Severity: Low]
Should this patch have a Fixes: tag, and possibly Cc: stable?

According to git blame, all of the following come from the initial driver
commit:

- the unchecked frag_len -= NET_IP_ALIGN above
- the frag_len = frame_len - skb->len underflow at EOF
- the skb_fill_page_desc() append of zero-length or oversized fragments

So the tag would be:

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

Without the tag, stable tooling cannot tell which trees need this fix.

> @@ -1872,15 +1876,33 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
>  			goto err_drop;
>  		}
>  
> -		if (word3.bits32 & EOF_BIT)
> +		if (word3.bits32 & EOF_BIT) {
> +			if (frame_len < ETH_ZLEN ||
> +			    frame_len < skb->len)
> +				goto err_drop;
>  			frag_len = frame_len - skb->len;
> +		}
> +
> +		if (!frag_len) {
> +			if (word3.bits32 & EOF_BIT) {
> +				put_page(page);
> +				page = NULL;
> +				goto complete_frame;
> +			}

[Severity: Low]
Does this count rejected frames twice in the interface statistics?

gmac_skb_if_good_frame() is called on the SOF descriptor. On success it
falls through to update_exit, which does:

	port->stats.rx_bytes += frame_len;
	port->stats.rx_packets++;

That happens before gmac_rx() runs any of the new checks. The chain can
still be rejected afterwards by one of them:

- frag_len < NET_IP_ALIGN on the SOF descriptor
- frame_len < ETH_ZLEN or frame_len < skb->len at EOF
- a zero-length non-EOF descriptor
- frag_len running past the free queue fragment or the page

In each case the code goes to err_drop. That frees the skb with
napi_free_frags() and increments port->stats.rx_dropped. The earlier
rx_packets and rx_bytes increments are left in place.

So the same frame shows up as both received and dropped. rx_bytes also
includes a byte_count that gmac_rx() has just judged inconsistent.

The commit message says descriptor inconsistencies are now accounted as
drops, but they are still counted as received as well.

Should the rx_packets and rx_bytes accounting move to the complete_frame
path? Then it would only happen once the frame is actually handed to
napi_gro_frags().

The existing MAX_SKB_FRAGS drop and the restarted-SOF drop already have
the same problem. This patch adds several more ways to reach it.

[Severity: Medium]
Are these two EOF cases handled consistently?

The empty EOF path delivers the frame when frame_len == skb->len at EOF.
For a valid frame, this seems possible only if two things are true:

- the GMAC writes trailing bytes that byte_count does not count (probably
  the 4-byte FCS) into the free queue buffers
- buffer_size in the earlier descriptors includes those bytes

If the hardware works that way, the trailing bytes could also straddle a
buffer boundary. gmac_start_dma() sets:

	dma_ctrl.bits.rd_insert_bytes = NET_IP_ALIGN;

Take 2048-byte fragments and a jumbo frame with byte_count 2044. The first
buffer would be full: buffer_size is 2048, and frag_len is 2046 after the
NET_IP_ALIGN adjustment, which includes 2 FCS bytes. The other 2 FCS bytes
land in the EOF buffer.

At EOF, frame_len (2044) < skb->len (2046). Wouldn't this valid, CRC-good
frame then go to err_drop and be counted in rx_dropped?

Could the last appended fragment be trimmed by skb->len - frame_len, and
the frame completed, instead?

Frames only span several descriptors with jumbo MTUs. The driver supports
them: max_mtu is MTU_SIZE_BIT_MASK - VLAN_ETH_HLEN, and
gmac_pick_rx_max_len() allows 9212 and 10236. Testing at the default MTU
would not hit this case.

If the hardware does behave this way, a 3-byte window of frame sizes just
below each 2048-byte boundary would always be dropped. Whether buffer_size
counts bytes that byte_count leaves out is defined only by the Gemini
datasheet.

> +
> +			if (net_ratelimit())
> +				netdev_err(netdev,
> +					   "Received fragment with len = 0\n");
> +			goto err_drop;
> +		}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 12/14] net: ethernet: cortina: Account RX buffer size in truesize
  2026-11-20 17:29 ` [PATCH net-next v9 12/14] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

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 "net: ethernet: cortina: Account RX buffer size in
  truesize" fixes a truesize undercount that has been present since the…

--

net: ethernet: cortina: Account RX buffer size in truesize

Before this patch, gmac_rx() charged each page fragment attached to an skb
with only the received payload length. This patch charges the full posted
free queue fragment size instead. Each fragment pins a whole free queue DMA
buffer, so truesize now reflects that.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index fe23ef8be9e51..5f8f220ad9d73 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -1907,7 +1907,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
>  		skb_fill_page_desc(skb, frag_nr, page, page_offs, frag_len);
>  		skb->len += frag_len;
>  		skb->data_len += frag_len;
> -		skb->truesize += frag_len;
> +		skb->truesize += freeq_frag_len;

[Severity: Low]
The code change looks right. Should the commit carry a Fixes: tag, though?

The commit message calls this a bug ("short packets understate their
memory use to GRO and socket accounting"). The line being replaced:

    skb->truesize += frag_len;

goes back to the original driver submission, so this undercount has been
there since then:

Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")

Without the tag, stable tooling can't tell which kernels have the problem.
Is this meant for net rather than net-next?

>  		frag_nr++;
>  
>  		if (!(word3.bits32 & EOF_BIT))

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH net-next v9 13/14] net: ethernet: cortina: Release partial RX frames on stop
  2026-11-20 17:29 ` [PATCH net-next v9 13/14] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
@ 2026-11-24 18:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 24+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 18:29 UTC (permalink / raw)
  To: linusw
  Cc: ulli.kroll, andrew+netdev, davem, kuba, pabeni, mirq-linux,
	mhun512, edumazet, netdev

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 fixes a real lifetime bug but has no Fixes: tag.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it sits in the
  stop path the patch changes.

--

net: ethernet: cortina: Release partial RX frames on stop

This patch frees a partially assembled RX skb held in napi->skb when
gmac_stop() runs, so a reopened interface does not get the stale skb back
from napi_get_frags(). The dropped frame is counted in rx_dropped under
the RX stats seqcount, using the irqsave update helpers.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 5f8f220ad9d73..3d121eec88733 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -2269,12 +2269,19 @@ static int gmac_open(struct net_device *netdev)
>  static int gmac_stop(struct net_device *netdev)
>  {
>  	struct gemini_ethernet_port *port = netdev_priv(netdev);
> +	unsigned long flags;
>  
>  	hrtimer_cancel(&port->rx_coalesce_timer);

[Severity: High]
This isn't a bug introduced by this patch, but it is in the stop path this
patch changes. Can the RX coalesce timer be re-armed after this
hrtimer_cancel()?

The RX interrupt is not masked until gmac_enable_irq(netdev, 0) and
free_irq() run later in gmac_stop(). An RX interrupt in that window goes
through gmac_irq():

	if (val & (DEFAULT_Q0_INT_BIT << netdev->dev_id)) {
		gmac_enable_rx_irq(netdev, 0);

		if (!port->rx_coalesce_nsecs) {
			napi_schedule(&port->napi);
		} else {
			...
			hrtimer_start(&port->rx_coalesce_timer, ktime,
				      HRTIMER_MODE_REL);
		}
	}

In that case ndo_stop returns with the timer still queued.
gmac_set_coalesce() sets rx_coalesce_nsecs to rx_coalesce_usecs * 1000
with no upper bound, so the timer can stay queued for up to about 4.29
seconds.

If the interface is reopened during that time, gmac_open() calls
hrtimer_setup() on a timer that is still queued. Could that corrupt the
hrtimer timerqueue?

If the device is removed instead, could gmac_coalesce_delay_expired()
fire after the netdev private area is freed and call napi_schedule() on
freed memory?

gmac_open() has a related ordering problem. request_irq(),
gmac_enable_irq(netdev, 1) and gmac_enable_tx_rx() all run before
hrtimer_setup(). gmac_set_coalesce() has no netif_running() check, so
coalescing can be set before the first open.

On that first open, an early RX interrupt would call hrtimer_start() on a
zero-initialized hrtimer whose timer->base is NULL. Would that oops in
lock_hrtimer_base()?

Would it make sense to set up the hrtimer once, at probe or ndo_init
time, and to cancel it only after the RX interrupt is masked or the IRQ
is freed?

>  	netif_tx_stop_all_queues(netdev);
>  	gmac_disable_tx_rx(netdev);
>  	gmac_stop_dma(port);
>  	napi_disable(&port->napi);
> +	if (port->rx_skb) {
> +		napi_free_frags(&port->napi);
> +		flags = u64_stats_update_begin_irqsave(&port->rx_stats_syncp);
> +		port->stats.rx_dropped++;
> +		u64_stats_update_end_irqrestore(&port->rx_stats_syncp, flags);
> +	}
>  	port->rx_skb = NULL;

[Severity: Low]
Should this patch have a Fixes: tag?

The port->rx_skb = NULL assignment here was added by commit 06937db21ee3
("net: ethernet: cortina: Make RX SKB per-port"). Before that commit, the
static skb in gmac_rx() kept its value across stop and open. The next SOF
descriptor then freed the leftover frame in gmac_rx():

			if (skb) {
				napi_free_frags(&port->napi);
				port->stats.rx_dropped++;
				skb = NULL;

Since 06937db21ee3, that check no longer fires after a reopen.
gmac_skb_if_good_frame()->napi_get_frags() then returns the stale
napi->skb.

Commit ebd8ec2b309e ("net: ethernet: cortina: Carry over frag counter")
later added port->rx_frag_nr = 0 to the same stop path, and the gap
remained.

06937db21ee3 has its own Fixes: tag and was merged through net, so it is
probably in stable trees. This change only touches gmac_stop() and does
not appear to depend on the earlier free-queue rework in the series, so
it could be backported by itself. Would this tag fit?

Fixes: 06937db21ee3 ("net: ethernet: cortina: Make RX SKB per-port")

>  	port->rx_frag_nr = 0;
>  	port->rx_dropping = false;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-gemini-ethernet-fixes-3-v9-0-298671d799d5%40kernel.org

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2026-11-24 18:30 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 17:29 [PATCH net-next v9 00/14] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 01/14] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 02/14] net: ethernet: cortina: Keep ports bound for shared IRQ Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 03/14] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 04/14] net: ethernet: cortina: Normalize free queue pointers on rebuild Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 05/14] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 06/14] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 07/14] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 08/14] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 09/14] net: ethernet: cortina: Recycle claimed free queue pages Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 10/14] net: ethernet: cortina: Separate RX buffer capacity from free queue size Linus Walleij
2026-11-20 17:29 ` [PATCH net-next v9 11/14] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 12/14] net: ethernet: cortina: Account RX buffer size in truesize Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 13/14] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
2026-11-24 18:29   ` netdev-bot+sashiko
2026-11-20 17:29 ` [PATCH net-next v9 14/14] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox