Commit 3e813c90 authored by Dylan Yudaken's avatar Dylan Yudaken Committed by Jens Axboe

io_uring: rework io_uring_enter to simplify return value

io_uring_enter returns the count submitted preferrably over an error
code. In some code paths this check is not required, so reorganise the
code so that the check is only done as needed.
This is also a prep for returning error codes only in waiting scenarios.
Signed-off-by: default avatarDylan Yudaken <dylany@fb.com>
Link: https://lore.kernel.org/r/20220421091345.2115755-4-dylany@fb.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 08dcd028
...@@ -10872,7 +10872,6 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -10872,7 +10872,6 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
size_t, argsz) size_t, argsz)
{ {
struct io_ring_ctx *ctx; struct io_ring_ctx *ctx;
int submitted = 0;
struct fd f; struct fd f;
long ret; long ret;
...@@ -10935,15 +10934,15 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -10935,15 +10934,15 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
if (ret) if (ret)
goto out; goto out;
} }
submitted = to_submit; ret = to_submit;
} else if (to_submit) { } else if (to_submit) {
ret = io_uring_add_tctx_node(ctx); ret = io_uring_add_tctx_node(ctx);
if (unlikely(ret)) if (unlikely(ret))
goto out; goto out;
mutex_lock(&ctx->uring_lock); mutex_lock(&ctx->uring_lock);
submitted = io_submit_sqes(ctx, to_submit); ret = io_submit_sqes(ctx, to_submit);
if (submitted != to_submit) { if (ret != to_submit) {
mutex_unlock(&ctx->uring_lock); mutex_unlock(&ctx->uring_lock);
goto out; goto out;
} }
...@@ -10952,6 +10951,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -10952,6 +10951,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
mutex_unlock(&ctx->uring_lock); mutex_unlock(&ctx->uring_lock);
} }
if (flags & IORING_ENTER_GETEVENTS) { if (flags & IORING_ENTER_GETEVENTS) {
int ret2;
if (ctx->syscall_iopoll) { if (ctx->syscall_iopoll) {
/* /*
* We disallow the app entering submit/complete with * We disallow the app entering submit/complete with
...@@ -10961,22 +10961,29 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -10961,22 +10961,29 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
*/ */
mutex_lock(&ctx->uring_lock); mutex_lock(&ctx->uring_lock);
iopoll_locked: iopoll_locked:
ret = io_validate_ext_arg(flags, argp, argsz); ret2 = io_validate_ext_arg(flags, argp, argsz);
if (likely(!ret)) { if (likely(!ret2)) {
min_complete = min(min_complete, ctx->cq_entries); min_complete = min(min_complete,
ret = io_iopoll_check(ctx, min_complete); ctx->cq_entries);
ret2 = io_iopoll_check(ctx, min_complete);
} }
mutex_unlock(&ctx->uring_lock); mutex_unlock(&ctx->uring_lock);
} else { } else {
const sigset_t __user *sig; const sigset_t __user *sig;
struct __kernel_timespec __user *ts; struct __kernel_timespec __user *ts;
ret = io_get_ext_arg(flags, argp, &argsz, &ts, &sig); ret2 = io_get_ext_arg(flags, argp, &argsz, &ts, &sig);
if (unlikely(ret)) if (likely(!ret2)) {
goto out; min_complete = min(min_complete,
min_complete = min(min_complete, ctx->cq_entries); ctx->cq_entries);
ret = io_cqring_wait(ctx, min_complete, sig, argsz, ts); ret2 = io_cqring_wait(ctx, min_complete, sig,
argsz, ts);
}
} }
if (!ret)
ret = ret2;
} }
out: out:
...@@ -10984,7 +10991,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -10984,7 +10991,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
out_fput: out_fput:
if (!(flags & IORING_ENTER_REGISTERED_RING)) if (!(flags & IORING_ENTER_REGISTERED_RING))
fdput(f); fdput(f);
return submitted ? submitted : ret; return ret;
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
......
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