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 0419F80063 for ; Tue, 1 Dec 2026 08:52:11 +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 6B18p1TJ021401; Tue, 1 Dec 2026 11:51:02 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B18p1TJ021401 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="RkIn6iid" Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B18oOAg021260 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 1 Dec 2026 11:50:25 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B18oOAg021260 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c508bafaddfso875492566b.1 for ; Tue, 01 Dec 2026 00:50:25 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHPr+PfJTSHZ9jtftYpts3ytGZTt5WCBKo/47MgHOdXXJAEHyQt3/O+xihxf0bNjsWbffIG4g==@openvz.org X-Gm-Message-State: APuU4Z84lIOTVDUMXaEsqkR7AWlmXTUQWi87luVeQFZ504Qstlw86bdu nALwc7qeAWtVc8n2wqAXRiRvGsRH6p4yvc8gixgyucNhyKWGAlRwrCugaRJzyjvhEyWOVUPoEJK vMuxfpvuHiHmLkTP2PzFM6xO3sYVe0DKdQWYLBmbw7sO9e6MAT/xZ5A== X-Gm-Gg: AZFdTZc9/7E5fCcnRenbnSgEl6wwofPc1g/MVl00Z7715cF2GQRLB53X/HAooGXOaBq CrWfwpbmMN3/lw5AqZq+CcHGVt8v7f7k4517t0L62JRouUnl6BasgIecn7YLKuk/5rw+1kHUjw6 dAZa+PmIroexssmGbTfuacjDYMJJbymTMxpF/9XpBlAXcaCbT0Ab8y6jetRf8VKy8Cz8WJggr+z hPn1ud7NkhcE5yR3EogFgHNrCTm062ITfFhhdzho+GshBoQqn6+PddB4z+3mG5+RSz9vDsWho0D lZRxoppG8tkTqFTsOlD9GnXxwKzlqXL9e4vy9VyuEFrNQVtyKxduzsOeWq/wvloRJVv38KGfF35 DoXGUE6voPnJWGCN/YayDwNWfxUo= X-Received: by 2002:a17:907:9584:b0:c34:e9fe:82ed with SMTP id a640c23a62f3a-c513a88223amr2774825666b.28.1796115024471; Tue, 01 Dec 2026 00:50:24 -0800 (PST) X-Received: by 2002:a17:907:9584:b0:c34:e9fe:82ed with SMTP id a640c23a62f3a-c513a88223amr2774824266b.28.1796115023985; Tue, 01 Dec 2026 00:50:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796115023; cv=none; d=google.com; s=arc-20260327; b=sRj/153P01jZJnNoXG+iAsP7fH0+RT8v4xK3IlfYYVISX6UmWsCJvK/F6RtIRM8mo5 3T2ALRuquPhXhOXEMqze8zk81Mln+pVPnazWnIFnD/jEnbdDLq81uBoU5W+jQS5Tmkm0 RmCotY1ZDwuH7kJ9Qhf0G6/QHZ78+CNt/P3RB+bU8bPhXzbxdUT3xSkDr1wXTMSSNNlI d9rJJGRh7kdbAH/jj8MZ3KjpqoBrG7Eq9923PevAmM99ZUdLDmf3VhE2804+rr/CyWmb bngvmdSORAgCWxagdH18KDq1TvMsG9Z1CUf9xFYsqSxzD3QZ3KYpMTUR35R4S87Y+CU4 HoYw== 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=JJRKhRrSDCIlBLTL2GGAMAr3jSi4aKY7BhCmrmCMJyM=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=NEt1HMHm4wBnwbMDMUnHhk4X1paqWwP3IuHV4r4xzszydAbC6lfUzNFq8jVV6X0rqh 7QXvu8liDD1VxgWC9Q44iySRwjHRA+f0s5QYNZjAeHmLmItOc8Txe46SGt4gvfCGhtUo n8FEvw69u/4RVG6GoYSWRre2Y8HU11gPlAaqfXiMYcJ74leQI3qyBevArvPBz4gcadOM DMTyptpD20S8hOuMkWtUvwb5Y+wTGSHnXpIQy9t6S9XcerXTS5VTYmtxy53tWmBfkIF/ ctseOyEXBW5cIalZQmlysptcBJG610B1yKyg4vsBimEtZO5REJ94SmVdD3C4Pyg8naHg 5neQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=RkIn6iid; 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 a640c23a62f3a-c521fdc16c0si162823066b.291.2026.12.01.00.50.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 00:50:23 -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=RkIn6iid; 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=JJRKhRrSDCIlBLTL2GGAMAr3jSi4aKY7BhCmrmCMJyM=; b=RkIn6iidXqct vcc2IwIH0h8HIeDhSpQyBGPTeuOBtFRP8eZaktqZSsbBTSrOFVFSMnVUVG2qDumvR00UlPvJxgzXT nmpRHrFb0kb45uF+oINHkec40U6RpqNAxSb3V5bxvCoWKTOTZUxEvkR6ThS/pFgVkRMzxKMqcU0b8 BbSbbWCqr5BDpgKs+e0Xm00O45TpN5hWIiPw/oa/+3/XnA2Ru8T3F1njk6l8dqMlHbDwXq1WbFPWl NiqHqkes1gypUBfYCNWn99l4JFNkh1yeSNqp7pKcsI97+O/1Fci/eBPLD/YsnBNRBjnTm91kKRO9m F3zbiRLmfYvvD0ZiBPQDCg==; 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 1xYJYp-000HJh-1R; Tue, 01 Dec 2026 09:50:14 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 1 Dec 2026 09:50:20 +0100 Message-ID: <20261201085020.1884923-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201085020.1884923-1-alexander.ivanov@virtuozzo.com> References: <20261201085020.1884923-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v3 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 out of range or still in flight fails with -EINVAL or -EBUSY before the descriptor chain is walked, as the walk and the request parser 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 | 70 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 15 ++++++++ 2 files changed, 85 insertions(+) diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c index c11b5be5d6bf..fcf51aab4203 100644 --- a/drivers/vhost/blk.c +++ b/drivers/vhost/blk.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1229,6 +1230,72 @@ 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; + } + + if (r->head >= vq->num) { + ret = -EINVAL; + goto out; + } + if (blk->vqs[r->vq].req[r->head].inflight) { + ret = -EBUSY; + goto out; + } + + ret = vhost_get_desc_chain(vq, r->head, vq->iov, ARRAY_SIZE(vq->iov), + &out, &in, NULL, NULL); + 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) { @@ -1246,6 +1313,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; } @@ -1272,6 +1341,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 21bf6e39a85a..f024c8784974 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -296,4 +296,19 @@ */ #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. A head passed again after its request + * completed, still owned by the guest, or reused by the guest since the backend + * was set, is completed twice, or fails with -EBUSY while still in flight. + * error and type are ignored, reserved must be 0. On error, nr is set to the + * index of the entry that failed; the entries before it were resubmitted. + * On -ENOMEM pass the same entry again; -ENODEV and -EINTR fail the rest as + * well. Any other error concerns only that entry: the ones after it may still + * be passed from nr + 1. Fails with -ENODEV until the backend is set. + */ +#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