Commit 4ff3d012 authored by John Garry's avatar John Garry Committed by Jens Axboe

virtio_blk: Fix default logical block size fallback

If we fail to read a logical block size in virtblk_read_limits() ->
virtio_cread_feature(), then we default to what is in
lim->logical_block_size, but that would be 0.

We can deal with lim->logical_block_size = 0 later in the
blk_mq_alloc_disk(), but the code in virtblk_read_limits() needs a proper
default, so give a default of SECTOR_SIZE.

Fixes: 27e32cd2 ("block: pass a queue_limits argument to blk_mq_alloc_disk")
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20240708091651.177447-2-john.g.garry@oracle.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 6b43537f
...@@ -1250,7 +1250,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk, ...@@ -1250,7 +1250,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
struct queue_limits *lim) struct queue_limits *lim)
{ {
struct virtio_device *vdev = vblk->vdev; struct virtio_device *vdev = vblk->vdev;
u32 v, blk_size, max_size, sg_elems, opt_io_size; u32 v, max_size, sg_elems, opt_io_size;
u32 max_discard_segs = 0; u32 max_discard_segs = 0;
u32 discard_granularity = 0; u32 discard_granularity = 0;
u16 min_io_size; u16 min_io_size;
...@@ -1291,44 +1291,43 @@ static int virtblk_read_limits(struct virtio_blk *vblk, ...@@ -1291,44 +1291,43 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
/* Host can optionally specify the block size of the device */ /* Host can optionally specify the block size of the device */
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE, err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
struct virtio_blk_config, blk_size, struct virtio_blk_config, blk_size,
&blk_size); &lim->logical_block_size);
if (!err) { if (!err) {
err = blk_validate_block_size(blk_size); err = blk_validate_block_size(lim->logical_block_size);
if (err) { if (err) {
dev_err(&vdev->dev, dev_err(&vdev->dev,
"virtio_blk: invalid block size: 0x%x\n", "virtio_blk: invalid block size: 0x%x\n",
blk_size); lim->logical_block_size);
return err; return err;
} }
}
lim->logical_block_size = blk_size;
} else
blk_size = lim->logical_block_size;
/* Use topology information if available */ /* Use topology information if available */
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY, err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
struct virtio_blk_config, physical_block_exp, struct virtio_blk_config, physical_block_exp,
&physical_block_exp); &physical_block_exp);
if (!err && physical_block_exp) if (!err && physical_block_exp)
lim->physical_block_size = blk_size * (1 << physical_block_exp); lim->physical_block_size =
lim->logical_block_size * (1 << physical_block_exp);
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY, err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
struct virtio_blk_config, alignment_offset, struct virtio_blk_config, alignment_offset,
&alignment_offset); &alignment_offset);
if (!err && alignment_offset) if (!err && alignment_offset)
lim->alignment_offset = blk_size * alignment_offset; lim->alignment_offset =
lim->logical_block_size * alignment_offset;
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY, err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
struct virtio_blk_config, min_io_size, struct virtio_blk_config, min_io_size,
&min_io_size); &min_io_size);
if (!err && min_io_size) if (!err && min_io_size)
lim->io_min = blk_size * min_io_size; lim->io_min = lim->logical_block_size * min_io_size;
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY, err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
struct virtio_blk_config, opt_io_size, struct virtio_blk_config, opt_io_size,
&opt_io_size); &opt_io_size);
if (!err && opt_io_size) if (!err && opt_io_size)
lim->io_opt = blk_size * opt_io_size; lim->io_opt = lim->logical_block_size * opt_io_size;
if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) { if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
virtio_cread(vdev, struct virtio_blk_config, virtio_cread(vdev, struct virtio_blk_config,
...@@ -1422,7 +1421,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk, ...@@ -1422,7 +1421,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
lim->discard_granularity = lim->discard_granularity =
discard_granularity << SECTOR_SHIFT; discard_granularity << SECTOR_SHIFT;
else else
lim->discard_granularity = blk_size; lim->discard_granularity = lim->logical_block_size;
} }
if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) { if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
...@@ -1453,6 +1452,7 @@ static int virtblk_probe(struct virtio_device *vdev) ...@@ -1453,6 +1452,7 @@ static int virtblk_probe(struct virtio_device *vdev)
struct virtio_blk *vblk; struct virtio_blk *vblk;
struct queue_limits lim = { struct queue_limits lim = {
.features = BLK_FEAT_ROTATIONAL, .features = BLK_FEAT_ROTATIONAL,
.logical_block_size = SECTOR_SIZE,
}; };
int err, index; int err, index;
unsigned int queue_depth; unsigned int queue_depth;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment