Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e993db2

Browse files
Hannes Reineckeaxboe
authored andcommitted
block: check for max_hw_sectors underflow
The logical block size need to be smaller than the max_hw_sector setting, otherwise we can't even transfer a single LBA. Signed-off-by: Hannes Reinecke <hare@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: John Garry <john.g.garry@oracle.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e528bed commit e993db2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

block/blk-settings.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static int blk_validate_zoned_limits(struct queue_limits *lim)
104104
static int blk_validate_limits(struct queue_limits *lim)
105105
{
106106
unsigned int max_hw_sectors;
107+
unsigned int logical_block_sectors;
107108

108109
/*
109110
* Unless otherwise specified, default to 512 byte logical blocks and a
@@ -134,8 +135,11 @@ static int blk_validate_limits(struct queue_limits *lim)
134135
lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS;
135136
if (WARN_ON_ONCE(lim->max_hw_sectors < PAGE_SECTORS))
136137
return -EINVAL;
138+
logical_block_sectors = lim->logical_block_size >> SECTOR_SHIFT;
139+
if (WARN_ON_ONCE(logical_block_sectors > lim->max_hw_sectors))
140+
return -EINVAL;
137141
lim->max_hw_sectors = round_down(lim->max_hw_sectors,
138-
lim->logical_block_size >> SECTOR_SHIFT);
142+
logical_block_sectors);
139143

140144
/*
141145
* The actual max_sectors value is a complex beast and also takes the
@@ -153,7 +157,7 @@ static int blk_validate_limits(struct queue_limits *lim)
153157
lim->max_sectors = min(max_hw_sectors, BLK_DEF_MAX_SECTORS_CAP);
154158
}
155159
lim->max_sectors = round_down(lim->max_sectors,
156-
lim->logical_block_size >> SECTOR_SHIFT);
160+
logical_block_sectors);
157161

158162
/*
159163
* Random default for the maximum number of segments. Driver should not

0 commit comments

Comments
 (0)