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 679C180063 for ; Fri, 27 Nov 2026 11:17:51 +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 6ARBGb0w022386; Fri, 27 Nov 2026 14:16:38 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ARBGb0w022386 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="EIC1Ah4W" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6ARBG8es022267 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Fri, 27 Nov 2026 14:16:08 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ARBG8es022267 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6b897016acbso1119104a12.3 for ; Fri, 27 Nov 2026 03:16:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEZdBOAcReGqHsbfHAVcT+3tA3J6+CFRtHmbeEFk6/eaABgLs6/KuAaJUThUdlKSZxhOCW8tA==@openvz.org X-Gm-Message-State: APuU4Z+wxH6enVzXhSOUdkX/9tdNy8VxVQ9/NJJpEO3Xy2qbYV3fm1AI grwQ47e4nETIkuVWcTuTFZthjkzVjge1NFa9d6Z8vUJbV5W1MB0gC+ZuzYqQg8Iu310F3smcdiT ISyudCF1aygQPp5J41DiHVl3PbWXoUL4tqTaw0Pngii4o6+xpJ24RVQ== X-Gm-Gg: AZFdTZf8DFwI/BhkTHO4udt8yhTY9VCySk9aXpo5bWDXFsXO0GHVF/RxIMf1Hm6afCq RseEa9GYwpNBo+cGTByLm7bwCYQYLz580JZGOUCxCuuuqe19uSbDZIEim4UIrp4qEsN9pEiLGgz VamYlpI7DtYCFkYeyG75RtkwtPCyh6x9x0C+p3yvMJa+4d2IyK0XG5xeB8W9C3uYHQh7GFSBGay kAoOwRsMpQbyESHEC7msDm5NUfHvSGtcYhHbZ4HYkMzdkFQB5Xrhx4MydaESuiLV1/lKWBLH4Ko YRlsjqhDbfi76BSXNwZyPbRmA+oEG0Se3PfLB6aOF11WhoSwqhRioGef7gWpRS/x+UmFlsY06+v rpFgfHEoopFQ0GGgggSZWs1vtJYEX X-Received: by 2002:aa7:d597:0:b0:6b6:f5b0:88b3 with SMTP id 4fb4d7f45d1cf-6ba37c76678mr14251081a12.3.1795778168375; Fri, 27 Nov 2026 03:16:08 -0800 (PST) X-Received: by 2002:aa7:d597:0:b0:6b6:f5b0:88b3 with SMTP id 4fb4d7f45d1cf-6ba37c76678mr14251062a12.3.1795778167881; Fri, 27 Nov 2026 03:16:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795778167; cv=none; d=google.com; s=arc-20260327; b=bNJUeyBfC1QhI77BzejCNDfUqxl/QF3x+H5Y48cmvlMsGAH2+IazlJjxAoNobTjP2q TdCAKpkAX+Ns3wPNhC/Qwcab4y3bFkN4qIQKYnx96hdUWOWeHqmjT+KiGYQJxHGnuOJg SAPC68wM9XoW70lCumaWzE5439tq6bJ4aiCUh2N9npI0051ayMSuqcqOsMPLGa32jAuI poc2cgQ3jM/qM4pnpnYPqTVMT+Dw7mJwjuKP+IbpfrazObU5D9OCNtGjZV+fUejdSv0a tIvwTMSN1BIImqM62RLcqYiM6dJiOGLiGfkj8wlA/C8fXMmPal8xe/edDQaEjgucfMzi 2jIw== 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=yk98cV1J9NgBL8syaR+SZAqDNVvBt/QGsR5hrFr4cWI=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=oaliPIB+L/XgeLePCg2pPeHXugHSbLpUodAyzUCwkx1KUqicwdPkeJhsHRVbhUnSfe 1A7XmlAY8CRX7HD9I8LVqoDFldfAE5Kga6OpmN6+yFCVyliI5sdesNM22f9T4/6ZJKjS b3j5kyQ8ZNUCdEkOfEbBFho2nm1akk+ME9MWv379Y2m+O3JqOZsYNkedkFeag4n4YKj4 JZ0bs3/T2sbwam3EpGBPBzTyLtk8V/4BRoUD0KTbzX67R+aMHD3WUFZYEGvaodd5YA4o gyZ4S0aWXzr60ho8WQRhPN7f6SgdEFIfZaQxQsw+GqIzkA2AxvF8A0u/baVuEbj77JtG mXCg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=EIC1Ah4W; 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 4fb4d7f45d1cf-6ba3c451db1si21760656a12.139.2026.11.27.03.16.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2026 03:16:07 -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=EIC1Ah4W; 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=yk98cV1J9NgBL8syaR+SZAqDNVvBt/QGsR5hrFr4cWI=; b=EIC1Ah4W0Xjo IqS9NDnCdrBtrtDkizlAfMCVtqPn6VChCKlNvH0IPF8xfw30RrDBn7982ACYnwDRVdZ5cLlo8LTxr w5+nqUs17Ga9AVNv0nORJg5OL435nlcGoTieFfiJb4f0oWCOd4LkVjQe6uYKBrZupE29co+yUN8rM ZvcTq9ReF+prhjOEymUCGdJunb2IzYaIGUF36UtZ4UUXNgfrbGWoOnYvmM50va4KJpDNfczkelHKP VJfH31RQR7Jt6l3uiKwsnMyRTTw1RGRbHpqREHGatY/Jg6YjiG9lf7vxJgIyJckGv965uakMs+xOk Q5YOAo5azyx4ZiqJsdnvUw==; 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 1xWtvl-007zWP-0x; Fri, 27 Nov 2026 12:16:03 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Fri, 27 Nov 2026 12:16:03 +0100 Message-ID: <20261127111604.1151696-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261127111604.1151696-1-alexander.ivanov@virtuozzo.com> References: <20261127111604.1151696-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 4/4] drivers/vhost/blk: add the VHOST_BLK_RESUBMIT ioctl 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 QEMU stops vhost-blk to pause the VM on a held request, and the list of held requests is emptied when the device starts again. The heads of these requests are already taken from the avail ring, so the kick handler never sees them, and the guest waits for them forever. VHOST_BLK_RESUBMIT parses the descriptor chain of each given head and submits the request as if it were just taken from the avail ring. The request data stays in guest memory, so QEMU needs only the vq and head pairs it read with VHOST_BLK_GET_HELD_REQS, also after a migration. A request that fails with ENOSPC again is held again. Only the owner may resubmit, as the descriptors are walked and the data pages are pinned through the mm of the caller. A head still in flight fails with -EBUSY before it reaches the request parser, which would report it as a guest error on the vring error eventfd: here the caller is at fault, and the errno already says so. https://virtuozzo.atlassian.net/browse/VSTOR-152175 Feature: vhost-blk: in-kernel accelerator for virtio-blk guests Signed-off-by: Alexander Ivanov --- drivers/vhost/blk.c | 63 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 11 +++++++ 2 files changed, 74 insertions(+) diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c index e1e39b361b68..614b8c68f576 100644 --- a/drivers/vhost/blk.c +++ b/drivers/vhost/blk.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1165,6 +1166,65 @@ static long vhost_blk_get_held_reqs(struct vhost_blk *blk, return ret; } +static int vhost_blk_resubmit_one(struct vhost_blk *blk, + const struct vhost_blk_held_req *r) +{ + struct vhost_virtqueue *vq; + unsigned int out, in; + int ret; + + if (r->vq >= VHOST_BLK_VQ_MAX || r->reserved) + return -EINVAL; + + vq = &blk->vqs[r->vq].vq; + mutex_lock(&vq->mutex); + if (!vhost_vq_get_backend(vq)) { + ret = -ENODEV; + goto out; + } + + ret = vhost_get_desc_chain(vq, r->head, vq->iov, ARRAY_SIZE(vq->iov), + &out, &in, NULL, NULL); + if (!ret && blk->vqs[r->vq].req[r->head].inflight) + ret = -EBUSY; + if (!ret) + ret = vhost_blk_handle_desc(vq, r->head, out, in); +out: + mutex_unlock(&vq->mutex); + return ret; +} + +static long vhost_blk_resubmit(struct vhost_blk *blk, + struct vhost_blk_held_reqs __user *argp) +{ + struct vhost_blk_held_req r; + u32 nr, i; + int ret; + + ret = vhost_blk_get_held_nr(argp, &nr); + if (ret) + return ret; + + for (i = 0; i < nr; i++) { + if (fatal_signal_pending(current)) { + ret = -EINTR; + break; + } + cond_resched(); + if (copy_from_user(&r, &argp->reqs[i], sizeof(r))) { + ret = -EFAULT; + break; + } + ret = vhost_blk_resubmit_one(blk, &r); + if (ret) + break; + } + + if (ret && put_user(i, &argp->nr)) + ret = -EFAULT; + return ret; +} + static long vhost_blk_error_ioctl(struct vhost_blk *blk, unsigned int ioctl, void __user *argp) { @@ -1182,6 +1242,8 @@ static long vhost_blk_error_ioctl(struct vhost_blk *blk, unsigned int ioctl, return vhost_blk_set_error_fd(blk, argp); case VHOST_BLK_GET_HELD_REQS: return vhost_blk_get_held_reqs(blk, argp); + case VHOST_BLK_RESUBMIT: + return vhost_blk_resubmit(blk, argp); } return -ENOIOCTLCMD; } @@ -1208,6 +1270,7 @@ static long vhost_blk_ioctl(struct file *f, unsigned int ioctl, case VHOST_BLK_SET_ERROR_POLICY: case VHOST_BLK_SET_ERROR_FD: case VHOST_BLK_GET_HELD_REQS: + case VHOST_BLK_RESUBMIT: mutex_lock(&blk->dev.mutex); ret = vhost_dev_check_owner(&blk->dev); if (!ret) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index 4dee1b53e97e..9581c9840750 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -304,4 +304,15 @@ */ #define VHOST_BLK_GET_HELD_REQS _IOWR(VHOST_VIRTIO, 0xFB, \ struct vhost_blk_held_reqs) + +/* + * Resubmit requests by vq and head, as if they were just taken from the avail + * ring. Only heads read with VHOST_BLK_GET_HELD_REQS after the last stop may be + * passed: the kernel does not track them, and a head passed again after its + * request completed, or still owned by the guest, is completed twice. A head + * still in flight fails with -EBUSY. error and type are ignored, reserved + * must be 0. On error, nr is set to the number of requests resubmitted. + */ +#define VHOST_BLK_RESUBMIT _IOWR(VHOST_VIRTIO, 0xFA, \ + struct vhost_blk_held_reqs) #endif -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel