Skip to content

Commit 8d09a88

Browse files
isilenceaxboe
authored andcommitted
io_uring: always lock __io_cqring_overflow_flush
Conditional locking is never great, in case of __io_cqring_overflow_flush(), which is a slow path, it's not justified. Don't handle IOPOLL separately, always grab uring_lock for overflow flushing. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/162947df299aa12693ac4b305dacedab32ec7976.1712708261.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 408024b commit 8d09a88

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

io_uring/io_uring.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ static void io_cqring_overflow_kill(struct io_ring_ctx *ctx)
673673
struct io_overflow_cqe *ocqe;
674674
LIST_HEAD(list);
675675

676+
lockdep_assert_held(&ctx->uring_lock);
677+
676678
spin_lock(&ctx->completion_lock);
677679
list_splice_init(&ctx->cq_overflow_list, &list);
678680
clear_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq);
@@ -689,6 +691,8 @@ static void __io_cqring_overflow_flush(struct io_ring_ctx *ctx)
689691
{
690692
size_t cqe_size = sizeof(struct io_uring_cqe);
691693

694+
lockdep_assert_held(&ctx->uring_lock);
695+
692696
if (__io_cqring_events(ctx) == ctx->cq_entries)
693697
return;
694698

@@ -718,12 +722,9 @@ static void __io_cqring_overflow_flush(struct io_ring_ctx *ctx)
718722

719723
static void io_cqring_do_overflow_flush(struct io_ring_ctx *ctx)
720724
{
721-
/* iopoll syncs against uring_lock, not completion_lock */
722-
if (ctx->flags & IORING_SETUP_IOPOLL)
723-
mutex_lock(&ctx->uring_lock);
725+
mutex_lock(&ctx->uring_lock);
724726
__io_cqring_overflow_flush(ctx);
725-
if (ctx->flags & IORING_SETUP_IOPOLL)
726-
mutex_unlock(&ctx->uring_lock);
727+
mutex_unlock(&ctx->uring_lock);
727728
}
728729

729730
/* can be called by any task */
@@ -1522,6 +1523,8 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, long min)
15221523
unsigned int nr_events = 0;
15231524
unsigned long check_cq;
15241525

1526+
lockdep_assert_held(&ctx->uring_lock);
1527+
15251528
if (!io_allowed_run_tw(ctx))
15261529
return -EEXIST;
15271530

0 commit comments

Comments
 (0)