From: John Garry <john.g.garry@oracle.com>
To: axboe@kernel.dk, mst@redhat.com, jasowang@redhat.com,
xuanzhuo@linux.alibaba.com, eperezma@redhat.com,
pbonzini@redhat.com, stefanha@redhat.com, hare@suse.de,
kbusch@kernel.org, hch@lst.de
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
virtualization@lists.linux.dev,
John Garry <john.g.garry@oracle.com>
Subject: [PATCH 1/5] virtio_blk: Fix default logical block size fallback
Date: Fri, 5 Jul 2024 11:51:23 +0000 [thread overview]
Message-ID: <20240705115127.3417539-2-john.g.garry@oracle.com> (raw)
In-Reply-To: <20240705115127.3417539-1-john.g.garry@oracle.com>
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: 27e32cd23fed ("block: pass a queue_limits argument to blk_mq_alloc_disk")
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
drivers/block/virtio_blk.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 84c3efd0c611..f11b0c3b2625 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1250,7 +1250,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
struct queue_limits *lim)
{
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 discard_granularity = 0;
u16 min_io_size;
@@ -1291,44 +1291,43 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
/* Host can optionally specify the block size of the device */
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
struct virtio_blk_config, blk_size,
- &blk_size);
+ &lim->logical_block_size);
if (!err) {
- err = blk_validate_block_size(blk_size);
+ err = blk_validate_block_size(lim->logical_block_size);
if (err) {
dev_err(&vdev->dev,
"virtio_blk: invalid block size: 0x%x\n",
- blk_size);
+ lim->logical_block_size);
return err;
}
-
- lim->logical_block_size = blk_size;
- } else
- blk_size = lim->logical_block_size;
+ }
/* Use topology information if available */
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
struct virtio_blk_config, physical_block_exp,
&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,
struct virtio_blk_config, alignment_offset,
&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,
struct virtio_blk_config, min_io_size,
&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,
struct virtio_blk_config, opt_io_size,
&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)) {
virtio_cread(vdev, struct virtio_blk_config,
@@ -1422,7 +1421,7 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
lim->discard_granularity =
discard_granularity << SECTOR_SHIFT;
else
- lim->discard_granularity = blk_size;
+ lim->discard_granularity = lim->logical_block_size;
}
if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
@@ -1453,6 +1452,7 @@ static int virtblk_probe(struct virtio_device *vdev)
struct virtio_blk *vblk;
struct queue_limits lim = {
.features = BLK_FEAT_ROTATIONAL,
+ .logical_block_size = SECTOR_SIZE,
};
int err, index;
unsigned int queue_depth;
--
2.31.1
next prev parent reply other threads:[~2024-07-05 11:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-05 11:51 [PATCH 0/5] Validate logical block size in blk_validate_limits() John Garry
2024-07-05 11:51 ` John Garry [this message]
2024-07-05 12:14 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback Christoph Hellwig
2024-07-08 7:39 ` Stefan Hajnoczi
2024-07-05 11:51 ` [PATCH 2/5] block: Validate logical block size in blk_validate_limits() John Garry
2024-07-05 12:16 ` Christoph Hellwig
2024-07-05 12:34 ` John Garry
2024-07-05 12:38 ` Christoph Hellwig
2024-07-05 11:51 ` [PATCH 3/5] null_blk: Don't bother validating blocksize John Garry
2024-07-05 12:17 ` Christoph Hellwig
2024-07-05 11:51 ` [PATCH 4/5] virtio_blk: " John Garry
2024-07-05 12:17 ` Christoph Hellwig
2024-07-08 7:45 ` Stefan Hajnoczi
2024-07-05 11:51 ` [PATCH 5/5] loop: " John Garry
2024-07-05 12:18 ` Christoph Hellwig
2024-07-05 15:29 ` [PATCH 0/5] Validate logical block size in blk_validate_limits() Michael S. Tsirkin
2024-07-05 16:06 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240705115127.3417539-2-john.g.garry@oracle.com \
--to=john.g.garry@oracle.com \
--cc=axboe@kernel.dk \
--cc=eperezma@redhat.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jasowang@redhat.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®