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 88F8580031 for ; Fri, 27 Nov 2026 11:17:42 +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 6ARBGUBV022349; Fri, 27 Nov 2026 14:16:31 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ARBGUBV022349 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="YoZokRbq" Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6ARBG8b5022251 (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 6ARBG8b5022251 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-c4d58203e40so567342866b.1 for ; Fri, 27 Nov 2026 03:16:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHdpqGYv4rCKBqCBDcMNMOxf2v8w6X8uqKaKxZdreIPLrZlvkJSahtM1LzTuHIx2R8StKEatQ==@openvz.org X-Gm-Message-State: APuU4Z8fXPzMWyK6McnlqRtoOoVy/4dH22GCsmiXH5V8CuVrGXdZLd2X VLCZK/8P4BaYMpr1d/xzp7Uya22wHuL+CUcxC35JxwI8LIzLZoxlD9mByTBkpBv4R6muzjYpp7y RHpgnmO3p+BYpnpl4gC4FQ7Z2tTU/bbJ+acQJEGNOyrFYkGDsbh8pwQ== X-Gm-Gg: AZFdTZdjNCcOozYiqOGwqvMcrriiqxLtukYR5Oy8SPyS3R5AwTRYQp4Suyee1mtPQYV mHHTuZmDFIznkP1p0eN9GJ1rvsRZZN0GVJtg0dItG08e5wKgyAjNYnU5VPtMUZGbnr8oWYoSkJn 2j+gVs0TBvs/25OAi6b4ehjjpDno3mijUIHzuSFhfAIn9cs5X8kB0YhFqAyUr4osfwhDN9eWfSd D+QZqAH5q8iiYN5WwBQaHDhsu6xw2K2F3u8AGvR/4/Qu8uYf2C3aVxAE/ofmg38j51LkIX/zFJ8 ta+21mpL9K9XsfgrocDmh7L8Y/tSR8LfsFrySRB8AF5Y2Jmnz4iY2HX6xozJLCxVBrHTwryXpq/ czolafso/8CQmWoRwg6D/o7iSa04W X-Received: by 2002:a17:907:ba01:b0:c50:521f:13de with SMTP id a640c23a62f3a-c513a897601mr1893662166b.35.1795778167742; Fri, 27 Nov 2026 03:16:07 -0800 (PST) X-Received: by 2002:a17:907:ba01:b0:c50:521f:13de with SMTP id a640c23a62f3a-c513a897601mr1893659466b.35.1795778167229; 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=DpcjoN/NXbvsZX1DWV3PieSfgHObPpo4Btdvih+h0W9WtvrlEQzAZYFT9H04EQ6uDa SSuVcArKlKhY+n0LaLqguqOC7WsbBBq4a7EPsJnaFRpY3GK3B3d3+F4rJVsSSL5e78ih VokJwCv9PrkzC9v/bQ7CFR7UspYCwtAqdqvwRExg7Sv3DDuXNIU5TB2cROvBWVgGkDL/ 7qzjriRaCZ/G+J5qsleR8SgiuIKtgcRZnaclZ81/8xRJKX4NFxGIoy7uK7XnaVeE8+xm CVrSPb5InMbchtcCCxlyJsOzZH/F//rVSknPp7iUz8OZMpED1dy7zvAsLAUJlj5wzJou N8+Q== 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=3D0OK52ESHjeOys8fyBLNL6JcajlzBdJBsiFu6upMVc=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=gjVxS4rv0T8kiLc43HPibr3lP/BT02Po3FJoMZnIwzZPgdN4pbgrY0DXW9ox2jqDX4 e9FUp/weGg4elmFsCLOld0wc9x/nGlmZwUYKrzkFqUs5qFQvCvwhM/zKZ4FrzE7jJu0k HmieWj4/glpQTZgEvqwX6tExubkaTcYGGn9fh0/xIQOYGHO8OLR1YiHCUm0Y/SYuYpC5 a9J9WPgwMAGqli+HV1hRGFoXKFfrlgYL4mBRladkIcJ8LXrpoRXRzJ94DecPAbFscH9f wK2H18w4gu//vIkI2e5XvX25XTD/yJohar3gK6RY+hY/GLWgnvfAx4EWcfX7MAJajUgT N9PQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=YoZokRbq; 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-c513b074a03si1439746366b.259.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=YoZokRbq; 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=3D0OK52ESHjeOys8fyBLNL6JcajlzBdJBsiFu6upMVc=; b=YoZokRbqO+qr oZxDCQNy/eyDc9GXvL5ALzASrPdRkBzvnz7FRw9KM0GtudZ7P0akmfDuTbBADvuqKlz+1cdOU92+4 rQ7UIyZtd9VJ3D5XVq+HT/s7fI7XSwwQ8oFqIPVdTBsamVbZTAcWJl8xqMBHO8LIzWJQXh9r+rtq5 z8J93YBKSpz041AUP8RWk+Vq0rqcslmylt5c0WIEiN1enmYCs7yKtwW39BKuHCzw/92VOxVsNis6H coXeM8WskVqr4Ox563oVnamICC1TZe7YI/bu5fX4Jeq4u6WTrkleSX3yAPLoRaRPUuFfcwnb+xeb4 X1DQB5gn/fipgeINFAqz4g==; 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 1xWtvk-007zWP-2A; Fri, 27 Nov 2026 12:16:03 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Fri, 27 Nov 2026 12:16:00 +0100 Message-ID: <20261127111604.1151696-2-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 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 --- 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 422cac6f2298..19b1e6b37654 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2838,45 +2838,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", @@ -2956,6 +2930,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 37ade2f1cb7d..98ee3c438e6a 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -224,6 +224,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