Skip to content

Commit dcee179

Browse files
committed
Merge branch 'for-6.11/block' into for-next
* for-6.11/block: block: fix get_max_segment_size() warning loop: Don't bother validating blocksize virtio_blk: Don't bother validating blocksize null_blk: Don't bother validating blocksize block: Validate logical block size in blk_validate_limits() virtio_blk: Fix default logical block size fallback
2 parents 758bc2b + 0ffc46e commit dcee179

File tree

6 files changed

+18
-35
lines changed

6 files changed

+18
-35
lines changed

block/blk-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static inline unsigned get_max_io_size(struct bio *bio,
210210
* get_max_segment_size() - maximum number of bytes to add as a single segment
211211
* @lim: Request queue limits.
212212
* @paddr: address of the range to add
213-
* @max_len: maximum length available to add at @paddr
213+
* @len: maximum length available to add at @paddr
214214
*
215215
* Returns the maximum number of bytes of the range starting at @paddr that can
216216
* be added to a single segment.

block/blk-settings.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ static int blk_validate_limits(struct queue_limits *lim)
235235
*/
236236
if (!lim->logical_block_size)
237237
lim->logical_block_size = SECTOR_SIZE;
238+
else if (blk_validate_block_size(lim->logical_block_size)) {
239+
pr_warn("Invalid logical block size (%d)\n", lim->logical_block_size);
240+
return -EINVAL;
241+
}
238242
if (lim->physical_block_size < lim->logical_block_size)
239243
lim->physical_block_size = lim->logical_block_size;
240244

drivers/block/loop.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,12 +1061,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10611061
goto out_unlock;
10621062
}
10631063

1064-
if (config->block_size) {
1065-
error = blk_validate_block_size(config->block_size);
1066-
if (error)
1067-
goto out_unlock;
1068-
}
1069-
10701064
error = loop_set_status_from_info(lo, &config->info);
10711065
if (error)
10721066
goto out_unlock;
@@ -1098,7 +1092,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
10981092
mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
10991093

11001094
error = loop_reconfigure_limits(lo, config->block_size);
1101-
if (WARN_ON_ONCE(error))
1095+
if (error)
11021096
goto out_unlock;
11031097

11041098
loop_update_dio(lo);
@@ -1470,10 +1464,6 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
14701464
if (lo->lo_state != Lo_bound)
14711465
return -ENXIO;
14721466

1473-
err = blk_validate_block_size(arg);
1474-
if (err)
1475-
return err;
1476-
14771467
if (lo->lo_queue->limits.logical_block_size == arg)
14781468
return 0;
14791469

drivers/block/null_blk/main.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,9 +1831,6 @@ static int null_validate_conf(struct nullb_device *dev)
18311831
dev->queue_mode = NULL_Q_MQ;
18321832
}
18331833

1834-
if (blk_validate_block_size(dev->blocksize))
1835-
return -EINVAL;
1836-
18371834
if (dev->use_per_node_hctx) {
18381835
if (dev->submit_queues != nr_online_nodes)
18391836
dev->submit_queues = nr_online_nodes;

drivers/block/virtio_blk.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
12501250
struct queue_limits *lim)
12511251
{
12521252
struct virtio_device *vdev = vblk->vdev;
1253-
u32 v, blk_size, max_size, sg_elems, opt_io_size;
1253+
u32 v, max_size, sg_elems, opt_io_size;
12541254
u32 max_discard_segs = 0;
12551255
u32 discard_granularity = 0;
12561256
u16 min_io_size;
@@ -1289,46 +1289,36 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
12891289
lim->max_segment_size = max_size;
12901290

12911291
/* Host can optionally specify the block size of the device */
1292-
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
1292+
virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
12931293
struct virtio_blk_config, blk_size,
1294-
&blk_size);
1295-
if (!err) {
1296-
err = blk_validate_block_size(blk_size);
1297-
if (err) {
1298-
dev_err(&vdev->dev,
1299-
"virtio_blk: invalid block size: 0x%x\n",
1300-
blk_size);
1301-
return err;
1302-
}
1303-
1304-
lim->logical_block_size = blk_size;
1305-
} else
1306-
blk_size = lim->logical_block_size;
1294+
&lim->logical_block_size);
13071295

13081296
/* Use topology information if available */
13091297
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
13101298
struct virtio_blk_config, physical_block_exp,
13111299
&physical_block_exp);
13121300
if (!err && physical_block_exp)
1313-
lim->physical_block_size = blk_size * (1 << physical_block_exp);
1301+
lim->physical_block_size =
1302+
lim->logical_block_size * (1 << physical_block_exp);
13141303

13151304
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
13161305
struct virtio_blk_config, alignment_offset,
13171306
&alignment_offset);
13181307
if (!err && alignment_offset)
1319-
lim->alignment_offset = blk_size * alignment_offset;
1308+
lim->alignment_offset =
1309+
lim->logical_block_size * alignment_offset;
13201310

13211311
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
13221312
struct virtio_blk_config, min_io_size,
13231313
&min_io_size);
13241314
if (!err && min_io_size)
1325-
lim->io_min = blk_size * min_io_size;
1315+
lim->io_min = lim->logical_block_size * min_io_size;
13261316

13271317
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
13281318
struct virtio_blk_config, opt_io_size,
13291319
&opt_io_size);
13301320
if (!err && opt_io_size)
1331-
lim->io_opt = blk_size * opt_io_size;
1321+
lim->io_opt = lim->logical_block_size * opt_io_size;
13321322

13331323
if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
13341324
virtio_cread(vdev, struct virtio_blk_config,
@@ -1422,7 +1412,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
14221412
lim->discard_granularity =
14231413
discard_granularity << SECTOR_SHIFT;
14241414
else
1425-
lim->discard_granularity = blk_size;
1415+
lim->discard_granularity = lim->logical_block_size;
14261416
}
14271417

14281418
if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
@@ -1453,6 +1443,7 @@ static int virtblk_probe(struct virtio_device *vdev)
14531443
struct virtio_blk *vblk;
14541444
struct queue_limits lim = {
14551445
.features = BLK_FEAT_ROTATIONAL,
1446+
.logical_block_size = SECTOR_SIZE,
14561447
};
14571448
int err, index;
14581449
unsigned int queue_depth;

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ static inline dev_t disk_devt(struct gendisk *disk)
268268
return MKDEV(disk->major, disk->first_minor);
269269
}
270270

271+
/* blk_validate_limits() validates bsize, so drivers don't usually need to */
271272
static inline int blk_validate_block_size(unsigned long bsize)
272273
{
273274
if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))

0 commit comments

Comments
 (0)