From nobody Mon Feb 9 22:59:51 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 1644867350537433.9110451473923; Mon, 14 Feb 2022 11:35:50 -0800 (PST) Received: from localhost ([::1]:52712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJh8X-0002U9-CI for importer@patchew.org; Mon, 14 Feb 2022 14:35:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqV-0002wR-PH for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47317) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJgqT-0001FW-Kr for qemu-devel@nongnu.org; Mon, 14 Feb 2022 14:17:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-83-JCpfY3zkN8etghK73UaSaw-1; Mon, 14 Feb 2022 14:17:05 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49D4F18397A7; Mon, 14 Feb 2022 19:17:04 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.195.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 056C25F9B0; Mon, 14 Feb 2022 19:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644866229; 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=4eHPTaikCQbJVrEmx1ahQ35mWO0n70e57bZoijuIK14=; b=A2Nfd0oVMbc32ojtSZDFW+4V6VSzzFZ6n1Ayqz+BFUnP7EfkQt8f0OSLRWiSc72F/6wRxr 1vMc5V8pyyqzx26svLTFjyw0mQFQuuSHtbKjiX685ywTVZoB3QZkLm7aBWU/wx1i0SbzdR 6AH329op6ju+y8UlFCBN9Q1Fag2Mq7Y= X-MC-Unique: JCpfY3zkN8etghK73UaSaw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 4/9] vhost: Add SVQElement Date: Mon, 14 Feb 2022 20:16:30 +0100 Message-Id: <20220214191635.1604932-5-eperezma@redhat.com> In-Reply-To: <20220214191635.1604932-1-eperezma@redhat.com> References: <20220214191635.1604932-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.129.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.083, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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 , Gautam Dawar , Harpreet Singh Anand , Eli Cohen , 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: 1644867352512100001 This allows SVQ to add metadata to the different queue elements Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 52 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 873e39e9cf..ea32b7ae7f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -17,6 +17,10 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 +typedef struct SVQElement { + VirtQueueElement elem; +} SVQElement; + /* Shadow virtqueue to relay notifications */ struct VhostShadowVirtqueue { /* Shadow vring */ @@ -50,10 +54,10 @@ struct VhostShadowVirtqueue { VhostIOVATree *iova_tree; =20 /* Map for returning guest's descriptors */ - VirtQueueElement **ring_id_maps; + SVQElement **ring_id_maps; =20 /* Next VirtQueue element that guest made available */ - VirtQueueElement *next_guest_avail_elem; + SVQElement *next_guest_avail_elem; =20 /* Next head to expose to device */ uint16_t avail_idx_shadow; @@ -281,9 +285,10 @@ static void vhost_vring_write_descs(VhostShadowVirtque= ue *svq, } =20 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, - VirtQueueElement *elem, + SVQElement *svq_elem, unsigned *head) { + const VirtQueueElement *elem =3D &svq_elem->elem; unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; bool ok; @@ -324,7 +329,7 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *s= vq, return true; } =20 -static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +static bool vhost_svq_add(VhostShadowVirtqueue *svq, SVQElement *elem) { unsigned qemu_head; bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); @@ -372,19 +377,21 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) } =20 while (true) { + SVQElement *svq_elem; VirtQueueElement *elem; bool ok; =20 if (svq->next_guest_avail_elem) { - elem =3D g_steal_pointer(&svq->next_guest_avail_elem); + svq_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); } else { - elem =3D virtqueue_pop(svq->vq, sizeof(*elem)); + svq_elem =3D virtqueue_pop(svq->vq, sizeof(*elem)); } =20 - if (!elem) { + if (!svq_elem) { break; } =20 + elem =3D &svq_elem->elem; if (elem->out_num + elem->in_num > vhost_svq_available_slots(svq)) { /* @@ -398,11 +405,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqu= eue *svq) * queue the current guest descriptor and ignore further k= icks * until some elements are used. */ - svq->next_guest_avail_elem =3D elem; + svq->next_guest_avail_elem =3D svq_elem; return; } =20 - ok =3D vhost_svq_add(svq, elem); + ok =3D vhost_svq_add(svq, svq_elem); if (unlikely(!ok)) { /* VQ is broken, just return and ignore any other kicks */ return; @@ -437,7 +444,7 @@ static bool vhost_svq_more_used(VhostShadowVirtqueue *s= vq) return svq->last_used_idx !=3D svq->shadow_used_idx; } =20 -static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq) +static SVQElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq) { vring_desc_t *descs =3D svq->vring.desc; const vring_used_t *used =3D svq->vring.used; @@ -471,7 +478,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq) descs[used_elem.id].next =3D svq->free_head; svq->free_head =3D used_elem.id; =20 - svq->ring_id_maps[used_elem.id]->len =3D used_elem.len; + svq->ring_id_maps[used_elem.id]->elem.len =3D used_elem.len; return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); } =20 @@ -486,11 +493,13 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq, =20 vhost_svq_set_notification(svq, false); while (true) { - g_autofree VirtQueueElement *elem =3D vhost_svq_get_buf(svq); - if (!elem) { + g_autofree SVQElement *svq_elem =3D vhost_svq_get_buf(svq); + VirtQueueElement *elem; + if (!svq_elem) { break; } =20 + elem =3D &svq_elem->elem; if (unlikely(i >=3D svq->vring.num)) { virtio_error(svq->vdev, "More than %u used buffers obtained in a %u size = SVQ", @@ -667,7 +676,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, void vhost_svq_stop(VhostShadowVirtqueue *svq) { event_notifier_set_handler(&svq->svq_kick, NULL); - g_autofree VirtQueueElement *next_avail_elem =3D NULL; + g_autofree SVQElement *next_avail_elem =3D NULL; =20 if (!svq->vq) { return; @@ -677,17 +686,18 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) vhost_svq_flush(svq, false); =20 for (unsigned i =3D 0; i < svq->vring.num; ++i) { - g_autofree VirtQueueElement *elem =3D NULL; - elem =3D g_steal_pointer(&svq->ring_id_maps[i]); - if (elem) { - virtqueue_detach_element(svq->vq, elem, elem->len); + g_autofree SVQElement *svq_elem =3D NULL; + svq_elem =3D g_steal_pointer(&svq->ring_id_maps[i]); + if (svq_elem) { + virtqueue_detach_element(svq->vq, &svq_elem->elem, + svq_elem->elem.len); } } =20 next_avail_elem =3D g_steal_pointer(&svq->next_guest_avail_elem); if (next_avail_elem) { - virtqueue_detach_element(svq->vq, next_avail_elem, - next_avail_elem->len); + virtqueue_detach_element(svq->vq, &next_avail_elem->elem, + next_avail_elem->elem.len); } } =20 @@ -735,7 +745,7 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, Vho= stIOVATree *iova_tree) svq->vring.used =3D qemu_memalign(qemu_real_host_page_size, device_siz= e); memset(svq->vring.used, 0, device_size); svq->iova_tree =3D iova_tree; - svq->ring_id_maps =3D g_new0(VirtQueueElement *, qsize); + svq->ring_id_maps =3D g_new0(SVQElement *, qsize); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); return g_steal_pointer(&svq); =20 --=20 2.27.0