virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check
Subsystems (3)
PATCH 1/1 virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check
virtio zoned block device support is added by commit 0562d7bf1604 ("virtio-blk: add support for zoned block devices") which adds VIRTIO_BLK_F_ZONED to the features array in virtio_blk.c but makes it conditional on CONFIG_BLK_DEV_ZONED.
In it virtblk_probe() calls virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED) unconditionally, which invokes virtio_check_driver_offered_feature(). This function checks whether virtio_blk.feature_table (assigned to the static features array) contains the specified feature enum, and if not _causes a kernel panic_ via BUG().
This therefore means that failing to enable CONFIG_BLK_DEV_ZONED while using virtio is a guaranteed kernel panic. Fix the issue by making the feature test also conditional on CONFIG_BLK_DEV_ZONED.
--- drivers/block/virtio_blk.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/block/virtio_blk.c +2 -0
@@ -1580,11 +1580,13 @@ static int virtblk_probe(struct virtio_device *vdev)virtblk_update_capacity (vblk, false);virtio_device_ready (vdev); +#ifdef CONFIG_BLK_DEV_ZONED if (virtio_has_feature (vdev,VIRTIO_BLK_F_ZONED )) { err =virtblk_probe_zoned_device (vdev, vblk, q);if (err) goto out_cleanup_disk; } +#endif /* CONFIG_BLK_DEV_ZONED */ dev_info (&vdev->dev,"blk config size: %zu\n" ,sizeof (struct virtio_blk_config ));
--
2.39.0
Quoted 39 lines · Lorenzo Stoakes
virtio zoned block device support is added by commit
0562d7bf1604("virtio-blk: add support for zoned block devices") which addsVIRTIO_BLK_F_ZONEDto the features array invirtio_blk.cbut makes it conditional onCONFIG_BLK_DEV_ZONED.In it
virtblk_probe()callsvirtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)unconditionally, which invokesvirtio_check_driver_offered_feature(). This function checks whether virtio_blk.feature_table (assigned to the static features array) contains the specified feature enum, and if not_causesa kernelpanic_viaBUG().This therefore means that failing to enable
CONFIG_BLK_DEV_ZONEDwhile using virtio is a guaranteed kernel panic. Fix the issue by making the feature test also conditional onCONFIG_BLK_DEV_ZONED.Signed-off-by Lorenzo Stoakes <[email protected]>--- drivers/block/virtio_blk.c | 2 ++ 1 file changed, 2 insertions(+)drivers/block/virtio_blk.c +2
-1@@ -1580,11 +1580,13 @@ static int virtblk_probe(struct virtio_device *vdev)virtblk_update_capacity (vblk, false);virtio_device_ready (vdev); +#ifdef CONFIG_BLK_DEV_ZONED if (virtio_has_feature (vdev,VIRTIO_BLK_F_ZONED )) { err =virtblk_probe_zoned_device (vdev, vblk, q);if (err) goto out_cleanup_disk; } +#endif /* CONFIG_BLK_DEV_ZONED */ dev_info (&vdev->dev,"blk config size: %zu\n" ,sizeof (struct virtio_blk_config )); --
Quoted 1 line
2.39.0
Steven suggested use of IS_ENABLED() here which makes it rather less ugly, will send as a v2.