Skip to content

Commit 29ebfdd

Browse files
joannekoongaxboe
authored andcommitted
io_uring/rsrc: rename io_buffer_register_bvec()/io_buffer_unregister_bvec()
Currently, io_buffer_register_bvec() takes in a request. In preparation for supporting kernel-populated buffers in fuse io-uring (which will need to register bvecs directly, not through a struct request), rename this to io_buffer_register_request(). A subsequent patch will commandeer the "io_buffer_register_bvec()" function name to support registering bvecs directly. Rename io_buffer_unregister_bvec() to a more generic name, io_buffer_unregister(), as both io_buffer_register_request() and io_buffer_register_bvec() callers will use it for unregistration. Signed-off-by: Joanne Koong <joannelkoong@gmail.com> Reviewed-by: Caleb Sander Mateos <csander@purestorage.com> Link: https://patch.msgid.link/20260403174139.3634824-2-joannelkoong@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 381b604 commit 29ebfdd

4 files changed

Lines changed: 44 additions & 31 deletions

File tree

Documentation/block/ublk.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,17 @@ Zero copy
382382
---------
383383

384384
ublk zero copy relies on io_uring's fixed kernel buffer, which provides
385-
two APIs: `io_buffer_register_bvec()` and `io_buffer_unregister_bvec`.
385+
two APIs: `io_buffer_register_request()` and `io_buffer_unregister`.
386386

387387
ublk adds IO command of `UBLK_IO_REGISTER_IO_BUF` to call
388-
`io_buffer_register_bvec()` for ublk server to register client request
388+
`io_buffer_register_request()` for ublk server to register client request
389389
buffer into io_uring buffer table, then ublk server can submit io_uring
390390
IOs with the registered buffer index. IO command of `UBLK_IO_UNREGISTER_IO_BUF`
391-
calls `io_buffer_unregister_bvec()` to unregister the buffer, which is
392-
guaranteed to be live between calling `io_buffer_register_bvec()` and
393-
`io_buffer_unregister_bvec()`. Any io_uring operation which supports this
394-
kind of kernel buffer will grab one reference of the buffer until the
395-
operation is completed.
391+
calls `io_buffer_unregister()` to unregister the buffer, which is guaranteed
392+
to be live between calling `io_buffer_register_request()` and
393+
`io_buffer_unregister()`. Any io_uring operation which supports this kind of
394+
kernel buffer will grab one reference of the buffer until the operation is
395+
completed.
396396

397397
ublk server implementing zero copy or user copy has to be CAP_SYS_ADMIN and
398398
be trusted, because it is ublk server's responsibility to make sure IO buffer

drivers/block/ublk_drv.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,8 +1627,8 @@ ublk_auto_buf_register(const struct ublk_queue *ubq, struct request *req,
16271627
{
16281628
int ret;
16291629

1630-
ret = io_buffer_register_bvec(cmd, req, ublk_io_release,
1631-
io->buf.auto_reg.index, issue_flags);
1630+
ret = io_buffer_register_request(cmd, req, ublk_io_release,
1631+
io->buf.auto_reg.index, issue_flags);
16321632
if (ret) {
16331633
if (io->buf.auto_reg.flags & UBLK_AUTO_BUF_REG_FALLBACK) {
16341634
ublk_auto_buf_reg_fallback(ubq, req->tag);
@@ -1828,7 +1828,7 @@ static noinline void ublk_batch_dispatch_fail(struct ublk_queue *ubq,
18281828
ublk_io_unlock(io);
18291829

18301830
if (index != -1)
1831-
io_buffer_unregister_bvec(data->cmd, index,
1831+
io_buffer_unregister(data->cmd, index,
18321832
data->issue_flags);
18331833
}
18341834

@@ -3097,8 +3097,8 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
30973097
if (!req)
30983098
return -EINVAL;
30993099

3100-
ret = io_buffer_register_bvec(cmd, req, ublk_io_release, index,
3101-
issue_flags);
3100+
ret = io_buffer_register_request(cmd, req, ublk_io_release, index,
3101+
issue_flags);
31023102
if (ret) {
31033103
ublk_put_req_ref(io, req);
31043104
return ret;
@@ -3129,8 +3129,8 @@ ublk_daemon_register_io_buf(struct io_uring_cmd *cmd,
31293129
if (!ublk_dev_support_zero_copy(ub) || !ublk_rq_has_data(req))
31303130
return -EINVAL;
31313131

3132-
ret = io_buffer_register_bvec(cmd, req, ublk_io_release, index,
3133-
issue_flags);
3132+
ret = io_buffer_register_request(cmd, req, ublk_io_release, index,
3133+
issue_flags);
31343134
if (ret)
31353135
return ret;
31363136

@@ -3145,7 +3145,7 @@ static int ublk_unregister_io_buf(struct io_uring_cmd *cmd,
31453145
if (!(ub->dev_info.flags & UBLK_F_SUPPORT_ZERO_COPY))
31463146
return -EINVAL;
31473147

3148-
return io_buffer_unregister_bvec(cmd, index, issue_flags);
3148+
return io_buffer_unregister(cmd, index, issue_flags);
31493149
}
31503150

31513151
static int ublk_check_fetch_buf(const struct ublk_device *ub, __u64 buf_addr)
@@ -3286,7 +3286,7 @@ static int ublk_ch_uring_cmd_local(struct io_uring_cmd *cmd,
32863286
goto out;
32873287

32883288
/*
3289-
* io_buffer_unregister_bvec() doesn't access the ubq or io,
3289+
* io_buffer_unregister() doesn't access the ubq or io,
32903290
* so no need to validate the q_id, tag, or task
32913291
*/
32923292
if (_IOC_NR(cmd_op) == UBLK_IO_UNREGISTER_IO_BUF)
@@ -3353,7 +3353,7 @@ static int ublk_ch_uring_cmd_local(struct io_uring_cmd *cmd,
33533353
req = ublk_fill_io_cmd(io, cmd);
33543354
ret = ublk_config_io_buf(ub, io, cmd, addr, &buf_idx);
33553355
if (buf_idx != UBLK_INVALID_BUF_IDX)
3356-
io_buffer_unregister_bvec(cmd, buf_idx, issue_flags);
3356+
io_buffer_unregister(cmd, buf_idx, issue_flags);
33573357
compl = ublk_need_complete_req(ub, io);
33583358

33593359
if (req_op(req) == REQ_OP_ZONE_APPEND)
@@ -3688,7 +3688,7 @@ static int ublk_batch_commit_io(struct ublk_queue *ubq,
36883688
}
36893689

36903690
if (buf_idx != UBLK_INVALID_BUF_IDX)
3691-
io_buffer_unregister_bvec(data->cmd, buf_idx, data->issue_flags);
3691+
io_buffer_unregister(data->cmd, buf_idx, data->issue_flags);
36923692
if (req_op(req) == REQ_OP_ZONE_APPEND)
36933693
req->__sector = ublk_batch_zone_lba(uc, elem);
36943694
if (compl)

include/linux/io_uring/cmd.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ struct io_br_sel io_uring_cmd_buffer_select(struct io_uring_cmd *ioucmd,
9191
bool io_uring_mshot_cmd_post_cqe(struct io_uring_cmd *ioucmd,
9292
struct io_br_sel *sel, unsigned int issue_flags);
9393

94+
int io_buffer_register_request(struct io_uring_cmd *cmd, struct request *rq,
95+
void (*release)(void *), unsigned int index,
96+
unsigned int issue_flags);
97+
int io_buffer_unregister(struct io_uring_cmd *cmd, unsigned int index,
98+
unsigned int issue_flags);
9499
#else
95100
static inline int
96101
io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
@@ -133,6 +138,20 @@ static inline bool io_uring_mshot_cmd_post_cqe(struct io_uring_cmd *ioucmd,
133138
{
134139
return true;
135140
}
141+
static inline int io_buffer_register_request(struct io_uring_cmd *cmd,
142+
struct request *rq,
143+
void (*release)(void *),
144+
unsigned int index,
145+
unsigned int issue_flags)
146+
{
147+
return -EOPNOTSUPP;
148+
}
149+
static inline int io_buffer_unregister(struct io_uring_cmd *cmd,
150+
unsigned int index,
151+
unsigned int issue_flags)
152+
{
153+
return -EOPNOTSUPP;
154+
}
136155
#endif
137156

138157
static inline struct io_uring_cmd *io_uring_cmd_from_tw(struct io_tw_req tw_req)
@@ -182,10 +201,4 @@ static inline void io_uring_cmd_done32(struct io_uring_cmd *ioucmd, s32 ret,
182201
return __io_uring_cmd_done(ioucmd, ret, res2, issue_flags, true);
183202
}
184203

185-
int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
186-
void (*release)(void *), unsigned int index,
187-
unsigned int issue_flags);
188-
int io_buffer_unregister_bvec(struct io_uring_cmd *cmd, unsigned int index,
189-
unsigned int issue_flags);
190-
191204
#endif /* _LINUX_IO_URING_CMD_H */

io_uring/rsrc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,9 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
924924
return ret;
925925
}
926926

927-
int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
928-
void (*release)(void *), unsigned int index,
929-
unsigned int issue_flags)
927+
int io_buffer_register_request(struct io_uring_cmd *cmd, struct request *rq,
928+
void (*release)(void *), unsigned int index,
929+
unsigned int issue_flags)
930930
{
931931
struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
932932
struct io_rsrc_data *data = &ctx->buf_table;
@@ -986,10 +986,10 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
986986
io_ring_submit_unlock(ctx, issue_flags);
987987
return ret;
988988
}
989-
EXPORT_SYMBOL_GPL(io_buffer_register_bvec);
989+
EXPORT_SYMBOL_GPL(io_buffer_register_request);
990990

991-
int io_buffer_unregister_bvec(struct io_uring_cmd *cmd, unsigned int index,
992-
unsigned int issue_flags)
991+
int io_buffer_unregister(struct io_uring_cmd *cmd, unsigned int index,
992+
unsigned int issue_flags)
993993
{
994994
struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
995995
struct io_rsrc_data *data = &ctx->buf_table;
@@ -1019,7 +1019,7 @@ int io_buffer_unregister_bvec(struct io_uring_cmd *cmd, unsigned int index,
10191019
io_ring_submit_unlock(ctx, issue_flags);
10201020
return ret;
10211021
}
1022-
EXPORT_SYMBOL_GPL(io_buffer_unregister_bvec);
1022+
EXPORT_SYMBOL_GPL(io_buffer_unregister);
10231023

10241024
static int validate_fixed_range(u64 buf_addr, size_t len,
10251025
const struct io_mapped_ubuf *imu)

0 commit comments

Comments
 (0)