Skip to content

Commit

Permalink
blk-settings: round down io_opt to physical_block_size
Browse files Browse the repository at this point in the history
There was a bug report [1] where the user got a warning alignment
inconsistency. The user has optimal I/O 16776704 (0xFFFE00) and physical
block size 4096. Note that the optimal I/O size may be set by the DMA
engines or SCSI controllers and they have no knowledge about the disks
attached to them, so the situation with optimal I/O not aligned to
physical block size may happen.

This commit makes blk_validate_limits round down optimal I/O size to the
physical block size of the block device.

Closes: https://lore.kernel.org/dm-devel/1426ad71-79b4-4062-b2bf-84278be66a5d@redhat.com/T/ [1]
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: a236346 ("block: take io_opt and io_min into account for max_sectors")
Cc: stable@vger.kernel.org	# v6.11+
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/3dc0014b-9690-dc38-81c9-4a316a2d4fb2@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Mikulas Patocka authored and axboe committed Nov 18, 2024
1 parent a3f143c commit 9c0ba14
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions block/blk-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ int blk_validate_limits(struct queue_limits *lim)
if (lim->io_min < lim->physical_block_size)
lim->io_min = lim->physical_block_size;

/*
* The optimal I/O size may not be aligned to physical block size
* (because it may be limited by dma engines which have no clue about
* block size of the disks attached to them), so we round it down here.
*/
lim->io_opt = round_down(lim->io_opt, lim->physical_block_size);

/*
* max_hw_sectors has a somewhat weird default for historical reason,
* but driver really should set their own instead of relying on this
Expand Down

0 comments on commit 9c0ba14

Please sign in to comment.