Skip to content

Commit 4aa84f2

Browse files
isilenceaxboe
authored andcommitted
io_uring: dont kill fasync under completion_lock
CPU0 CPU1 ---- ---- lock(&new->fa_lock); local_irq_disable(); lock(&ctx->completion_lock); lock(&new->fa_lock); <Interrupt> lock(&ctx->completion_lock); *** DEADLOCK *** Move kill_fasync() out of io_commit_cqring() to io_cqring_ev_posted(), so it doesn't hold completion_lock while doing it. That saves from the reported deadlock, and it's just nice to shorten the locking time and untangle nested locks (compl_lock -> wq_head::lock). Reported-by: syzbot+91ca3f25bd7f795f019c@syzkaller.appspotmail.com Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 80c18e4 commit 4aa84f2

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

fs/io_uring.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,11 +1345,6 @@ static void __io_commit_cqring(struct io_ring_ctx *ctx)
13451345

13461346
/* order cqe stores with ring update */
13471347
smp_store_release(&rings->cq.tail, ctx->cached_cq_tail);
1348-
1349-
if (wq_has_sleeper(&ctx->cq_wait)) {
1350-
wake_up_interruptible(&ctx->cq_wait);
1351-
kill_fasync(&ctx->cq_fasync, SIGIO, POLL_IN);
1352-
}
13531348
}
13541349

13551350
static void io_put_identity(struct io_uring_task *tctx, struct io_kiocb *req)
@@ -1711,6 +1706,10 @@ static void io_cqring_ev_posted(struct io_ring_ctx *ctx)
17111706
wake_up(&ctx->sq_data->wait);
17121707
if (io_should_trigger_evfd(ctx))
17131708
eventfd_signal(ctx->cq_ev_fd, 1);
1709+
if (wq_has_sleeper(&ctx->cq_wait)) {
1710+
wake_up_interruptible(&ctx->cq_wait);
1711+
kill_fasync(&ctx->cq_fasync, SIGIO, POLL_IN);
1712+
}
17141713
}
17151714

17161715
static void io_cqring_ev_posted_iopoll(struct io_ring_ctx *ctx)
@@ -1721,6 +1720,10 @@ static void io_cqring_ev_posted_iopoll(struct io_ring_ctx *ctx)
17211720
}
17221721
if (io_should_trigger_evfd(ctx))
17231722
eventfd_signal(ctx->cq_ev_fd, 1);
1723+
if (wq_has_sleeper(&ctx->cq_wait)) {
1724+
wake_up_interruptible(&ctx->cq_wait);
1725+
kill_fasync(&ctx->cq_fasync, SIGIO, POLL_IN);
1726+
}
17241727
}
17251728

17261729
/* Returns true if there are no backlogged entries after the flush */

0 commit comments

Comments
 (0)