Commit fbb8bb02 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

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: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/a11c57ad33a1be53541fce90669c1b79cf4d8940.1656153286.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 3273c440
...@@ -3049,14 +3049,10 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -3049,14 +3049,10 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
return -EBADF; return -EBADF;
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
if (unlikely(!io_is_uring_fops(f.file))) if (unlikely(!io_is_uring_fops(f.file)))
goto out_fput; goto out;
} }
ret = -ENXIO;
ctx = f.file->private_data; ctx = f.file->private_data;
if (unlikely(!percpu_ref_tryget(&ctx->refs)))
goto out_fput;
ret = -EBADFD; ret = -EBADFD;
if (unlikely(ctx->flags & IORING_SETUP_R_DISABLED)) if (unlikely(ctx->flags & IORING_SETUP_R_DISABLED))
goto out; goto out;
...@@ -3141,10 +3137,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -3141,10 +3137,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
&ctx->check_cq); &ctx->check_cq);
} }
} }
out: out:
percpu_ref_put(&ctx->refs);
out_fput:
fdput(f); fdput(f);
return ret; return ret;
} }
...@@ -3730,11 +3723,10 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, ...@@ -3730,11 +3723,10 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
int ret; int ret;
/* /*
* We're inside the ring mutex, if the ref is already dying, then * We don't quiesce the refs for register anymore and so it can't be
* someone else killed the ctx or is already going through * dying as we're holding a file ref here.
* io_uring_register().
*/ */
if (percpu_ref_is_dying(&ctx->refs)) if (WARN_ON_ONCE(percpu_ref_is_dying(&ctx->refs)))
return -ENXIO; return -ENXIO;
if (ctx->restricted) { if (ctx->restricted) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment