Skip to content

Commit ac787ff

Browse files
committed
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
2 parents 69fb073 + 9eb8034 commit ac787ff

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

include/uapi/linux/io_uring.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010

1111
#include <linux/fs.h>
1212
#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
1320
#include <linux/time_types.h>
21+
#endif
1422

1523
#ifdef __cplusplus
1624
extern "C" {

io_uring/cancel.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,24 +288,23 @@ int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg)
288288

289289
ret = __io_sync_cancel(current->io_uring, &cd, sc.fd);
290290

291+
mutex_unlock(&ctx->uring_lock);
291292
if (ret != -EALREADY)
292293
break;
293294

294-
mutex_unlock(&ctx->uring_lock);
295295
ret = io_run_task_work_sig(ctx);
296-
if (ret < 0) {
297-
mutex_lock(&ctx->uring_lock);
296+
if (ret < 0)
298297
break;
299-
}
300298
ret = schedule_hrtimeout(&timeout, HRTIMER_MODE_ABS);
301-
mutex_lock(&ctx->uring_lock);
302299
if (!ret) {
303300
ret = -ETIME;
304301
break;
305302
}
303+
mutex_lock(&ctx->uring_lock);
306304
} while (1);
307305

308306
finish_wait(&ctx->cq_wait, &wait);
307+
mutex_lock(&ctx->uring_lock);
309308

310309
if (ret == -ENOENT || ret > 0)
311310
ret = 0;

io_uring/io_uring.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -677,16 +677,20 @@ static void __io_cqring_overflow_flush(struct io_ring_ctx *ctx)
677677
io_cq_unlock_post(ctx);
678678
}
679679

680+
static 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+
680690
static void io_cqring_overflow_flush(struct io_ring_ctx *ctx)
681691
{
682-
if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) {
683-
/* iopoll syncs against uring_lock, not completion_lock */
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-
}
692+
if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq))
693+
io_cqring_do_overflow_flush(ctx);
690694
}
691695

692696
void __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,
25492553

25502554
trace_io_uring_cqring_wait(ctx, min_events);
25512555
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+
}
25532560
prepare_to_wait_exclusive(&ctx->cq_wait, &iowq.wq,
25542561
TASK_INTERRUPTIBLE);
25552562
ret = io_cqring_wait_schedule(ctx, &iowq, timeout);
@@ -4013,8 +4020,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
40134020
return -EEXIST;
40144021

40154022
if (ctx->restricted) {
4016-
if (opcode >= IORING_REGISTER_LAST)
4017-
return -EINVAL;
40184023
opcode = array_index_nospec(opcode, IORING_REGISTER_LAST);
40194024
if (!test_bit(opcode, ctx->restrictions.register_op))
40204025
return -EACCES;
@@ -4170,6 +4175,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
41704175
long ret = -EBADF;
41714176
struct fd f;
41724177

4178+
if (opcode >= IORING_REGISTER_LAST)
4179+
return -EINVAL;
4180+
41734181
f = fdget(fd);
41744182
if (!f.file)
41754183
return -EBADF;

0 commit comments

Comments
 (0)