🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Juanlu Herrero Mon, 23 Nov 2026 18:07
[PATCH] io_uring/zcrx: reclaim returned fallback buffers before ENOMEM
#21207
Author: Juanlu Herrero
Date: Mon, 23 Nov 2026 18:07
112 lines
16126 bytes
Copy fallback can return `-ENOMEM` with an empty freelist even when
reusable buffers are queued in the refill ring.

Drain pending returns on an allocation miss and retry once. Drop
`alloc_lock` before draining so buffer returns can acquire it.

Link: https://github.com/jlhe97/liburing/commit/0509277390db1e25a340b7b5bf5dedb158c702f3
Fixes: bc57c7d36c4c ("io_uring/zcrx: add copy fallback")
Cc: stable@vger.kernel.org
Suggested-by: Yedidya Feldblum <yfeldblum@meta.com>
Signed-off-by: Juanlu Herrero <juanlu@fastmail.com>
---
Drain queued returns when copy fallback runs out of free buffers.

Testing: premature `-ENOMEM` after reusable returns, 20 liburing trials
per arm:
  7.4-rc1:         20 before, 0 after.
  7.1.3 backport:  20 before, 0 after.
The existing ZCRX suite and regression use loopback `ZCRX_REG_NODEV`.

Regression test:
https://github.com/jlhe97/liburing/commit/0509277390db1e25a340b7b5bf5dedb158c702f3
---
 io_uring/zcrx.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 6d7abb1636e7f..35ad924970064 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -1517,17 +1517,12 @@ static void zcrx_return_buffers(netmem_ref *netmems, unsigned nr)
 	}
 }
 
-static int zcrx_flush_rq(struct io_ring_ctx *ctx, struct io_zcrx_ifq *zcrx,
-			 struct zcrx_ctrl *ctrl)
+static void io_zcrx_flush_rq(struct io_zcrx_ifq *zcrx)
 {
-	struct zcrx_ctrl_flush_rq *frq = &ctrl->zc_flush;
 	netmem_ref netmems[ZCRX_FLUSH_BATCH];
 	unsigned total = 0;
 	unsigned nr;
 
-	if (!mem_is_zero(&frq->__resv, sizeof(frq->__resv)))
-		return -EINVAL;
-
 	do {
 		struct zcrx_rq *rq = &zcrx->rq;
 
@@ -1542,7 +1537,17 @@ static int zcrx_flush_rq(struct io_ring_ctx *ctx, struct io_zcrx_ifq *zcrx,
 			break;
 		cond_resched();
 	} while (nr == ZCRX_FLUSH_BATCH && total < zcrx->rq.nr_entries);
+}
+
+static int zcrx_flush_rq(struct io_ring_ctx *ctx, struct io_zcrx_ifq *zcrx,
+			 struct zcrx_ctrl *ctrl)
+{
+	struct zcrx_ctrl_flush_rq *frq = &ctrl->zc_flush;
+
+	if (!mem_is_zero(&frq->__resv, sizeof(frq->__resv)))
+		return -EINVAL;
 
+	io_zcrx_flush_rq(zcrx);
 	return 0;
 }
 
@@ -1656,20 +1661,28 @@ static struct net_iov *io_alloc_fallback_niov(struct io_zcrx_ifq *ifq)
 {
 	struct net_iov *niov = NULL;
 	unsigned area_idx;
+	bool reclaimed = false;
 
 	if (!ifq->kern_readable)
 		return NULL;
 
-	guard(spinlock_bh)(&ifq->alloc_lock);
-
-	for (area_idx = 0; area_idx < ifq->nr_areas; area_idx++) {
-		niov = zcrx_get_free_niov(ifq->areas[area_idx]);
-		if (niov) {
-			page_pool_fragment_netmem(net_iov_to_netmem(niov), 1);
-			return niov;
+retry:
+	scoped_guard(spinlock_bh, &ifq->alloc_lock) {
+		for (area_idx = 0; area_idx < ifq->nr_areas; area_idx++) {
+			niov = zcrx_get_free_niov(ifq->areas[area_idx]);
+			if (niov) {
+				page_pool_fragment_netmem(net_iov_to_netmem(niov), 1);
+				return niov;
+			}
 		}
 	}
 
+	if (!reclaimed) {
+		io_zcrx_flush_rq(ifq);
+		reclaimed = true;
+		goto retry;
+	}
+
 	return NULL;
 }
 

---
base-commit: 0659e44ce739ecd856164c75a5325b7959a2921d
change-id: 20261120-b4-zcrx-fallback-reclaim-39d7a99f71dd

Best regards,
-- 
Juanlu Herrero
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads