* [RFC 1/1] io_uring: pin context while queueing deferred tw
@ 2023-01-04 1:34 Pavel Begunkov
2023-01-04 1:36 ` Pavel Begunkov
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2023-01-04 1:34 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, asml.silence
Unlike normal tw, nothing prevents deferred tw to be executed right
after an tw item added to ->work_llist in io_req_local_work_add(). For
instance, the waiting task may get waken up by CQ posting or a normal
tw. Thus we need to pin the ring for the rest of io_req_local_work_add()
Cc: [email protected]
Fixes: c0e0d6ba25f18 ("io_uring: add IORING_SETUP_DEFER_TASKRUN")
Signed-off-by: Pavel Begunkov <[email protected]>
---
io_uring/io_uring.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 58ac13b69dc8..6bed44855679 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1236,13 +1236,18 @@ static void io_req_local_work_add(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
- if (!llist_add(&req->io_task_work.node, &ctx->work_llist))
+ percpu_ref_get(&ctx->refs);
+
+ if (!llist_add(&req->io_task_work.node, &ctx->work_llist)) {
+ percpu_ref_put(&ctx->refs);
return;
+ }
/* need it for the following io_cqring_wake() */
smp_mb__after_atomic();
if (unlikely(atomic_read(&req->task->io_uring->in_idle))) {
io_move_task_work_from_local(ctx);
+ percpu_ref_put(&ctx->refs);
return;
}
@@ -1252,6 +1257,7 @@ static void io_req_local_work_add(struct io_kiocb *req)
if (ctx->has_evfd)
io_eventfd_signal(ctx);
__io_cqring_wake(ctx);
+ percpu_ref_put(&ctx->refs);
}
void __io_req_task_work_add(struct io_kiocb *req, bool allow_local)
--
2.38.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC 1/1] io_uring: pin context while queueing deferred tw
@ 2023-01-04 16:13 Jens Axboe
0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2023-01-04 16:13 UTC (permalink / raw)
To: io-uring, Pavel Begunkov
On Wed, 04 Jan 2023 01:34:02 +0000, Pavel Begunkov wrote:
> Unlike normal tw, nothing prevents deferred tw to be executed right
> after an tw item added to ->work_llist in io_req_local_work_add(). For
> instance, the waiting task may get waken up by CQ posting or a normal
> tw. Thus we need to pin the ring for the rest of io_req_local_work_add()
>
>
Applied, thanks!
[1/1] io_uring: pin context while queueing deferred tw
(no commit info)
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-04 16:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-04 1:34 [RFC 1/1] io_uring: pin context while queueing deferred tw Pavel Begunkov
2023-01-04 1:36 ` Pavel Begunkov
-- strict thread matches above, loose matches on Subject: below --
2023-01-04 16:13 Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox