msg-ring clean ups
cover msg-ring clean ups
Random cleanups I've got for msg_ring while doing some other feature. The confusion from Patch 1 reminded about itself the hard way.
Pavel Begunkov (3):
io_uring/msg: rename io_double_lock_ctx() io_uring/msg: initialise msg request opcode
io_uring: don't pass ctx to tw add remote helper
io_uring/io_uring.c | 14 ++++++-------- io_uring/io_uring.h | 3 +-- io_uring/msg_ring.c | 11 ++++++----- 3 files changed, 13 insertions(+), 15 deletions(-)
Signature · 1 line
2.48.1
PATCH 1/3 io_uring/msg: rename io_double_lock_ctx()
io_double_lock_ctx() doesn't lock both rings. Rename it to prevent any future confusion.
--- io_uring/msg_ring.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
io_uring/msg_ring.c +4 -4
@@ -38,8 +38,8 @@ static void io_double_unlock_ctx(struct io_ring_ctx *octx)mutex_unlock (&octx->uring_lock); } -static int io_double_lock_ctx (struct io_ring_ctx *octx, -unsigned int issue_flags) +static int io_lock_external_ctx (struct io_ring_ctx *octx, +unsigned int issue_flags) {/* * To ensure proper ordering between the two ctxs, we can only
@@ -154,7 +154,7 @@ static int __io_msg_ring_data(struct io_ring_ctx *target_ctx, ret = -EOVERFLOW ;if (target_ctx->flags &IORING_SETUP_IOPOLL ) { -if (unlikely (io_double_lock_ctx (target_ctx, issue_flags))) +if (unlikely (io_lock_external_ctx (target_ctx, issue_flags)))return -EAGAIN ; }if (io_post_aux_cqe (target_ctx, msg->user_data, msg->len, flags))
@@ -199,7 +199,7 @@ static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flagstruct file *src_file = msg->src_file;int ret; -if (unlikely (io_double_lock_ctx (target_ctx, issue_flags))) +if (unlikely (io_lock_external_ctx (target_ctx, issue_flags)))return -EAGAIN ; ret =__io_fixed_fd_install (target_ctx, src_file, msg->dst_fd);
Signature · 1 line
2.48.1
PATCH 2/3 io_uring/msg: initialise msg request opcode
In reply to Pavel BegunkovIt's risky to have msg request opcode set to garbage, so at least initialise it to nop. Later we might want to add a user inaccessible opcode for such cases.
--- io_uring/msg_ring.c | 1 + 1 file changed, 1 insertion(+)
io_uring/msg_ring.c +1 -0
@@ -93,6 +93,7 @@ static int io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req,kmem_cache_free (req_cachep, req);return -EOWNERDEAD ; } + req->opcode =IORING_OP_NOP ; req->cqe.user_data = user_data;io_req_set_res (req, res, cflags);percpu_ref_get (&ctx->refs);
Signature · 1 line
2.48.1
PATCH 3/3 io_uring: don't pass ctx to tw add remote helper
In reply to Pavel BegunkovUnlike earlier versions, io_msg_remote_post() creates a valid request with a proper context, so don't pass a context to io_req_task_work_add_remote() explicitly but derive it from the request.
--- io_uring/io_uring.c | 14 ++++++-------- io_uring/io_uring.h | 3 +-- io_uring/msg_ring.c | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-)
io_uring/io_uring.c +6 -8
@@ -1141,10 +1141,9 @@ void tctx_task_work(struct callback_head *cb)WARN_ON_ONCE (ret); } -static inline void io_req_local_work_add (struct io_kiocb *req, -struct io_ring_ctx *ctx, -unsigned flags) +static void io_req_local_work_add (struct io_kiocb *req,unsigned flags) { +struct io_ring_ctx *ctx = req->ctx;unsigned nr_wait, nr_tw, nr_tw_prev;struct llist_node *head;
@@ -1239,17 +1238,16 @@ static void io_req_normal_work_add(struct io_kiocb *req)void __io_req_task_work_add (struct io_kiocb *req,unsigned flags) {if (req->ctx->flags &IORING_SETUP_DEFER_TASKRUN ) -io_req_local_work_add (req, req->ctx, flags); +io_req_local_work_add (req, flags);else io_req_normal_work_add (req); } -void io_req_task_work_add_remote (struct io_kiocb *req,struct io_ring_ctx *ctx, -unsigned flags) +void io_req_task_work_add_remote (struct io_kiocb *req,unsigned flags) { -if (WARN_ON_ONCE (!(ctx->flags &IORING_SETUP_DEFER_TASKRUN ))) +if (WARN_ON_ONCE (!(req->ctx->flags &IORING_SETUP_DEFER_TASKRUN )))return ; -io_req_local_work_add (req, ctx, flags); +__io_req_task_work_add (req, flags); }static void __cold io_move_task_work_from_local (struct io_ring_ctx *ctx)
io_uring/io_uring.h +1 -2
@@ -89,8 +89,7 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags);void __io_req_task_work_add (struct io_kiocb *req,unsigned flags); -void io_req_task_work_add_remote (struct io_kiocb *req,struct io_ring_ctx *ctx, -unsigned flags); +void io_req_task_work_add_remote (struct io_kiocb *req,unsigned flags);bool io_alloc_async_data (struct io_kiocb *req);void io_req_task_queue (struct io_kiocb *req);void io_req_task_complete (struct io_kiocb *req,io_tw_token_t tw);
io_uring/msg_ring.c +1 -1
@@ -100,7 +100,7 @@ static int io_msg_remote_post(struct io_ring_ctx *ctx, struct io_kiocb *req, req->ctx = ctx; req->tctx =NULL ; req->io_task_work.func = io_msg_tw_complete; -io_req_task_work_add_remote (req, ctx,IOU_F_TWQ_LAZY_WAKE ); +io_req_task_work_add_remote (req,IOU_F_TWQ_LAZY_WAKE );return 0 ; }
Signature · 1 line
2.48.1
Quoted 9 lines · Pavel Begunkov
Random cleanups I've got for
msg_ringwhile doing some other feature. The confusion from Patch 1 reminded about itself the hard way.Pavel Begunkov (3):
io_uring/msg: renameio_double_lock_ctx()io_uring/msg: initialise msg request opcode
io_uring: don't pass ctx to tw add remote helper[...]
Applied, thanks!
[1/3] io_uring/msg: rename io_double_lock_ctx()
commit: b0e9570a6b19fb0e53090489838dc0de27795eb9
[2/3] io_uring/msg: initialise msg request opcode
commit: 9cc0bbdaba2a66ad90bc6ce45163b7745baffe98
[3/3] io_uring: don't pass ctx to tw add remote helper
commit: ea9106786e264483312b9b270fca1b506223338dBest regards,
Signature · 1 line
Jens Axboe