From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v2 9/9] drivers/vhost/blk: fix a hang on release after the vhost worker is killed
Date: Tue, 17 Nov 2026 11:10:26 +0100 [thread overview]
Message-ID: <20261117101026.3071579-10-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261117101026.3071579-1-alexander.ivanov@virtuozzo.com>
When the owner is killed, vhost_worker_killed() detaches the worker
from the vqs. A bio completing after that fails to queue the
completion work, so its request stays on llhead and is never removed
from req_inflight. vhost_blk_flush() on release then waits forever
and the process is stuck in D state. Any kill of a VM with I/O in
flight can hit this.
If the work cannot be queued, drop the completed requests right in
the bio end_io: forget them without writing a status, as there is no
guest left to see it. llist_del_all() makes sure a request is dropped
once even if it races with the last run of the host kick handler.
forget_request() can now run in irq context, so take flush_lock with
interrupts disabled. The end_io may run in atomic context and the
request buffers may be vmalloc'ed, so free them on release instead:
a dropped request is the one left with ->inflight set.
Once a request is on llhead, a concurrent consumer may forget it and
let release free the request array and blk while the end_io is still
using blk_vq. Keep the end_io tail in an RCU read-side section and
wait for a grace period before freeing the requests. The same window
existed before with the host kick handler as the consumer.
https://virtuozzo.atlassian.net/browse/VSTOR-152175
Fixes: c57a98d65796 ("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 | 52 +++++++++++++++++++++++++++++++++------------
1 file changed, 39 insertions(+), 13 deletions(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index b95358cdf3bc..b67255580031 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -146,6 +146,8 @@ static inline int vhost_blk_set_status(struct vhost_blk_req *req, u8 status)
return 0;
}
+static void vhost_blk_drop_completed(struct vhost_blk_vq *blk_vq);
+
static void vhost_blk_req_done(struct bio *bio)
{
struct vhost_blk_req *req = bio->bi_private;
@@ -168,8 +170,14 @@ 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;
+
+ /* req and blk may be freed once req is on llhead */
+ rcu_read_lock();
+ llist_add(&req->llnode, &blk_vq->llhead);
+ if (!vhost_vq_work_queue(&blk_vq->vq, &blk_vq->work))
+ vhost_blk_drop_completed(blk_vq);
+ rcu_read_unlock();
}
}
@@ -394,22 +402,34 @@ static inline void vhost_blk_bio_send(struct vhost_blk_req *req)
static inline void note_request(struct vhost_blk_req *req)
{
- spin_lock(&req->blk->flush_lock);
+ spin_lock_irq(&req->blk->flush_lock);
req->req_bin = req->blk->new_req_bin;
atomic_inc(&req->blk->req_inflight[req->req_bin]);
- spin_unlock(&req->blk->flush_lock);
+ spin_unlock_irq(&req->blk->flush_lock);
}
static inline void forget_request(struct vhost_blk_req *req)
{
struct vhost_blk *blk = req->blk;
+ unsigned long flags;
int zero;
- spin_lock(&blk->flush_lock);
+ spin_lock_irqsave(&blk->flush_lock, flags);
zero = atomic_dec_and_test(&blk->req_inflight[req->req_bin]);
if (zero && blk->during_flush)
wake_up(&blk->flush_wait);
- spin_unlock(&blk->flush_lock);
+ spin_unlock_irqrestore(&blk->flush_lock, flags);
+}
+
+/* Called when the worker is killed: nobody will complete these to the guest */
+static void vhost_blk_drop_completed(struct vhost_blk_vq *blk_vq)
+{
+ struct vhost_blk_req *req, *tmp;
+ struct llist_node *llnode;
+
+ llnode = llist_del_all(&blk_vq->llhead);
+ llist_for_each_entry_safe(req, tmp, llnode, llnode)
+ forget_request(req);
}
static int vhost_blk_req_submit(struct vhost_blk_req *req)
@@ -688,12 +708,12 @@ static void vhost_blk_flush(struct vhost_blk *blk)
{
int flush_bin;
- spin_lock(&blk->flush_lock);
+ spin_lock_irq(&blk->flush_lock);
WARN_ON(blk->during_flush);
blk->during_flush = 1;
flush_bin = blk->new_req_bin;
blk->new_req_bin = !blk->new_req_bin;
- spin_unlock(&blk->flush_lock);
+ spin_unlock_irq(&blk->flush_lock);
vhost_dev_flush(&blk->dev);
/*
@@ -707,15 +727,15 @@ static void vhost_blk_flush(struct vhost_blk *blk)
*/
wait_event(blk->flush_wait, !atomic_read(&blk->req_inflight[flush_bin]));
- spin_lock(&blk->flush_lock);
+ spin_lock_irq(&blk->flush_lock);
blk->during_flush = 0;
- spin_unlock(&blk->flush_lock);
+ spin_unlock_irq(&blk->flush_lock);
}
static void vhost_blk_drop_backend(struct vhost_blk *blk)
{
struct vhost_virtqueue *vq;
- int i;
+ int i, j;
if (!blk->backend)
return;
@@ -729,10 +749,16 @@ 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++) {
- kvfree(blk->vqs[i].req);
- blk->vqs[i].req = NULL;
+ struct vhost_blk_vq *blk_vq = &blk->vqs[i];
+
+ for (j = 0; blk_vq->req && j < blk_vq->vq.num; j++)
+ if (blk_vq->req[j].inflight)
+ vhost_blk_req_cleanup(&blk_vq->req[j]);
+ kvfree(blk_vq->req);
+ blk_vq->req = NULL;
}
fput(blk->backend);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-17 10:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:10 [Devel] [PATCH hci-8.1 v2 0/9] dm-qcow2: support the werror/rerror policies for vhost-blk disks Alexander Ivanov
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 1/9] drivers/md/dm-qcow2: cancel the event work and ENOSPC timer in the destructor Alexander Ivanov
2026-11-17 10:22 ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 2/9] drivers/md/dm-qcow2: always resubmit delayed ENOSPC requests in presuspend Alexander Ivanov
2026-11-17 10:25 ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 3/9] drivers/md/dm-qcow2: rename the ENOSPC delay list to a held request list Alexander Ivanov
2026-11-17 10:25 ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 4/9] drivers/md/dm-qcow2: arm the hold timer only for the first held request Alexander Ivanov
2026-11-17 10:27 ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 5/9] drivers/md/dm-qcow2: report held requests with an IO_ERROR uevent Alexander Ivanov
2026-11-17 10:29 ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 6/9] drivers/md/dm-qcow2: add the resubmit and fail_held messages Alexander Ivanov
2026-11-17 10:32 ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 7/9] drivers/md/dm-qcow2: add the error_policy table argument Alexander Ivanov
2026-11-17 10:34 ` no-reply
2026-11-17 10:10 ` [Devel] [PATCH hci-8.1 v2 8/9] drivers/md/dm-qcow2: requeue held requests on a noflush suspend Alexander Ivanov
2026-11-17 10:37 ` no-reply
2026-11-17 10:10 ` Alexander Ivanov [this message]
2026-11-17 10:42 ` [Devel] [PATCH hci-8.1 v2 9/9] drivers/vhost/blk: fix a hang on release after the vhost worker is killed no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117101026.3071579-10-alexander.ivanov@virtuozzo.com \
--to=alexander.ivanov@virtuozzo.com \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=devel@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox