Skip to content

Commit 6ff1407

Browse files
committed
io_uring: ensure local task_work is run on wait timeout
A previous commit added an earlier break condition here, which is fine if we're using non-local task_work as it'll be run on return to userspace. However, if DEFER_TASKRUN is used, then we could be leaving local task_work that is ready to process in the ctx list until next time that we enter the kernel to wait for events. Move the break condition to _after_ we have run task_work. Cc: [email protected] Fixes: 846072f ("io_uring: mimimise io_cqring_wait_schedule") Signed-off-by: Jens Axboe <[email protected]>
1 parent d293b1a commit 6ff1407

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

io_uring/io_uring.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,8 +2615,6 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
26152615
__set_current_state(TASK_RUNNING);
26162616
atomic_set(&ctx->cq_wait_nr, 0);
26172617

2618-
if (ret < 0)
2619-
break;
26202618
/*
26212619
* Run task_work after scheduling and before io_should_wake().
26222620
* If we got woken because of task_work being processed, run it
@@ -2626,6 +2624,18 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
26262624
if (!llist_empty(&ctx->work_llist))
26272625
io_run_local_work(ctx);
26282626

2627+
/*
2628+
* Non-local task_work will be run on exit to userspace, but
2629+
* if we're using DEFER_TASKRUN, then we could have waited
2630+
* with a timeout for a number of requests. If the timeout
2631+
* hits, we could have some requests ready to process. Ensure
2632+
* this break is _after_ we have run task_work, to avoid
2633+
* deferring running potentially pending requests until the
2634+
* next time we wait for events.
2635+
*/
2636+
if (ret < 0)
2637+
break;
2638+
26292639
check_cq = READ_ONCE(ctx->check_cq);
26302640
if (unlikely(check_cq)) {
26312641
/* let the caller flush overflows, retry */

0 commit comments

Comments
 (0)