From: Pavel Begunkov <asml.silence@gmail.com>
To: Joanne Koong <joannelkoong@gmail.com>,
axboe@kernel.dk, io-uring@vger.kernel.org
Cc: csander@purestorage.com, krisman@suse.de, bernd@bsbernd.com,
hch@infradead.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v1 03/11] io_uring/kbuf: add support for kernel-managed buffer rings
Date: Tue, 10 Feb 2026 16:34:47 +0000 [thread overview]
Message-ID: <89c75fc1-2def-4681-a790-78b12b45478a@gmail.com> (raw)
In-Reply-To: <20260210002852.1394504-4-joannelkoong@gmail.com>
On 2/10/26 00:28, Joanne Koong wrote:
> Add support for kernel-managed buffer rings (kmbuf rings), which allow
> the kernel to allocate and manage the backing buffers for a buffer
> ring, rather than requiring the application to provide and manage them.
>
> This introduces two new registration opcodes:
> - IORING_REGISTER_KMBUF_RING: Register a kernel-managed buffer ring
> - IORING_UNREGISTER_KMBUF_RING: Unregister a kernel-managed buffer ring
>
> The existing io_uring_buf_reg structure is extended with a union to
> support both application-provided buffer rings (pbuf) and kernel-managed
> buffer rings (kmbuf):
> - For pbuf rings: ring_addr specifies the user-provided ring address
> - For kmbuf rings: buf_size specifies the size of each buffer. buf_size
> must be non-zero and page-aligned.
>
> The implementation follows the same pattern as pbuf ring registration,
> reusing the validation and buffer list allocation helpers introduced in
> earlier refactoring. The IOBL_KERNEL_MANAGED flag marks buffer lists as
> kernel-managed for appropriate handling in the I/O path.
>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
> include/uapi/linux/io_uring.h | 15 ++++-
> io_uring/kbuf.c | 81 ++++++++++++++++++++++++-
> io_uring/kbuf.h | 7 ++-
> io_uring/memmap.c | 111 ++++++++++++++++++++++++++++++++++
> io_uring/memmap.h | 4 ++
> io_uring/register.c | 7 +++
> 6 files changed, 219 insertions(+), 6 deletions(-)
>
> diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
> index fc473af6feb4..a0889c1744bd 100644
> --- a/include/uapi/linux/io_uring.h
> +++ b/include/uapi/linux/io_uring.h
> @@ -715,6 +715,10 @@ enum io_uring_register_op {
> /* register bpf filtering programs */
> IORING_REGISTER_BPF_FILTER = 37,
>
> + /* register/unregister kernel-managed ring buffer group */
> + IORING_REGISTER_KMBUF_RING = 38,
> + IORING_UNREGISTER_KMBUF_RING = 39,
> +
> /* this goes last */
> IORING_REGISTER_LAST,
>
> @@ -891,9 +895,16 @@ enum io_uring_register_pbuf_ring_flags {
> IOU_PBUF_RING_INC = 2,
> };
>
> -/* argument for IORING_(UN)REGISTER_PBUF_RING */
> +/* argument for IORING_(UN)REGISTER_PBUF_RING and
> + * IORING_(UN)REGISTER_KMBUF_RING
> + */
> struct io_uring_buf_reg {
> - __u64 ring_addr;
> + union {
> + /* used for pbuf rings */
> + __u64 ring_addr;
> + /* used for kmbuf rings */
> + __u32 buf_size;
If you're creating a region, there should be no reason why it
can't work with user passed memory. You're fencing yourself off
optimisations that are already there like huge pages.
> + };
> __u32 ring_entries;
> __u16 bgid;
> __u16 flags;
> diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
> index aa9b70b72db4..9bc36451d083 100644
> --- a/io_uring/kbuf.c
> +++ b/io_uring/kbuf.c
...
> +static int io_setup_kmbuf_ring(struct io_ring_ctx *ctx,
> + struct io_buffer_list *bl,
> + struct io_uring_buf_reg *reg)
> +{
> + struct io_uring_buf_ring *ring;
> + unsigned long ring_size;
> + void *buf_region;
> + unsigned int i;
> + int ret;
> +
> + /* allocate pages for the ring structure */
> + ring_size = flex_array_size(ring, bufs, bl->nr_entries);
> + ring = kzalloc(ring_size, GFP_KERNEL_ACCOUNT);
> + if (!ring)
> + return -ENOMEM;
> +
> + ret = io_create_region_multi_buf(ctx, &bl->region, bl->nr_entries,
> + reg->buf_size);
Please use io_create_region(), the new function does nothing new
and only violates abstractions.
Provided buffer rings with kernel addresses could be an interesting
abstraction, but why is it also responsible for allocating buffers?
What I'd do:
1. Strip buffer allocation from IORING_REGISTER_KMBUF_RING.
2. Replace *_REGISTER_KMBUF_RING with *_REGISTER_PBUF_RING + a new flag.
Or maybe don't expose it to the user at all and create it from
fuse via internal API.
3. Require the user to register a memory region of appropriate size,
see IORING_REGISTER_MEM_REGION, ctx->param_region. Make fuse
populating the buffer ring using the memory region.
I wanted to make regions shareable anyway (need it for other purposes),
I can toss patches for that tomorrow.
A separate question is whether extending buffer rings is the right
approach as it seems like you're only using it for fuse requests and
not for passing buffers to normal requests, but I don't see the
big picture here.
> + if (ret) {
> + kfree(ring);
> + return ret;
> + }
> +
> + /* initialize ring buf entries to point to the buffers */
> + buf_region = bl->region.ptr;
io_region_get_ptr()
> + for (i = 0; i < bl->nr_entries; i++) {
> + struct io_uring_buf *buf = &ring->bufs[i];
> +
> + buf->addr = (u64)(uintptr_t)buf_region;
> + buf->len = reg->buf_size;
> + buf->bid = i;
> +
> + buf_region += reg->buf_size;
> + }
> + ring->tail = bl->nr_entries;
> +
> + bl->buf_ring = ring;
> + bl->flags |= IOBL_KERNEL_MANAGED;
> +
> + return 0;
> +}
> +
> +int io_register_kmbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
> +{
> + struct io_uring_buf_reg reg;
> + struct io_buffer_list *bl;
> + int ret;
> +
> + lockdep_assert_held(&ctx->uring_lock);
> +
> + ret = io_copy_and_validate_buf_reg(arg, ®, 0);
> + if (ret)
> + return ret;
> +
> + if (!reg.buf_size || !PAGE_ALIGNED(reg.buf_size))
With io_create_region_multi_buf() gone, you shouldn't need
to align every buffer, that could be a lot of wasted memory
(thinking about 64KB pages).
> + return -EINVAL;
> +
> + bl = io_alloc_new_buffer_list(ctx, ®);
> + if (IS_ERR(bl))
> + return PTR_ERR(bl);
> +
> + ret = io_setup_kmbuf_ring(ctx, bl, ®);
> + if (ret) {
> + kfree(bl);
> + return ret;
> + }
> +
> + ret = io_buffer_add_list(ctx, bl, reg.bgid);
> + if (ret)
> + io_put_bl(ctx, bl);
> +
> + return ret;
--
Pavel Begunkov
next prev parent reply other threads:[~2026-02-10 16:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-10 0:28 [PATCH v1 00/11] io_uring: add kernel-managed buffer rings Joanne Koong
2026-02-10 0:28 ` [PATCH v1 01/11] io_uring/kbuf: refactor io_register_pbuf_ring() logic into generic helpers Joanne Koong
2026-02-10 0:28 ` [PATCH v1 02/11] io_uring/kbuf: rename io_unregister_pbuf_ring() to io_unregister_buf_ring() Joanne Koong
2026-02-10 0:28 ` [PATCH v1 03/11] io_uring/kbuf: add support for kernel-managed buffer rings Joanne Koong
2026-02-10 16:34 ` Pavel Begunkov [this message]
2026-02-10 19:39 ` Joanne Koong
2026-02-11 12:01 ` Pavel Begunkov
2026-02-11 22:06 ` Joanne Koong
2026-02-12 10:07 ` Christoph Hellwig
2026-02-12 10:52 ` Pavel Begunkov
2026-02-12 17:29 ` Joanne Koong
2026-02-13 7:27 ` Christoph Hellwig
2026-02-13 7:21 ` Christoph Hellwig
2026-02-13 13:18 ` Pavel Begunkov
2026-02-11 15:45 ` Christoph Hellwig
2026-02-12 10:44 ` Pavel Begunkov
2026-02-13 7:18 ` Christoph Hellwig
2026-02-13 12:41 ` Pavel Begunkov
2026-02-10 0:28 ` [PATCH v1 04/11] io_uring/kbuf: add mmap " Joanne Koong
2026-02-10 1:02 ` Jens Axboe
2026-02-10 0:28 ` [PATCH v1 05/11] io_uring/kbuf: support kernel-managed buffer rings in buffer selection Joanne Koong
2026-02-10 0:28 ` [PATCH v1 06/11] io_uring/kbuf: add buffer ring pinning/unpinning Joanne Koong
2026-02-10 1:07 ` Jens Axboe
2026-02-10 17:57 ` Caleb Sander Mateos
2026-02-10 18:00 ` Jens Axboe
2026-02-10 0:28 ` [PATCH v1 07/11] io_uring/kbuf: add recycling for kernel managed buffer rings Joanne Koong
2026-02-10 0:52 ` Jens Axboe
2026-02-10 0:28 ` [PATCH v1 08/11] io_uring/kbuf: add io_uring_is_kmbuf_ring() Joanne Koong
2026-02-10 0:28 ` [PATCH v1 09/11] io_uring/kbuf: export io_ring_buffer_select() Joanne Koong
2026-02-10 0:28 ` [PATCH v1 10/11] io_uring/kbuf: return buffer id in buffer selection Joanne Koong
2026-02-10 0:53 ` Jens Axboe
2026-02-10 22:36 ` Joanne Koong
2026-02-10 0:28 ` [PATCH v1 11/11] io_uring/cmd: set selected buffer index in __io_uring_cmd_done() Joanne Koong
2026-02-10 0:55 ` [PATCH v1 00/11] io_uring: add kernel-managed buffer rings Jens Axboe
2026-02-10 22:45 ` Joanne Koong
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=89c75fc1-2def-4681-a790-78b12b45478a@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=bernd@bsbernd.com \
--cc=csander@purestorage.com \
--cc=hch@infradead.org \
--cc=io-uring@vger.kernel.org \
--cc=joannelkoong@gmail.com \
--cc=krisman@suse.de \
--cc=linux-fsdevel@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