Skip to content

Commit

Permalink
virtio-blk: Ensure no requests in virtqueues before deleting vqs.
Browse files Browse the repository at this point in the history
[ Upstream commit 4ce6e2d ]

Ensure no remaining requests in virtqueues before resetting vdev and
deleting virtqueues. Otherwise these requests will never be completed.
It may cause the system to become unresponsive.

Function blk_mq_quiesce_queue() can ensure that requests have become
in_flight status, but it cannot guarantee that requests have been
processed by the device. Virtqueues should never be deleted before
all requests become complete status.

Function blk_mq_freeze_queue() ensure that all requests in virtqueues
become complete status. And no requests can enter in virtqueues.

Signed-off-by: Yi Sun <yi.sun@unisoc.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Link: https://lore.kernel.org/r/20240129085250.1550594-1-yi.sun@unisoc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yi Sun authored and gregkh committed Mar 1, 2024
1 parent cacc0a9 commit 8946924
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,14 +1629,15 @@ static int virtblk_freeze(struct virtio_device *vdev)
{
struct virtio_blk *vblk = vdev->priv;

/* Ensure no requests in virtqueues before deleting vqs. */
blk_mq_freeze_queue(vblk->disk->queue);

/* Ensure we don't receive any more interrupts */
virtio_reset_device(vdev);

/* Make sure no work handler is accessing the device. */
flush_work(&vblk->config_work);

blk_mq_quiesce_queue(vblk->disk->queue);

vdev->config->del_vqs(vdev);
kfree(vblk->vqs);

Expand All @@ -1654,7 +1655,7 @@ static int virtblk_restore(struct virtio_device *vdev)

virtio_device_ready(vdev);

blk_mq_unquiesce_queue(vblk->disk->queue);
blk_mq_unfreeze_queue(vblk->disk->queue);
return 0;
}
#endif
Expand Down

0 comments on commit 8946924

Please sign in to comment.