This is a note to let you know that I've just added the patch titled io_uring: wait interruptibly for request completions on exit to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: io_uring-wait-interruptibly-for-request-completions-on-exit.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 4826c59453b3b4677d6bf72814e7ababdea86949 Mon Sep 17 00:00:00 2001 From: Jens Axboe <axboe@xxxxxxxxx> Date: Sun, 11 Jun 2023 21:14:09 -0600 Subject: io_uring: wait interruptibly for request completions on exit From: Jens Axboe <axboe@xxxxxxxxx> commit 4826c59453b3b4677d6bf72814e7ababdea86949 upstream. 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@xxxxxxxxxxxxxxx # 5.10+ Link: https://lore.kernel.org/r/b0e4aaef-7088-56ce-244c-976edeac0e66@xxxxxxxxx Signed-off-by: Jens Axboe <axboe@xxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- io_uring/io_uring.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2748,7 +2748,18 @@ static __cold void io_ring_exit_work(str /* there is little hope left, don't run it too often */ interval = HZ * 60; } - } while (!wait_for_completion_timeout(&ctx->ref_comp, interval)); + /* + * This is really an uninterruptible wait, as it has to be + * complete. But it's also run from a kworker, which doesn't + * take signals, so it's fine to make it interruptible. This + * avoids scenarios where we knowingly can wait much longer + * on completions, for example if someone does a SIGSTOP on + * a task that needs to finish task_work to make this loop + * complete. That's a synthetic situation that should not + * cause a stuck task backtrace, and hence a potential panic + * on stuck tasks if that is enabled. + */ + } while (!wait_for_completion_interruptible_timeout(&ctx->ref_comp, interval)); init_completion(&exit.completion); init_task_work(&exit.task_work, io_tctx_exit_cb); @@ -2772,7 +2783,12 @@ static __cold void io_ring_exit_work(str continue; mutex_unlock(&ctx->uring_lock); - wait_for_completion(&exit.completion); + /* + * See comment above for + * wait_for_completion_interruptible_timeout() on why this + * wait is marked as interruptible. + */ + wait_for_completion_interruptible(&exit.completion); mutex_lock(&ctx->uring_lock); } mutex_unlock(&ctx->uring_lock); Patches currently in stable-queue which might be from axboe@xxxxxxxxx are queue-6.1/block-fix-the-type-of-the-second-bdev_op_is_zoned_wr.patch queue-6.1/block-change-all-__u32-annotations-to-__be32-in-affs_hardblocks.h.patch queue-6.1/bcache-fix-__bch_btree_node_alloc-to-make-the-failure-behavior-consistent.patch queue-6.1/blk-cgroup-don-t-update-io-stat-for-root-cgroup.patch queue-6.1/block-add-overflow-checks-for-amiga-partition-support.patch queue-6.1/block-fix-blktrace-debugfs-entries-leakage.patch queue-6.1/io_uring-wait-interruptibly-for-request-completions-on-exit.patch queue-6.1/bcache-fixup-btree_cache_wait-list-damage.patch queue-6.1/bcache-remove-unnecessary-null-point-check-in-node-allocations.patch queue-6.1/blk-iocost-use-spin_lock_irqsave-in-adjust_inuse_and.patch queue-6.1/blk-mq-fix-potential-io-hang-by-wrong-wake_batch.patch queue-6.1/block-fix-signed-int-overflow-in-amiga-partition-support.patch queue-6.1/blk-cgroup-optimize-blkcg_rstat_flush.patch queue-6.1/block-increment-diskseq-on-all-media-change-events.patch queue-6.1/blk-throttle-fix-io-statistics-for-cgroup-v1.patch