Skip to contentSkip to conversation

io_uring zcrx: allow sharing of ifqs with other instances

PATCH In review David Wei 2 participants 3 messages Oct 23, 2025 – Oct 24, 2025

Subsystems (4)
lore
Share & tools
lore

David Wei

author
#0 lore raw

PATCH 1/1 io_uring zcrx: allow sharing of ifqs with other instances

Each ifq is bound to a HW RX queue with no way to share this across multiple io_uring instances. It is possible that one io_uring instance will not be able to fully saturate an entire HW RX queue. To handle more work the only way is to add additional io_uring instances w/ ifqs, but HW RX queues are a limited resource on a system.

From userspace it is possible to move work from this io_uring instance w/ an ifq to other threads, but this will incur context switch overhead. What I'd like to do is share an ifq (and hence a HW RX queue) across multiple rings.

Add a way for io_uring instances to clone an ifq from another. This is done by passing a new flag IORING_ZCRX_IFQ_REG_CLONE in the registration struct io_uring_zcrx_ifq_reg, alongside the fd and ifq id of the ifq to be cloned.

The cloned ifq holds two refs:
1. On the source io_ring_ctx percpu_ref
2. On the source ifq refcount_t

This ensures that the source ifq and ring ctx remains valid while there are proxies.

The only way to destroy an ifq today is to destroy the entire ring, so both the real ifq and the proxy ifq are freed together.

At runtime, io_zcrx_recv_frag checks the ifq in the net_iov->priv field. This is expected to be the primary ifq that is bound to a HW RX queue, and is what prevents another ring from issuing io_recvzc on a zero copy socket. Once a secondary ring clones the ifq, this check will pass.

It's expected for userspace to coordinate the sharing and synchronisation of the refill queue when returning buffers. The kernel is not involved at all.

It's also expected userspace to distributed accepted sockets with connections steered to zero copy queues across multiple rings for load balancing.

---
 include/uapi/linux/io_uring.h |  4 ++
 io_uring/net.c                |  2 +
 io_uring/rsrc.c               |  2 +-
 io_uring/rsrc.h               |  1 +
 io_uring/zcrx.c               | 90 +++++++++++++++++++++++++++++++++--
 io_uring/zcrx.h               |  3 ++
 6 files changed, 98 insertions(+), 4 deletions(-)
include/uapi/linux/io_uring.h +4 -0
index 263bed13473e..8e4227a40d09 100644
@@ -1055,6 +1055,10 @@ struct io_uring_zcrx_area_reg {
 	__u64	__resv2[2];
 };
 
+enum io_uring_zcrx_ifq_reg_flags {
+	IORING_ZCRX_IFQ_REG_CLONE	= 1,
+};
+
 /*
  * Argument for IORING_REGISTER_ZCRX_IFQ
  */
io_uring/net.c +2 -0
index a95cc9ca2a4d..8eb6145e0f4d 100644
@@ -1250,6 +1250,8 @@ int io_recvzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	zc->ifq = xa_load(&req->ctx->zcrx_ctxs, ifq_idx);
 	if (!zc->ifq)
 		return -EINVAL;
+	if (zc->ifq->proxy)
+		zc->ifq = zc->ifq->proxy;
 
 	zc->len = READ_ONCE(sqe->len);
 	zc->flags = READ_ONCE(sqe->ioprio);
io_uring/rsrc.c +1 -1
index d787c16dc1c3..aae5f2acfcf1 100644
@@ -1148,7 +1148,7 @@ int io_import_reg_buf(struct io_kiocb *req, struct iov_iter *iter,
 }
 
 /* Lock two rings at once. The rings must be different! */
-static void lock_two_rings(struct io_ring_ctx *ctx1, struct io_ring_ctx *ctx2)
+void lock_two_rings(struct io_ring_ctx *ctx1, struct io_ring_ctx *ctx2)
 {
 	if (ctx1 > ctx2)
 		swap(ctx1, ctx2);
io_uring/rsrc.h +1 -0
index a3ca6ba66596..3a9b9e398249 100644
@@ -70,6 +70,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
 int io_prep_reg_iovec(struct io_kiocb *req, struct iou_vec *iv,
 			const struct iovec __user *uvec, size_t uvec_segs);
 
+void lock_two_rings(struct io_ring_ctx *ctx1, struct io_ring_ctx *ctx2);
 int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg);
 int io_sqe_buffers_unregister(struct io_ring_ctx *ctx);
 int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
io_uring/zcrx.c +87 -3

135 lines not on this page · raw message

io_uring/zcrx.h +3 -0
index 33ef61503092..0df956cb9592 100644
@@ -60,6 +60,9 @@ struct io_zcrx_ifq {
 	 */
 	struct mutex			pp_lock;
 	struct io_mapped_region		region;
+
+	refcount_t			refs;
+	struct io_zcrx_ifq		*proxy;
 };
 
 #if defined(CONFIG_IO_URING_ZCRX)
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 31 lines · David Wei

Each ifq is bound to a HW RX queue with no way to share this across multiple io_uring instances. It is possible that one io_uring instance will not be able to fully saturate an entire HW RX queue. To handle more work the only way is to add additional io_uring instances w/ ifqs, but HW RX queues are a limited resource on a system.

From userspace it is possible to move work from this io_uring instance w/ an ifq to other threads, but this will incur context switch overhead. What I'd like to do is share an ifq (and hence a HW RX queue) across multiple rings.

Add a way for io_uring instances to clone an ifq from another. This is done by passing a new flag IORING_ZCRX_IFQ_REG_CLONE in the registration struct io_uring_zcrx_ifq_reg, alongside the fd and ifq id of the ifq to be cloned.

The cloned ifq holds two refs:
1. On the source io_ring_ctx percpu_ref
2. On the source ifq refcount_t

This ensures that the source ifq and ring ctx remains valid while there are proxies.

The only way to destroy an ifq today is to destroy the entire ring, so both the real ifq and the proxy ifq are freed together.

At runtime, io_zcrx_recv_frag checks the ifq in the net_iov->priv field. This is expected to be the primary ifq that is bound to a HW RX queue, and is what prevents another ring from issuing io_recvzc on a zero copy socket. Once a secondary ring clones the ifq, this check will pass.

Quoted 7 lines

It's expected for userspace to coordinate the sharing and synchronisation of the refill queue when returning buffers. The kernel is not involved at all.

It's also expected userspace to distributed accepted sockets with connections steered to zero copy queues across multiple rings for load balancing.

I think this would be a lot easier to review, if you split out a few things. Like:

The locking of two rings, just make that a prep patch. You also need to change the name, it's too generic. That was fine when it was a static in a single file, but should be better now.

Add the reference counting. It looks a bit suspicious on the io_shutdown_zcrx_ifqs() side, having it separate would also make that clearer.

And then you can have the meat of it on top of those.

Side note - you need to check the return value of kzalloc(), it can indeed return NULL.

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 1 line · Jens Axboe

On 10/23/25 3:39 PM, David Wei wrote:

[...]

Quoted 3 lines

I think this would be a lot easier to review, if you split out a few things. Like:

You got it, I'll split it up in v2. Sorry I was recently traumatised that I was splitting up a patchset into useless patches, so that's why I sent this as one.