History

Merge tag 'io_uring-6.2-2022-12-29' of git://git.kernel.dk/linux

Pull io_uring fixes from Jens Axboe: - Two fixes for mutex grabbing when the task state is != TASK_RUNNING (me) - Check for invalid opcode in io_uring_register() a bit earlier, to avoid going through the quiesce machinery just to return -EINVAL later in the process (me) - Fix for the uapi io_uring header, skipping including time_types.h when necessary (Stefan) * tag 'io_uring-6.2-2022-12-29' of git://git.kernel.dk/linux: uapi:io_uring.h: allow linux/time_types.h to be skipped io_uring: check for valid register opcode earlier io_uring/cancel: re-grab ctx mutex after finishing wait io_uring: finish waiting before flushing overflow entries

Linus Torvalds committed 3 years ago

Commit ac787ff2 parents 69fb073 9eb80343 files · +31 −16Browse files

Unified · Split

3 files
  1. include/uapi/linux/io_uring.h +8 −0
  2. io_uring/cancel.c +4 −5
  3. io_uring/io_uring.c +19 −11
include/uapi/linux/io_uring.h+8−0
@@ -10,7 +10,15 @@ · 9 unmodified lines
10 10
11#include <linux/fs.h>11#include <linux/fs.h>
12#include <linux/types.h>12#include <linux/types.h>
13/*
14 * this file is shared with liburing and that has to autodetect
15 * if linux/time_types.h is available or not, it can
16 * define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
17 * if linux/time_types.h is not available
18 */
19#ifndef UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
13#include <linux/time_types.h>20#include <linux/time_types.h>
21#endif
14 22
15#ifdef __cplusplus23#ifdef __cplusplus
16extern "C" {24extern "C" {
io_uring/cancel.c+4−5
@@ -288,24 +288,23 @@ int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg) · 287 unmodified lines
288 288
289 ret = __io_sync_cancel(current->io_uring, &cd, sc.fd);289 ret = __io_sync_cancel(current->io_uring, &cd, sc.fd);
290 290
291 mutex_unlock(&ctx->uring_lock);
291 if (ret != -EALREADY)292 if (ret != -EALREADY)
292 break;293 break;
293 294
294 mutex_unlock(&ctx->uring_lock);
295 ret = io_run_task_work_sig(ctx);295 ret = io_run_task_work_sig(ctx);
296 if (ret < 0) {296 if (ret < 0)
297 mutex_lock(&ctx->uring_lock);
298 break;297 break;
299 }
300 ret = schedule_hrtimeout(&timeout, HRTIMER_MODE_ABS);298 ret = schedule_hrtimeout(&timeout, HRTIMER_MODE_ABS);
301 mutex_lock(&ctx->uring_lock);
302 if (!ret) {299 if (!ret) {
303 ret = -ETIME;300 ret = -ETIME;
304 break;301 break;
305 }302 }
303 mutex_lock(&ctx->uring_lock);
306 } while (1);304 } while (1);
307 305
308 finish_wait(&ctx->cq_wait, &wait);306 finish_wait(&ctx->cq_wait, &wait);
307 mutex_lock(&ctx->uring_lock);
309 308
310 if (ret == -ENOENT || ret > 0)309 if (ret == -ENOENT || ret > 0)
311 ret = 0;310 ret = 0;
io_uring/io_uring.c+19−11
@@ -677,16 +677,20 @@ static void __io_cqring_overflow_flush(struct io_ring_ctx *ctx) · 676 unmodified lines
677 io_cq_unlock_post(ctx);677 io_cq_unlock_post(ctx);
678}678}
679 679
680static void io_cqring_do_overflow_flush(struct io_ring_ctx *ctx)
681{
682 /* iopoll syncs against uring_lock, not completion_lock */
683 if (ctx->flags & IORING_SETUP_IOPOLL)
684 mutex_lock(&ctx->uring_lock);
685 __io_cqring_overflow_flush(ctx);
686 if (ctx->flags & IORING_SETUP_IOPOLL)
687 mutex_unlock(&ctx->uring_lock);
688}
689
680static void io_cqring_overflow_flush(struct io_ring_ctx *ctx)690static void io_cqring_overflow_flush(struct io_ring_ctx *ctx)
681{691{
682 if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) {692 if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq))
683 /* iopoll syncs against uring_lock, not completion_lock */693 io_cqring_do_overflow_flush(ctx);
684 if (ctx->flags & IORING_SETUP_IOPOLL)
685 mutex_lock(&ctx->uring_lock);
686 __io_cqring_overflow_flush(ctx);
687 if (ctx->flags & IORING_SETUP_IOPOLL)
688 mutex_unlock(&ctx->uring_lock);
689 }
690}694}
691 695
692void __io_put_task(struct task_struct *task, int nr)696void __io_put_task(struct task_struct *task, int nr)
@@ -2549,7 +2553,10 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, · 1856 unmodified lines
2549 2553
2550 trace_io_uring_cqring_wait(ctx, min_events);2554 trace_io_uring_cqring_wait(ctx, min_events);
2551 do {2555 do {
2552 io_cqring_overflow_flush(ctx);2556 if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) {
2557 finish_wait(&ctx->cq_wait, &iowq.wq);
2558 io_cqring_do_overflow_flush(ctx);
2559 }
2553 prepare_to_wait_exclusive(&ctx->cq_wait, &iowq.wq,2560 prepare_to_wait_exclusive(&ctx->cq_wait, &iowq.wq,
2554 TASK_INTERRUPTIBLE);2561 TASK_INTERRUPTIBLE);
2555 ret = io_cqring_wait_schedule(ctx, &iowq, timeout);2562 ret = io_cqring_wait_schedule(ctx, &iowq, timeout);
@@ -4013,8 +4020,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, · 1457 unmodified lines
4013 return -EEXIST;4020 return -EEXIST;
4014 4021
4015 if (ctx->restricted) {4022 if (ctx->restricted) {
4016 if (opcode >= IORING_REGISTER_LAST)
4017 return -EINVAL;
4018 opcode = array_index_nospec(opcode, IORING_REGISTER_LAST);4023 opcode = array_index_nospec(opcode, IORING_REGISTER_LAST);
4019 if (!test_bit(opcode, ctx->restrictions.register_op))4024 if (!test_bit(opcode, ctx->restrictions.register_op))
4020 return -EACCES;4025 return -EACCES;
@@ -4170,6 +4175,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode, · 149 unmodified lines
4170 long ret = -EBADF;4175 long ret = -EBADF;
4171 struct fd f;4176 struct fd f;
4172 4177
4178 if (opcode >= IORING_REGISTER_LAST)
4179 return -EINVAL;
4180
4173 f = fdget(fd);4181 f = fdget(fd);
4174 if (!f.file)4182 if (!f.file)
4175 return -EBADF;4183 return -EBADF;