Skip to content

Commit 817046e

Browse files
damien-lemoalaxboe
authored andcommitted
block: Align max_hw_sectors to logical blocksize
Block device drivers do not have to call blk_queue_max_hw_sectors() to set a limit on request size if the default limit BLK_SAFE_MAX_SECTORS is acceptable. However, this limit (255 sectors) may not be aligned to the device logical block size which cannot be used as is for a request maximum size. This is the case for the null_blk device driver. Modify blk_queue_max_hw_sectors() to make sure that the request size limits specified by the max_hw_sectors and max_sectors queue limits are always aligned to the device logical block size. Additionally, to avoid introducing a dependence on the execution order of this function with blk_queue_logical_block_size(), also modify blk_queue_logical_block_size() to perform the same alignment when the logical block size is set after max_hw_sectors. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 2e896d8 commit 817046e

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

block/blk-settings.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto
157157
__func__, max_hw_sectors);
158158
}
159159

160+
max_hw_sectors = round_down(max_hw_sectors,
161+
limits->logical_block_size >> SECTOR_SHIFT);
160162
limits->max_hw_sectors = max_hw_sectors;
163+
161164
max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors);
162165
max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
166+
max_sectors = round_down(max_sectors,
167+
limits->logical_block_size >> SECTOR_SHIFT);
163168
limits->max_sectors = max_sectors;
169+
164170
q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9);
165171
}
166172
EXPORT_SYMBOL(blk_queue_max_hw_sectors);
@@ -321,13 +327,20 @@ EXPORT_SYMBOL(blk_queue_max_segment_size);
321327
**/
322328
void blk_queue_logical_block_size(struct request_queue *q, unsigned int size)
323329
{
324-
q->limits.logical_block_size = size;
330+
struct queue_limits *limits = &q->limits;
325331

326-
if (q->limits.physical_block_size < size)
327-
q->limits.physical_block_size = size;
332+
limits->logical_block_size = size;
328333

329-
if (q->limits.io_min < q->limits.physical_block_size)
330-
q->limits.io_min = q->limits.physical_block_size;
334+
if (limits->physical_block_size < size)
335+
limits->physical_block_size = size;
336+
337+
if (limits->io_min < limits->physical_block_size)
338+
limits->io_min = limits->physical_block_size;
339+
340+
limits->max_hw_sectors =
341+
round_down(limits->max_hw_sectors, size >> SECTOR_SHIFT);
342+
limits->max_sectors =
343+
round_down(limits->max_sectors, size >> SECTOR_SHIFT);
331344
}
332345
EXPORT_SYMBOL(blk_queue_logical_block_size);
333346

0 commit comments

Comments
 (0)