Skip to content

Commit f42b58e

Browse files
committed
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: Jens Axboe <[email protected]>
1 parent 2b8e976 commit f42b58e

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

io_uring/io_uring.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,13 +2384,18 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
23842384
return ret;
23852385
}
23862386

2387+
struct ext_arg {
2388+
size_t argsz;
2389+
struct __kernel_timespec __user *ts;
2390+
const sigset_t __user *sig;
2391+
};
2392+
23872393
/*
23882394
* Wait until events become available, if we don't already have some. The
23892395
* application must reap them itself, as they reside on the shared cq ring.
23902396
*/
23912397
static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
2392-
const sigset_t __user *sig, size_t sigsz,
2393-
struct __kernel_timespec __user *uts)
2398+
struct ext_arg *ext_arg)
23942399
{
23952400
struct io_wait_queue iowq;
23962401
struct io_rings *rings = ctx->rings;
@@ -2415,25 +2420,25 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
24152420
iowq.cq_tail = READ_ONCE(ctx->rings->cq.head) + min_events;
24162421
iowq.timeout = KTIME_MAX;
24172422

2418-
if (uts) {
2423+
if (ext_arg->ts) {
24192424
struct timespec64 ts;
24202425

2421-
if (get_timespec64(&ts, uts))
2426+
if (get_timespec64(&ts, ext_arg->ts))
24222427
return -EFAULT;
24232428

24242429
iowq.timeout = timespec64_to_ktime(ts);
24252430
if (!(flags & IORING_ENTER_ABS_TIMER))
24262431
iowq.timeout = ktime_add(iowq.timeout, io_get_time(ctx));
24272432
}
24282433

2429-
if (sig) {
2434+
if (ext_arg->sig) {
24302435
#ifdef CONFIG_COMPAT
24312436
if (in_compat_syscall())
2432-
ret = set_compat_user_sigmask((const compat_sigset_t __user *)sig,
2433-
sigsz);
2437+
ret = set_compat_user_sigmask((const compat_sigset_t __user *)ext_arg->sig,
2438+
ext_arg->argsz);
24342439
else
24352440
#endif
2436-
ret = set_user_sigmask(sig, sigsz);
2441+
ret = set_user_sigmask(ext_arg->sig, ext_arg->argsz);
24372442

24382443
if (ret)
24392444
return ret;
@@ -3112,9 +3117,8 @@ static int io_validate_ext_arg(unsigned flags, const void __user *argp, size_t a
31123117
return 0;
31133118
}
31143119

3115-
static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz,
3116-
struct __kernel_timespec __user **ts,
3117-
const sigset_t __user **sig)
3120+
static int io_get_ext_arg(unsigned flags, const void __user *argp,
3121+
struct ext_arg *ext_arg)
31183122
{
31193123
struct io_uring_getevents_arg arg;
31203124

@@ -3123,24 +3127,24 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp, size_t *argsz
31233127
* is just a pointer to the sigset_t.
31243128
*/
31253129
if (!(flags & IORING_ENTER_EXT_ARG)) {
3126-
*sig = (const sigset_t __user *) argp;
3127-
*ts = NULL;
3130+
ext_arg->sig = (const sigset_t __user *) argp;
3131+
ext_arg->ts = NULL;
31283132
return 0;
31293133
}
31303134

31313135
/*
31323136
* EXT_ARG is set - ensure we agree on the size of it and copy in our
31333137
* timespec and sigset_t pointers if good.
31343138
*/
3135-
if (*argsz != sizeof(arg))
3139+
if (ext_arg->argsz != sizeof(arg))
31363140
return -EINVAL;
31373141
if (copy_from_user(&arg, argp, sizeof(arg)))
31383142
return -EFAULT;
31393143
if (arg.pad)
31403144
return -EINVAL;
3141-
*sig = u64_to_user_ptr(arg.sigmask);
3142-
*argsz = arg.sigmask_sz;
3143-
*ts = u64_to_user_ptr(arg.ts);
3145+
ext_arg->sig = u64_to_user_ptr(arg.sigmask);
3146+
ext_arg->argsz = arg.sigmask_sz;
3147+
ext_arg->ts = u64_to_user_ptr(arg.ts);
31443148
return 0;
31453149
}
31463150

@@ -3246,15 +3250,14 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
32463250
}
32473251
mutex_unlock(&ctx->uring_lock);
32483252
} else {
3249-
const sigset_t __user *sig;
3250-
struct __kernel_timespec __user *ts;
3253+
struct ext_arg ext_arg = { .argsz = argsz };
32513254

3252-
ret2 = io_get_ext_arg(flags, argp, &argsz, &ts, &sig);
3255+
ret2 = io_get_ext_arg(flags, argp, &ext_arg);
32533256
if (likely(!ret2)) {
32543257
min_complete = min(min_complete,
32553258
ctx->cq_entries);
32563259
ret2 = io_cqring_wait(ctx, min_complete, flags,
3257-
sig, argsz, ts);
3260+
&ext_arg);
32583261
}
32593262
}
32603263

0 commit comments

Comments
 (0)