Re-using the same device id when a device is re-added after it was
previously hot-unplugged should be avoided.
An additional test is added to check a potential broken virtqueue when
freeing the device id.

Signed-off-by: Heinz Graalfs <[email protected]>
---
 drivers/block/virtio_blk.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 98f081a..a787e6e 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -874,6 +874,7 @@ static void virtblk_remove(struct virtio_device *vdev)
        struct virtio_blk *vblk = vdev->priv;
        int index = vblk->index;
        int refc;
+       bool queue_broken = false;
 
        /* Prevent config work handler from accessing the device. */
        mutex_lock(&vblk->config_lock);
@@ -882,6 +883,7 @@ static void virtblk_remove(struct virtio_device *vdev)
 
        virtqueue_notify(vblk->vq);
        if (virtqueue_is_broken(vblk->vq)) {
+               queue_broken = true;
                blk_cleanup_queue(vblk->disk->queue);
                del_gendisk(vblk->disk);
        } else {
@@ -900,8 +902,10 @@ static void virtblk_remove(struct virtio_device *vdev)
        vdev->config->del_vqs(vdev);
        kfree(vblk);
 
-       /* Only free device id if we don't have any users */
-       if (refc == 1)
+       /* Only free device id if we don't have any users
+        * and virtqueue is not broken due to a hot-unplugged device
+        */
+       if (refc == 1 && !queue_broken)
                ida_simple_remove(&vd_index_ida, index);
 }
 
-- 
1.8.3.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reply via email to