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 9335C80033 for ; Mon, 30 Nov 2026 16:26:56 +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 6AUGPZWh019781; Mon, 30 Nov 2026 19:25:36 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AUGPZWh019781 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="Tovh5yxM" Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AUGPCow019674 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 30 Nov 2026 19:25:12 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AUGPCow019674 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-6b4f1fcf171so3989840a12.1 for ; Mon, 30 Nov 2026 08:25:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErH7hid65TB8S5hkD/MDDRF8DtKHbp5rS1CR1iiLBt2iiHhvj9G1dWQb2vM6pSzwlcMf2Iq07g==@openvz.org X-Gm-Message-State: APuU4Z+RUXWeHUMN7rhLqzH7rmtJ3Il/ZRFXIu9aCLDpUrTjrWYcqOOQ Zz3xufJkrZ+Yc5Ajqx8usvs1cdsTNs0IBpZ4G6iyW5PfO7ijqDMvU28R39foincm4YUNzTRaPbL zNrxJu/VT0Bn5ksun5oB2bkKRa6lNxjk4fDY0AdCSrF/xDtF043/LHg== X-Gm-Gg: AZFdTZeQNE7RISc8wnxnTGwc0K5ddBf0X2aAWOKSbngtCELuoD3vVJRgs7gJoHEEqDt apidHsmE+MQr6FQof/ukM/Htr7/dqfDV29Y/XS56n2vls8lQ4k1ewngxDAP7SCuSSLAxeuxTHjh TQN3Dmi3w0H6XyGNRinlj42xxPydS3l9X+Ga7pJO5ZaVWkpBk4h1kCkTbafw1Wj9W/s1NXI6juj ERssPNHHAK5O+D0E0MYt4GlAnHSpv176DoNPD9xQjpB+VjsJUSnYKb4PWavPCNGwwOfUfYCMwNx mmj2XClC61VQOtKVqr/nvUaq8czUeZ1V3HdIjU4Rdf3cILkcbRH8six5czPvahzBxo2HhaB/2dR lhjk5yTE8bryUiifrEJBHC1kVaow= X-Received: by 2002:a05:6402:1e90:b0:6b5:7d7b:8e9b with SMTP id 4fb4d7f45d1cf-6ba37ebe4dbmr25871258a12.39.1796055911986; Mon, 30 Nov 2026 08:25:11 -0800 (PST) X-Received: by 2002:a05:6402:1e90:b0:6b5:7d7b:8e9b with SMTP id 4fb4d7f45d1cf-6ba37ebe4dbmr25871200a12.39.1796055909954; Mon, 30 Nov 2026 08:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796055909; cv=none; d=google.com; s=arc-20260327; b=ILGXBOTWtG+Byvrao8r1HhCz/76czCzmbS8FyVIVTmsLB2wzbeSd+IxhszMEH45el1 8xRgpJLcRdsOmfHVHB8GLYHAIKFrc/q4nEBbERpKox48024swBg35jtuqfhc6Cgn8roH MH4itqsZ1961uKSwqko9PJyPZ165ZBxzzcio9nOSp94DIE5pZBvN7du5LkWfbBTxBhNw rwGW79M3NFp3Mr2OyaGNSR8QIwsjwYsIMLodOFKRbTS+7+2rdIqon4tTuyxEnW0xZcLn IceSGsZO/3J3tIdaR9iWHK8YfM9XjWIJFHU1JFkt3KABJ5JzAb9E59XbqGt0ZI3DXKi1 iLPQ== 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=La79W1ZJi3tPKD0j+RzpNHTOJGZxqqRlZIqwVHPgrk7SSmSp34Ps6RJZ2qxYmk2Pkt qITd5wZttaSoKkiPtIW1NiijEQwWND3tGpue+Vixr+xF7/mqNHAKH83AnZSbUJ8aBv3A 0E2GGj1b1ui8Cks930IQ5MzjbqwaI1cd1qVdBnbz3hOdWHkfswCLz29TT8DVMeVia9jE W7QXNODtJfosRUlP4T9OG2W9pZ/C6OKIcPjmqqfIKwsKQxgi0d8zD/urBDc6AIAeCl9v 6RlS0X0UlriSByxkwQOiIQhdZHbH8rHGT6h7mjJMrQ5/ymPJsTUXDV1CGfG4AgF+hI/0 n1XA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Tovh5yxM; 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-6ba373a80bdsi27014411a12.194.2026.11.30.08.25.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 08:25:09 -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=Tovh5yxM; 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=Tovh5yxMBMX4 ppnGYLjjJwPKwxORgDuZp9jSRTFxpdPEalBezM0Fna42Rl1L4LLRJAFZ+LZUkfDjZ5Icvp1Vypyxh DBToM4XROUatgGAgm5wtr60ATdgDfk1tv0WmIs9I/jg4avKJg4e7Jd89RIGlE2Nv48Y0lFjFTLeYG 0go7cfD340tEgDhUwG78O6nEGdVTl/NCPHU/kHP9dYVU1lXOBwc1+bz5mnmnniadit57wJAI7zbOI unwwJlPbIg+90ZnM4cX+phxAVhqBlF2saxFzufUaOtF53KNeddx1k1SuSn81bltEo/A7bCIw7UnaX bKlmqZVSxJPQiXk0xUDaAQ==; 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 1xY4BO-00Gm8b-1W; Mon, 30 Nov 2026 17:25:01 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Mon, 30 Nov 2026 17:25:04 +0100 Message-ID: <20261130162507.1822477-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261130162507.1822477-1-alexander.ivanov@virtuozzo.com> References: <20261130162507.1822477-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 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