From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, netdev@vger.kernel.org
Subject: [RFC 6/6] io_uring/zcrx: add dynamic area creation
Date: Tue, 12 May 2026 11:25:06 +0100 [thread overview]
Message-ID: <ba6903f8619b69787b1e3dd97244c08f7ef319d2.1778581283.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1778581283.git.asml.silence@gmail.com>
It's not always possible for the user to predict during registration how
much memory zcrx will need to sustain the traffic. Allow to dynamically
add more areas with a new ctrl code ZCRX_CTRL_ADD_AREA.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
include/uapi/linux/io_uring/zcrx.h | 7 ++++++
io_uring/zcrx.c | 39 +++++++++++++++++++++++++++++-
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/io_uring/zcrx.h b/include/uapi/linux/io_uring/zcrx.h
index 5ce02c7a6096..de696eb10db4 100644
--- a/include/uapi/linux/io_uring/zcrx.h
+++ b/include/uapi/linux/io_uring/zcrx.h
@@ -88,6 +88,7 @@ struct io_uring_zcrx_ifq_reg {
enum zcrx_ctrl_op {
ZCRX_CTRL_FLUSH_RQ,
ZCRX_CTRL_EXPORT,
+ ZCRX_CTRL_ADD_AREA,
__ZCRX_CTRL_LAST,
};
@@ -101,6 +102,11 @@ struct zcrx_ctrl_export {
__u32 __resv1[11];
};
+struct zcrx_ctrl_add_area {
+ __u64 area_ptr; /* pointer to struct io_uring_zcrx_area_reg */
+ __u64 __resv[5];
+};
+
struct zcrx_ctrl {
__u32 zcrx_id;
__u32 op; /* see enum zcrx_ctrl_op */
@@ -109,6 +115,7 @@ struct zcrx_ctrl {
union {
struct zcrx_ctrl_export zc_export;
struct zcrx_ctrl_flush_rq zc_flush;
+ struct zcrx_ctrl_add_area zc_area;
};
};
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 5fb81bb6f819..4bcf68b8d682 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -481,7 +481,7 @@ static int __zcrx_create_area(struct io_zcrx_ifq *ifq,
return -EINVAL;
buf_size_shift = ilog2(rx_buf_len);
}
- if (WARN_ON_ONCE(ifq->niov_shift))
+ if (ifq->niov_shift && ifq->niov_shift != buf_size_shift)
return -EINVAL;
if (!ifq->dev && buf_size_shift != PAGE_SHIFT)
return -EOPNOTSUPP;
@@ -967,6 +967,8 @@ int io_register_zcrx(struct io_ring_ctx *ctx,
goto err;
}
+ WARN_ON_ONCE(!ifq->niov_shift);
+
reg.zcrx_id = id;
scoped_guard(mutex, &ctx->mmap_lock) {
@@ -1325,6 +1327,39 @@ static int zcrx_flush_rq(struct io_ring_ctx *ctx, struct io_zcrx_ifq *zcrx,
return 0;
}
+static int zcrx_ctrl_add_area(struct io_ring_ctx *ctx, struct io_zcrx_ifq *ifq,
+ struct zcrx_ctrl *ctrl)
+{
+ struct zcrx_ctrl_add_area *ctrl_add = &ctrl->zc_area;
+ struct io_uring_zcrx_area_reg __user *area_uptr;
+ struct io_uring_zcrx_area_reg area_reg;
+ struct io_zcrx_area *area;
+ int ret;
+
+ area_uptr = u64_to_user_ptr(ctrl_add->area_ptr);
+
+ if (!mem_is_zero(&ctrl_add->__resv, sizeof(ctrl_add->__resv)))
+ return -EINVAL;
+ if (copy_from_user(&area_reg, area_uptr, sizeof(area_reg)))
+ return -EFAULT;
+
+ ret = __zcrx_create_area(ifq, &area_reg, &area, 0);
+ if (ret)
+ return ret;
+
+ if (copy_to_user(area_uptr, &area_reg, sizeof(area_reg))) {
+ io_zcrx_free_area(ifq, area);
+ return -EFAULT;
+ }
+
+ ret = io_zcrx_append_area(ifq, area);
+ if (ret) {
+ io_zcrx_free_area(ifq, area);
+ return ret;
+ }
+ return 0;
+}
+
int io_zcrx_ctrl(struct io_ring_ctx *ctx, void __user *arg, unsigned nr_args)
{
struct zcrx_ctrl ctrl;
@@ -1348,6 +1383,8 @@ int io_zcrx_ctrl(struct io_ring_ctx *ctx, void __user *arg, unsigned nr_args)
return zcrx_flush_rq(ctx, zcrx, &ctrl);
case ZCRX_CTRL_EXPORT:
return zcrx_export(ctx, zcrx, &ctrl, arg);
+ case ZCRX_CTRL_ADD_AREA:
+ return zcrx_ctrl_add_area(ctx, zcrx, &ctrl);
}
return -EOPNOTSUPP;
--
2.53.0
next prev parent reply other threads:[~2026-05-12 10:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 10:25 [RFC 0/6] dynamic area addition Pavel Begunkov
2026-05-12 10:25 ` [RFC 1/6] io_uring/zcrx: remove extra ifq close Pavel Begunkov
2026-05-12 10:25 ` [RFC 2/6] io_uring/zcrx: move freelist lock to struct zcrx Pavel Begunkov
2026-05-12 10:25 ` [RFC 3/6] io_uring/zcrx: store area pointers in an array Pavel Begunkov
2026-05-12 10:25 ` [RFC 4/6] io_uring/zcrx: don't pass ifq_reg for for area creation Pavel Begunkov
2026-05-12 10:25 ` [RFC 5/6] io_uring/zcrx: split append from " Pavel Begunkov
2026-05-12 10:25 ` Pavel Begunkov [this message]
2026-05-12 10:28 ` [RFC 0/6] dynamic area addition Pavel Begunkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ba6903f8619b69787b1e3dd97244c08f7ef319d2.1778581283.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox