Skip to content

Commit fbb8bb0

Browse files
isilenceaxboe
authored andcommitted
io_uring: remove ctx->refs pinning on enter
io_uring_enter() takes ctx->refs, which was previously preventing racing with register quiesce. However, as register now doesn't touch the refs, we can freely kill extra ctx pinning and rely on the fact that we're holding a file reference preventing the ring from being destroyed. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/a11c57ad33a1be53541fce90669c1b79cf4d8940.1656153286.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 3273c44 commit fbb8bb0

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

io_uring/io_uring.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,14 +3049,10 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
30493049
return -EBADF;
30503050
ret = -EOPNOTSUPP;
30513051
if (unlikely(!io_is_uring_fops(f.file)))
3052-
goto out_fput;
3052+
goto out;
30533053
}
30543054

3055-
ret = -ENXIO;
30563055
ctx = f.file->private_data;
3057-
if (unlikely(!percpu_ref_tryget(&ctx->refs)))
3058-
goto out_fput;
3059-
30603056
ret = -EBADFD;
30613057
if (unlikely(ctx->flags & IORING_SETUP_R_DISABLED))
30623058
goto out;
@@ -3141,10 +3137,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
31413137
&ctx->check_cq);
31423138
}
31433139
}
3144-
31453140
out:
3146-
percpu_ref_put(&ctx->refs);
3147-
out_fput:
31483141
fdput(f);
31493142
return ret;
31503143
}
@@ -3730,11 +3723,10 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
37303723
int ret;
37313724

37323725
/*
3733-
* We're inside the ring mutex, if the ref is already dying, then
3734-
* someone else killed the ctx or is already going through
3735-
* io_uring_register().
3726+
* We don't quiesce the refs for register anymore and so it can't be
3727+
* dying as we're holding a file ref here.
37363728
*/
3737-
if (percpu_ref_is_dying(&ctx->refs))
3729+
if (WARN_ON_ONCE(percpu_ref_is_dying(&ctx->refs)))
37383730
return -ENXIO;
37393731

37403732
if (ctx->restricted) {

0 commit comments

Comments
 (0)