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 2EC86803F6 for ; Fri, 13 Nov 2026 08:30:07 +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 6AD8RoaP015947; Fri, 13 Nov 2026 11:27:52 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AD8RoaP015947 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="vja+aB4n" Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AD8RmMI015936 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Fri, 13 Nov 2026 11:27:48 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AD8RmMI015936 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4ba078abd78so4447165e9.1 for ; Fri, 13 Nov 2026 00:27:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErECVKUwphnyGTBTFKnel7e9I3aedPzBLyygx5XX1ZjnE6tiKckRKU/HfrMB2enQXd3h0dC0tQ==@openvz.org X-Gm-Message-State: APuU4Z/W8G4VWwX1tJ4eIKSt7u3EacHz0QyLFNbA5xSAztMfY52OQeL5 Cy7y92GQKo+UeNFrX63pav3L5cEXWE7W7Eqs24sLs9uESGXThJhfwrjCIxjooYDCmBf9SfYW0C7 cQmS+KQ5cSUWqKQ9KA0hMXHjaCb9Mo6O/NSrecFjaWfDq+1ruV3iW8Q== X-Gm-Gg: AYBFou2oESTb2rFgCGNsc6KvgBC4kgJO8SfT4mx/nCUC64zZcaXpCFVvv0/PjFaDVFD tTRZnfY2JrmFg3UW52rWHqnWRhwB0LMvVBpYR4qxwo1rpF938g1hLIWNeZ6E6vsERIeGu8O7Wt4 rQn3hSZ/tcmeDxa79mPRZjFWjMXM2F0MyElXZwWVk7v9INFnvTpGEiATcWAm/SmC6W4paZKqpdN op1c1H8uV7qVnsLVtu7NA1sPZAOaunEn0C6mi1yNegjViXWW58Qul5Olbs2BnCUIL/G4Z+J4rkB rofaMfidTtvmJPD2EuL4Qc2jgUFTcsIvXxrcev5ZOHtnKYhf0YmmJe08xYeuDNq8Qzc/hP/EDT2 z99rcehfcvoJGyBkSsrtW+MW9Ogs= X-Received: by 2002:a05:600c:46c5:b0:4b6:5dac:b61e with SMTP id 5b1f17b1804b1-4bb55a9b453mr33709345e9.32.1794558468127; Fri, 13 Nov 2026 00:27:48 -0800 (PST) X-Received: by 2002:a05:600c:46c5:b0:4b6:5dac:b61e with SMTP id 5b1f17b1804b1-4bb55a9b453mr33708865e9.32.1794558467607; Fri, 13 Nov 2026 00:27:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794558467; cv=none; d=google.com; s=arc-20260327; b=iGi1SNHNMURTKtK2UbyBn/F/9mKZk1yNTkKRfpuFzm10hjXzSL8+VYYwFIi1AzySVk /dCAFb7OKvGkrfXUOGCPli6YyaX7r6YQi+bPWnvhBm0/rrzNt77+g69s6hMtJcQ3F/Tx /dOAFbAH0NyJYdMdusKYE9akKzCZIo5wQLSJCHGHIPXja4ruOgRZokRNk4exTwBXGZup uX6UKzWEw4ANgxb6VW6Ky9NzIW10h1BeCoogIbKTV0yl4bjtcoNLBFCgrcKcw5xomwTG AEq2f+5SFL2xaUDtHAd+tRF7g9p20bUhllOin+tHBqoVhDdyHautvkMRAGirxtYT72Pq oExA== 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=JLkjLx6Tz8x9rDyWbNJXp2ZLrnVP4KrtqjMqXtm7Il8=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=Ch5Mp8RyOgl+mur21X1ZmPCvrUwidvSgGhXrT1VA8TaBsne20+euhxpyZ5reTS07xS y2vSXksrTYr6bOZigtQQx++zqzSyGcstWv+1hNyFeb/jAybjawN7BbZ+yoQ5z9A8uAXC SvWyAaZSpJkz9+N/lXldHgCzCAbHHMeDnnflVx6nNMQRTKuDj09VTf5QHz7CoJ3AEgzT xJ2OCuxkGnL7CJ94TTN+FBz22veUXvMKwBP5n4BWBAbiZgISSseFj4J+iLuX0kXITCx6 7v+K6j+3M5sATPmum4H2HZ5PLSfb20MZgOy1cUpxVYRvN5WUN/4UAzBf9tAaGEOdxmnp 3guw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=vja+aB4n; 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-49c64455e6esi4004493f8f.310.2026.11.13.00.27.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 00:27:47 -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=vja+aB4n; 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=JLkjLx6Tz8x9rDyWbNJXp2ZLrnVP4KrtqjMqXtm7Il8=; b=vja+aB4nBY5U dl9VQqLhavyyDoDySGCeFgCThfNmfWNclXayddFKEsF/3JEIx9ZBq5Oebi+LUS7C8fgN5giq47+mj Fbfcupc+x1RsnXxvjD3Ze5UY+IdqPjc+xXtYweIomCrOaLfxaDl4Locv74ojxroz5QKT3H7p1fMUI soagKbJSlAB7dnIZZhvkIJfopiEW+D+sjywO4B2Zh6m9n3LrjxcBzCPbTeVkQIKPy6OFCtUEAd7T7 4YzuGq8Em2RsMFLfsVb3TqquYEi5f7MXDA7qP82DR7EW1e7wV/u4J4ZjPZeyRTkyQbDd66OUr3vw5 yM17o45fGCCu10jTgZ6MeQ==; 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 1xRmZF-003ta7-0O; Fri, 13 Nov 2026 09:27:43 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Fri, 13 Nov 2026 09:27:43 +0100 Message-ID: <20261113082744.2334476-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113082744.2334476-1-alexander.ivanov@virtuozzo.com> References: <20261113082744.2334476-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 1/2] drivers/vhost/blk: fix a flush hang on requests completed after worker kill 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 virtqueues and runs 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 forget_request() and the kvfree() of the request buffers are not allowed. 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. Flushing there rather than in release also keeps a stale drop work from releasing requests of the next owner after VHOST_RESET_OWNER. 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 --- 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