public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] msg-ring clean ups
@ 2025-03-28 23:11 Pavel Begunkov
  2025-03-28 23:11 ` [PATCH 1/3] io_uring/msg: rename io_double_lock_ctx() Pavel Begunkov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pavel Begunkov @ 2025-03-28 23:11 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

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(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] io_uring/msg: rename io_double_lock_ctx()
  2025-03-28 23:11 [PATCH 0/3] msg-ring clean ups Pavel Begunkov
@ 2025-03-28 23:11 ` Pavel Begunkov
  2025-03-28 23:11 ` [PATCH 2/3] io_uring/msg: initialise msg request opcode Pavel Begunkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2025-03-28 23:11 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

io_double_lock_ctx() doesn't lock both rings. Rename it to prevent any
future confusion.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/msg_ring.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index 0bbcbbcdebfd..bea5a96587b7 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -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_flag
 	struct 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);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] io_uring/msg: initialise msg request opcode
  2025-03-28 23:11 [PATCH 0/3] msg-ring clean ups Pavel Begunkov
  2025-03-28 23:11 ` [PATCH 1/3] io_uring/msg: rename io_double_lock_ctx() Pavel Begunkov
@ 2025-03-28 23:11 ` Pavel Begunkov
  2025-03-28 23:11 ` [PATCH 3/3] io_uring: don't pass ctx to tw add remote helper Pavel Begunkov
  2025-03-29 11:57 ` [PATCH 0/3] msg-ring clean ups Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2025-03-28 23:11 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

It'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.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/msg_ring.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index bea5a96587b7..6c51b942d020 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -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);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] io_uring: don't pass ctx to tw add remote helper
  2025-03-28 23:11 [PATCH 0/3] msg-ring clean ups Pavel Begunkov
  2025-03-28 23:11 ` [PATCH 1/3] io_uring/msg: rename io_double_lock_ctx() Pavel Begunkov
  2025-03-28 23:11 ` [PATCH 2/3] io_uring/msg: initialise msg request opcode Pavel Begunkov
@ 2025-03-28 23:11 ` Pavel Begunkov
  2025-03-29 11:57 ` [PATCH 0/3] msg-ring clean ups Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2025-03-28 23:11 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Unlike 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.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 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(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 4e362c8542a7..cb17deffd6ca 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -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)
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 2308f39ed915..861f4fcb1398 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -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);
diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index 6c51b942d020..50a958e9c921 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -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;
 }
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] msg-ring clean ups
  2025-03-28 23:11 [PATCH 0/3] msg-ring clean ups Pavel Begunkov
                   ` (2 preceding siblings ...)
  2025-03-28 23:11 ` [PATCH 3/3] io_uring: don't pass ctx to tw add remote helper Pavel Begunkov
@ 2025-03-29 11:57 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2025-03-29 11:57 UTC (permalink / raw)
  To: io-uring, Pavel Begunkov


On Fri, 28 Mar 2025 23:11:48 +0000, Pavel Begunkov wrote:
> 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
> 
> [...]

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: ea9106786e264483312b9b270fca1b506223338d

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-29 11:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-28 23:11 [PATCH 0/3] msg-ring clean ups Pavel Begunkov
2025-03-28 23:11 ` [PATCH 1/3] io_uring/msg: rename io_double_lock_ctx() Pavel Begunkov
2025-03-28 23:11 ` [PATCH 2/3] io_uring/msg: initialise msg request opcode Pavel Begunkov
2025-03-28 23:11 ` [PATCH 3/3] io_uring: don't pass ctx to tw add remote helper Pavel Begunkov
2025-03-29 11:57 ` [PATCH 0/3] msg-ring clean ups Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox