Skip to content

Commit 4826c59

Browse files
committed
io_uring: wait interruptibly for request completions on exit
WHen the ring exits, cleanup is done and the final cancelation and waiting on completions is done by io_ring_exit_work. That function is invoked by kworker, which doesn't take any signals. Because of that, it doesn't really matter if we wait for completions in TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE state. However, it does matter to the hung task detection checker! Normally we expect cancelations and completions to happen rather quickly. Some test cases, however, will exit the ring and park the owning task stopped (eg via SIGSTOP). If the owning task needs to run task_work to complete requests, then io_ring_exit_work won't make any progress until the task is runnable again. Hence io_ring_exit_work can trigger the hung task detection, which is particularly problematic if panic-on-hung-task is enabled. As the ring exit doesn't take signals to begin with, have it wait interruptibly rather than uninterruptibly. io_uring has a separate stuck-exit warning that triggers independently anyway, so we're not really missing anything by making this switch. Cc: stable@vger.kernel.org # 5.10+ Link: https://lore.kernel.org/r/b0e4aaef-7088-56ce-244c-976edeac0e66@kernel.dk Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 003f242 commit 4826c59

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

io_uring/io_uring.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,18 @@ static __cold void io_ring_exit_work(struct work_struct *work)
31213121
/* there is little hope left, don't run it too often */
31223122
interval = HZ * 60;
31233123
}
3124-
} while (!wait_for_completion_timeout(&ctx->ref_comp, interval));
3124+
/*
3125+
* This is really an uninterruptible wait, as it has to be
3126+
* complete. But it's also run from a kworker, which doesn't
3127+
* take signals, so it's fine to make it interruptible. This
3128+
* avoids scenarios where we knowingly can wait much longer
3129+
* on completions, for example if someone does a SIGSTOP on
3130+
* a task that needs to finish task_work to make this loop
3131+
* complete. That's a synthetic situation that should not
3132+
* cause a stuck task backtrace, and hence a potential panic
3133+
* on stuck tasks if that is enabled.
3134+
*/
3135+
} while (!wait_for_completion_interruptible_timeout(&ctx->ref_comp, interval));
31253136

31263137
init_completion(&exit.completion);
31273138
init_task_work(&exit.task_work, io_tctx_exit_cb);
@@ -3145,7 +3156,12 @@ static __cold void io_ring_exit_work(struct work_struct *work)
31453156
continue;
31463157

31473158
mutex_unlock(&ctx->uring_lock);
3148-
wait_for_completion(&exit.completion);
3159+
/*
3160+
* See comment above for
3161+
* wait_for_completion_interruptible_timeout() on why this
3162+
* wait is marked as interruptible.
3163+
*/
3164+
wait_for_completion_interruptible(&exit.completion);
31493165
mutex_lock(&ctx->uring_lock);
31503166
}
31513167
mutex_unlock(&ctx->uring_lock);

0 commit comments

Comments
 (0)