From cb875051c00d7ee930f6724d1ceac17e6f35eb7f Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 8 Jan 2020 08:26:07 -0700 Subject: [PATCH] io_uring: file set registration should use interruptible waits to #26323588 commit c150368b496837cb207712e78f903ccfd7633b93 upstream. If an application attempts to register a set with unbounded requests pending, we can be stuck here forever if they don't complete. We can make this wait interruptible, and just abort if we get signaled. Signed-off-by: Jens Axboe Signed-off-by: Joseph Qi Acked-by: Xiaoguang Wang --- fs/io_uring.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 05f256b4100e..f7055ac0ad91 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6509,8 +6509,13 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, * after we've killed the percpu ref. */ mutex_unlock(&ctx->uring_lock); - wait_for_completion(&ctx->completions[0]); + ret = wait_for_completion_interruptible(&ctx->completions[0]); mutex_lock(&ctx->uring_lock); + if (ret) { + percpu_ref_resurrect(&ctx->refs); + ret = -EINTR; + goto out; + } } switch (opcode) { @@ -6556,8 +6561,9 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, if (opcode != IORING_UNREGISTER_FILES && opcode != IORING_REGISTER_FILES_UPDATE) { /* bring the ctx back to life */ - reinit_completion(&ctx->completions[0]); percpu_ref_reinit(&ctx->refs); +out: + reinit_completion(&ctx->completions[0]); } return ret; } -- GitLab