From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 06563803BB for ; Tue, 17 Nov 2026 10:45:35 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AHAiNFB008414; Tue, 17 Nov 2026 13:44:24 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AHAiNFB008414 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="OyqUALTf" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AHAhYBl008327 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 17 Nov 2026 13:43:34 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AHAhYBl008327 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48e29c25101so2006687f8f.3 for ; Tue, 17 Nov 2026 02:43:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFC/mn2mGYIpl5g0XeCYXhJ5PgLPuMwIfUvpnEKWB0IPHjogMWnm6pYV7WbZn9RC7JbiXbZ0g==@openvz.org X-Gm-Message-State: APuU4Z9VjojkfYVWx+rnIqeBd4asPSjs7tDY3UsMEVdCbUJ5+7hoIrTU tbwzIqkBXj2VbQXhRWU3YTAS1lyHRgF4M2Dwm8Znf8gG8Al2rKa5mRG5alUyu81aPETbEOutXUR U2XnlQ9030CodcVKIkJlQW20nCYem3JibqSijgcH8ppB+LIPdRD/iBg== X-Gm-Gg: AZFdTZeBwZSFYCWVdStDJ3yJC/eX+FC7XujEfE2pOV/7/1XrbGJy2xWpCpAWYRHOKnW ekcrptcZKL4q3bMWccZpSa5lzEjwWSDat76kg9hr0Xv6igWtbakqOBfvJHiuX7TrwU4gzmwdGgo FsrKVSlOaAGRIHjYaXblz8TFKblwL+L12FzHn3D+aI8F8tlutJOdrglw3dMr2NerOHOFhqYuhOO REZkIFRVFYpxPnbjMmaUUl7j2mI1DKgNY3TlKcjoEF7qGUe0t2KNvgTJWxMpXWR/lk41MjO5YbV bzXsUoZDfsFn+PfDzF/kYxQL02eqd2PlDav/2L/MrOIWNNvctQJaN49RjthYseTO9N77GyG68OZ 5MZLUEgpMIcW+uVDwaq5/Bu+n/5k= X-Received: by 2002:a05:6000:4804:b0:48d:fd4b:cdd6 with SMTP id ffacd0b85a97d-49c73631545mr30431429f8f.25.1794912213783; Tue, 17 Nov 2026 02:43:33 -0800 (PST) X-Received: by 2002:a05:6000:4804:b0:48d:fd4b:cdd6 with SMTP id ffacd0b85a97d-49c73631545mr30431371f8f.25.1794912213193; Tue, 17 Nov 2026 02:43:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794912213; cv=none; d=google.com; s=arc-20260327; b=fbUJfU0F89ojCXPpk/tKG5wxHne29D+V9YdaP2piFpaYcIEBFc+Ysnpn5XY5c2Ut6L 5FbGyePrsfBDJNqQmA+oB/hkGZhxWjhbaObSIPOttiEU9AqBekhvZF83LF6tYkx2KKbu w4K88IdyKSM+7ZttEUHkjbkuWIVXEsag47LtInNZmkhEaJvz5AiqaqFn/JoZLaI0EiU4 oV/D7I6BaD8N21OL9jfCqvI7Oz3Gw59il0k+qnZNR2kcKphP1qpIZIKkOcTc2PNH/dfd qbzyFXQkM8Hix7cfNoeFYgB+8j3Vkn2aEn118lBHWu3Wo0uB5vG0/7yr4NVO/1dNmcNM VrYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Rtfvhn28D5Dbg0F6JGT0ER8iuZ3spLY+mS3k9wn5Kw8=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=ciiUfiTCvY4XN46B9K3ZHs9nER0GS9JOQL/XUUYJ0UdKRfVdSZy2j9/GJsXjBK6NMO ZieKBRCwic+wRDcXqwF+f+LWoEq7lmrPaNCyFeSbY2TReomG5+uWAkM6ibvrwwRL23IQ suvY1iU8YgQSnn/V/xgS43phGhKLFA1m6bUCZmAzt4hmsHSDMwqD9sZNsWmI9rlR3LfE 81PZW0lmRQlHZh/mob2idF7pRW7tf2uPTN9iq8rVgcEgIlh6RcRVgMkAS9QWqjz7GF+P bh0OD6rB4jkzG9BgXKowuPweo1/8hSkB+2WdMBEG0kZsVX6uLJYyjbatSlQQL0EGSpVg 28yA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=OyqUALTf; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a5547f6808si561212f8f.367.2026.11.17.02.43.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2026 02:43:33 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=OyqUALTf; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=Rtfvhn28D5Dbg0F6JGT0ER8iuZ3spLY+mS3k9wn5Kw8=; b=OyqUALTfbFnq /ey9ZTZdzF3V4Q5TV+2uZ9LKFUa9rt7SMQZqTmxguGNIDnrqLAV7m0RtRFHhkKG9q+qZOOZo1lzA0 RbW9zyqLshxh5ZKmCR/IpOs4Vm7/6MkVGZut/bU8urSZtYKSzsUjUIB0Ix32ZccY2sQfWS94wOLA/ d8Jai9hyd+GF1AN34Dci8+do4g6YQSC3NuLcr/mbHlZiZDysG4qFku2J6PHBL1QhZ6VI3+dBfO6B5 vNaxbHYxqzkvexs5bK5fNM3oiiEpPemcOOsY45lh43iJ6Iy7FZNHUUSYF3GCDT1U/+EAahB0ev04I OyW37hqDtLIJvhudDf5WPQ==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=sky) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xTGai-009vj8-1l; Tue, 17 Nov 2026 11:43:23 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 17 Nov 2026 11:43:29 +0100 Message-ID: <20261117104329.3079812-10-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261117104329.3079812-1-alexander.ivanov@virtuozzo.com> References: <20261117104329.3079812-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v3 9/9] drivers/vhost/blk: fix a hang on release after the vhost worker is killed X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org 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 --- 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