io_uring: refactor scheduling in io_cqring_wait
authorPavel Begunkov <asml.silence@gmail.com>
Thu, 4 Feb 2021 13:51:57 +0000 (13:51 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Mar 2021 09:51:12 +0000 (10:51 +0100)
[ Upstream commit c1d5a224683b333ddbe278e455d639ccd4f5ca2b ]

schedule_timeout() with timeout=MAX_SCHEDULE_TIMEOUT is guaranteed to
work just as schedule(), so instead of hand-coding it based on arguments
always use the timeout version and simplify code.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/io_uring.c

index 68508f010b908122e1b39e2c68cd6ebfb206844c..3e610ac062a332e474c10b47380823a52348e5d7 100644 (file)
@@ -7226,9 +7226,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
                .to_wait        = min_events,
        };
        struct io_rings *rings = ctx->rings;
-       struct timespec64 ts;
-       signed long timeout = 0;
-       int ret = 0;
+       signed long timeout = MAX_SCHEDULE_TIMEOUT;
+       int ret;
 
        do {
                io_cqring_overflow_flush(ctx, false, NULL, NULL);
@@ -7252,6 +7251,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
        }
 
        if (uts) {
+               struct timespec64 ts;
+
                if (get_timespec64(&ts, uts))
                        return -EFAULT;
                timeout = timespec64_to_jiffies(&ts);
@@ -7277,14 +7278,10 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
                        finish_wait(&ctx->wait, &iowq.wq);
                        continue;
                }
-               if (uts) {
-                       timeout = schedule_timeout(timeout);
-                       if (timeout == 0) {
-                               ret = -ETIME;
-                               break;
-                       }
-               } else {
-                       schedule();
+               timeout = schedule_timeout(timeout);
+               if (timeout == 0) {
+                       ret = -ETIME;
+                       break;
                }
        } while (1);
        finish_wait(&ctx->wait, &iowq.wq);