Skip to content

Commit 0efc331

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: replace reg buffer bit field with flags
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> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 417d029 commit 0efc331

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

io_uring/rsrc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
828828
imu->folio_shift = PAGE_SHIFT;
829829
imu->release = io_release_ubuf;
830830
imu->priv = imu;
831-
imu->is_kbuf = false;
831+
imu->flags = 0;
832832
imu->dir = IO_IMU_DEST | IO_IMU_SOURCE;
833833
if (coalesced)
834834
imu->folio_shift = data.folio_shift;
@@ -985,7 +985,7 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
985985
refcount_set(&imu->refs, 1);
986986
imu->release = release;
987987
imu->priv = rq;
988-
imu->is_kbuf = true;
988+
imu->flags = IO_REGBUF_F_KBUF;
989989
imu->dir = 1 << rq_data_dir(rq);
990990

991991
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,
10201020
ret = -EINVAL;
10211021
goto unlock;
10221022
}
1023-
if (!node->buf->is_kbuf) {
1023+
if (!(node->buf->flags & IO_REGBUF_F_KBUF)) {
10241024
ret = -EBUSY;
10251025
goto unlock;
10261026
}
@@ -1076,7 +1076,7 @@ static int io_import_fixed(int ddir, struct iov_iter *iter,
10761076

10771077
offset = buf_addr - imu->ubuf;
10781078

1079-
if (imu->is_kbuf)
1079+
if (imu->flags & IO_REGBUF_F_KBUF)
10801080
return io_import_kbuf(ddir, iter, imu, len, offset);
10811081

10821082
/*
@@ -1496,7 +1496,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
14961496
iovec_off = vec->nr - nr_iovs;
14971497
iov = vec->iovec + iovec_off;
14981498

1499-
if (imu->is_kbuf) {
1499+
if (imu->flags & IO_REGBUF_F_KBUF) {
15001500
int ret = io_kern_bvec_size(iov, nr_iovs, imu, &nr_segs);
15011501

15021502
if (unlikely(ret))
@@ -1534,7 +1534,7 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter,
15341534
req->flags |= REQ_F_NEED_CLEANUP;
15351535
}
15361536

1537-
if (imu->is_kbuf)
1537+
if (imu->flags & IO_REGBUF_F_KBUF)
15381538
return io_vec_fill_kern_bvec(ddir, iter, imu, iov, nr_iovs, vec);
15391539

15401540
return io_vec_fill_bvec(ddir, iter, imu, iov, nr_iovs, vec);

io_uring/rsrc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ enum {
2828
IO_IMU_SOURCE = 1 << ITER_SOURCE,
2929
};
3030

31+
enum {
32+
IO_REGBUF_F_KBUF = 1,
33+
};
34+
3135
struct io_mapped_ubuf {
3236
u64 ubuf;
3337
unsigned int len;
@@ -37,7 +41,7 @@ struct io_mapped_ubuf {
3741
unsigned long acct_pages;
3842
void (*release)(void *);
3943
void *priv;
40-
bool is_kbuf;
44+
u8 flags;
4145
u8 dir;
4246
struct bio_vec bvec[] __counted_by(nr_bvecs);
4347
};

io_uring/rw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ static ssize_t loop_rw_iter(int ddir, struct io_rw *rw, struct iov_iter *iter)
702702
if ((kiocb->ki_flags & IOCB_NOWAIT) &&
703703
!(kiocb->ki_filp->f_flags & O_NONBLOCK))
704704
return -EAGAIN;
705-
if ((req->flags & REQ_F_BUF_NODE) && req->buf_node->buf->is_kbuf)
705+
if ((req->flags & REQ_F_BUF_NODE) &&
706+
(req->buf_node->buf->flags & IO_REGBUF_F_KBUF))
706707
return -EFAULT;
707708

708709
ppos = io_kiocb_ppos(kiocb);

0 commit comments

Comments
 (0)