* [PATCH v2] virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check
@ 2022-12-21 14:54 Lorenzo Stoakes
2022-12-21 19:15 ` Michael S. Tsirkin
0 siblings, 1 reply; 3+ messages in thread
From: Lorenzo Stoakes @ 2022-12-21 14:54 UTC (permalink / raw)
To: linux-block, Dmitry Fomichev, Stefan Hajnoczi,
Michael S . Tsirkin, Jason Wang, Paolo Bonzini, Jens Axboe
Cc: Damien Le Moal, virtualization, virtio-dev, linux-kernel,
Hannes Reinecke, Sam Li, Steven Rostedt, Lorenzo Stoakes
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.
Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
---
drivers/block/virtio_blk.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index ff49052e26f7..94d210b10ebb 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1580,7 +1580,8 @@ static int virtblk_probe(struct virtio_device *vdev)
virtblk_update_capacity(vblk, false);
virtio_device_ready(vdev);
- if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
+ if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
+ virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
err = virtblk_probe_zoned_device(vdev, vblk, q);
if (err)
goto out_cleanup_disk;
--
2.39.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check
2022-12-21 14:54 [PATCH v2] virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check Lorenzo Stoakes
@ 2022-12-21 19:15 ` Michael S. Tsirkin
2022-12-21 19:27 ` Lorenzo Stoakes
0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2022-12-21 19:15 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: linux-block, Dmitry Fomichev, Stefan Hajnoczi, Jason Wang,
Paolo Bonzini, Jens Axboe, Damien Le Moal, virtualization,
virtio-dev, linux-kernel, Hannes Reinecke, Sam Li, Steven Rostedt
On Wed, Dec 21, 2022 at 02:54:33PM +0000, Lorenzo Stoakes wrote:
> 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.
>
> Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
I think this was fixed by
Message-ID: <20221220112340.518841-1-mst@redhat.com>
> ---
> drivers/block/virtio_blk.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index ff49052e26f7..94d210b10ebb 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -1580,7 +1580,8 @@ static int virtblk_probe(struct virtio_device *vdev)
> virtblk_update_capacity(vblk, false);
> virtio_device_ready(vdev);
>
> - if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
> + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
> + virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) {
> err = virtblk_probe_zoned_device(vdev, vblk, q);
> if (err)
> goto out_cleanup_disk;
> --
> 2.39.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check
2022-12-21 19:15 ` Michael S. Tsirkin
@ 2022-12-21 19:27 ` Lorenzo Stoakes
0 siblings, 0 replies; 3+ messages in thread
From: Lorenzo Stoakes @ 2022-12-21 19:27 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jens Axboe, virtio-dev, Dmitry Fomichev, Sam Li, linux-kernel,
Steven Rostedt, virtualization, linux-block, Stefan Hajnoczi,
Paolo Bonzini, Damien Le Moal
On Wed, Dec 21, 2022 at 02:15:58PM -0500, Michael S. Tsirkin wrote:
> I think this was fixed by
> Message-ID: <20221220112340.518841-1-mst@redhat.com>
You're right! Sorry I don't usually pay attention to virtio stuff, so missed
that this was patched already, just noticed that my dev env was killed by the
issue.
I have tested your patch + confirmed working so will at least add a tested-by to
it :)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-21 19:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-21 14:54 [PATCH v2] virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check Lorenzo Stoakes
2022-12-21 19:15 ` Michael S. Tsirkin
2022-12-21 19:27 ` Lorenzo Stoakes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox