Skip to content

Commit ac5902f

Browse files
Ming Leiaxboe
authored andcommitted
ublk: fix AB-BA lockdep warning
When handling UBLK_IO_FETCH_REQ, ctx->uring_lock is grabbed first, then ub->mutex is acquired. When handling UBLK_CMD_STOP_DEV or UBLK_CMD_DEL_DEV, ub->mutex is grabbed first, then calling io_uring_cmd_done() for canceling uring command, in which ctx->uring_lock may be required. Real deadlock only happens when all the above commands are issued from same uring context, and in reality different uring contexts are often used for handing control command and IO command. Fix the issue by using io_uring_cmd_complete_in_task() to cancel command in ublk_cancel_dev(ublk_cancel_queue). Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com> Closes: https://lore.kernel.org/linux-block/becol2g7sawl4rsjq2dztsbc7mqypfqko6wzsyoyazqydoasml@rcxarzwidrhk Cc: Ziyang Zhang <ZiyangZhang@linux.alibaba.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Tested-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com> Link: https://lore.kernel.org/r/20230517133408.210944-1-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 56cdea9 commit ac5902f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/block/ublk_drv.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,11 @@ static inline bool ublk_queue_ready(struct ublk_queue *ubq)
11201120
return ubq->nr_io_ready == ubq->q_depth;
11211121
}
11221122

1123+
static void ublk_cmd_cancel_cb(struct io_uring_cmd *cmd, unsigned issue_flags)
1124+
{
1125+
io_uring_cmd_done(cmd, UBLK_IO_RES_ABORT, 0, issue_flags);
1126+
}
1127+
11231128
static void ublk_cancel_queue(struct ublk_queue *ubq)
11241129
{
11251130
int i;
@@ -1131,8 +1136,8 @@ static void ublk_cancel_queue(struct ublk_queue *ubq)
11311136
struct ublk_io *io = &ubq->ios[i];
11321137

11331138
if (io->flags & UBLK_IO_FLAG_ACTIVE)
1134-
io_uring_cmd_done(io->cmd, UBLK_IO_RES_ABORT, 0,
1135-
IO_URING_F_UNLOCKED);
1139+
io_uring_cmd_complete_in_task(io->cmd,
1140+
ublk_cmd_cancel_cb);
11361141
}
11371142

11381143
/* all io commands are canceled */

0 commit comments

Comments
 (0)