Skip to content

Commit c4706c5

Browse files
Ming Leiaxboe
authored andcommitted
loop: use kiocb helpers to fix lockdep warning
The lockdep tool can report a circular lock dependency warning in the loop driver's AIO read/write path: ``` [ 6540.587728] kworker/u96:5/72779 is trying to acquire lock: [ 6540.593856] ff110001b5968440 (sb_writers#9){.+.+}-{0:0}, at: loop_process_work+0x11a/0xf70 [loop] [ 6540.603786] [ 6540.603786] but task is already holding lock: [ 6540.610291] ff110001b5968440 (sb_writers#9){.+.+}-{0:0}, at: loop_process_work+0x11a/0xf70 [loop] [ 6540.620210] [ 6540.620210] other info that might help us debug this: [ 6540.627499] Possible unsafe locking scenario: [ 6540.627499] [ 6540.634110] CPU0 [ 6540.636841] ---- [ 6540.639574] lock(sb_writers#9); [ 6540.643281] lock(sb_writers#9); [ 6540.646988] [ 6540.646988] *** DEADLOCK *** ``` This patch fixes the issue by using the AIO-specific helpers `kiocb_start_write()` and `kiocb_end_write()`. These functions are designed to be used with a `kiocb` and manage write sequencing correctly for asynchronous I/O without introducing the problematic lock dependency. The `kiocb` is already part of the `loop_cmd` struct, so this change also simplifies the completion function `lo_rw_aio_do_completion()` by using the `iocb` from the `cmd` struct directly, instead of retrieving the loop device from the request queue. Fixes: 39d86db ("loop: add file_start_write() and file_end_write()") Cc: Changhui Zhong <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 3051247 commit c4706c5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/block/loop.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,13 @@ static void lo_complete_rq(struct request *rq)
308308
static void lo_rw_aio_do_completion(struct loop_cmd *cmd)
309309
{
310310
struct request *rq = blk_mq_rq_from_pdu(cmd);
311-
struct loop_device *lo = rq->q->queuedata;
312311

313312
if (!atomic_dec_and_test(&cmd->ref))
314313
return;
315314
kfree(cmd->bvec);
316315
cmd->bvec = NULL;
317316
if (req_op(rq) == REQ_OP_WRITE)
318-
file_end_write(lo->lo_backing_file);
317+
kiocb_end_write(&cmd->iocb);
319318
if (likely(!blk_should_fake_timeout(rq->q)))
320319
blk_mq_complete_request(rq);
321320
}
@@ -391,7 +390,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
391390
}
392391

393392
if (rw == ITER_SOURCE) {
394-
file_start_write(lo->lo_backing_file);
393+
kiocb_start_write(&cmd->iocb);
395394
ret = file->f_op->write_iter(&cmd->iocb, &iter);
396395
} else
397396
ret = file->f_op->read_iter(&cmd->iocb, &iter);

0 commit comments

Comments
 (0)