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 3479B80064 for ; Tue, 1 Dec 2026 08:52:10 +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 6B18otTl021384; Tue, 1 Dec 2026 11:50:56 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B18otTl021384 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="skE5kh6W" Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B18oOau021252 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 1 Dec 2026 11:50:24 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B18oOau021252 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-6b5654ad27fso2272643a12.1 for ; Tue, 01 Dec 2026 00:50:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErH/HWxg2uZ/BDZpCvtQEjMKJcEoebqDCjPXLVd56IzE+DOja+4fiVU0T2eXCHPxakG/esM+Ig==@openvz.org X-Gm-Message-State: APuU4Z875vFucOsJKFGZkg2VRKcrm1xbEOzqlXNA2GhZuZ7ONYuGlzj0 9YislNyMF6aGVM3W6rlGM6TDqpmyuG+vkm3NutEkFOGVjc7zjY4flALJ4REFTMC78HHO+fAjAZ1 z65CRxkwuloteZDW0CZKbi3FvDMzoxdxplO4NR3SSnvK9Joav5mZiPA== X-Gm-Gg: AZFdTZfUzjFNXIIcnCB6u3vU9JC7JkvqiaD9XQ0CCwQQbTIfiXGnpK+OxlOOG208FU5 fUj6K5/wZ/Je5DymUzgRsScgCPTPok1HUkRwPBHcLKTGWLhYAPSIDZYdyAFz+iCcn6pUUv5D/Ss IQPhLfNFCHNFS7lGS74YJ+yFSoFGsuCRYtiiITqqb6tuLKtuEJhFC6MW2N5s0QDOnM02wv+jW1i Faxmz4ohqCfJA/PI0qwSxN2mQXnwPE8GcaxWEXgbpsalaM4zwXVZJqN0GYUZdI4AwgJbGYVVV5D xw9/2oD5qh6pwalAyeRDF4iZjXAFEFf0iyTuj4mmHjhKbhXFaq+56nysdp9AM8aLppzPcZyld1Q vfDuSbHWnLxIEA6lsKzFVmkplqEY= X-Received: by 2002:a05:6402:11ce:b0:6bb:d63d:e29e with SMTP id 4fb4d7f45d1cf-6bbd63de361mr4732423a12.5.1796115023867; Tue, 01 Dec 2026 00:50:23 -0800 (PST) X-Received: by 2002:a05:6402:11ce:b0:6bb:d63d:e29e with SMTP id 4fb4d7f45d1cf-6bbd63de361mr4732411a12.5.1796115023353; 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=jxmKhQg39708S+3M/LrlR/WW4IgwdcXDCsP92ai5g8xKf49vtUrgu+Uwv+bgFVs4EY p5ywTIiG+6O0c4MfIM/NK0ZqI6vhxesqwp1Iyp7uKcHhMM/OWCSTT/WDHQZfiM4jKvfp ljcE1x6MejGfxjXbG85MVMYj+D8Xb3K7nBE/QbRJuRbKcvvivFZHIdsUjr7p3WdpPSOa cHIWyp6WISazxM3hzUdIeSFHGbvVCA4Xol6DIsPwosjIDRGXQm5GrXhWPvvefneWvKGX 2xBF6DoRLg/7UET3ckE5RvEWPC9J3hnrITHhqBEqUre+v7FeKLjAKuDHnPiOhce3AoAF O17g== 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=Ds5Is0UpNcLvqxsEIHfKg1TtwMeYvxDv6SRqveQeb2U=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=Q+fMDjC+7rnqM5EVkrRT8NrZ+b5TP5aZqPY54uqmPqWPiVPuVvFE7dyxaLu5dKnhqO ocUZXe3wZ1BvdHP1u/EA/xGHDJAO6vmHVJL7/SZfOFBInyKS7otnXwOAE8r+FxA+Nwe1 rcZp9N3XO1WAaBU1zZiCmBwz1Tj1h0eQsVsRfhf2siqRzEVgGQ/tkvyQxykN3fIaG3MT +SPxKd74lwkJeTnye36Nd+ohfcfNq1lHVF8YNoVhdc5dFjID4t1CBem5GV91bGnHrr3t NyRXDDAhjTYGdkjFirzPyWtzxOgLAgYK5UhMZhMbYgySucsNDc3xYPaNokf3U9MIFohs bq+w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=skE5kh6W; 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-6ba57cd421dsi26460615a12.166.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=skE5kh6W; 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=Ds5Is0UpNcLvqxsEIHfKg1TtwMeYvxDv6SRqveQeb2U=; b=skE5kh6WPLyP tH1icfUhuSekWtVgA37WP5ibMMB1MuWVchEA8s6kWPJDTzstNw30EKCmCfw4yN2xsgIL4FYHwzCmL XJq8QG1H3Tq7Pm+4l7GOFMjAlYBVsd3UnwZhDBEuKpL2GzxCOPQRx1mqF4SvMSK4eJ4qvsxiqWLM9 7VMH/zYXsv0p4bTqd/syGK8k5P2A9G4nDFitoTmb9whvdG2UQsUJzLy29CKJVSVTZmSa3eUqboXJl dr+iAgQPlfHgNTeYXGrn5yLIo+gFvyxdnSfytFHDpd91ss8qui+a/VYbioaFYIOMVftViPxbPeYYq fH0cfsgIeRKjG9h2c8XXyw==; 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 1xYJYo-000HJh-2e; Tue, 01 Dec 2026 09:50:13 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 1 Dec 2026 09:50:17 +0100 Message-ID: <20261201085020.1884923-2-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 1/4] drivers/vhost: split the descriptor chain walk out of vhost_get_vq_desc() 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 vhost-blk is to hold a request failed with ENOSPC instead of completing it, and resubmit it later by its head when QEMU asks. That head was already taken from the avail ring, so vhost_get_vq_desc() cannot parse it again. Move the walk over the chain of a given head into vhost_get_desc_chain(), and let vhost_get_vq_desc() call it for the head it takes from the avail ring. https://virtuozzo.atlassian.net/browse/VSTOR-152175 Feature: vhost-blk: in-kernel accelerator for virtio-blk guests Signed-off-by: Alexander Ivanov Reviewed-by: Sashiko --- drivers/vhost/vhost.c | 91 ++++++++++++++++++++++++++----------------- drivers/vhost/vhost.h | 4 ++ 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 56c0ecbb8352..922e588938b2 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2783,45 +2783,19 @@ static int get_indirect(struct vhost_virtqueue *vq, return 0; } -/* This looks in the virtqueue and for the first available buffer, and converts - * it to an iovec for convenient access. Since descriptors consist of some - * number of output then some number of input descriptors, it's actually two - * iovecs, but we pack them into one and note how many of each there were. - * - * This function returns the descriptor number found, or vq->num (which is - * never a valid descriptor number) if none was found. A negative code is - * returned on error. */ -int vhost_get_vq_desc(struct vhost_virtqueue *vq, - struct iovec iov[], unsigned int iov_size, - unsigned int *out_num, unsigned int *in_num, - struct vhost_log *log, unsigned int *log_num) +/* + * Convert the descriptor chain of @head to an iovec without consuming anything + * from the avail ring. Call with vq->mutex held. + */ +int vhost_get_desc_chain(struct vhost_virtqueue *vq, unsigned int head, + struct iovec iov[], unsigned int iov_size, + unsigned int *out_num, unsigned int *in_num, + struct vhost_log *log, unsigned int *log_num) { struct vring_desc desc; - unsigned int i, head, found = 0; - u16 last_avail_idx = vq->last_avail_idx; - __virtio16 ring_head; + unsigned int i, found = 0; int ret, access; - if (vq->avail_idx == vq->last_avail_idx) { - ret = vhost_get_avail_idx(vq); - if (unlikely(ret < 0)) - return ret; - - if (!ret) - return vq->num; - } - - /* Grab the next descriptor number they're advertising, and increment - * the index we've seen. */ - if (unlikely(vhost_get_avail_head(vq, &ring_head, last_avail_idx))) { - vq_err(vq, "Failed to read head: idx %d address %p\n", - last_avail_idx, - &vq->avail->ring[last_avail_idx % vq->num]); - return -EFAULT; - } - - head = vhost16_to_cpu(vq, ring_head); - /* If their number is silly, that's an error. */ if (unlikely(head >= vq->num)) { vq_err(vq, "Guest says index %u > %u is available", @@ -2901,6 +2875,53 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, } } while ((i = next_desc(vq, &desc)) != -1); + return 0; +} +EXPORT_SYMBOL_GPL(vhost_get_desc_chain); + +/* This looks in the virtqueue and for the first available buffer, and converts + * it to an iovec for convenient access. Since descriptors consist of some + * number of output then some number of input descriptors, it's actually two + * iovecs, but we pack them into one and note how many of each there were. + * + * This function returns the descriptor number found, or vq->num (which is + * never a valid descriptor number) if none was found. A negative code is + * returned on error. */ +int vhost_get_vq_desc(struct vhost_virtqueue *vq, + struct iovec iov[], unsigned int iov_size, + unsigned int *out_num, unsigned int *in_num, + struct vhost_log *log, unsigned int *log_num) +{ + unsigned int head; + u16 last_avail_idx = vq->last_avail_idx; + __virtio16 ring_head; + int ret; + + if (vq->avail_idx == vq->last_avail_idx) { + ret = vhost_get_avail_idx(vq); + if (unlikely(ret < 0)) + return ret; + + if (!ret) + return vq->num; + } + + /* Grab the next descriptor number they're advertising, and increment + * the index we've seen. */ + if (unlikely(vhost_get_avail_head(vq, &ring_head, last_avail_idx))) { + vq_err(vq, "Failed to read head: idx %d address %p\n", + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); + return -EFAULT; + } + + head = vhost16_to_cpu(vq, ring_head); + + ret = vhost_get_desc_chain(vq, head, iov, iov_size, out_num, in_num, + log, log_num); + if (unlikely(ret)) + return ret; + /* On success, increment avail index. */ vq->last_avail_idx++; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 077fa4d0cf36..88c322d8462c 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -223,6 +223,10 @@ bool vhost_vq_access_ok(struct vhost_virtqueue *vq); bool vhost_log_access_ok(struct vhost_dev *); void vhost_clear_msg(struct vhost_dev *dev); +int vhost_get_desc_chain(struct vhost_virtqueue *vq, unsigned int head, + struct iovec iov[], unsigned int iov_size, + unsigned int *out_num, unsigned int *in_num, + struct vhost_log *log, unsigned int *log_num); int vhost_get_vq_desc(struct vhost_virtqueue *, struct iovec iov[], unsigned int iov_size, unsigned int *out_num, unsigned int *in_num, -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel