Skip to content

Commit bc79ff0

Browse files
isilencegregkh
authored andcommitted
io_uring: fix wqe->lock/completion_lock deadlock
commit 907d1df upstream. Joseph reports following deadlock: CPU0: ... io_kill_linked_timeout // &ctx->completion_lock io_commit_cqring __io_queue_deferred __io_queue_async_work io_wq_enqueue io_wqe_enqueue // &wqe->lock CPU1: ... __io_uring_files_cancel io_wq_cancel_cb io_wqe_cancel_pending_work // &wqe->lock io_cancel_task_cb // &ctx->completion_lock Only __io_queue_deferred() calls queue_async_work() while holding ctx->completion_lock, enqueue drained requests via io_req_task_queue() instead. Cc: stable@vger.kernel.org # 5.9+ Reported-by: Joseph Qi <joseph.qi@linux.alibaba.com> Tested-by: Joseph Qi <joseph.qi@linux.alibaba.com> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 256a004 commit bc79ff0

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

fs/io_uring.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ static int io_setup_async_rw(struct io_kiocb *req, const struct iovec *iovec,
972972
const struct iovec *fast_iov,
973973
struct iov_iter *iter, bool force);
974974
static void io_req_drop_files(struct io_kiocb *req);
975+
static void io_req_task_queue(struct io_kiocb *req);
975976

976977
static struct kmem_cache *req_cachep;
977978

@@ -1502,18 +1503,11 @@ static void __io_queue_deferred(struct io_ring_ctx *ctx)
15021503
do {
15031504
struct io_defer_entry *de = list_first_entry(&ctx->defer_list,
15041505
struct io_defer_entry, list);
1505-
struct io_kiocb *link;
15061506

15071507
if (req_need_defer(de->req, de->seq))
15081508
break;
15091509
list_del_init(&de->list);
1510-
/* punt-init is done before queueing for defer */
1511-
link = __io_queue_async_work(de->req);
1512-
if (link) {
1513-
__io_queue_linked_timeout(link);
1514-
/* drop submission reference */
1515-
io_put_req_deferred(link, 1);
1516-
}
1510+
io_req_task_queue(de->req);
15171511
kfree(de);
15181512
} while (!list_empty(&ctx->defer_list));
15191513
}

0 commit comments

Comments
 (0)