All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill
@ 2026-11-17 13:59 Alexander Ivanov
  2026-11-17 14:04 ` no-reply
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexander Ivanov @ 2026-11-17 13:59 UTC (permalink / raw)
  To: andrey.zhadchenko; +Cc: devel

With vhost_task workers (not the default kthread ones), killing the
owner makes vhost_worker_killed() detach the worker from the virtqueues
and run only the work already queued. A request that completes after
that is added to blk_vq->llhead, but vhost_vq_work_queue() returns
false and queues nothing, so the request is never forgotten.
req_inflight[] stays elevated and vhost_blk_flush() hangs
uninterruptibly in release when the fd is closed. A request in flight
at the kill is enough.

Release such requests from a work item when the worker cannot be
queued, as vhost-scsi does in vhost_scsi_drop_cmds(). The bio
completion may run in interrupt context, where a request cannot be
released: that takes vq->mutex, and flush_lock with plain spin_lock().
The guest is not answered, its memory is no longer reachable.

Once the completion publishes the request, the request can be
forgotten and vhost_blk_flush() can return while the completion is
still queueing work into blk, which release then frees. Queue under
rcu_read_lock() and wait for it with synchronize_rcu() in
vhost_blk_drop_backend(), then flush the drop work before freeing the
requests.

https://virtuozzo.atlassian.net/browse/VSTOR-141684

Fixes: 1629db092dd7 ("drivers/vhost: vhost-blk accelerator for virtio-blk guests")
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 drivers/vhost/blk.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index b95358cdf3bc..eea8cca59cac 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -91,6 +91,7 @@ struct vhost_blk_vq {
 	struct iovec iov[UIO_MAXIOV];
 	struct llist_head llhead;
 	struct vhost_work work;
+	struct work_struct drop_work;
 };
 
 struct vhost_blk {
@@ -168,8 +169,13 @@ static void vhost_blk_req_done(struct bio *bio)
 	}
 
 	if (atomic_dec_and_test(&req->bio_nr)) {
-		llist_add(&req->llnode, &req->blk_vq->llhead);
-		vhost_vq_work_queue(&req->blk_vq->vq, &req->blk_vq->work);
+		struct vhost_blk_vq *blk_vq = req->blk_vq;
+
+		rcu_read_lock();
+		llist_add(&req->llnode, &blk_vq->llhead);
+		if (!vhost_vq_work_queue(&blk_vq->vq, &blk_vq->work))
+			schedule_work(&blk_vq->drop_work);
+		rcu_read_unlock();
 	}
 }
 
@@ -683,6 +689,24 @@ static void vhost_blk_handle_host_kick(struct vhost_work *work)
 	mutex_unlock(&vq->mutex);
 }
 
+static void vhost_blk_drop_reqs(struct work_struct *work)
+{
+	struct vhost_blk_vq *blk_vq;
+	struct vhost_blk_req *req, *tmp;
+	struct llist_node *llnode;
+
+	blk_vq = container_of(work, struct vhost_blk_vq, drop_work);
+
+	mutex_lock(&blk_vq->vq.mutex);
+	llnode = llist_del_all(&blk_vq->llhead);
+	llist_for_each_entry_safe(req, tmp, llnode, llnode) {
+		vhost_blk_req_cleanup(req);
+		req->inflight = false;
+		forget_request(req);
+	}
+	mutex_unlock(&blk_vq->vq.mutex);
+}
+
 /* It is forbidden to call more than one vhost_blk_flush() simultaneously */
 static void vhost_blk_flush(struct vhost_blk *blk)
 {
@@ -730,6 +754,10 @@ static void vhost_blk_drop_backend(struct vhost_blk *blk)
 
 	vhost_blk_flush(blk);
 
+	synchronize_rcu();
+	for (i = 0; i < VHOST_BLK_VQ_MAX; i++)
+		flush_work(&blk->vqs[i].drop_work);
+
 	for (i = 0; i < VHOST_BLK_VQ_MAX; i++) {
 		kvfree(blk->vqs[i].req);
 		blk->vqs[i].req = NULL;
@@ -803,8 +831,10 @@ static int vhost_blk_open(struct inode *inode, struct file *file)
 		       VHOST_DEV_WEIGHT, VHOST_DEV_PKT_WEIGHT, true, NULL);
 	file->private_data = blk;
 
-	for (i = 0; i < VHOST_BLK_VQ_MAX; i++)
+	for (i = 0; i < VHOST_BLK_VQ_MAX; i++) {
 		vhost_work_init(&blk->vqs[i].work, vhost_blk_handle_host_kick);
+		INIT_WORK(&blk->vqs[i].drop_work, vhost_blk_drop_reqs);
+	}
 
 	return ret;
 out_blk:
-- 
2.53.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

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

* Re: [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill
  2026-11-17 13:59 [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill Alexander Ivanov
@ 2026-11-17 14:04 ` no-reply
  2026-11-17 14:38 ` Konstantin Khorenko
  2026-11-17 14:38 ` Konstantin Khorenko
  2 siblings, 0 replies; 4+ messages in thread
