linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] virtio-blk: Ensure no requests in virtqueues before deleting vqs.
@ 2024-01-29  8:52 Yi Sun
  2024-01-30 21:15 ` Stefan Hajnoczi
  2024-02-08 18:32 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Yi Sun @ 2024-01-29  8:52 UTC (permalink / raw)
  To: stefanha, mst, jasowang, axboe
  Cc: yi.sun, sunyibuaa, hongyu.jin, zhiguo.niu, xuanzhuo, pbonzini,
	virtualization, linux-block, linux-kernel

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>
---
 drivers/block/virtio_blk.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 3b6b9abb8ce1..14ecc14ce8db 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1595,14 +1595,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);
 
@@ -1620,7 +1621,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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] virtio-blk: Ensure no requests in virtqueues before deleting vqs.
  2024-01-29  8:52 [PATCH V2] virtio-blk: Ensure no requests in virtqueues before deleting vqs Yi Sun
@ 2024-01-30 21:15 ` Stefan Hajnoczi
  2024-02-08 18:32 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2024-01-30 21:15 UTC (permalink / raw)
  To: Yi Sun
  Cc: stefanha, mst, jasowang, axboe, sunyibuaa, hongyu.jin,
	zhiguo.niu, xuanzhuo, pbonzini, virtualization, linux-block,
	linux-kernel

On Mon, 29 Jan 2024 at 03:54, Yi Sun <yi.sun@unisoc.com> wrote:
>
> 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>
> ---
>  drivers/block/virtio_blk.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

>
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 3b6b9abb8ce1..14ecc14ce8db 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -1595,14 +1595,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);
>
> @@ -1620,7 +1621,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
> --
> 2.25.1
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] virtio-blk: Ensure no requests in virtqueues before deleting vqs.
  2024-01-29  8:52 [PATCH V2] virtio-blk: Ensure no requests in virtqueues before deleting vqs Yi Sun
  2024-01-30 21:15 ` Stefan Hajnoczi
@ 2024-02-08 18:32 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2024-02-08 18:32 UTC (permalink / raw)
  To: stefanha, mst, jasowang, Yi Sun
  Cc: sunyibuaa, hongyu.jin, zhiguo.niu, xuanzhuo, pbonzini,
	virtualization, linux-block, linux-kernel


On Mon, 29 Jan 2024 16:52:50 +0800, Yi Sun wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] virtio-blk: Ensure no requests in virtqueues before deleting vqs.
      (no commit info)

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-08 18:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29  8:52 [PATCH V2] virtio-blk: Ensure no requests in virtqueues before deleting vqs Yi Sun
2024-01-30 21:15 ` Stefan Hajnoczi
2024-02-08 18:32 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).