Skip to content

Commit dc11632

Browse files
isilencegregkh
authored andcommitted
io_uring: return back safer resurrect
commit f70865d upstream. Revert of revert of "io_uring: wait potential ->release() on resurrect", which adds a helper for resurrect not racing completion reinit, as was removed because of a strange bug with no clear root or link to the patch. Was improved, instead of rcu_synchronize(), just wait_for_completion() because we're at 0 refs and it will happen very shortly. Specifically use non-interruptible version to ignore all pending signals that may have ended prior interruptible wait. This reverts commit cb5e1b8. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/7a080c20f686d026efade810b116b72f88abaff9.1618101759.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Cc: Lee Jones <lee.jones@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8fdaab3 commit dc11632

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

fs/io_uring.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,18 @@ static inline bool __io_match_files(struct io_kiocb *req,
10091009
req->work.identity->files == files;
10101010
}
10111011

1012+
static void io_refs_resurrect(struct percpu_ref *ref, struct completion *compl)
1013+
{
1014+
bool got = percpu_ref_tryget(ref);
1015+
1016+
/* already at zero, wait for ->release() */
1017+
if (!got)
1018+
wait_for_completion(compl);
1019+
percpu_ref_resurrect(ref);
1020+
if (got)
1021+
percpu_ref_put(ref);
1022+
}
1023+
10121024
static bool io_match_task(struct io_kiocb *head,
10131025
struct task_struct *task,
10141026
struct files_struct *files)
@@ -9757,12 +9769,11 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
97579769
if (ret < 0)
97589770
break;
97599771
} while (1);
9760-
97619772
mutex_lock(&ctx->uring_lock);
97629773

97639774
if (ret) {
9764-
percpu_ref_resurrect(&ctx->refs);
9765-
goto out_quiesce;
9775+
io_refs_resurrect(&ctx->refs, &ctx->ref_comp);
9776+
return ret;
97669777
}
97679778
}
97689779

@@ -9855,7 +9866,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
98559866
if (io_register_op_must_quiesce(opcode)) {
98569867
/* bring the ctx back to life */
98579868
percpu_ref_reinit(&ctx->refs);
9858-
out_quiesce:
98599869
reinit_completion(&ctx->ref_comp);
98609870
}
98619871
return ret;

0 commit comments

Comments
 (0)