Skip to content

Commit 7143b5a

Browse files
stefano-garzarellaaxboe
authored andcommitted
io_uring: prevent sq_thread from spinning when it should stop
This patch drops 'cur_mm' before calling cond_resched(), to prevent the sq_thread from spinning even when the user process is finished. Before this patch, if the user process ended without closing the io_uring fd, the sq_thread continues to spin until the 'sq_thread_idle' timeout ends. In the worst case where the 'sq_thread_idle' parameter is bigger than INT_MAX, the sq_thread will spin forever. Fixes: 6c271ce ("io_uring: add submission polling") Signed-off-by: Stefano Garzarella <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 929a3af commit 7143b5a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

fs/io_uring.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5142,6 +5142,18 @@ static int io_sq_thread(void *data)
51425142
* to enter the kernel to reap and flush events.
51435143
*/
51445144
if (!to_submit || ret == -EBUSY) {
5145+
/*
5146+
* Drop cur_mm before scheduling, we can't hold it for
5147+
* long periods (or over schedule()). Do this before
5148+
* adding ourselves to the waitqueue, as the unuse/drop
5149+
* may sleep.
5150+
*/
5151+
if (cur_mm) {
5152+
unuse_mm(cur_mm);
5153+
mmput(cur_mm);
5154+
cur_mm = NULL;
5155+
}
5156+
51455157
/*
51465158
* We're polling. If we're within the defined idle
51475159
* period, then let us spin without work before going
@@ -5156,18 +5168,6 @@ static int io_sq_thread(void *data)
51565168
continue;
51575169
}
51585170

5159-
/*
5160-
* Drop cur_mm before scheduling, we can't hold it for
5161-
* long periods (or over schedule()). Do this before
5162-
* adding ourselves to the waitqueue, as the unuse/drop
5163-
* may sleep.
5164-
*/
5165-
if (cur_mm) {
5166-
unuse_mm(cur_mm);
5167-
mmput(cur_mm);
5168-
cur_mm = NULL;
5169-
}
5170-
51715171
prepare_to_wait(&ctx->sqo_wait, &wait,
51725172
TASK_INTERRUPTIBLE);
51735173

0 commit comments

Comments
 (0)