Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <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>

authored by

Christoph Hellwig and committed by
Jens Axboe
b03732a9 b38c8be2

+16 -2
+16 -2
drivers/block/loop.c
··· 311 311 lim.discard_granularity = 0; 312 312 } 313 313 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 + */ 314 321 queue_limits_commit_update(lo->lo_queue, &lim); 315 322 } 316 323 ··· 1098 1091 1099 1092 lim = queue_limits_start_update(lo->lo_queue); 1100 1093 loop_update_limits(lo, &lim, config->block_size); 1094 + /* No need to freeze the queue as the device isn't bound yet. */ 1101 1095 error = queue_limits_commit_update(lo->lo_queue, &lim); 1102 1096 if (error) 1103 1097 goto out_unlock; ··· 1159 1151 lo->lo_sizelimit = 0; 1160 1152 memset(lo->lo_file_name, 0, LO_NAME_SIZE); 1161 1153 1162 - /* reset the block size to the default */ 1154 + /* 1155 + * Reset the block size to the default. 1156 + * 1157 + * No queue freezing needed because this is called from the final 1158 + * ->release call only, so there can't be any outstanding I/O. 1159 + */ 1163 1160 lim = queue_limits_start_update(lo->lo_queue); 1164 1161 lim.logical_block_size = SECTOR_SIZE; 1165 1162 lim.physical_block_size = SECTOR_SIZE; ··· 1484 1471 sync_blockdev(lo->lo_device); 1485 1472 invalidate_bdev(lo->lo_device); 1486 1473 1487 - blk_mq_freeze_queue(lo->lo_queue); 1488 1474 lim = queue_limits_start_update(lo->lo_queue); 1489 1475 loop_update_limits(lo, &lim, arg); 1476 + 1477 + blk_mq_freeze_queue(lo->lo_queue); 1490 1478 err = queue_limits_commit_update(lo->lo_queue, &lim); 1491 1479 loop_update_dio(lo); 1492 1480 blk_mq_unfreeze_queue(lo->lo_queue);