UPSTREAM: 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. Change-Id: Ia906c96b35abd306a35a43a7e81ef581f21792ef Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20250110054726.1499538-12-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk> (cherry picked from commit b03732a9c0db91522914185739505d92d3b0d816) Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
committed by
Bart Van Assche
parent
d2eefa734f
commit
4a77dbe5c5
@@ -311,6 +311,13 @@ static void loop_clear_limits(struct loop_device *lo, int mode)
|
||||
lim.discard_granularity = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: this updates the queue limits without freezing the queue, which
|
||||
* is against the locking protocol and dangerous. But we can't just
|
||||
* freeze the queue as we're inside the ->queue_rq method here. So this
|
||||
* should move out into a workqueue unless we get the file operations to
|
||||
* advertise if they support specific fallocate operations.
|
||||
*/
|
||||
queue_limits_commit_update(lo->lo_queue, &lim);
|
||||
}
|
||||
|
||||
@@ -1091,6 +1098,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
|
||||
|
||||
lim = queue_limits_start_update(lo->lo_queue);
|
||||
loop_update_limits(lo, &lim, config->block_size);
|
||||
/* No need to freeze the queue as the device isn't bound yet. */
|
||||
error = queue_limits_commit_update(lo->lo_queue, &lim);
|
||||
if (error)
|
||||
goto out_unlock;
|
||||
@@ -1151,7 +1159,12 @@ static void __loop_clr_fd(struct loop_device *lo)
|
||||
lo->lo_sizelimit = 0;
|
||||
memset(lo->lo_file_name, 0, LO_NAME_SIZE);
|
||||
|
||||
/* reset the block size to the default */
|
||||
/*
|
||||
* Reset the block size to the default.
|
||||
*
|
||||
* No queue freezing needed because this is called from the final
|
||||
* ->release call only, so there can't be any outstanding I/O.
|
||||
*/
|
||||
lim = queue_limits_start_update(lo->lo_queue);
|
||||
lim.logical_block_size = SECTOR_SIZE;
|
||||
lim.physical_block_size = SECTOR_SIZE;
|
||||
@@ -1471,9 +1484,10 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
|
||||
sync_blockdev(lo->lo_device);
|
||||
invalidate_bdev(lo->lo_device);
|
||||
|
||||
blk_mq_freeze_queue(lo->lo_queue);
|
||||
lim = queue_limits_start_update(lo->lo_queue);
|
||||
loop_update_limits(lo, &lim, arg);
|
||||
|
||||
blk_mq_freeze_queue(lo->lo_queue);
|
||||
err = queue_limits_commit_update(lo->lo_queue, &lim);
|
||||
loop_update_dio(lo);
|
||||
blk_mq_unfreeze_queue(lo->lo_queue);
|
||||
|
||||
Reference in New Issue
Block a user