Commit f42b58e4 authored by Jens Axboe's avatar Jens Axboe

io_uring: encapsulate extraneous wait flags into a separate struct

Rather than need to pass in 2 or 3 separate arguments, add a struct
to encapsulate the timeout and sigset_t parts of waiting. In preparation
for adding another argument for waiting.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 2b8e976b
...@@ -2384,13 +2384,18 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx, ...@@ -2384,13 +2384,18 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
return ret; return ret;
} }
struct ext_arg {
size_t argsz;
struct __kernel_timespec __user *ts;
const sigset_t __user *sig;
};
/* /*
* Wait until events become available, if we don't already have some. The * Wait until events become available, if we don't already have some. The
* application must reap them itself, as they reside on the shared cq ring. * application must reap them itself, as they reside on the shared cq ring.
*/ */
static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags, static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
const sigset_t __user *sig, size_t sigsz, struct ext_arg *ext_arg)
struct __kernel_timespec __user *uts)
{ {
struct io_wait_queue iowq; struct io_wait_queue iowq;
struct io_rings *rings = ctx->rings; struct io_rings *rings = ctx->rings;
...@@ -2415,10 +2420,10 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags, ...@@ -2415,10 +2420,10 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
iowq.cq_tail = READ_ONCE(ctx->rings->cq.head) + min_events; iowq.cq_tail = READ_ONCE(ctx->rings->cq.head) + min_events;
iowq.timeout = KTIME_MAX; iowq.timeout = KTIME_MAX;
if (uts) { if (ext_arg->ts) {
struct timespec64 ts; struct timespec64 ts;
if (get_timespec64(&ts, uts)) if (get_timespec64(&ts, ext_arg->ts))
return -EFAULT; return -EFAULT;
iowq.timeout = timespec64_to_ktime(ts); iowq.timeout = timespec64_to_ktime(ts);
...@@ -2426,14 +2431,14 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags, ...@@ -2426,14 +2431,14 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
iowq.timeout = ktime_add(iowq.timeout, io_get_time(ctx)); iowq.timeout = ktime_add(iowq.timeout, io_get_time(ctx));
} }
if (sig) { if (ext_arg->sig) {
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
if (in_compat_syscall()) if (in_compat_syscall())
ret = set_compat_user_sigmask((const compat_sigset_t __user *)sig, ret = set_compat_user_sigmask((const compat_sigset_t __user *)ext_arg->sig,
sigsz); ext_arg->argsz);
else else
#endif #endif
ret = set_user_sigmask(sig, sigsz); ret = set_user_sigmask(ext_arg->sig, ext_arg->argsz);
if (ret) if (ret)
return ret; return ret;
...@@ -3112,9 +3117,8 @@ static int io_validate_ext_arg(unsigned flags, const void __user *argp, size_t a ...@@ -3112,9 +3117,8 @@ static int io_validate_ext_arg(unsigned flags, const void __user *argp, size_t a
return 0; return 0;
} }
static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz, static int io_get_ext_arg(unsigned flags, const void __user *argp,
struct __kernel_timespec __user **ts, struct ext_arg *ext_arg)
const sigset_t __user **sig)
{ {
struct io_uring_getevents_arg arg; struct io_uring_getevents_arg arg;
...@@ -3123,8 +3127,8 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz ...@@ -3123,8 +3127,8 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz
* is just a pointer to the sigset_t. * is just a pointer to the sigset_t.
*/ */
if (!(flags & IORING_ENTER_EXT_ARG)) { if (!(flags & IORING_ENTER_EXT_ARG)) {
*sig = (const sigset_t __user *) argp; ext_arg->sig = (const sigset_t __user *) argp;
*ts = NULL; ext_arg->ts = NULL;
return 0; return 0;
} }
...@@ -3132,15 +3136,15 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz ...@@ -3132,15 +3136,15 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz
* EXT_ARG is set - ensure we agree on the size of it and copy in our * EXT_ARG is set - ensure we agree on the size of it and copy in our
* timespec and sigset_t pointers if good. * timespec and sigset_t pointers if good.
*/ */
if (*argsz != sizeof(arg)) if (ext_arg->argsz != sizeof(arg))
return -EINVAL; return -EINVAL;
if (copy_from_user(&arg, argp, sizeof(arg))) if (copy_from_user(&arg, argp, sizeof(arg)))
return -EFAULT; return -EFAULT;
if (arg.pad) if (arg.pad)
return -EINVAL; return -EINVAL;
*sig = u64_to_user_ptr(arg.sigmask); ext_arg->sig = u64_to_user_ptr(arg.sigmask);
*argsz = arg.sigmask_sz; ext_arg->argsz = arg.sigmask_sz;
*ts = u64_to_user_ptr(arg.ts); ext_arg->ts = u64_to_user_ptr(arg.ts);
return 0; return 0;
} }
...@@ -3246,15 +3250,14 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, ...@@ -3246,15 +3250,14 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
} }
mutex_unlock(&ctx->uring_lock); mutex_unlock(&ctx->uring_lock);
} else { } else {
const sigset_t __user *sig; struct ext_arg ext_arg = { .argsz = argsz };
struct __kernel_timespec __user *ts;
ret2 = io_get_ext_arg(flags, argp, &argsz, &ts, &sig); ret2 = io_get_ext_arg(flags, argp, &ext_arg);
if (likely(!ret2)) { if (likely(!ret2)) {
min_complete = min(min_complete, min_complete = min(min_complete,
ctx->cq_entries); ctx->cq_entries);
ret2 = io_cqring_wait(ctx, min_complete, flags, ret2 = io_cqring_wait(ctx, min_complete, flags,
sig, argsz, ts); &ext_arg);
} }
} }
......
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