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 2095E80067 for ; Tue, 1 Dec 2026 12:51:22 +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 6B1Co6PF008074; Tue, 1 Dec 2026 15:50:07 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1Co6PF008074 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="JW1SMk7m" Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1CnaTu007993 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 1 Dec 2026 15:49:37 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1CnaTu007993 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c4163a5400eso1046367466b.1 for ; Tue, 01 Dec 2026 04:49:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEZIM2bOepnJ9PO4eSr4Blk1HS6Ly1XsKSh/8mFHjVmwPQSbt3/QooOiJTcjuy2wi5wx4/QiA==@openvz.org X-Gm-Message-State: APuU4Z+d4J2Gm5r0WLU1IplkViPDFuwQe+CANEF8pX98QDKh4vbpS0HR 1VJhYWXE5RgfuI4zQ1gSFn2prLus+oyAlvcvWY+9mhvrBVefXoxB0a3Ltgq6ag+lZxf1HKm5Tos jhCHqwzV+REqQ6oQBjtD0/oRSRdiiDPrDeKhzOp6Uc6ayfQC7OTiLhw== X-Gm-Gg: AZFdTZcccaQ/quRTYixL/VX/SatijkL367cUE9lGTNsHL71GY3WPbisWoum5lgfPIWn 8DmNvqnP0/tCV4nMfXJ2Rale/MGrKNkIRk8HdXAwe94qE/FW4MEai1DLhZB46+hNwpqkqisJdjN On0WFJ2SPNlQ2wG7Y9hXNRt1seQvttoWtEsX+8nu4HRZY2Q8vEGZh/UwRHSBSLj2Kxm8KQFZgqC f8jCoVux8bU+IHIqw1Fe7lE47JSOiV/U/z5FU6ngpMDyxf4dpZDa3P7w5baKLbmBeBNxKm4eMnU aMWeZp/MY8JU/R/mGT8g14PsF8+BVt3mQX7rb3Y0y1MK/rwRBRPsfd+kBV3J5MqwhJkPld94RSv XUu2JeG+sjFsmdM88XA9VsTYalbs= X-Received: by 2002:a05:6402:c521:20b0:6bb:bf06:495a with SMTP id 4fb4d7f45d1cf-6bbbf064a4fmr4721253a12.17.1796129376476; Tue, 01 Dec 2026 04:49:36 -0800 (PST) X-Received: by 2002:a05:6402:c521:20b0:6bb:bf06:495a with SMTP id 4fb4d7f45d1cf-6bbbf064a4fmr4721239a12.17.1796129375958; Tue, 01 Dec 2026 04:49:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796129375; cv=none; d=google.com; s=arc-20260327; b=gG9dZuYp5v7h21M40sFjb7szBdmQvTYaNSqJc+LEhitDAIYDpLjAiq+axPvlsQO5ah aU7nKZvVtI355AvazC7KsmPDU7WC0bsGeRl4jmNFBL1LSc6KscvcDYhoxtMcnsoJJuM0 IpSukszihmOr3BSF72yQQ+tZYZRJNJbiCf/QuKQnyWxxKZp2p94Fp/QX9CHgWad7aUFm oiRN1p5M71tosSYGu5NWd80h8nDY1WRKX5nicqe3fvj24rkq+wDLW+4jyc8NWPbL6omc 8b2xKkVcWkjRhRejU1XPUaXlPat9A4a+4PwAxL7nAX5B1BAkYp3Dr80R5AXns5WfoUdY eodA== 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=S/RUGzFEXGghvtV+4qPLahXPQSgEUhqemqTNwCr2WRY=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=bAXqB0WAyv2qjD2pLffFz7lg+/ok1Bj8R81vJ4hvZsm2wUi4BZ7ilat4S4VcJA9omS DY2VbSmbSRFDTHyrfhFdA8STh8OdY+QePxq9ahwF+2UXz+qbHwERK7hYuVo7+nDOaFyv 8d1ngL9P4MqCusX298tlMBLR5H7t5CibLQdScNPZQytAKa8nwfLzx5X8vWAyOPCIZ90s nEm/4XU+nIebfJrdG9XOnnDk1awr/C16DFFgDN76Zq+c+GjnSnCckEL8xUeSudNV0LEM cuVTotOo5pro2fiIUEPTenMMQK30c1P3gaAE6UHjpkDjzNJ94g4dVkOWJO8rppnnsaAu fx7Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=JW1SMk7m; 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-6bb33a3bd26si14553176a12.66.2026.12.01.04.49.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:49:35 -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=JW1SMk7m; 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=S/RUGzFEXGghvtV+4qPLahXPQSgEUhqemqTNwCr2WRY=; b=JW1SMk7mbylN E/zrXC5eJLOsadrYhD3ZIQRJxHHgpGdOnnf7YNGKwjGe6bPhvh7fj/YqDQvHwJQLX1vX5SMulv36H h6NS6k9QZhC4GD7SNBZn1smvuRSWEU9gC54MKvEQQmLoMD4kssmccDRFogq7AdO/M6gGayw0oxZJC pyhXkk/dF2RPGamx4qhjpOkjeUCn9X4y84it2Gp6tIchbiGgfVgYLc6cfWYKG1SY7jmoFdLdebwCb ma0hSPeDjV8/nFPC/1zfXTM4wd7hcQpT81drXNx4DiD85eJGsuwmPPy91s7q7wdwuBVNPD75TA7B6 QLqz54B0MGYqiN5c52PBzg==; 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 1xYNIJ-004oY7-0d; Tue, 01 Dec 2026 13:49:25 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 1 Dec 2026 13:49:31 +0100 Message-ID: <20261201124931.1969095-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124931.1969095-1-alexander.ivanov@virtuozzo.com> References: <20261201124931.1969095-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v4 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. -EFAULT ends the call, so it is left for a fault on the array of the caller. A fault on the guest memory of one entry returns -EIO, and QEMU goes on with the entries after it. 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 | 73 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 19 ++++++++++ 2 files changed, 92 insertions(+) diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c index f67d8f9fee75..ee6199e2a0f9 100644 --- a/drivers/vhost/blk.c +++ b/drivers/vhost/blk.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1235,6 +1236,75 @@ 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); + /* -EFAULT is left for a fault on the caller's buffer */ + if (ret == -EFAULT) + ret = -EIO; +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) { @@ -1252,6 +1322,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; } @@ -1278,6 +1350,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 87acc4737347..8d7892d0ed76 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -296,4 +296,23 @@ */ #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. -EPERM, and -EFAULT or + * -EINVAL on the header, fail before any entry and leave nr as passed in. + * Otherwise, 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. + * -EINTR, -EFAULT (the entry is not readable from reqs) and -ENODEV (the vq + * of that entry has no backend: the device is stopped, or the vq is not set + * up) end the call: do not go on. Any other error concerns only that entry, + * as -EIO for a fault on its request in guest memory: the ones after it may + * still be passed from nr + 1. A skipped entry's request is never completed. + */ +#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