|
| 1 | +From 1863335f591d6a708fb5321fe10504174fddc9ee Mon Sep 17 00:00:00 2001 |
| 2 | +From: Pavel Begunkov <asml.silence@gmail.com> |
| 3 | +Date: Wed, 10 Apr 2024 02:26:54 +0100 |
| 4 | +Subject: [PATCH] io_uring: always lock __io_cqring_overflow_flush |
| 5 | + |
| 6 | +Commit 8d09a88ef9d3cb7d21d45c39b7b7c31298d23998 upstream. |
| 7 | + |
| 8 | +Conditional locking is never great, in case of |
| 9 | +__io_cqring_overflow_flush(), which is a slow path, it's not justified. |
| 10 | +Don't handle IOPOLL separately, always grab uring_lock for overflow |
| 11 | +flushing. |
| 12 | + |
| 13 | +Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> |
| 14 | +Link: https://lore.kernel.org/r/162947df299aa12693ac4b305dacedab32ec7976.1712708261.git.asml.silence@gmail.com |
| 15 | +Signed-off-by: Jens Axboe <axboe@kernel.dk> |
| 16 | +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| 17 | +--- |
| 18 | + io_uring/io_uring.c | 11 ++++++----- |
| 19 | + 1 file changed, 6 insertions(+), 5 deletions(-) |
| 20 | + |
| 21 | +diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c |
| 22 | +index f902b161f02c..92c1aa8f3501 100644 |
| 23 | +--- a/io_uring/io_uring.c |
| 24 | ++++ b/io_uring/io_uring.c |
| 25 | +@@ -593,6 +593,8 @@ static bool __io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force) |
| 26 | + bool all_flushed; |
| 27 | + size_t cqe_size = sizeof(struct io_uring_cqe); |
| 28 | + |
| 29 | ++ lockdep_assert_held(&ctx->uring_lock); |
| 30 | ++ |
| 31 | + if (!force && __io_cqring_events(ctx) == ctx->cq_entries) |
| 32 | + return false; |
| 33 | + |
| 34 | +@@ -647,12 +649,9 @@ static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx) |
| 35 | + bool ret = true; |
| 36 | + |
| 37 | + if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) { |
| 38 | +- /* iopoll syncs against uring_lock, not completion_lock */ |
| 39 | +- if (ctx->flags & IORING_SETUP_IOPOLL) |
| 40 | +- mutex_lock(&ctx->uring_lock); |
| 41 | ++ mutex_lock(&ctx->uring_lock); |
| 42 | + ret = __io_cqring_overflow_flush(ctx, false); |
| 43 | +- if (ctx->flags & IORING_SETUP_IOPOLL) |
| 44 | +- mutex_unlock(&ctx->uring_lock); |
| 45 | ++ mutex_unlock(&ctx->uring_lock); |
| 46 | + } |
| 47 | + |
| 48 | + return ret; |
| 49 | +@@ -1405,6 +1404,8 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, long min) |
| 50 | + int ret = 0; |
| 51 | + unsigned long check_cq; |
| 52 | + |
| 53 | ++ lockdep_assert_held(&ctx->uring_lock); |
| 54 | ++ |
| 55 | + if (!io_allowed_run_tw(ctx)) |
| 56 | + return -EEXIST; |
| 57 | + |
| 58 | +-- |
| 59 | +2.47.0 |
| 60 | + |
0 commit comments