From: no-reply @ 2026-11-17 14:04 UTC (permalink / raw)
  To: Alexander Ivanov, andrey.zhadchenko; +Cc: devel

> With vhost_task workers (not the default kthread ones), killing the
> owner makes vhost_worker_killed() detach the worker from the virtqueues
> and run only the work already queued. A request that completes after
> that is added to blk_vq->llhead, but vhost_vq_work_queue() returns
> false and queues nothing, so the request is never forgotten.
> req_inflight[] stays elevated and vhost_blk_flush() hangs
> uninterruptibly in release when the fd is closed. A request in flight
> at the kill is enough.
> 
> Release such requests from a work item when the worker cannot be
> queued, as vhost-scsi does in vhost_scsi_drop_cmds(). The bio
> completion may run in interrupt context, where a request cannot be
> released: that takes vq->mutex, and flush_lock with plain spin_lock().
> The guest is not answered, its memory is no longer reachable.
> 
> Once the completion publishes the request, the request can be
> forgotten and vhost_blk_flush() can return while the completion is
> still queueing work into blk, which release then frees. Queue under
> rcu_read_lock() and wait for it with synchronize_rcu() in
> vhost_blk_drop_backend(), then flush the drop work before freeing the
> requests.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-141684
> 
> Fixes: 1629db092dd7 ("drivers/vhost: vhost-blk accelerator for virtio-blk guests")
> Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261117135955.3157381-1-alexander.ivanov@virtuozzo.com?part=1


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

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

* Re: [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill
  2026-11-17 13:59 [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill Alexander Ivanov
  2026-11-17 14:04 ` no-reply
@ 2026-11-17 14:38 ` Konstantin Khorenko
  2026-11-17 14:38 ` Konstantin Khorenko
  2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-11-17 14:38 UTC (permalink / raw)
  To: Alexander Ivanov; +Cc: devel

Applying as is.

On Tue, 17 Nov 2026 14:59:55 +0100, Alexander Ivanov wrote:
> drivers/vhost/blk: fix a flush hang on requests completed after worker kill

This is patch 1 of the VIRTIO_BLK_F_WRITE_ZEROES v3 series, unchanged,
so please send that v4 without it. The worker ioctls series goes in on
top of this patch.

Thanks.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

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

* Re: [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill
  2026-11-17 13:59 [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill Alexander Ivanov
  2026-11-17 14:04 ` no-reply
  2026-11-17 14:38 ` Konstantin Khorenko
@ 2026-11-17 14:38 ` Konstantin Khorenko
  2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-11-17 14:38 UTC (permalink / raw)
  To: andrey.zhadchenko, Alexander Ivanov; +Cc: devel

On Tue, 17 Nov 2026 14:59:55 +0100, Alexander Ivanov wrote:
> drivers/vhost/blk: fix a flush hang on requests completed after worker kill

Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.24.3.vz10, thanks!

[1/1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/7c3a94b1ef24

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team


_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

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

end of thread, other threads:[~2026-11-17 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 13:59 [Devel] [PATCH hci-8.1] drivers/vhost/blk: fix a flush hang on requests completed after worker kill Alexander Ivanov
2026-11-17 14:04 ` no-reply
2026-11-17 14:38 ` Konstantin Khorenko
2026-11-17 14:38 ` Konstantin Khorenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.