io_uring-6.2-2022-12-29

-----BEGIN PGP SIGNATURE-----
 
 iQJEBAABCAAuFiEEwPw5LcreJtl1+l5K99NY+ylx4KYFAmOt37UQHGF4Ym9lQGtl
 cm5lbC5kawAKCRD301j7KXHgpouKEACDwViycFQjYhITw6ENTvJMfAAY7TU1p8Di
 widhpRYUYQxuVJHdfyvOs/NTWMzj7okfsjilVLapq+v8jyNc+9TAMmbOJhYTydP0
 7MXCt8hRP304zKil0EsPR+U6WT1n8H8Jf5fxqduyYG3tfrB1ao+EMEyEZVKiufGj
 x78BOYfDQqtnbMNsxnUDfjl0zJP0tAjHYOncW09u/43Y/3XeOqdT1/fCGqO0N0Fn
 RnnnKtCRiZVSnnImTGqVHPkUKSL4FRCmChI8k42cYirP6rtjaWP/zmHyTAYs1ww0
 DHeq2n8MnRC156WpIAMGWoSv9G4YMpsnIfVH1JeAgp3FOErngLTX6+eMgcYITfJG
 BfcqxmqDdLSuJJp6uSZo14j5eIRDtxFryuPLLhuWfegc1FY7Ls1d+uaibOg9NMh3
 aYH/ij/VKzNhtdCh59mUeV/nrs6tXnsYpw1GMzNpriH3P9YeuYR2h3LdAiAAUHcC
 Z1/OtwThxWyKC4qEJPvQCqrJViDtLd5wEZDMicPu7HMKpYiypFiGlzA6sraHRKHp
 Bz/VnBFTWN+YqlJORKJPoDYbjMHd8gHzkbLV0dSjVOqHAw5S385YL7u8x8pPWD0f
 GSz96Nxi6UpRrW9zIcgFOrBleyYtr9Ip2r/6F6cXdDxONFOwtObB3Wrxhc7+Vwgh
 uNfRVUL6WQ==
 =SQf6
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2022-12-29 16:48:21 -08:00
commit ac787ffa5a
3 changed files with 31 additions and 16 deletions

View File

@ -10,7 +10,15 @@
#include <linux/fs.h>
#include <linux/types.h>
/*
* this file is shared with liburing and that has to autodetect
* if linux/time_types.h is available or not, it can
* define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
* if linux/time_types.h is not available
*/
#ifndef UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
#include <linux/time_types.h>
#endif
#ifdef __cplusplus
extern "C" {

View File

@ -288,24 +288,23 @@ int io_sync_cancel(struct io_ring_ctx *ctx, void __user *arg)
ret = __io_sync_cancel(current->io_uring, &cd, sc.fd);
mutex_unlock(&ctx->uring_lock);
if (ret != -EALREADY)
break;
mutex_unlock(&ctx->uring_lock);
ret = io_run_task_work_sig(ctx);
if (ret < 0) {
mutex_lock(&ctx->uring_lock);
if (ret < 0)
break;
}
ret = schedule_hrtimeout(&timeout, HRTIMER_MODE_ABS);
mutex_lock(&ctx->uring_lock);
if (!ret) {
ret = -ETIME;
break;
}
mutex_lock(&ctx->uring_lock);
} while (1);
finish_wait(&ctx->cq_wait, &wait);
mutex_lock(&ctx->uring_lock);
if (ret == -ENOENT || ret > 0)
ret = 0;

View File

@ -677,16 +677,20 @@ static void __io_cqring_overflow_flush(struct io_ring_ctx *ctx)
io_cq_unlock_post(ctx);
}
static void io_cqring_do_overflow_flush(struct io_ring_ctx *ctx)
{
/* iopoll syncs against uring_lock, not completion_lock */
if (ctx->flags & IORING_SETUP_IOPOLL)
mutex_lock(&ctx->uring_lock);
__io_cqring_overflow_flush(ctx);
if (ctx->flags & IORING_SETUP_IOPOLL)
mutex_unlock(&ctx->uring_lock);
}
static void io_cqring_overflow_flush(struct io_ring_ctx *ctx)
{
if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) {
/* iopoll syncs against uring_lock, not completion_lock */
if (ctx->flags & IORING_SETUP_IOPOLL)
mutex_lock(&ctx->uring_lock);
__io_cqring_overflow_flush(ctx);
if (ctx->flags & IORING_SETUP_IOPOLL)
mutex_unlock(&ctx->uring_lock);
}
if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq))
io_cqring_do_overflow_flush(ctx);
}
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,
trace_io_uring_cqring_wait(ctx, min_events);
do {
io_cqring_overflow_flush(ctx);
if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) {
finish_wait(&ctx->cq_wait, &iowq.wq);
io_cqring_do_overflow_flush(ctx);
}
prepare_to_wait_exclusive(&ctx->cq_wait, &iowq.wq,
TASK_INTERRUPTIBLE);
ret = io_cqring_wait_schedule(ctx, &iowq, timeout);
@ -4013,8 +4020,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
return -EEXIST;
if (ctx->restricted) {
if (opcode >= IORING_REGISTER_LAST)
return -EINVAL;
opcode = array_index_nospec(opcode, IORING_REGISTER_LAST);
if (!test_bit(opcode, ctx->restrictions.register_op))
return -EACCES;
@ -4170,6 +4175,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
long ret = -EBADF;
struct fd f;
if (opcode >= IORING_REGISTER_LAST)
return -EINVAL;
f = fdget(fd);
if (!f.file)
return -EBADF;