Skip to content

Commit b03732a

Browse files
Christoph Hellwigaxboe
authored andcommitted
loop: fix queue freeze vs limits lock order
Match the locking order used by the core block code by only freezing the queue after taking the limits lock using the queue_limits_commit_update_frozen helper and document the callers that do not freeze the queue at all. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Nilay Shroff <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent b38c8be commit b03732a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/block/loop.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ static void loop_clear_limits(struct loop_device *lo, int mode)
311311
lim.discard_granularity = 0;
312312
}
313313

314+
/*
315+
* XXX: this updates the queue limits without freezing the queue, which
316+
* is against the locking protocol and dangerous. But we can't just
317+
* freeze the queue as we're inside the ->queue_rq method here. So this
318+
* should move out into a workqueue unless we get the file operations to
319+
* advertise if they support specific fallocate operations.
320+
*/
314321
queue_limits_commit_update(lo->lo_queue, &lim);
315322
}
316323

@@ -1091,6 +1098,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10911098

10921099
lim = queue_limits_start_update(lo->lo_queue);
10931100
loop_update_limits(lo, &lim, config->block_size);
1101+
/* No need to freeze the queue as the device isn't bound yet. */
10941102
error = queue_limits_commit_update(lo->lo_queue, &lim);
10951103
if (error)
10961104
goto out_unlock;
@@ -1151,7 +1159,12 @@ static void __loop_clr_fd(struct loop_device *lo)
11511159
lo->lo_sizelimit = 0;
11521160
memset(lo->lo_file_name, 0, LO_NAME_SIZE);
11531161

1154-
/* reset the block size to the default */
1162+
/*
1163+
* Reset the block size to the default.
1164+
*
1165+
* No queue freezing needed because this is called from the final
1166+
* ->release call only, so there can't be any outstanding I/O.
1167+
*/
11551168
lim = queue_limits_start_update(lo->lo_queue);
11561169
lim.logical_block_size = SECTOR_SIZE;
11571170
lim.physical_block_size = SECTOR_SIZE;
@@ -1471,9 +1484,10 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
14711484
sync_blockdev(lo->lo_device);
14721485
invalidate_bdev(lo->lo_device);
14731486

1474-
blk_mq_freeze_queue(lo->lo_queue);
14751487
lim = queue_limits_start_update(lo->lo_queue);
14761488
loop_update_limits(lo, &lim, arg);
1489+
1490+
blk_mq_freeze_queue(lo->lo_queue);
14771491
err = queue_limits_commit_update(lo->lo_queue, &lim);
14781492
loop_update_dio(lo);
14791493
blk_mq_unfreeze_queue(lo->lo_queue);

0 commit comments

Comments
 (0)