From nobody Mon Feb 9 04:59:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1648749989469414.5035408142726; Thu, 31 Mar 2022 11:06:29 -0700 (PDT) Received: from localhost ([::1]:35980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZzBk-0006H1-Bd for importer@patchew.org; Thu, 31 Mar 2022 14:06:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZz9m-0003Nt-Be for qemu-devel@nongnu.org; Thu, 31 Mar 2022 14:04:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZz9k-0007Jn-92 for qemu-devel@nongnu.org; Thu, 31 Mar 2022 14:04:25 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-468-Lu7TbR_3O7uawgSaYmvItA-1; Thu, 31 Mar 2022 14:04:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 597CE3C01C00; Thu, 31 Mar 2022 18:04:18 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FAB840D0160; Thu, 31 Mar 2022 18:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648749863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1geVC60KOCBqYcV0yzBh5c9nGhEBBky47+bYEoJUFqQ=; b=gAyrzoXvVH7GWhpdKVdH8S1WtI2Y9UlSojtQPQ/3THmOYIzrUgNFtWuWrYNWkd07Rfc9B0 1wQJfEak4ZWYdGNktmsN0J7QGd115XTuqCtj3KXAhT13lGXnecPKJZfVzTbDakSHgByImt tf9v8QqfMPNULupWS/o9vHk7zokI7eQ= X-MC-Unique: Lu7TbR_3O7uawgSaYmvItA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v4 01/20] vhost: Fix bad return of descriptors Date: Thu, 31 Mar 2022 20:03:51 +0200 Message-Id: <20220331180410.531837-2-eperezma@redhat.com> In-Reply-To: <20220331180410.531837-1-eperezma@redhat.com> References: <20220331180410.531837-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eperezma@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Parav Pandit , Cindy Lu , "Michael S. Tsirkin" , Jason Wang , Markus Armbruster , Gautam Dawar , Harpreet Singh Anand , Peter Xu , Eli Cohen , Liuxiangdong , Zhu Lingshan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1648749989850100001 Only the first one of them were properly enqueued back. Fixes: 100890f7ca ("vhost: Shadow virtqueue buffers forwarding") Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index b232803d1b..c17506df20 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -333,13 +333,25 @@ static void vhost_svq_disable_notification(VhostShado= wVirtqueue *svq) svq->vring.avail->flags |=3D cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); } =20 +static uint16_t vhost_svq_last_desc_of_chain(VhostShadowVirtqueue *svq, + uint16_t i) +{ + vring_desc_t *descs =3D svq->vring.desc; + + while (le16_to_cpu(descs[i].flags) & VRING_DESC_F_NEXT) { + i =3D le16_to_cpu(descs[i].next); + } + + return i; +} + static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) { vring_desc_t *descs =3D svq->vring.desc; const vring_used_t *used =3D svq->vring.used; vring_used_elem_t used_elem; - uint16_t last_used; + uint16_t last_used, last_used_chain; =20 if (!vhost_svq_more_used(svq)) { return NULL; @@ -365,7 +377,8 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, return NULL; } =20 - descs[used_elem.id].next =3D svq->free_head; + last_used_chain =3D vhost_svq_last_desc_of_chain(svq, used_elem.id); + descs[last_used_chain].next =3D svq->free_head; svq->free_head =3D used_elem.id; =20 *len =3D used_elem.len; --=20 2.27.0