* [PATCH] io_uring/rsrc: replace reg buffer bit field with flags
@ 2026-02-09 14:31 Pavel Begunkov
2026-02-09 16:44 ` Caleb Sander Mateos
2026-02-10 12:26 ` Jens Axboe
0 siblings, 2 replies; 4+ messages in thread
From: Pavel Begunkov @ 2026-02-09 14:31 UTC (permalink / raw)
To: io-uring; +Cc: asml.silence, axboe
I'll need a flag in the registered buffer struct for dmabuf work, and
it'll be more convenient to have a flags field rather than bit fields,
especially for io_mapped_ubuf initialisation.
We might want to add more flags in the future as well. For example, it
might be useful for debugging and potentially optimisations to split out
a flag indicating the shape of the buffer to gate iov_iter_advance()
walks vs bit/mask arithmetics. It can also be combined with the
direction mask field.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/rsrc.c | 12 ++++++------
io_uring/rsrc.h | 6 +++++-
io_uring/rw.c | 3 ++-
3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 95ce553fff8d..05f00bdb02d7 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -828,7 +828,7 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
imu->folio_shift = PAGE_SHIFT;
imu->release = io_release_ubuf;
imu->priv = imu;
- imu->is_kbuf = false;
+ imu->flags = 0;
imu->dir = IO_IMU_DEST | IO_IMU_SOURCE;
if (coalesced)
imu->folio_shift = data.folio_shift;
@@ -985,7 +985,7 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
refcount_set(&imu->refs, 1);
imu->release = release;
imu->priv = rq;
- imu->is_kbuf = true;
+ imu->flags = IO_REGBUF_F_KBUF;
imu->dir = 1 << rq_data_dir(rq);
rq_for_each_bvec(bv, rq, rq_iter)
@@ -1020,7 +1020,7 @@ int io_buffer_unregister_bvec(struct io_uring_cmd *cmd, unsigned int index,
ret = -EINVAL;
goto unlock;
}
- if (!node->buf->is_kbuf) {
+ if (!(node->buf->flags & IO_REGBUF_F_KBUF)) {
ret = -EBUSY;
goto unlock;
}
@@ -1076,7 +1076,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
offset = buf_addr - imu->ubuf;
- if (imu->is_kbuf)
+ if (imu->flags & IO_REGBUF_F_KBUF)
return io_import_kbuf(ddir, iter, imu, len, offset);
/*
@@ -1496,7 +1496,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
iovec_off = vec->nr - nr_iovs;
iov = vec->iovec + iovec_off;
- if (imu->is_kbuf) {
+ if (imu->flags & IO_REGBUF_F_KBUF) {
int ret = io_kern_bvec_size(iov, nr_iovs, imu, &nr_segs);
if (unlikely(ret))
@@ -1534,7 +1534,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
req->flags |= REQ_F_NEED_CLEANUP;
}
- if (imu->is_kbuf)
+ if (imu->flags & IO_REGBUF_F_KBUF)
return io_vec_fill_kern_bvec(ddir, iter, imu, iov, nr_iovs, vec);
return io_vec_fill_bvec(ddir, iter, imu, iov, nr_iovs, vec);
diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
index 4a5db2ad1af2..cff0f8834c35 100644
--- a/io_uring/rsrc.h
+++ b/io_uring/rsrc.h
@@ -28,6 +28,10 @@ enum {
IO_IMU_SOURCE = 1 << ITER_SOURCE,
};
+enum {
+ IO_REGBUF_F_KBUF = 1,
+};
+
struct io_mapped_ubuf {
u64 ubuf;
unsigned int len;
@@ -37,7 +41,7 @@ struct io_mapped_ubuf {
unsigned long acct_pages;
void (*release)(void *);
void *priv;
- bool is_kbuf;
+ u8 flags;
u8 dir;
struct bio_vec bvec[] __counted_by(nr_bvecs);
};
diff --git a/io_uring/rw.c b/io_uring/rw.c
index d10386f56d49..b3971171c342 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -702,7 +702,8 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter)
if ((kiocb->ki_flags & IOCB_NOWAIT) &&
!(kiocb->ki_filp->f_flags & O_NONBLOCK))
return -EAGAIN;
- if ((req->flags & REQ_F_BUF_NODE) && req->buf_node->buf->is_kbuf)
+ if ((req->flags & REQ_F_BUF_NODE) &&
+ (req->buf_node->buf->flags & IO_REGBUF_F_KBUF))
return -EFAULT;
ppos = io_kiocb_ppos(kiocb);
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] io_uring/rsrc: replace reg buffer bit field with flags
2026-02-09 14:31 [PATCH] io_uring/rsrc: replace reg buffer bit field with flags Pavel Begunkov
@ 2026-02-09 16:44 ` Caleb Sander Mateos
2026-02-10 9:51 ` Pavel Begunkov
2026-02-10 12:26 ` Jens Axboe
1 sibling, 1 reply; 4+ messages in thread
From: Caleb Sander Mateos @ 2026-02-09 16:44 UTC (permalink / raw)
To: Pavel Begunkov; +Cc: io-uring, axboe
On Mon, Feb 9, 2026 at 6:33 AM Pavel Begunkov <asml.silence@gmail.com> wrote:
>
> I'll need a flag in the registered buffer struct for dmabuf work, and
> it'll be more convenient to have a flags field rather than bit fields,
> especially for io_mapped_ubuf initialisation.
>
> We might want to add more flags in the future as well. For example, it
> might be useful for debugging and potentially optimisations to split out
> a flag indicating the shape of the buffer to gate iov_iter_advance()
> walks vs bit/mask arithmetics. It can also be combined with the
> direction mask field.
>
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
> io_uring/rsrc.c | 12 ++++++------
> io_uring/rsrc.h | 6 +++++-
> io_uring/rw.c | 3 ++-
> 3 files changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 95ce553fff8d..05f00bdb02d7 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -828,7 +828,7 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
> imu->folio_shift = PAGE_SHIFT;
> imu->release = io_release_ubuf;
> imu->priv = imu;
> - imu->is_kbuf = false;
> + imu->flags = 0;
> imu->dir = IO_IMU_DEST | IO_IMU_SOURCE;
> if (coalesced)
> imu->folio_shift = data.folio_shift;
> @@ -985,7 +985,7 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
> refcount_set(&imu->refs, 1);
> imu->release = release;
> imu->priv = rq;
> - imu->is_kbuf = true;
> + imu->flags = IO_REGBUF_F_KBUF;
> imu->dir = 1 << rq_data_dir(rq);
>
> rq_for_each_bvec(bv, rq, rq_iter)
> @@ -1020,7 +1020,7 @@ int io_buffer_unregister_bvec(struct io_uring_cmd *cmd, unsigned int index,
> ret = -EINVAL;
> goto unlock;
> }
> - if (!node->buf->is_kbuf) {
> + if (!(node->buf->flags & IO_REGBUF_F_KBUF)) {
> ret = -EBUSY;
> goto unlock;
> }
> @@ -1076,7 +1076,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
>
> offset = buf_addr - imu->ubuf;
>
> - if (imu->is_kbuf)
> + if (imu->flags & IO_REGBUF_F_KBUF)
> return io_import_kbuf(ddir, iter, imu, len, offset);
>
> /*
> @@ -1496,7 +1496,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
> iovec_off = vec->nr - nr_iovs;
> iov = vec->iovec + iovec_off;
>
> - if (imu->is_kbuf) {
> + if (imu->flags & IO_REGBUF_F_KBUF) {
> int ret = io_kern_bvec_size(iov, nr_iovs, imu, &nr_segs);
>
> if (unlikely(ret))
> @@ -1534,7 +1534,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
> req->flags |= REQ_F_NEED_CLEANUP;
> }
>
> - if (imu->is_kbuf)
> + if (imu->flags & IO_REGBUF_F_KBUF)
> return io_vec_fill_kern_bvec(ddir, iter, imu, iov, nr_iovs, vec);
>
> return io_vec_fill_bvec(ddir, iter, imu, iov, nr_iovs, vec);
> diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
> index 4a5db2ad1af2..cff0f8834c35 100644
> --- a/io_uring/rsrc.h
> +++ b/io_uring/rsrc.h
> @@ -28,6 +28,10 @@ enum {
> IO_IMU_SOURCE = 1 << ITER_SOURCE,
> };
>
> +enum {
> + IO_REGBUF_F_KBUF = 1,
1 << 0 if this is intended to be extended with more flag bits in the future?
Best,
Caleb
> +};
> +
> struct io_mapped_ubuf {
> u64 ubuf;
> unsigned int len;
> @@ -37,7 +41,7 @@ struct io_mapped_ubuf {
> unsigned long acct_pages;
> void (*release)(void *);
> void *priv;
> - bool is_kbuf;
> + u8 flags;
> u8 dir;
> struct bio_vec bvec[] __counted_by(nr_bvecs);
> };
> diff --git a/io_uring/rw.c b/io_uring/rw.c
> index d10386f56d49..b3971171c342 100644
> --- a/io_uring/rw.c
> +++ b/io_uring/rw.c
> @@ -702,7 +702,8 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter)
> if ((kiocb->ki_flags & IOCB_NOWAIT) &&
> !(kiocb->ki_filp->f_flags & O_NONBLOCK))
> return -EAGAIN;
> - if ((req->flags & REQ_F_BUF_NODE) && req->buf_node->buf->is_kbuf)
> + if ((req->flags & REQ_F_BUF_NODE) &&
> + (req->buf_node->buf->flags & IO_REGBUF_F_KBUF))
> return -EFAULT;
>
> ppos = io_kiocb_ppos(kiocb);
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] io_uring/rsrc: replace reg buffer bit field with flags
2026-02-09 16:44 ` Caleb Sander Mateos
@ 2026-02-10 9:51 ` Pavel Begunkov
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2026-02-10 9:51 UTC (permalink / raw)
To: Caleb Sander Mateos; +Cc: io-uring, axboe
On 2/9/26 16:44, Caleb Sander Mateos wrote:
> On Mon, Feb 9, 2026 at 6:33 AM Pavel Begunkov <asml.silence@gmail.com> wrote:
...
>> - if (imu->is_kbuf)
>> + if (imu->flags & IO_REGBUF_F_KBUF)
>> return io_vec_fill_kern_bvec(ddir, iter, imu, iov, nr_iovs, vec);
>>
>> return io_vec_fill_bvec(ddir, iter, imu, iov, nr_iovs, vec);
>> diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h
>> index 4a5db2ad1af2..cff0f8834c35 100644
>> --- a/io_uring/rsrc.h
>> +++ b/io_uring/rsrc.h
>> @@ -28,6 +28,10 @@ enum {
>> IO_IMU_SOURCE = 1 << ITER_SOURCE,
>> };
>>
>> +enum {
>> + IO_REGBUF_F_KBUF = 1,
>
> 1 << 0 if this is intended to be extended with more flag bits in the future?
It's not worth of respinning, will get converted if ever
becomes a problem.
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] io_uring/rsrc: replace reg buffer bit field with flags
2026-02-09 14:31 [PATCH] io_uring/rsrc: replace reg buffer bit field with flags Pavel Begunkov
2026-02-09 16:44 ` Caleb Sander Mateos
@ 2026-02-10 12:26 ` Jens Axboe
1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-02-10 12:26 UTC (permalink / raw)
To: io-uring, Pavel Begunkov
On Mon, 09 Feb 2026 14:31:22 +0000, Pavel Begunkov wrote:
> I'll need a flag in the registered buffer struct for dmabuf work, and
> it'll be more convenient to have a flags field rather than bit fields,
> especially for io_mapped_ubuf initialisation.
>
> We might want to add more flags in the future as well. For example, it
> might be useful for debugging and potentially optimisations to split out
> a flag indicating the shape of the buffer to gate iov_iter_advance()
> walks vs bit/mask arithmetics. It can also be combined with the
> direction mask field.
>
> [...]
Applied, thanks!
[1/1] io_uring/rsrc: replace reg buffer bit field with flags
commit: 0efc331d78b043b9d8477c64e279058062d36a0b
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-10 12:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-09 14:31 [PATCH] io_uring/rsrc: replace reg buffer bit field with flags Pavel Begunkov
2026-02-09 16:44 ` Caleb Sander Mateos
2026-02-10 9:51 ` Pavel Begunkov
2026-02-10 12:26 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox