Skip to content

Commit 0a54a7d

Browse files
committed
io_uring: switch struct ext_arg from __kernel_timespec to timespec64
This avoids intermediate storage for turning a __kernel_timespec user pointer into an on-stack struct timespec64, only then to turn it into a ktime_t. Signed-off-by: Jens Axboe <[email protected]>
1 parent b898b8c commit 0a54a7d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

io_uring/io_uring.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,9 +2495,10 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24952495

24962496
struct ext_arg {
24972497
size_t argsz;
2498-
struct __kernel_timespec __user *ts;
2498+
struct timespec64 ts;
24992499
const sigset_t __user *sig;
25002500
ktime_t min_time;
2501+
bool ts_set;
25012502
};
25022503

25032504
/*
@@ -2535,13 +2536,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
25352536
iowq.timeout = KTIME_MAX;
25362537
start_time = io_get_time(ctx);
25372538

2538-
if (ext_arg->ts) {
2539-
struct timespec64 ts;
2540-
2541-
if (get_timespec64(&ts, ext_arg->ts))
2542-
return -EFAULT;
2543-
2544-
iowq.timeout = timespec64_to_ktime(ts);
2539+
if (ext_arg->ts_set) {
2540+
iowq.timeout = timespec64_to_ktime(ext_arg->ts);
25452541
if (!(flags & IORING_ENTER_ABS_TIMER))
25462542
iowq.timeout = ktime_add(iowq.timeout, start_time);
25472543
}
@@ -3252,7 +3248,6 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp,
32523248
*/
32533249
if (!(flags & IORING_ENTER_EXT_ARG)) {
32543250
ext_arg->sig = (const sigset_t __user *) argp;
3255-
ext_arg->ts = NULL;
32563251
return 0;
32573252
}
32583253

@@ -3267,7 +3262,11 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp,
32673262
ext_arg->min_time = arg.min_wait_usec * NSEC_PER_USEC;
32683263
ext_arg->sig = u64_to_user_ptr(arg.sigmask);
32693264
ext_arg->argsz = arg.sigmask_sz;
3270-
ext_arg->ts = u64_to_user_ptr(arg.ts);
3265+
if (arg.ts) {
3266+
if (get_timespec64(&ext_arg->ts, u64_to_user_ptr(arg.ts)))
3267+
return -EFAULT;
3268+
ext_arg->ts_set = true;
3269+
}
32713270
return 0;
32723271
}
32733272

0 commit comments

Comments
 (0)