Skip to content

Commit 10805eb

Browse files
dmitry-fomichevmstsirkin
authored andcommitted
virtio-blk: fix ZBD probe in kernels without ZBD support
When the kernel is built without support for zoned block devices, virtio-blk probe needs to error out any host-managed device scans to prevent such devices from appearing in the system as non-zoned. The current virtio-blk code simply bypasses all ZBD checks if CONFIG_BLK_DEV_ZONED is not defined and this leads to host-managed block devices being presented as non-zoned in the OS. This is one of the main problems this patch series is aimed to fix. In this patch, make VIRTIO_BLK_F_ZONED feature defined even when CONFIG_BLK_DEV_ZONED is not. This change makes the code compliant with the voted revision of virtio-blk ZBD spec. Modify the probe code to look at the situation when VIRTIO_BLK_F_ZONED is negotiated in a kernel that is built without ZBD support. In this case, the code checks the zoned model of the device and fails the probe is the device is host-managed. The patch also adds the comment to clarify that the call to perform the zoned device probe is correctly placed after virtio_device ready(). Fixes: 95bfec4 ("virtio-blk: add support for zoned block devices") Cc: [email protected] Signed-off-by: Dmitry Fomichev <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent f1ba4e6 commit 10805eb

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

drivers/block/virtio_blk.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -866,16 +866,12 @@ static int virtblk_probe_zoned_device(struct virtio_device *vdev,
866866
return ret;
867867
}
868868

869-
static inline bool virtblk_has_zoned_feature(struct virtio_device *vdev)
870-
{
871-
return virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED);
872-
}
873-
874869
#else
875870

876871
/*
877872
* Zoned block device support is not configured in this kernel.
878-
* We only need to define a few symbols to avoid compilation errors.
873+
* Host-managed zoned devices can't be supported, but others are
874+
* good to go as regular block devices.
879875
*/
880876
#define virtblk_report_zones NULL
881877

@@ -886,12 +882,16 @@ static inline void virtblk_revalidate_zones(struct virtio_blk *vblk)
886882
static inline int virtblk_probe_zoned_device(struct virtio_device *vdev,
887883
struct virtio_blk *vblk, struct request_queue *q)
888884
{
889-
return -EOPNOTSUPP;
890-
}
885+
u8 model;
891886

892-
static inline bool virtblk_has_zoned_feature(struct virtio_device *vdev)
893-
{
894-
return false;
887+
virtio_cread(vdev, struct virtio_blk_config, zoned.model, &model);
888+
if (model == VIRTIO_BLK_Z_HM) {
889+
dev_err(&vdev->dev,
890+
"virtio_blk: zoned devices are not supported");
891+
return -EOPNOTSUPP;
892+
}
893+
894+
return 0;
895895
}
896896
#endif /* CONFIG_BLK_DEV_ZONED */
897897

@@ -1577,7 +1577,11 @@ static int virtblk_probe(struct virtio_device *vdev)
15771577
virtblk_update_capacity(vblk, false);
15781578
virtio_device_ready(vdev);
15791579

1580-
if (virtblk_has_zoned_feature(vdev)) {
1580+
/*
1581+
* All steps that follow use the VQs therefore they need to be
1582+
* placed after the virtio_device_ready() call above.
1583+
*/
1584+
if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
15811585
err = virtblk_probe_zoned_device(vdev, vblk, q);
15821586
if (err)
15831587
goto out_cleanup_disk;
@@ -1683,10 +1687,7 @@ static unsigned int features[] = {
16831687
VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
16841688
VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE,
16851689
VIRTIO_BLK_F_MQ, VIRTIO_BLK_F_DISCARD, VIRTIO_BLK_F_WRITE_ZEROES,
1686-
VIRTIO_BLK_F_SECURE_ERASE,
1687-
#ifdef CONFIG_BLK_DEV_ZONED
1688-
VIRTIO_BLK_F_ZONED,
1689-
#endif /* CONFIG_BLK_DEV_ZONED */
1690+
VIRTIO_BLK_F_SECURE_ERASE, VIRTIO_BLK_F_ZONED,
16901691
};
16911692

16921693
static struct virtio_driver virtio_blk = {

0 commit comments

Comments
 (0)