From nobody Fri May 3 05:35:58 2024 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 1642797790631444.3097330533467; Fri, 21 Jan 2022 12:43:10 -0800 (PST) Received: from localhost ([::1]:45892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0kX-0002s1-Hn for importer@patchew.org; Fri, 21 Jan 2022 15:43:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Z3-0005Qw-G9 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:31:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45365) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Yz-0003O0-BI for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:31:16 -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-313-QxYGyxqYP52AXUDqK_tzCw-1; Fri, 21 Jan 2022 15:29:36 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0AFA3193578C; Fri, 21 Jan 2022 20:29:35 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9E3116A31; Fri, 21 Jan 2022 20:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797045; 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=j67t6TpSga7nlGJsFIRGFk0h9tdDgayDDsYv/VIxliQ=; b=P3r7RbeF7H2DeH32+dAdmbeSb8dx28gZlfSSAs6TWU9wCySXk07wm52cpF0Ko3quzYT32B /OU687y+5hnoTnmUJvWGUSIuj+ZG9KQ7GgAfnZnoX1uGUWsjbT5jYG0vRHAbdmdeTQt2lg 7aEIcCCz4qUY9ylr6OUmAgd90YvPuwg= X-MC-Unique: QxYGyxqYP52AXUDqK_tzCw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 01/31] vdpa: Reorder virtio/vhost-vdpa.c functions Date: Fri, 21 Jan 2022 21:27:03 +0100 Message-Id: <20220121202733.404989-2-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797792417100002 vhost_vdpa_set_features and vhost_vdpa_init need to use vhost_vdpa_get_features in svq mode. vhost_vdpa_dev_start needs to use almost all _set_ functions: vhost_vdpa_set_vring_dev_kick, vhost_vdpa_set_vring_dev_call, vhost_vdpa_set_dev_vring_base and vhost_vdpa_set_dev_vring_num. No functional change intended. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 164 ++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 04ea43704f..6c10a7f05f 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -342,41 +342,6 @@ static bool vhost_vdpa_one_time_request(struct vhost_d= ev *dev) return v->index !=3D 0; } =20 -static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) -{ - struct vhost_vdpa *v; - assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); - trace_vhost_vdpa_init(dev, opaque); - int ret; - - /* - * Similar to VFIO, we end up pinning all guest memory and have to - * disable discarding of RAM. - */ - ret =3D ram_block_discard_disable(true); - if (ret) { - error_report("Cannot set discarding of RAM broken"); - return ret; - } - - v =3D opaque; - v->dev =3D dev; - dev->opaque =3D opaque ; - v->listener =3D vhost_vdpa_memory_listener; - v->msg_type =3D VHOST_IOTLB_MSG_V2; - - vhost_vdpa_get_iova_range(v); - - if (vhost_vdpa_one_time_request(dev)) { - return 0; - } - - vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | - VIRTIO_CONFIG_S_DRIVER); - - return 0; -} - static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev, int queue_index) { @@ -506,24 +471,6 @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *= dev, return 0; } =20 -static int vhost_vdpa_set_features(struct vhost_dev *dev, - uint64_t features) -{ - int ret; - - if (vhost_vdpa_one_time_request(dev)) { - return 0; - } - - trace_vhost_vdpa_set_features(dev, features); - ret =3D vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); - if (ret) { - return ret; - } - - return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); -} - static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) { uint64_t features; @@ -646,35 +593,6 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev= , uint8_t *config, return ret; } =20 -static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) -{ - struct vhost_vdpa *v =3D dev->opaque; - trace_vhost_vdpa_dev_start(dev, started); - - if (started) { - vhost_vdpa_host_notifiers_init(dev); - vhost_vdpa_set_vring_ready(dev); - } else { - vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); - } - - if (dev->vq_index + dev->nvqs !=3D dev->vq_index_end) { - return 0; - } - - if (started) { - memory_listener_register(&v->listener, &address_space_memory); - return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); - } else { - vhost_vdpa_reset_device(dev); - vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | - VIRTIO_CONFIG_S_DRIVER); - memory_listener_unregister(&v->listener); - - return 0; - } -} - static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) { @@ -735,6 +653,35 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev = *dev, return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); } =20 +static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) +{ + struct vhost_vdpa *v =3D dev->opaque; + trace_vhost_vdpa_dev_start(dev, started); + + if (started) { + vhost_vdpa_host_notifiers_init(dev); + vhost_vdpa_set_vring_ready(dev); + } else { + vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); + } + + if (dev->vq_index + dev->nvqs !=3D dev->vq_index_end) { + return 0; + } + + if (started) { + memory_listener_register(&v->listener, &address_space_memory); + return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); + } else { + vhost_vdpa_reset_device(dev); + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + memory_listener_unregister(&v->listener); + + return 0; + } +} + static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features) { @@ -745,6 +692,24 @@ static int vhost_vdpa_get_features(struct vhost_dev *d= ev, return ret; } =20 +static int vhost_vdpa_set_features(struct vhost_dev *dev, + uint64_t features) +{ + int ret; + + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + + trace_vhost_vdpa_set_features(dev, features); + ret =3D vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); + if (ret) { + return ret; + } + + return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); +} + static int vhost_vdpa_set_owner(struct vhost_dev *dev) { if (vhost_vdpa_one_time_request(dev)) { @@ -772,6 +737,41 @@ static bool vhost_vdpa_force_iommu(struct vhost_dev *= dev) return true; } =20 +static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) +{ + struct vhost_vdpa *v; + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); + trace_vhost_vdpa_init(dev, opaque); + int ret; + + /* + * Similar to VFIO, we end up pinning all guest memory and have to + * disable discarding of RAM. + */ + ret =3D ram_block_discard_disable(true); + if (ret) { + error_report("Cannot set discarding of RAM broken"); + return ret; + } + + v =3D opaque; + v->dev =3D dev; + dev->opaque =3D opaque ; + v->listener =3D vhost_vdpa_memory_listener; + v->msg_type =3D VHOST_IOTLB_MSG_V2; + + vhost_vdpa_get_iova_range(v); + + if (vhost_vdpa_one_time_request(dev)) { + return 0; + } + + vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); + + return 0; +} + const VhostOps vdpa_ops =3D { .backend_type =3D VHOST_BACKEND_TYPE_VDPA, .vhost_backend_init =3D vhost_vdpa_init, --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642797373081356.041133999576; Fri, 21 Jan 2022 12:36:13 -0800 (PST) Received: from localhost ([::1]:57150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0dm-0007uy-Kc for importer@patchew.org; Fri, 21 Jan 2022 15:36:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Z1-0005Pq-Ih for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:31:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Yw-00038c-Nt for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:31:15 -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-574--oFOokyKPkmDoW8ZvSPWVw-1; Fri, 21 Jan 2022 15:30:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B51E84BA1A; Fri, 21 Jan 2022 20:30:07 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86A083D7E; Fri, 21 Jan 2022 20:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797010; 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=iZfKQhsB/ktrhenT9moP6VzJa8291iIlZQu2980rWAM=; b=MJOnPjF+Oxm+o0PKKX+OjGcGpYYKEOEb6sLN8qLVWfpsoLJ7SZu5wKZ0cuBfLHgq6rypRH q1jpYmNXf5ADFLHTOAYEMO+SrRStFYueJ7gP3OH+K+7CSiaIhWzIUxqnD9fwjPYDZVjF2Q WH2qFIumWulon8oiqJG029VmH5Be/hg= X-MC-Unique: -oFOokyKPkmDoW8ZvSPWVw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 02/31] vhost: Add VhostShadowVirtqueue Date: Fri, 21 Jan 2022 21:27:04 +0100 Message-Id: <20220121202733.404989-3-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797374007100002 Vhost shadow virtqueue (SVQ) is an intermediate jump for virtqueue notifications and buffers, allowing qemu to track them. While qemu is forwarding the buffers and virtqueue changes, it is able to commit the memory it's being dirtied, the same way regular qemu's VirtIO devices do. This commit only exposes basic SVQ allocation and free. Next patches of the series add functionality like notifications and buffers forwarding. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 21 ++++++++++ hw/virtio/vhost-shadow-virtqueue.c | 64 ++++++++++++++++++++++++++++++ hw/virtio/meson.build | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/vhost-shadow-virtqueue.h create mode 100644 hw/virtio/vhost-shadow-virtqueue.c diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h new file mode 100644 index 0000000000..61ea112002 --- /dev/null +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -0,0 +1,21 @@ +/* + * vhost shadow virtqueue + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 + * SPDX-FileContributor: Author: Eugenio P=C3=A9rez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef VHOST_SHADOW_VIRTQUEUE_H +#define VHOST_SHADOW_VIRTQUEUE_H + +#include "hw/virtio/vhost.h" + +typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; + +VhostShadowVirtqueue *vhost_svq_new(void); + +void vhost_svq_free(VhostShadowVirtqueue *vq); + +#endif diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c new file mode 100644 index 0000000000..5ee7b401cb --- /dev/null +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -0,0 +1,64 @@ +/* + * vhost shadow virtqueue + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 + * SPDX-FileContributor: Author: Eugenio P=C3=A9rez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" + +#include "qemu/error-report.h" +#include "qemu/event_notifier.h" + +/* Shadow virtqueue to relay notifications */ +typedef struct VhostShadowVirtqueue { + /* Shadow kick notifier, sent to vhost */ + EventNotifier hdev_kick; + /* Shadow call notifier, sent to vhost */ + EventNotifier hdev_call; +} VhostShadowVirtqueue; + +/** + * Creates vhost shadow virtqueue, and instruct vhost device to use the sh= adow + * methods and file descriptors. + */ +VhostShadowVirtqueue *vhost_svq_new(void) +{ + g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); + int r; + + r =3D event_notifier_init(&svq->hdev_kick, 0); + if (r !=3D 0) { + error_report("Couldn't create kick event notifier: %s", + strerror(errno)); + goto err_init_hdev_kick; + } + + r =3D event_notifier_init(&svq->hdev_call, 0); + if (r !=3D 0) { + error_report("Couldn't create call event notifier: %s", + strerror(errno)); + goto err_init_hdev_call; + } + + return g_steal_pointer(&svq); + +err_init_hdev_call: + event_notifier_cleanup(&svq->hdev_kick); + +err_init_hdev_kick: + return NULL; +} + +/** + * Free the resources of the shadow virtqueue. + */ +void vhost_svq_free(VhostShadowVirtqueue *vq) +{ + event_notifier_cleanup(&vq->hdev_kick); + event_notifier_cleanup(&vq->hdev_call); + g_free(vq); +} diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 521f7d64a8..2dc87613bc 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-= stub.c')) =20 virtio_ss =3D ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backe= nd.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backe= nd.c', 'vhost-shadow-virtqueue.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloo= n.c')) --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642797461702140.9145187986826; Fri, 21 Jan 2022 12:37:41 -0800 (PST) Received: from localhost ([::1]:60134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0fE-0001eT-KS for importer@patchew.org; Fri, 21 Jan 2022 15:37:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Ze-0005sl-Ig for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:31:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zc-0003er-Tt for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:31:54 -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-660-77-PdLpNMp2fDOmOxU4nvQ-1; Fri, 21 Jan 2022 15:31:51 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 749FC814243; Fri, 21 Jan 2022 20:31:49 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89607E2CB; Fri, 21 Jan 2022 20:30:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797112; 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=XQR7/zXXZ1qr/kaP+WOypxUDZe+kG+bCuBCwWqVNujo=; b=OikDs3dRQ4sm9MdfLfXK79bQaaa3gG4v0JSeoEfy3qn4ptQ8EzEy4UQSuDsADSUqJ+Sh96 XtPOzEZIY4ouIQFykYUMaP1iEbb1gwRyikp36yn1Vuo9okUJllzChxboiOuzVNj/plfZkx PYR283B0y8kAS57ece3DnY+CPbewVbA= X-MC-Unique: 77-PdLpNMp2fDOmOxU4nvQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 03/31] vdpa: Add vhost_svq_get_dev_kick_notifier Date: Fri, 21 Jan 2022 21:27:05 +0100 Message-Id: <20220121202733.404989-4-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797463051100001 Is needed so vhost-vdpa knows the device's kick event fd. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 4 ++++ hw/virtio/vhost-shadow-virtqueue.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 61ea112002..400effd9f2 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -11,9 +11,13 @@ #define VHOST_SHADOW_VIRTQUEUE_H =20 #include "hw/virtio/vhost.h" +#include "qemu/event_notifier.h" =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 +const EventNotifier *vhost_svq_get_dev_kick_notifier( + const VhostShadowVirtqueue *= svq); + VhostShadowVirtqueue *vhost_svq_new(void); =20 void vhost_svq_free(VhostShadowVirtqueue *vq); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 5ee7b401cb..bd87110073 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -11,7 +11,6 @@ #include "hw/virtio/vhost-shadow-virtqueue.h" =20 #include "qemu/error-report.h" -#include "qemu/event_notifier.h" =20 /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { @@ -21,6 +20,15 @@ typedef struct VhostShadowVirtqueue { EventNotifier hdev_call; } VhostShadowVirtqueue; =20 +/** + * The notifier that SVQ will use to notify the device. + */ +const EventNotifier *vhost_svq_get_dev_kick_notifier( + const VhostShadowVirtqueue = *svq) +{ + return &svq->hdev_kick; +} + /** * Creates vhost shadow virtqueue, and instruct vhost device to use the sh= adow * methods and file descriptors. --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798106187956.8629890745112; Fri, 21 Jan 2022 12:48:26 -0800 (PST) Received: from localhost ([::1]:54292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0pd-0000MB-8q for importer@patchew.org; Fri, 21 Jan 2022 15:48:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zk-00064S-1Q for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zi-0003fG-16 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:31:59 -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-556-wQrbwDZDMhysgNMaWnkXvw-1; Fri, 21 Jan 2022 15:31:56 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB80394EE0; Fri, 21 Jan 2022 20:31:54 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id C046416A31; Fri, 21 Jan 2022 20:31:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797117; 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=4uUEthkLuffyBdIe45nACcX3HfetQ/LiHwxlBekizvI=; b=WY3Z51qsiRoobCOhlZdUu/5LpR1VaeeE8xqsA4M2XXFkujt5x16QvK5xfk95rm8b7PJ6Rt jnr0iBT8cB9J5dB1z1HTZQwvDhxneXnZQ8df+XwGUlwe14dOmsyKaTo9DfQS+R49ia85X2 pVvHsKk0+mmmQBsmwoqZL3O7zdpW+Kc= X-MC-Unique: wQrbwDZDMhysgNMaWnkXvw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 04/31] vdpa: Add vhost_svq_set_svq_kick_fd Date: Fri, 21 Jan 2022 21:27:06 +0100 Message-Id: <20220121202733.404989-5-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798139234100003 This function allows the vhost-vdpa backend to override kick_fd. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 45 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 400effd9f2..a56ecfc09d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,6 +15,7 @@ =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 +void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); const EventNotifier *vhost_svq_get_dev_kick_notifier( const VhostShadowVirtqueue *= svq); =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index bd87110073..21534bc94d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -11,6 +11,7 @@ #include "hw/virtio/vhost-shadow-virtqueue.h" =20 #include "qemu/error-report.h" +#include "qemu/main-loop.h" =20 /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { @@ -18,8 +19,20 @@ typedef struct VhostShadowVirtqueue { EventNotifier hdev_kick; /* Shadow call notifier, sent to vhost */ EventNotifier hdev_call; + + /* + * Borrowed virtqueue's guest to host notifier. + * To borrow it in this event notifier allows to register on the event + * loop and access the associated shadow virtqueue easily. If we use t= he + * VirtQueue, we don't have an easy way to retrieve it. + * + * So shadow virtqueue must not clean it, or we would lose VirtQueue o= ne. + */ + EventNotifier svq_kick; } VhostShadowVirtqueue; =20 +#define INVALID_SVQ_KICK_FD -1 + /** * The notifier that SVQ will use to notify the device. */ @@ -29,6 +42,35 @@ const EventNotifier *vhost_svq_get_dev_kick_notifier( return &svq->hdev_kick; } =20 +/** + * Set a new file descriptor for the guest to kick SVQ and notify for avail + * + * @svq The svq + * @svq_kick_fd The new svq kick fd + */ +void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd) +{ + EventNotifier tmp; + bool check_old =3D INVALID_SVQ_KICK_FD !=3D + event_notifier_get_fd(&svq->svq_kick); + + if (check_old) { + event_notifier_set_handler(&svq->svq_kick, NULL); + event_notifier_init_fd(&tmp, event_notifier_get_fd(&svq->svq_kick)= ); + } + + /* + * event_notifier_set_handler already checks for guest's notifications= if + * they arrive to the new file descriptor in the switch, so there is no + * need to explicitely check for them. + */ + event_notifier_init_fd(&svq->svq_kick, svq_kick_fd); + + if (!check_old || event_notifier_test_and_clear(&tmp)) { + event_notifier_set(&svq->hdev_kick); + } +} + /** * Creates vhost shadow virtqueue, and instruct vhost device to use the sh= adow * methods and file descriptors. @@ -52,6 +94,9 @@ VhostShadowVirtqueue *vhost_svq_new(void) goto err_init_hdev_call; } =20 + /* Placeholder descriptor, it should be deleted at set_kick_fd */ + event_notifier_init_fd(&svq->svq_kick, INVALID_SVQ_KICK_FD); + return g_steal_pointer(&svq); =20 err_init_hdev_call: --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642797409708818.2508454099412; Fri, 21 Jan 2022 12:36:49 -0800 (PST) Received: from localhost ([::1]:58934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0eO-0000nN-FI for importer@patchew.org; Fri, 21 Jan 2022 15:36:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zp-0006Ha-Hl for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24001) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zn-0003h0-Tk for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:05 -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-553-cSZAHH5sPs6otnF2LTqdmQ-1; Fri, 21 Jan 2022 15:32:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F5401091DAE; Fri, 21 Jan 2022 20:32:00 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CD17E2C3; Fri, 21 Jan 2022 20:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797123; 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=I7KVGVGYv6aHUnZa3/8oLvOmMKqz05J91diJpMm+2xY=; b=bb9eVgTiExIB5eIzYDbrYWhnTla7wsf9uuYPZwB077Qnfpn69VU1Q+uh8WEQdTaJ5Yn7QQ vTQwCd7s69Oba91INHjaj0ggLnuIR+eW7pPGNweX4VDr7GCSOi6nxeDgiNlyJv0WpaSkuM qLX37iudJfnZhVIT08MBezGe4gqIs8Q= X-MC-Unique: cSZAHH5sPs6otnF2LTqdmQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 05/31] vhost: Add Shadow VirtQueue kick forwarding capabilities Date: Fri, 21 Jan 2022 21:27:07 +0100 Message-Id: <20220121202733.404989-6-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797410832100001 At this mode no buffer forwarding will be performed in SVQ mode: Qemu will just forward the guest's kicks to the device. Also, host notifiers must be disabled at SVQ start, and they will not start if SVQ has been enabled when the device is stopped. This will be addressed in next patches. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index a56ecfc09d..4c583a9171 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -19,6 +19,8 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq,= int svq_kick_fd); const EventNotifier *vhost_svq_get_dev_kick_notifier( const VhostShadowVirtqueue *= svq); =20 +void vhost_svq_stop(VhostShadowVirtqueue *svq); + VhostShadowVirtqueue *vhost_svq_new(void); =20 void vhost_svq_free(VhostShadowVirtqueue *vq); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 21534bc94d..8991f0b3c3 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -42,11 +42,26 @@ const EventNotifier *vhost_svq_get_dev_kick_notifier( return &svq->hdev_kick; } =20 +/* Forward guest notifications */ +static void vhost_handle_guest_kick(EventNotifier *n) +{ + VhostShadowVirtqueue *svq =3D container_of(n, VhostShadowVirtqueue, + svq_kick); + + if (unlikely(!event_notifier_test_and_clear(n))) { + return; + } + + event_notifier_set(&svq->hdev_kick); +} + /** * Set a new file descriptor for the guest to kick SVQ and notify for avail * * @svq The svq - * @svq_kick_fd The new svq kick fd + * @svq_kick_fd The svq kick fd + * + * Note that SVQ will never close the old file descriptor. */ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd) { @@ -65,12 +80,22 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *sv= q, int svq_kick_fd) * need to explicitely check for them. */ event_notifier_init_fd(&svq->svq_kick, svq_kick_fd); + event_notifier_set_handler(&svq->svq_kick, vhost_handle_guest_kick); =20 if (!check_old || event_notifier_test_and_clear(&tmp)) { event_notifier_set(&svq->hdev_kick); } } =20 +/** + * Stop shadow virtqueue operation. + * @svq Shadow Virtqueue + */ +void vhost_svq_stop(VhostShadowVirtqueue *svq) +{ + event_notifier_set_handler(&svq->svq_kick, NULL); +} + /** * Creates vhost shadow virtqueue, and instruct vhost device to use the sh= adow * methods and file descriptors. --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798398310546.6737474381607; Fri, 21 Jan 2022 12:53:18 -0800 (PST) Received: from localhost ([::1]:34620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0uK-0006K0-Ux for importer@patchew.org; Fri, 21 Jan 2022 15:53:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zv-0006Ze-L4 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23437) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zt-0003hI-Gi for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32: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-445-Cg96zclgNViCv_TfrMrgPA-1; Fri, 21 Jan 2022 15:32:07 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E6FD1091DA1; Fri, 21 Jan 2022 20:32:05 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CDAD16A31; Fri, 21 Jan 2022 20:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797129; 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=idsA5O6IQeCAKLfC1zd6O9SVzjV/Vf6dX/YAqdkQnVg=; b=O1OgnSAYjBkCxWPor0sFhVoDw85yLe8h5jYnoB3rH4tMRZ/L+h8y4vPDfRozJnvetWDGHb HsIMN+FOjoFE7LO2MbG4BJZYpiPvMbCWDGYBxd33pMPoy3nPUuMlK7jtruYT1/g6vJ+/6h BIMcOCu6ElxmxYkCYSrlyj6WIZLYDgI= X-MC-Unique: Cg96zclgNViCv_TfrMrgPA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 06/31] vhost: Route guest->host notification through shadow virtqueue Date: Fri, 21 Jan 2022 21:27:08 +0100 Message-Id: <20220121202733.404989-7-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798400073100001 At this moment no buffer forwarding will be performed in SVQ mode: Qemu just forward the guest's kicks to the device. This commit also set up SVQs in the vhost device. Host memory notifiers regions are left out for simplicity, and they will not be addressed in this series. Signed-off-by: Eugenio P=C3=A9rez --- include/hw/virtio/vhost-vdpa.h | 4 ++ hw/virtio/vhost-vdpa.c | 122 ++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 3ce79a646d..009a9f3b6b 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -12,6 +12,8 @@ #ifndef HW_VIRTIO_VHOST_VDPA_H #define HW_VIRTIO_VHOST_VDPA_H =20 +#include + #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" =20 @@ -27,6 +29,8 @@ typedef struct vhost_vdpa { bool iotlb_batch_begin_sent; MemoryListener listener; struct vhost_vdpa_iova_range iova_range; + bool shadow_vqs_enabled; + GPtrArray *shadow_vqs; struct vhost_dev *dev; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 6c10a7f05f..18de14f0fb 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -17,12 +17,14 @@ #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" #include "hw/virtio/virtio-net.h" +#include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/vhost-vdpa.h" #include "exec/address-spaces.h" #include "qemu/main-loop.h" #include "cpu.h" #include "trace.h" #include "qemu-common.h" +#include "qapi/error.h" =20 /* * Return one past the end of the end of section. Be careful with uint64_t @@ -409,8 +411,14 @@ err: =20 static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev) { + struct vhost_vdpa *v =3D dev->opaque; int i; =20 + if (v->shadow_vqs_enabled) { + /* SVQ is not compatible with host notifiers mr */ + return; + } + for (i =3D dev->vq_index; i < dev->vq_index + dev->nvqs; i++) { if (vhost_vdpa_host_notifier_init(dev, i)) { goto err; @@ -424,6 +432,17 @@ err: return; } =20 +static void vhost_vdpa_svq_cleanup(struct vhost_dev *dev) +{ + struct vhost_vdpa *v =3D dev->opaque; + size_t idx; + + for (idx =3D 0; idx < v->shadow_vqs->len; ++idx) { + vhost_svq_stop(g_ptr_array_index(v->shadow_vqs, idx)); + } + g_ptr_array_free(v->shadow_vqs, true); +} + static int vhost_vdpa_cleanup(struct vhost_dev *dev) { struct vhost_vdpa *v; @@ -432,6 +451,7 @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev) trace_vhost_vdpa_cleanup(dev, v); vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); memory_listener_unregister(&v->listener); + vhost_vdpa_svq_cleanup(dev); =20 dev->opaque =3D NULL; ram_block_discard_disable(false); @@ -507,9 +527,15 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *= dev, =20 static int vhost_vdpa_reset_device(struct vhost_dev *dev) { + struct vhost_vdpa *v =3D dev->opaque; int ret; uint8_t status =3D 0; =20 + for (unsigned i =3D 0; i < v->shadow_vqs->len; ++i) { + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); + vhost_svq_stop(svq); + } + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status); trace_vhost_vdpa_reset_device(dev, status); return ret; @@ -639,13 +665,28 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev= *dev, return ret; } =20 -static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, - struct vhost_vring_file *file) +static int vhost_vdpa_set_vring_dev_kick(struct vhost_dev *dev, + struct vhost_vring_file *file) { trace_vhost_vdpa_set_vring_kick(dev, file->index, file->fd); return vhost_vdpa_call(dev, VHOST_SET_VRING_KICK, file); } =20 +static int vhost_vdpa_set_vring_kick(struct vhost_dev *dev, + struct vhost_vring_file *file) +{ + struct vhost_vdpa *v =3D dev->opaque; + int vdpa_idx =3D vhost_vdpa_get_vq_index(dev, file->index); + + if (v->shadow_vqs_enabled) { + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, vdp= a_idx); + vhost_svq_set_svq_kick_fd(svq, file->fd); + return 0; + } else { + return vhost_vdpa_set_vring_dev_kick(dev, file); + } +} + static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, struct vhost_vring_file *file) { @@ -653,6 +694,33 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev = *dev, return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); } =20 +/** + * Set shadow virtqueue descriptors to the device + * + * @dev The vhost device model + * @svq The shadow virtqueue + * @idx The index of the virtqueue in the vhost device + */ +static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, + VhostShadowVirtqueue *svq, + unsigned idx) +{ + struct vhost_vring_file file =3D { + .index =3D dev->vq_index + idx, + }; + const EventNotifier *event_notifier; + int r; + + event_notifier =3D vhost_svq_get_dev_kick_notifier(svq); + file.fd =3D event_notifier_get_fd(event_notifier); + r =3D vhost_vdpa_set_vring_dev_kick(dev, &file); + if (unlikely(r !=3D 0)) { + error_report("Can't set device kick fd (%d)", -r); + } + + return r =3D=3D 0; +} + static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started) { struct vhost_vdpa *v =3D dev->opaque; @@ -660,6 +728,13 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev,= bool started) =20 if (started) { vhost_vdpa_host_notifiers_init(dev); + for (unsigned i =3D 0; i < v->shadow_vqs->len; ++i) { + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs,= i); + bool ok =3D vhost_vdpa_svq_setup(dev, svq, i); + if (unlikely(!ok)) { + return -1; + } + } vhost_vdpa_set_vring_ready(dev); } else { vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); @@ -737,6 +812,41 @@ static bool vhost_vdpa_force_iommu(struct vhost_dev *= dev) return true; } =20 +/** + * Adaptor function to free shadow virtqueue through gpointer + * + * @svq The Shadow Virtqueue + */ +static void vhost_psvq_free(gpointer svq) +{ + vhost_svq_free(svq); +} + +static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *= v, + Error **errp) +{ + size_t n_svqs =3D v->shadow_vqs_enabled ? hdev->nvqs : 0; + g_autoptr(GPtrArray) shadow_vqs =3D g_ptr_array_new_full(n_svqs, + vhost_psvq_free= ); + if (!v->shadow_vqs_enabled) { + goto out; + } + + for (unsigned n =3D 0; n < hdev->nvqs; ++n) { + VhostShadowVirtqueue *svq =3D vhost_svq_new(); + + if (unlikely(!svq)) { + error_setg(errp, "Cannot create svq %u", n); + return -1; + } + g_ptr_array_add(v->shadow_vqs, svq); + } + +out: + v->shadow_vqs =3D g_steal_pointer(&shadow_vqs); + return 0; +} + static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) { struct vhost_vdpa *v; @@ -759,6 +869,10 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void= *opaque, Error **errp) dev->opaque =3D opaque ; v->listener =3D vhost_vdpa_memory_listener; v->msg_type =3D VHOST_IOTLB_MSG_V2; + ret =3D vhost_vdpa_init_svq(dev, v, errp); + if (ret) { + goto err; + } =20 vhost_vdpa_get_iova_range(v); =20 @@ -770,6 +884,10 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void= *opaque, Error **errp) VIRTIO_CONFIG_S_DRIVER); =20 return 0; + +err: + ram_block_discard_disable(false); + return ret; } =20 const VhostOps vdpa_ops =3D { --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798104407975.1824873603067; Fri, 21 Jan 2022 12:48:24 -0800 (PST) Received: from localhost ([::1]:54194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0pb-0000IP-1M for importer@patchew.org; Fri, 21 Jan 2022 15:48:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0a0-0006mv-8c for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48972) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0Zy-0003ht-Kg for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:15 -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-55-C2PuAsGCOVGbOqC5_-G7wQ-1; Fri, 21 Jan 2022 15:32:12 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEAD8193F560; Fri, 21 Jan 2022 20:32:10 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id E93BF16A31; Fri, 21 Jan 2022 20:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797134; 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=cRO/yZlUTUJlZKLMfu917BtbGKxWjzgaiwVMEYQxFp4=; b=CpkcS03YaIGbWe+34X1B4p+vYzNsQs9LnUnLGuneYXUVF07kbdgUOO5M9oXm7P4HOINxk4 ssvTRAq8/r6GamLeySIEFqMU7Tj7dvrZN1wJDt+d6aA8ITupovhg5PeTSbU3q92FYnHzoa GUKwJ3tcLCBA0ZqprWT+IT9mV6IneBQ= X-MC-Unique: C2PuAsGCOVGbOqC5_-G7wQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 07/31] vhost: dd vhost_svq_get_svq_call_notifier Date: Fri, 21 Jan 2022 21:27:09 +0100 Message-Id: <20220121202733.404989-8-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798139057100001 This allows vhost-vdpa device to retrieve device -> svq call eventfd. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 4c583a9171..a78234b52b 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -18,6 +18,8 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); const EventNotifier *vhost_svq_get_dev_kick_notifier( const VhostShadowVirtqueue *= svq); +const EventNotifier *vhost_svq_get_svq_call_notifier( + const VhostShadowVirtqueue *= svq); =20 void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 8991f0b3c3..25fcdf16ec 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -55,6 +55,18 @@ static void vhost_handle_guest_kick(EventNotifier *n) event_notifier_set(&svq->hdev_kick); } =20 +/** + * Obtain the SVQ call notifier, where vhost device notifies SVQ that there + * exists pending used buffers. + * + * @svq Shadow Virtqueue + */ +const EventNotifier *vhost_svq_get_svq_call_notifier( + const VhostShadowVirtqueue = *svq) +{ + return &svq->hdev_call; +} + /** * Set a new file descriptor for the guest to kick SVQ and notify for avail * --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 164279892055994.96453991614305; Fri, 21 Jan 2022 13:02:00 -0800 (PST) Received: from localhost ([::1]:43376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB12j-0003tN-L0 for importer@patchew.org; Fri, 21 Jan 2022 16:01:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0a7-0006th-Rf for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20164) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0a6-0003i9-6x for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:23 -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-39-WChwr_pjM9y56f_FyS4rRw-1; Fri, 21 Jan 2022 15:32:18 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A70542E72; Fri, 21 Jan 2022 20:32:16 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 471F988FE; Fri, 21 Jan 2022 20:32:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797141; 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=Ur4verNEZt35RQtM+FGC6dcyR0ZxFLYgYs4OfS5jfrw=; b=LKBq0Jk3c1SoW5KptSqgjUJRXcdGFGeb0ddAWDXJyI8qokAqn0Trr+LDLhOtVttLEyN2Dk rn3ob/DL1dzfRhYAtcZ8frVdjaqcf7ecDIyHzgKGfYLIQ8x4EHqeZy7wW7U2Tsbfk8Bioq bNhZGuv++XL7hSYOws+LSId6Naywg44= X-MC-Unique: WChwr_pjM9y56f_FyS4rRw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 08/31] vhost: Add vhost_svq_set_guest_call_notifier Date: Fri, 21 Jan 2022 21:27:10 +0100 Message-Id: <20220121202733.404989-9-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798922232100001 This allows the vhost-vdpa device to set SVQ -> guest notifier to SVQ. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index a78234b52b..c9ffa11fce 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -16,6 +16,7 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); +void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call= _fd); const EventNotifier *vhost_svq_get_dev_kick_notifier( const VhostShadowVirtqueue *= svq); const EventNotifier *vhost_svq_get_svq_call_notifier( diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 25fcdf16ec..9c2cf07fd9 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -29,6 +29,9 @@ typedef struct VhostShadowVirtqueue { * So shadow virtqueue must not clean it, or we would lose VirtQueue o= ne. */ EventNotifier svq_kick; + + /* Guest's call notifier, where SVQ calls guest. */ + EventNotifier svq_call; } VhostShadowVirtqueue; =20 #define INVALID_SVQ_KICK_FD -1 @@ -67,6 +70,19 @@ const EventNotifier *vhost_svq_get_svq_call_notifier( return &svq->hdev_call; } =20 +/** + * Set the call notifier for the SVQ to call the guest + * + * @svq Shadow virtqueue + * @call_fd call notifier + * + * Called on BQL context. + */ +void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call= _fd) +{ + event_notifier_init_fd(&svq->svq_call, call_fd); +} + /** * Set a new file descriptor for the guest to kick SVQ and notify for avail * --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642797677605129.9832646276068; Fri, 21 Jan 2022 12:41:17 -0800 (PST) Received: from localhost ([::1]:40268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0ii-0007NI-6k for importer@patchew.org; Fri, 21 Jan 2022 15:41:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aD-0006yQ-KH for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aB-0003j6-Km for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:28 -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-160-693d6SPaP9iJz2Vq-nDoRQ-1; Fri, 21 Jan 2022 15:32:23 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 465B01091DA0; Fri, 21 Jan 2022 20:32:22 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06695E2C8; Fri, 21 Jan 2022 20:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797147; 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=AliRB8dgnfCrf3c4W5t5STsB29NMG5OaO0aMVMH+PP0=; b=LrxtivqbsSki1C2UflR9Q+XTxRWrJw8Mykt66Vcc6MzzdaGYfcOjpo9Zy+4xFJTwlaCIYm 1EvO1DM3Jbe9C/67K2ML/Lvw6uCM/12C99fsGpHIUngjyqpEA4FKE8rZrkMoZv3NTeUGep umkNaQWcYC3WY0wM8DjJTkKHHsjcuOk= X-MC-Unique: 693d6SPaP9iJz2Vq-nDoRQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 09/31] vhost-vdpa: Take into account SVQ in vhost_vdpa_set_vring_call Date: Fri, 21 Jan 2022 21:27:11 +0100 Message-Id: <20220121202733.404989-10-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797679067100001 Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 18de14f0fb..029f98feee 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -687,13 +687,29 @@ static int vhost_vdpa_set_vring_kick(struct vhost_dev= *dev, } } =20 -static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, - struct vhost_vring_file *file) +static int vhost_vdpa_set_vring_dev_call(struct vhost_dev *dev, + struct vhost_vring_file *file) { trace_vhost_vdpa_set_vring_call(dev, file->index, file->fd); return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file); } =20 +static int vhost_vdpa_set_vring_call(struct vhost_dev *dev, + struct vhost_vring_file *file) +{ + struct vhost_vdpa *v =3D dev->opaque; + + if (v->shadow_vqs_enabled) { + int vdpa_idx =3D vhost_vdpa_get_vq_index(dev, file->index); + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, vdp= a_idx); + + vhost_svq_set_guest_call_notifier(svq, file->fd); + return 0; + } else { + return vhost_vdpa_set_vring_dev_call(dev, file); + } +} + /** * Set shadow virtqueue descriptors to the device * --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642797844322556.5141170961103; Fri, 21 Jan 2022 12:44:04 -0800 (PST) Received: from localhost ([::1]:48550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0lP-0004gg-4f for importer@patchew.org; Fri, 21 Jan 2022 15:44:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aK-0007Ck-IN for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:33899) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aH-0003jO-LF for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:35 -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-157-L-kd-eGqP9-33at7sgsmeQ-1; Fri, 21 Jan 2022 15:32:30 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A04C1018723; Fri, 21 Jan 2022 20:32:28 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0ADF194B9; Fri, 21 Jan 2022 20:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797153; 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=DSkdVsUBNlwf/1JjDqgiQAAL49ruuo1SfvHtdJq/Nn0=; b=XSHnh4iJ9ED2TiEsZHEztGiI5y47GM5yklQ8Ic4MuqneU5h7uUo70ZP92dkta2eRsHmpGo m6kSCwln+3uuU+mWd2H/T7t+bSOp5LZPV02xGUeJRCW3HiEgkPqxzNzaulf/Nyd8GUP9PZ cF2/G94GDbKr8jKljnr3dqQyGJjI9Pg= X-MC-Unique: L-kd-eGqP9-33at7sgsmeQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 10/31] vhost: Route host->guest notification through shadow virtqueue Date: Fri, 21 Jan 2022 21:27:12 +0100 Message-Id: <20220121202733.404989-11-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797846629100001 This will make qemu aware of the device used buffers, allowing it to write the guest memory with its contents if needed. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 15 +++++++++++++++ hw/virtio/vhost-vdpa.c | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 9c2cf07fd9..9619c8082c 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -58,6 +58,19 @@ static void vhost_handle_guest_kick(EventNotifier *n) event_notifier_set(&svq->hdev_kick); } =20 +/* Forward vhost notifications */ +static void vhost_svq_handle_call(EventNotifier *n) +{ + VhostShadowVirtqueue *svq =3D container_of(n, VhostShadowVirtqueue, + hdev_call); + + if (unlikely(!event_notifier_test_and_clear(n))) { + return; + } + + event_notifier_set(&svq->svq_call); +} + /** * Obtain the SVQ call notifier, where vhost device notifies SVQ that there * exists pending used buffers. @@ -150,6 +163,7 @@ VhostShadowVirtqueue *vhost_svq_new(void) /* Placeholder descriptor, it should be deleted at set_kick_fd */ event_notifier_init_fd(&svq->svq_kick, INVALID_SVQ_KICK_FD); =20 + event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); return g_steal_pointer(&svq); =20 err_init_hdev_call: @@ -165,6 +179,7 @@ err_init_hdev_kick: void vhost_svq_free(VhostShadowVirtqueue *vq) { event_notifier_cleanup(&vq->hdev_kick); + event_notifier_set_handler(&vq->hdev_call, NULL); event_notifier_cleanup(&vq->hdev_call); g_free(vq); } diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 029f98feee..bdb45c8808 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -716,6 +716,9 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *= dev, * @dev The vhost device model * @svq The shadow virtqueue * @idx The index of the virtqueue in the vhost device + * + * Note that this function does not rewind kick file descriptor if cannot = set + * call one. */ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, VhostShadowVirtqueue *svq, @@ -732,6 +735,14 @@ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, r =3D vhost_vdpa_set_vring_dev_kick(dev, &file); if (unlikely(r !=3D 0)) { error_report("Can't set device kick fd (%d)", -r); + return false; + } + + event_notifier =3D vhost_svq_get_svq_call_notifier(svq); + file.fd =3D event_notifier_get_fd(event_notifier); + r =3D vhost_vdpa_set_vring_dev_call(dev, &file); + if (unlikely(r !=3D 0)) { + error_report("Can't set device call fd (%d)", -r); } =20 return r =3D=3D 0; --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798306787273.71114763178696; Fri, 21 Jan 2022 12:51:46 -0800 (PST) Received: from localhost ([::1]:56954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0sr-0002DG-Lf for importer@patchew.org; Fri, 21 Jan 2022 15:51:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aW-0007Jv-1R for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aO-0003le-Gm for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:47 -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-655-WMWkOhbYOm6jex1YxIEusg-1; Fri, 21 Jan 2022 15:32:35 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E5A9814243; Fri, 21 Jan 2022 20:32:33 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB1DF167A7; Fri, 21 Jan 2022 20:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797158; 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=5jgARwVIGJsOLSejZ82BTrsFR4MjPE//QjHyrl1Conw=; b=ZjDG9wWdHe/hOQkBEr70YWWFXqsoHmzSecG8fCVRp6TCTe0hVwwmvixn4N5j/d4nFljWVl 2JoQ1kw+7ZdDhcqifQYOqmoNKD1zw6RtQxRqe0iKXvkR+4YcgYbxaZRLMJ2RQp53kE9MS9 Beg4H1uNDc/Kx0iteURjGkCCgIjnVqY= X-MC-Unique: WMWkOhbYOm6jex1YxIEusg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 11/31] vhost: Add vhost_svq_valid_device_features to shadow vq Date: Fri, 21 Jan 2022 21:27:13 +0100 Message-Id: <20220121202733.404989-12-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798309095100001 This allows SVQ to negotiate features with the device. For the device, SVQ is a driver. While this function needs to bypass all non-transport features, it needs to disable the features that SVQ does not support when forwarding buffers. This includes packed vq layout, indirect descriptors or event idx. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 ++ hw/virtio/vhost-shadow-virtqueue.c | 44 ++++++++++++++++++++++++++++++ hw/virtio/vhost-vdpa.c | 21 ++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index c9ffa11fce..d963867a04 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -15,6 +15,8 @@ =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 +bool vhost_svq_valid_device_features(uint64_t *features); + void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call= _fd); const EventNotifier *vhost_svq_get_dev_kick_notifier( diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 9619c8082c..51442b3dbf 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -45,6 +45,50 @@ const EventNotifier *vhost_svq_get_dev_kick_notifier( return &svq->hdev_kick; } =20 +/** + * Validate the transport device features that SVQ can use with the device + * + * @dev_features The device features. If success, the acknowledged featur= es. + * + * Returns true if SVQ can go with a subset of these, false otherwise. + */ +bool vhost_svq_valid_device_features(uint64_t *dev_features) +{ + bool r =3D true; + + for (uint64_t b =3D VIRTIO_TRANSPORT_F_START; b <=3D VIRTIO_TRANSPORT_= F_END; + ++b) { + switch (b) { + case VIRTIO_F_NOTIFY_ON_EMPTY: + case VIRTIO_F_ANY_LAYOUT: + continue; + + case VIRTIO_F_ACCESS_PLATFORM: + /* SVQ does not know how to translate addresses */ + if (*dev_features & BIT_ULL(b)) { + clear_bit(b, dev_features); + r =3D false; + } + break; + + case VIRTIO_F_VERSION_1: + /* SVQ trust that guest vring is little endian */ + if (!(*dev_features & BIT_ULL(b))) { + set_bit(b, dev_features); + r =3D false; + } + continue; + + default: + if (*dev_features & BIT_ULL(b)) { + clear_bit(b, dev_features); + } + } + } + + return r; +} + /* Forward guest notifications */ static void vhost_handle_guest_kick(EventNotifier *n) { diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index bdb45c8808..9d801cf907 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -855,10 +855,31 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev= , struct vhost_vdpa *v, size_t n_svqs =3D v->shadow_vqs_enabled ? hdev->nvqs : 0; g_autoptr(GPtrArray) shadow_vqs =3D g_ptr_array_new_full(n_svqs, vhost_psvq_free= ); + uint64_t dev_features; + uint64_t svq_features; + int r; + bool ok; + if (!v->shadow_vqs_enabled) { goto out; } =20 + r =3D vhost_vdpa_get_features(hdev, &dev_features); + if (r !=3D 0) { + error_setg(errp, "Can't get vdpa device features, got (%d)", r); + return r; + } + + svq_features =3D dev_features; + ok =3D vhost_svq_valid_device_features(&svq_features); + if (unlikely(!ok)) { + error_setg(errp, + "SVQ Invalid device feature flags, offer: 0x%"PRIx64", ok: 0x%= "PRIx64, + hdev->features, svq_features); + return -1; + } + + shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_psvq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { VhostShadowVirtqueue *svq =3D vhost_svq_new(); =20 --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799090209587.4106998329112; Fri, 21 Jan 2022 13:04:50 -0800 (PST) Received: from localhost ([::1]:52046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB15V-0001RT-3p for importer@patchew.org; Fri, 21 Jan 2022 16:04:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aX-0007LV-TC for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aT-0003rQ-Rs for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:48 -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-156-Q9pCp2_VP6qSBKq2CI6ocg-1; Fri, 21 Jan 2022 15:32:40 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2FD1B814249; Fri, 21 Jan 2022 20:32:39 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6F3EE2C8; Fri, 21 Jan 2022 20:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797164; 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=VT1x29yAk/vSXBIlwiZrSP2wvJcODXkHOut70Uo/oQA=; b=ViMDwMi97t6Z9bwQyFpWMfy484Udgx6VeiGYT0MZYhN4GREAC74WLIy9zhN3/kekbDRBaV ObPNPcQ/W175GeEnN6ZnwuVqXheiaVwLI9kzvzObWKfxloRH/7UyyfUXns89kfC7g2f437 M9dD4kOKtUEGEFp99n1/wrHaP0GEcdg= X-MC-Unique: Q9pCp2_VP6qSBKq2CI6ocg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 12/31] vhost: Add vhost_svq_valid_guest_features to shadow vq Date: Fri, 21 Jan 2022 21:27:14 +0100 Message-Id: <20220121202733.404989-13-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799092106100005 This allows it to test if the guest has acknowledged an invalid transport feature for SVQ. This will include packed vq layout or event_idx, where the VirtIO device needs help from SVQ. It is not needed at this moment, but since SVQ will not re-negotiate features again with the guest, a failure to acknowledge them is fatal for SVQ. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index d963867a04..1aae6a2297 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -16,6 +16,7 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 bool vhost_svq_valid_device_features(uint64_t *features); +bool vhost_svq_valid_guest_features(uint64_t *features); =20 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call= _fd); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 51442b3dbf..f70160d7ca 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -89,6 +89,30 @@ bool vhost_svq_valid_device_features(uint64_t *dev_featu= res) return r; } =20 +/** + * Offers SVQ valid transport features to the guest. + * + * @guest_features The device's supported features. Return SVQ's if succe= ss. + * + * Returns true if SVQ can handle them, false otherwise. + */ +bool vhost_svq_valid_guest_features(uint64_t *guest_features) +{ + static const uint64_t transport =3D MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F= _START, + VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_ST= ART); + + /* These transport features are handled by VirtQueue */ + static const uint64_t valid =3D BIT_ULL(VIRTIO_RING_F_INDIRECT_DESC) | + BIT_ULL(VIRTIO_F_VERSION_1) | + BIT_ULL(VIRTIO_F_IOMMU_PLATFORM); + + /* We are only interested in transport-related feature bits */ + uint64_t guest_transport_features =3D (*guest_features) & transport; + + *guest_features &=3D (valid | ~transport); + return !(guest_transport_features & (transport ^ valid)); +} + /* Forward guest notifications */ static void vhost_handle_guest_kick(EventNotifier *n) { --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799320477937.252348959086; Fri, 21 Jan 2022 13:08:40 -0800 (PST) Received: from localhost ([::1]:60734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB19D-0007L1-Cm for importer@patchew.org; Fri, 21 Jan 2022 16:08:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0ab-0007N9-NS for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:31315) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aY-00044k-Kw for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:52 -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-323-tmR_tWvQOvOZKJ0gjpW7jA-1; Fri, 21 Jan 2022 15:32:46 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B12E193F561; Fri, 21 Jan 2022 20:32:44 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87A1716A31; Fri, 21 Jan 2022 20:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797170; 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=8brTVOPh41D9JIYPtyJmyj23Qq54zpyRadZPX14hoHI=; b=MotHynt6UO92/DHWNGfh3bmviMJ84sljvJ5sZ3ZFoK+Yy4NHRQ0H/1q3Dq34ocTJGKJZyJ C+9Mf8aRRsoqd/GNJoterJJbrPBTZvs7Op19sxSO2PJ9efgDqdVIqxxz32P2slWBaUQpFv AQqku4Ut/m8rNscTgOpfDVpzMByQEvk= X-MC-Unique: tmR_tWvQOvOZKJ0gjpW7jA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 13/31] vhost: Add vhost_svq_ack_guest_features to shadow vq Date: Fri, 21 Jan 2022 21:27:15 +0100 Message-Id: <20220121202733.404989-14-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799322057100001 This combines the previous two feature functions, forwarding the guest ones to the device and setting the transport ones that the SVQ supports with the device. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 3 +++ hw/virtio/vhost-shadow-virtqueue.c | 31 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 1aae6a2297..af8f8264c0 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -17,6 +17,9 @@ typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 bool vhost_svq_valid_device_features(uint64_t *features); bool vhost_svq_valid_guest_features(uint64_t *features); +bool vhost_svq_ack_guest_features(uint64_t dev_features, + uint64_t guest_features, + uint64_t *acked_features); =20 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call= _fd); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index f70160d7ca..a6fb7e3c8f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -113,6 +113,37 @@ bool vhost_svq_valid_guest_features(uint64_t *guest_fe= atures) return !(guest_transport_features & (transport ^ valid)); } =20 +/** + * VirtIO features that SVQ must acknowledge to device. + * + * It combines the SVQ transport compatible features with the guest's devi= ce + * features. + * + * @dev_features The device offered features + * @guest_features The guest acknowledge features + * @acked_features The guest acknowledge features in the device side plus= SVQ + * transport ones. + * + * Returns true if SVQ can work with this features, false otherwise + */ +bool vhost_svq_ack_guest_features(uint64_t dev_features, + uint64_t guest_features, + uint64_t *acked_features) +{ + static const uint64_t transport =3D MAKE_64BIT_MASK(VIRTIO_TRANSPORT_F= _START, + VIRTIO_TRANSPORT_F_END - VIRTIO_TRANSPORT_F_ST= ART); + + bool ok =3D vhost_svq_valid_device_features(&dev_features) && + vhost_svq_valid_guest_features(&guest_features); + if (unlikely(!ok)) { + return false; + } + + *acked_features =3D (dev_features & transport) | + (guest_features & ~transport); + return true; +} + /* Forward guest notifications */ static void vhost_handle_guest_kick(EventNotifier *n) { --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798496922583.0246993586718; Fri, 21 Jan 2022 12:54:56 -0800 (PST) Received: from localhost ([::1]:37266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0vv-00087r-M6 for importer@patchew.org; Fri, 21 Jan 2022 15:54:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0af-0007RN-1X for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:50135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0ad-0004NQ-DU for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:32:56 -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-563-XXJGAbmmOq-wyRfo77ZfEA-1; Fri, 21 Jan 2022 15:32:51 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 206A01091DA0; Fri, 21 Jan 2022 20:32:50 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6A0F16A31; Fri, 21 Jan 2022 20:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797175; 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=ktbFpXy5rbogZOmevw7kvsLjO26c5CD3uDtdIHvMfGk=; b=XMWQRVqfQKIsAFRcYDGzqFGQw84WFhdGbqx7jNRiAVXrZZWckFMNfDSuTHeMMD1LArPB4g 76RRcqtWgAvyyzgJSTOY5GN7mzbjwIJxIjFsL5d59dSxQv4zeWHtwCa5XglOENpXaIwaVT rzu4mhJ65HQFsz1VeQyrgaNYVi3Q1HA= X-MC-Unique: XXJGAbmmOq-wyRfo77ZfEA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 14/31] virtio: Add vhost_shadow_vq_get_vring_addr Date: Fri, 21 Jan 2022 21:27:16 +0100 Message-Id: <20220121202733.404989-15-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798497941100001 It reports the shadow virtqueue address from qemu virtual address space. Since this will be different from the guest's vaddr, but the device can access it, SVQ takes special care about its alignment & lack of garbage data. It assumes that IOMMU will work in host_page_size ranges for that. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 4 ++++ hw/virtio/vhost-shadow-virtqueue.c | 33 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index af8f8264c0..3521e8094d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -27,6 +27,10 @@ const EventNotifier *vhost_svq_get_dev_kick_notifier( const VhostShadowVirtqueue *= svq); const EventNotifier *vhost_svq_get_svq_call_notifier( const VhostShadowVirtqueue *= svq); +void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, + struct vhost_vring_addr *addr); +size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq); +size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); =20 void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index a6fb7e3c8f..0f2c2403ff 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -9,12 +9,16 @@ =20 #include "qemu/osdep.h" #include "hw/virtio/vhost-shadow-virtqueue.h" +#include "standard-headers/linux/vhost_types.h" =20 #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 /* Shadow virtqueue to relay notifications */ typedef struct VhostShadowVirtqueue { + /* Shadow vring */ + struct vring vring; + /* Shadow kick notifier, sent to vhost */ EventNotifier hdev_kick; /* Shadow call notifier, sent to vhost */ @@ -195,6 +199,35 @@ void vhost_svq_set_guest_call_notifier(VhostShadowVirt= queue *svq, int call_fd) event_notifier_init_fd(&svq->svq_call, call_fd); } =20 +/* + * Get the shadow vq vring address. + * @svq Shadow virtqueue + * @addr Destination to store address + */ +void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, + struct vhost_vring_addr *addr) +{ + addr->desc_user_addr =3D (uint64_t)svq->vring.desc; + addr->avail_user_addr =3D (uint64_t)svq->vring.avail; + addr->used_user_addr =3D (uint64_t)svq->vring.used; +} + +size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq) +{ + size_t desc_size =3D sizeof(vring_desc_t) * svq->vring.num; + size_t avail_size =3D offsetof(vring_avail_t, ring) + + sizeof(uint16_t) * svq->vring= .num; + + return ROUND_UP(desc_size + avail_size, qemu_real_host_page_size); +} + +size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq) +{ + size_t used_size =3D offsetof(vring_used_t, ring) + + sizeof(vring_used_elem_t) * svq->vring= .num; + return ROUND_UP(used_size, qemu_real_host_page_size); +} + /** * Set a new file descriptor for the guest to kick SVQ and notify for avail * --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799598927393.33898497727773; Fri, 21 Jan 2022 13:13:18 -0800 (PST) Received: from localhost ([::1]:41108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1Dh-0004nR-LY for importer@patchew.org; Fri, 21 Jan 2022 16:13:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0ax-0007hV-5s for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:33:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39284) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0aj-0004Ru-6b for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:33:02 -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-439--6SNr3USMI2VgkbkekxEAQ-1; Fri, 21 Jan 2022 15:32:57 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70C951018721; Fri, 21 Jan 2022 20:32:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EFF916A31; Fri, 21 Jan 2022 20:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797180; 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=mX1u+VRvEu/MKYJ+9U6Q5yB4hfXrY2qAQfHNhif0XMQ=; b=FWhjIyvvNQkvqgV/jKq4IyLiAHE1lS2gTnZTCbQ126tR0iQ9OWXQ45zhAlBitAMvaQYLIa cwVbuGoZoBwhqVChfzV1Iz6q5OJ+bfk+ckN1/5rXZ0oe8I3mJYI0dhod0teLuDn7lDTbLG WJNprdSuUAkfRqfFX22L8Lg3896IOmA= X-MC-Unique: -6SNr3USMI2VgkbkekxEAQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 15/31] vdpa: Add vhost_svq_get_num Date: Fri, 21 Jan 2022 21:27:17 +0100 Message-Id: <20220121202733.404989-16-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799600935100001 This reports the guest's visible SVQ effective length, not the device's one. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 3521e8094d..035207a469 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -29,6 +29,7 @@ const EventNotifier *vhost_svq_get_svq_call_notifier( const VhostShadowVirtqueue *= svq); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, struct vhost_vring_addr *addr); +uint16_t vhost_svq_get_num(const VhostShadowVirtqueue *svq); size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq); size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 0f2c2403ff..f129ec8395 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -212,6 +212,11 @@ void vhost_svq_get_vring_addr(const VhostShadowVirtque= ue *svq, addr->used_user_addr =3D (uint64_t)svq->vring.used; } =20 +uint16_t vhost_svq_get_num(const VhostShadowVirtqueue *svq) +{ + return svq->vring.num; +} + size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq) { size_t desc_size =3D sizeof(vring_desc_t) * svq->vring.num; --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798969109636.3436870619893; Fri, 21 Jan 2022 13:02:49 -0800 (PST) Received: from localhost ([::1]:46106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB13X-0005w4-GQ for importer@patchew.org; Fri, 21 Jan 2022 16:02:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0b2-0007ip-Tx for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:33:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37651) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0b0-0004eJ-Vq for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:33:20 -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-636-AYuvous5O_CxpgDHr9DRww-1; Fri, 21 Jan 2022 15:33:02 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33B308143F3; Fri, 21 Jan 2022 20:33:01 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC40F194B9; Fri, 21 Jan 2022 20:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797187; 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=kpVBSmi8b+5c9eY3V8MzBirBYLy/emMG/e8Cfu5oI5E=; b=A3TDvHC9vYsxyFUBHS0Mc5ok6A14lFa08WXiXYyg5bDc6ygOk6Bkuld8Fsduq5C/JIdBp/ yEJ/EKb32XHNLnAsKh5OZOTcWmywcJexmRmuzSIZK2Xd0fkT1d2WsmXWylT3ppr+ZY4FGR +nh3eWnAmBiUKSBfCP4WxoSw/9py59s= X-MC-Unique: AYuvous5O_CxpgDHr9DRww-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 16/31] vhost: pass queue index to vhost_vq_get_addr Date: Fri, 21 Jan 2022 21:27:18 +0100 Message-Id: <20220121202733.404989-17-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798970405100001 Doing that way allows vhost backend to know what address to return. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 7b03efccec..64b955ba0c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -798,9 +798,10 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *= dev, struct vhost_virtqueue *vq, unsigned idx, bool enable_log) { - struct vhost_vring_addr addr; + struct vhost_vring_addr addr =3D { + .index =3D idx, + }; int r; - memset(&addr, 0, sizeof(struct vhost_vring_addr)); =20 if (dev->vhost_ops->vhost_vq_get_addr) { r =3D dev->vhost_ops->vhost_vq_get_addr(dev, &addr, vq); @@ -813,7 +814,6 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *d= ev, addr.avail_user_addr =3D (uint64_t)(unsigned long)vq->avail; addr.used_user_addr =3D (uint64_t)(unsigned long)vq->used; } - addr.index =3D idx; addr.log_guest_addr =3D vq->used_phys; addr.flags =3D enable_log ? (1 << VHOST_VRING_F_LOG) : 0; r =3D dev->vhost_ops->vhost_set_vring_addr(dev, &addr); --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642797663252283.7872174938326; Fri, 21 Jan 2022 12:41:03 -0800 (PST) Received: from localhost ([::1]:39378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0iU-0006l9-2T for importer@patchew.org; Fri, 21 Jan 2022 15:41:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0c0-0008Ti-D2 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0by-000545-3T for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:19 -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-659-c5uIs9dEO2y-2O3Mk4PZlw-1; Fri, 21 Jan 2022 15:34:14 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D4991363AA; Fri, 21 Jan 2022 20:34:12 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1688E2C9; Fri, 21 Jan 2022 20:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797257; 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=zUCb43WBvNInoSEet9F8geea5XOeRrNSbG6HjazuDeY=; b=aqDuoJePfSPTANJoF1mGMsYMPbOVUv4LgG2lxWL9n/Z2J2Za5KbnB18oCJ2THx1S0joLEN IveoRzE6LEARheufcVPSozJm6tiOo9ZBe5pR5zHwKygTEykRCMxWirlfT4jY9MXKHWMgqP P4nFMz9EnlhihfBLZBinSykiXs1heU0= X-MC-Unique: c5uIs9dEO2y-2O3Mk4PZlw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 17/31] vdpa: adapt vhost_ops callbacks to svq Date: Fri, 21 Jan 2022 21:27:19 +0100 Message-Id: <20220121202733.404989-18-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797665395100001 First half of the buffers forwarding part, preparing vhost-vdpa callbacks to SVQ to offer it. QEMU cannot enable it at this moment, so this is effectively dead code at the moment, but it helps to reduce patch size. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 +- hw/virtio/vhost-shadow-virtqueue.c | 21 ++++- hw/virtio/vhost-vdpa.c | 133 ++++++++++++++++++++++++++--- 3 files changed, 143 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 035207a469..39aef5ffdf 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -35,7 +35,7 @@ size_t vhost_svq_device_area_size(const VhostShadowVirtqu= eue *svq); =20 void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(void); +VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize); =20 void vhost_svq_free(VhostShadowVirtqueue *vq); =20 diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index f129ec8395..7c168075d7 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -277,9 +277,17 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) /** * Creates vhost shadow virtqueue, and instruct vhost device to use the sh= adow * methods and file descriptors. + * + * @qsize Shadow VirtQueue size + * + * Returns the new virtqueue or NULL. + * + * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new(void) +VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize) { + size_t desc_size =3D sizeof(vring_desc_t) * qsize; + size_t device_size, driver_size; g_autofree VhostShadowVirtqueue *svq =3D g_new0(VhostShadowVirtqueue, = 1); int r; =20 @@ -300,6 +308,15 @@ VhostShadowVirtqueue *vhost_svq_new(void) /* Placeholder descriptor, it should be deleted at set_kick_fd */ event_notifier_init_fd(&svq->svq_kick, INVALID_SVQ_KICK_FD); =20 + svq->vring.num =3D qsize; + driver_size =3D vhost_svq_driver_area_size(svq); + device_size =3D vhost_svq_device_area_size(svq); + svq->vring.desc =3D qemu_memalign(qemu_real_host_page_size, driver_siz= e); + svq->vring.avail =3D (void *)((char *)svq->vring.desc + desc_size); + memset(svq->vring.desc, 0, driver_size); + svq->vring.used =3D qemu_memalign(qemu_real_host_page_size, device_siz= e); + memset(svq->vring.used, 0, device_size); + event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); return g_steal_pointer(&svq); =20 @@ -318,5 +335,7 @@ void vhost_svq_free(VhostShadowVirtqueue *vq) event_notifier_cleanup(&vq->hdev_kick); event_notifier_set_handler(&vq->hdev_call, NULL); event_notifier_cleanup(&vq->hdev_call); + qemu_vfree(vq->vring.desc); + qemu_vfree(vq->vring.used); g_free(vq); } diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 9d801cf907..53e14bafa0 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -641,20 +641,52 @@ static int vhost_vdpa_set_vring_addr(struct vhost_dev= *dev, return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); } =20 -static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, - struct vhost_vring_state *ring) +static int vhost_vdpa_set_dev_vring_num(struct vhost_dev *dev, + struct vhost_vring_state *ring) { trace_vhost_vdpa_set_vring_num(dev, ring->index, ring->num); return vhost_vdpa_call(dev, VHOST_SET_VRING_NUM, ring); } =20 -static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, - struct vhost_vring_state *ring) +static int vhost_vdpa_set_vring_num(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + struct vhost_vdpa *v =3D dev->opaque; + + if (v->shadow_vqs_enabled) { + /* + * Vring num was set at device start. SVQ num is handled by VirtQu= eue + * code + */ + return 0; + } + + return vhost_vdpa_set_dev_vring_num(dev, ring); +} + +static int vhost_vdpa_set_dev_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring) { trace_vhost_vdpa_set_vring_base(dev, ring->index, ring->num); return vhost_vdpa_call(dev, VHOST_SET_VRING_BASE, ring); } =20 +static int vhost_vdpa_set_vring_base(struct vhost_dev *dev, + struct vhost_vring_state *ring) +{ + struct vhost_vdpa *v =3D dev->opaque; + + if (v->shadow_vqs_enabled) { + /* + * Vring base was set at device start. SVQ base is handled by Virt= Queue + * code + */ + return 0; + } + + return vhost_vdpa_set_dev_vring_base(dev, ring); +} + static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { @@ -784,8 +816,8 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, = bool started) } } =20 -static int vhost_vdpa_get_features(struct vhost_dev *dev, - uint64_t *features) +static int vhost_vdpa_get_dev_features(struct vhost_dev *dev, + uint64_t *features) { int ret; =20 @@ -794,15 +826,64 @@ static int vhost_vdpa_get_features(struct vhost_dev *= dev, return ret; } =20 +static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *featur= es) +{ + struct vhost_vdpa *v =3D dev->opaque; + int ret =3D vhost_vdpa_get_dev_features(dev, features); + + if (ret =3D=3D 0 && v->shadow_vqs_enabled) { + /* Filter only features that SVQ can offer to guest */ + vhost_svq_valid_guest_features(features); + } + + return ret; +} + static int vhost_vdpa_set_features(struct vhost_dev *dev, uint64_t features) { + struct vhost_vdpa *v =3D dev->opaque; int ret; =20 if (vhost_vdpa_one_time_request(dev)) { return 0; } =20 + if (v->shadow_vqs_enabled) { + uint64_t dev_features, svq_features, acked_features; + bool ok; + + ret =3D vhost_vdpa_get_dev_features(dev, &dev_features); + if (ret !=3D 0) { + error_report("Can't get vdpa device features, got (%d)", ret); + return ret; + } + + svq_features =3D dev_features; + ok =3D vhost_svq_valid_device_features(&svq_features); + if (unlikely(!ok)) { + error_report("SVQ Invalid device feature flags, offer: 0x%" + PRIx64", ok: 0x%"PRIx64, dev->features, svq_featu= res); + return -1; + } + + ok =3D vhost_svq_valid_guest_features(&features); + if (unlikely(!ok)) { + error_report( + "Invalid guest acked feature flag, acked: 0x%" + PRIx64", ok: 0x%"PRIx64, dev->acked_features, features); + return -1; + } + + ok =3D vhost_svq_ack_guest_features(svq_features, features, + &acked_features); + if (unlikely(!ok)) { + return -1; + } + + features =3D acked_features; + } + trace_vhost_vdpa_set_features(dev, features); ret =3D vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features); if (ret) { @@ -822,13 +903,31 @@ static int vhost_vdpa_set_owner(struct vhost_dev *dev) return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL); } =20 -static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev, - struct vhost_vring_addr *addr, struct vhost_virtqueue = *vq) +static void vhost_vdpa_vq_get_guest_addr(struct vhost_vring_addr *addr, + struct vhost_virtqueue *vq) { - assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); addr->desc_user_addr =3D (uint64_t)(unsigned long)vq->desc_phys; addr->avail_user_addr =3D (uint64_t)(unsigned long)vq->avail_phys; addr->used_user_addr =3D (uint64_t)(unsigned long)vq->used_phys; +} + +static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev, + struct vhost_vring_addr *addr, + struct vhost_virtqueue *vq) +{ + struct vhost_vdpa *v =3D dev->opaque; + + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); + + if (v->shadow_vqs_enabled) { + int idx =3D vhost_vdpa_get_vq_index(dev, addr->index); + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, idx= ); + + vhost_svq_get_vring_addr(svq, addr); + } else { + vhost_vdpa_vq_get_guest_addr(addr, vq); + } + trace_vhost_vdpa_vq_get_addr(dev, vq, addr->desc_user_addr, addr->avail_user_addr, addr->used_user_ad= dr); return 0; @@ -849,6 +948,12 @@ static void vhost_psvq_free(gpointer svq) vhost_svq_free(svq); } =20 +static int vhost_vdpa_get_max_queue_size(struct vhost_dev *dev, + uint16_t *qsize) +{ + return vhost_vdpa_call(dev, VHOST_VDPA_GET_VRING_NUM, qsize); +} + static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *= v, Error **errp) { @@ -857,6 +962,7 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, vhost_psvq_free= ); uint64_t dev_features; uint64_t svq_features; + uint16_t qsize; int r; bool ok; =20 @@ -864,7 +970,7 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, = struct vhost_vdpa *v, goto out; } =20 - r =3D vhost_vdpa_get_features(hdev, &dev_features); + r =3D vhost_vdpa_get_dev_features(hdev, &dev_features); if (r !=3D 0) { error_setg(errp, "Can't get vdpa device features, got (%d)", r); return r; @@ -879,9 +985,14 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev,= struct vhost_vdpa *v, return -1; } =20 + r =3D vhost_vdpa_get_max_queue_size(hdev, &qsize); + if (unlikely(r)) { + qsize =3D 256; + } + shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_psvq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { - VhostShadowVirtqueue *svq =3D vhost_svq_new(); + VhostShadowVirtqueue *svq =3D vhost_svq_new(qsize); =20 if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799185510662.1743052177128; Fri, 21 Jan 2022 13:06:25 -0800 (PST) Received: from localhost ([::1]:54758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB172-0003Gy-DG for importer@patchew.org; Fri, 21 Jan 2022 16:06:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0c6-00008F-Ia for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0c4-00054P-1e for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:26 -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-662-9HcAvsDUPQ256H0dxBRCEQ-1; Fri, 21 Jan 2022 15:34:20 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADE9186A8A2; Fri, 21 Jan 2022 20:34:18 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DA1016A31; Fri, 21 Jan 2022 20:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797263; 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=qGTC2ae1I3zxNNdMKzoTzAek2BabxKIwDAoX64igs+E=; b=HQ/3cSOcEsR5Woie1v+MAKA8gmDHKFXvO6OCv5NrVMLXFANb6897Hv2uklPkTgcDujEgRc JOAqP89QiRPkz82GSgTptThGLM4eD7CV/ot0Q34k5A67rFpw18eWH3UC3LW73NrZvAM0sZ sigREZcc7QIbI2OIfDR/i93u86Z8Cu8= X-MC-Unique: 9HcAvsDUPQ256H0dxBRCEQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 18/31] vhost: Shadow virtqueue buffers forwarding Date: Fri, 21 Jan 2022 21:27:20 +0100 Message-Id: <20220121202733.404989-19-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799186646100001 Initial version of shadow virtqueue that actually forward buffers. There is no iommu support at the moment, and that will be addressed in future patches of this series. Since all vhost-vdpa devices use forced IOMMU, this means that SVQ is not usable at this point of the series on any device. For simplicity it only supports modern devices, that expects vring in little endian, with split ring and no event idx or indirect descriptors. Support for them will not be added in this series. It reuses the VirtQueue code for the device part. The driver part is based on Linux's virtio_ring driver, but with stripped functionality and optimizations so it's easier to review. However, forwarding buffers have some particular pieces: One of the most unexpected ones is that a guest's buffer can expand through more than one descriptor in SVQ. While this is handled gracefully by qemu's emulated virtio devices, it may cause unexpected SVQ queue full. This patch also solves it by checking for this condition at both guest's kicks and device's calls. The code may be more elegant in the future if SVQ code runs in its own iocontext. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 2 + hw/virtio/vhost-shadow-virtqueue.c | 365 ++++++++++++++++++++++++++++- hw/virtio/vhost-vdpa.c | 111 ++++++++- 3 files changed, 462 insertions(+), 16 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 39aef5ffdf..19c934af49 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -33,6 +33,8 @@ uint16_t vhost_svq_get_num(const VhostShadowVirtqueue *sv= q); size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq); size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); =20 +void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, + VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 7c168075d7..a1a404f68f 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -9,6 +9,8 @@ =20 #include "qemu/osdep.h" #include "hw/virtio/vhost-shadow-virtqueue.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/virtio-access.h" #include "standard-headers/linux/vhost_types.h" =20 #include "qemu/error-report.h" @@ -36,6 +38,33 @@ typedef struct VhostShadowVirtqueue { =20 /* Guest's call notifier, where SVQ calls guest. */ EventNotifier svq_call; + + /* Virtio queue shadowing */ + VirtQueue *vq; + + /* Virtio device */ + VirtIODevice *vdev; + + /* Map for returning guest's descriptors */ + VirtQueueElement **ring_id_maps; + + /* Next VirtQueue element that guest made available */ + VirtQueueElement *next_guest_avail_elem; + + /* Next head to expose to device */ + uint16_t avail_idx_shadow; + + /* Next free descriptor */ + uint16_t free_head; + + /* Last seen used idx */ + uint16_t shadow_used_idx; + + /* Next head to consume from device */ + uint16_t last_used_idx; + + /* Cache for the exposed notification flag */ + bool notification; } VhostShadowVirtqueue; =20 #define INVALID_SVQ_KICK_FD -1 @@ -148,30 +177,294 @@ bool vhost_svq_ack_guest_features(uint64_t dev_featu= res, return true; } =20 -/* Forward guest notifications */ -static void vhost_handle_guest_kick(EventNotifier *n) +/** + * Number of descriptors that SVQ can make available from the guest. + * + * @svq The svq + */ +static uint16_t vhost_svq_available_slots(const VhostShadowVirtqueue *svq) { - VhostShadowVirtqueue *svq =3D container_of(n, VhostShadowVirtqueue, - svq_kick); + return svq->vring.num - (svq->avail_idx_shadow - svq->shadow_used_idx); +} + +static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool ena= ble) +{ + uint16_t notification_flag; =20 - if (unlikely(!event_notifier_test_and_clear(n))) { + if (svq->notification =3D=3D enable) { + return; + } + + notification_flag =3D cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); + + svq->notification =3D enable; + if (enable) { + svq->vring.avail->flags &=3D ~notification_flag; + } else { + svq->vring.avail->flags |=3D notification_flag; + } +} + +static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, + const struct iovec *iovec, + size_t num, bool more_descs, bool writ= e) +{ + uint16_t i =3D svq->free_head, last =3D svq->free_head; + unsigned n; + uint16_t flags =3D write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0; + vring_desc_t *descs =3D svq->vring.desc; + + if (num =3D=3D 0) { + return; + } + + for (n =3D 0; n < num; n++) { + if (more_descs || (n + 1 < num)) { + descs[i].flags =3D flags | cpu_to_le16(VRING_DESC_F_NEXT); + } else { + descs[i].flags =3D flags; + } + descs[i].addr =3D cpu_to_le64((hwaddr)iovec[n].iov_base); + descs[i].len =3D cpu_to_le32(iovec[n].iov_len); + + last =3D i; + i =3D cpu_to_le16(descs[i].next); + } + + svq->free_head =3D le16_to_cpu(descs[last].next); +} + +static unsigned vhost_svq_add_split(VhostShadowVirtqueue *svq, + VirtQueueElement *elem) +{ + int head; + unsigned avail_idx; + vring_avail_t *avail =3D svq->vring.avail; + + head =3D svq->free_head; + + /* We need some descriptors here */ + assert(elem->out_num || elem->in_num); + + vhost_vring_write_descs(svq, elem->out_sg, elem->out_num, + elem->in_num > 0, false); + vhost_vring_write_descs(svq, elem->in_sg, elem->in_num, false, true); + + /* + * Put entry in available array (but don't update avail->idx until they + * do sync). + */ + avail_idx =3D svq->avail_idx_shadow & (svq->vring.num - 1); + avail->ring[avail_idx] =3D cpu_to_le16(head); + svq->avail_idx_shadow++; + + /* Update avail index after the descriptor is wrote */ + smp_wmb(); + avail->idx =3D cpu_to_le16(svq->avail_idx_shadow); + + return head; +} + +static void vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +{ + unsigned qemu_head =3D vhost_svq_add_split(svq, elem); + + svq->ring_id_maps[qemu_head] =3D elem; +} + +static void vhost_svq_kick(VhostShadowVirtqueue *svq) +{ + /* We need to expose available array entries before checking used flag= s */ + smp_mb(); + if (svq->vring.used->flags & VRING_USED_F_NO_NOTIFY) { return; } =20 event_notifier_set(&svq->hdev_kick); } =20 -/* Forward vhost notifications */ +/** + * Forward available buffers. + * + * @svq Shadow VirtQueue + * + * Note that this function does not guarantee that all guest's available + * buffers are available to the device in SVQ avail ring. The guest may ha= ve + * exposed a GPA / GIOVA congiuous buffer, but it may not be contiguous in= qemu + * vaddr. + * + * If that happens, guest's kick notifications will be disabled until devi= ce + * makes some buffers used. + */ +static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq) +{ + /* Clear event notifier */ + event_notifier_test_and_clear(&svq->svq_kick); + + /* Make available as many buffers as possible */ + do { + if (virtio_queue_get_notification(svq->vq)) { + virtio_queue_set_notification(svq->vq, false); + } + + while (true) { + VirtQueueElement *elem; + + if (svq->next_guest_avail_elem) { + elem =3D g_steal_pointer(&svq->next_guest_avail_elem); + } else { + elem =3D virtqueue_pop(svq->vq, sizeof(*elem)); + } + + if (!elem) { + break; + } + + if (elem->out_num + elem->in_num > + vhost_svq_available_slots(svq)) { + /* + * This condition is possible since a contiguous buffer in= GPA + * does not imply a contiguous buffer in qemu's VA + * scatter-gather segments. If that happen, the buffer exp= osed + * to the device needs to be a chain of descriptors at this + * moment. + * + * SVQ cannot hold more available buffers if we are here: + * queue the current guest descriptor and ignore further k= icks + * until some elements are used. + */ + svq->next_guest_avail_elem =3D elem; + return; + } + + vhost_svq_add(svq, elem); + vhost_svq_kick(svq); + } + + virtio_queue_set_notification(svq->vq, true); + } while (!virtio_queue_empty(svq->vq)); +} + +/** + * Handle guest's kick. + * + * @n guest kick event notifier, the one that guest set to notify svq. + */ +static void vhost_handle_guest_kick_notifier(EventNotifier *n) +{ + VhostShadowVirtqueue *svq =3D container_of(n, VhostShadowVirtqueue, + svq_kick); + vhost_handle_guest_kick(svq); +} + +static bool vhost_svq_more_used(VhostShadowVirtqueue *svq) +{ + if (svq->last_used_idx !=3D svq->shadow_used_idx) { + return true; + } + + svq->shadow_used_idx =3D cpu_to_le16(svq->vring.used->idx); + + return svq->last_used_idx !=3D svq->shadow_used_idx; +} + +static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq) +{ + 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; + + if (!vhost_svq_more_used(svq)) { + return NULL; + } + + /* Only get used array entries after they have been exposed by dev */ + smp_rmb(); + last_used =3D svq->last_used_idx & (svq->vring.num - 1); + used_elem.id =3D le32_to_cpu(used->ring[last_used].id); + used_elem.len =3D le32_to_cpu(used->ring[last_used].len); + + svq->last_used_idx++; + if (unlikely(used_elem.id >=3D svq->vring.num)) { + error_report("Device %s says index %u is used", svq->vdev->name, + used_elem.id); + return NULL; + } + + if (unlikely(!svq->ring_id_maps[used_elem.id])) { + error_report( + "Device %s says index %u is used, but it was not available", + svq->vdev->name, used_elem.id); + return NULL; + } + + descs[used_elem.id].next =3D svq->free_head; + svq->free_head =3D used_elem.id; + + svq->ring_id_maps[used_elem.id]->len =3D used_elem.len; + return g_steal_pointer(&svq->ring_id_maps[used_elem.id]); +} + +static void vhost_svq_flush(VhostShadowVirtqueue *svq, + bool check_for_avail_queue) +{ + VirtQueue *vq =3D svq->vq; + + /* Make as many buffers as possible used. */ + do { + unsigned i =3D 0; + + vhost_svq_set_notification(svq, false); + while (true) { + g_autofree VirtQueueElement *elem =3D vhost_svq_get_buf(svq); + if (!elem) { + break; + } + + if (unlikely(i >=3D svq->vring.num)) { + virtio_error(svq->vdev, + "More than %u used buffers obtained in a %u size = SVQ", + i, svq->vring.num); + virtqueue_fill(vq, elem, elem->len, i); + virtqueue_flush(vq, i); + i =3D 0; + } + virtqueue_fill(vq, elem, elem->len, i++); + } + + virtqueue_flush(vq, i); + event_notifier_set(&svq->svq_call); + + if (check_for_avail_queue && svq->next_guest_avail_elem) { + /* + * Avail ring was full when vhost_svq_flush was called, so it'= s a + * good moment to make more descriptors available if possible + */ + vhost_handle_guest_kick(svq); + } + + vhost_svq_set_notification(svq, true); + } while (vhost_svq_more_used(svq)); +} + +/** + * Forward used buffers. + * + * @n hdev call event notifier, the one that device set to notify svq. + * + * Note that we are not making any buffers available in the loop, there is= no + * way that it runs more than virtqueue size times. + */ static void vhost_svq_handle_call(EventNotifier *n) { VhostShadowVirtqueue *svq =3D container_of(n, VhostShadowVirtqueue, hdev_call); =20 - if (unlikely(!event_notifier_test_and_clear(n))) { - return; - } + /* Clear event notifier */ + event_notifier_test_and_clear(n); =20 - event_notifier_set(&svq->svq_call); + vhost_svq_flush(svq, true); } =20 /** @@ -258,13 +551,38 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *= svq, int svq_kick_fd) * need to explicitely check for them. */ event_notifier_init_fd(&svq->svq_kick, svq_kick_fd); - event_notifier_set_handler(&svq->svq_kick, vhost_handle_guest_kick); + event_notifier_set_handler(&svq->svq_kick, + vhost_handle_guest_kick_notifier); =20 if (!check_old || event_notifier_test_and_clear(&tmp)) { event_notifier_set(&svq->hdev_kick); } } =20 +/** + * Start shadow virtqueue operation. + * + * @svq Shadow Virtqueue + * @vdev VirtIO device + * @vq Virtqueue to shadow + */ +void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, + VirtQueue *vq) +{ + svq->next_guest_avail_elem =3D NULL; + svq->avail_idx_shadow =3D 0; + svq->shadow_used_idx =3D 0; + svq->last_used_idx =3D 0; + svq->vdev =3D vdev; + svq->vq =3D vq; + + memset(svq->vring.avail, 0, sizeof(*svq->vring.avail)); + memset(svq->vring.used, 0, sizeof(*svq->vring.avail)); + for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { + svq->vring.desc[i].next =3D cpu_to_le16(i + 1); + } +} + /** * Stop shadow virtqueue operation. * @svq Shadow Virtqueue @@ -272,6 +590,28 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *s= vq, int svq_kick_fd) void vhost_svq_stop(VhostShadowVirtqueue *svq) { event_notifier_set_handler(&svq->svq_kick, NULL); + g_autofree VirtQueueElement *next_avail_elem =3D NULL; + + if (!svq->vq) { + return; + } + + /* Send all pending used descriptors to guest */ + vhost_svq_flush(svq, false); + + 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); + } + } + + 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); + } } =20 /** @@ -316,7 +656,7 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize) memset(svq->vring.desc, 0, driver_size); svq->vring.used =3D qemu_memalign(qemu_real_host_page_size, device_siz= e); memset(svq->vring.used, 0, device_size); - + svq->ring_id_maps =3D g_new0(VirtQueueElement *, qsize); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); return g_steal_pointer(&svq); =20 @@ -335,6 +675,7 @@ void vhost_svq_free(VhostShadowVirtqueue *vq) event_notifier_cleanup(&vq->hdev_kick); event_notifier_set_handler(&vq->hdev_call, NULL); event_notifier_cleanup(&vq->hdev_call); + g_free(vq->ring_id_maps); qemu_vfree(vq->vring.desc); qemu_vfree(vq->vring.used); g_free(vq); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 53e14bafa0..0e5c00ed7e 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -752,9 +752,9 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev *= dev, * Note that this function does not rewind kick file descriptor if cannot = set * call one. */ -static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, - VhostShadowVirtqueue *svq, - unsigned idx) +static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev, + VhostShadowVirtqueue *svq, + unsigned idx) { struct vhost_vring_file file =3D { .index =3D dev->vq_index + idx, @@ -767,7 +767,7 @@ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, r =3D vhost_vdpa_set_vring_dev_kick(dev, &file); if (unlikely(r !=3D 0)) { error_report("Can't set device kick fd (%d)", -r); - return false; + return r; } =20 event_notifier =3D vhost_svq_get_svq_call_notifier(svq); @@ -777,6 +777,99 @@ static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, error_report("Can't set device call fd (%d)", -r); } =20 + return r; +} + +/** + * Unmap SVQ area in the device + */ +static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr iova, + hwaddr size) +{ + int r; + + size =3D ROUND_UP(size, qemu_real_host_page_size); + r =3D vhost_vdpa_dma_unmap(v, iova, size); + return r =3D=3D 0; +} + +static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, + const VhostShadowVirtqueue *svq) +{ + struct vhost_vdpa *v =3D dev->opaque; + struct vhost_vring_addr svq_addr; + size_t device_size =3D vhost_svq_device_area_size(svq); + size_t driver_size =3D vhost_svq_driver_area_size(svq); + bool ok; + + vhost_svq_get_vring_addr(svq, &svq_addr); + + ok =3D vhost_vdpa_svq_unmap_ring(v, svq_addr.desc_user_addr, driver_si= ze); + if (unlikely(!ok)) { + return false; + } + + return vhost_vdpa_svq_unmap_ring(v, svq_addr.used_user_addr, device_si= ze); +} + +/** + * Map shadow virtqueue rings in device + * + * @dev The vhost device + * @svq The shadow virtqueue + */ +static bool vhost_vdpa_svq_map_rings(struct vhost_dev *dev, + const VhostShadowVirtqueue *svq) +{ + struct vhost_vdpa *v =3D dev->opaque; + struct vhost_vring_addr svq_addr; + size_t device_size =3D vhost_svq_device_area_size(svq); + size_t driver_size =3D vhost_svq_driver_area_size(svq); + int r; + + vhost_svq_get_vring_addr(svq, &svq_addr); + + r =3D vhost_vdpa_dma_map(v, svq_addr.desc_user_addr, driver_size, + (void *)svq_addr.desc_user_addr, true); + if (unlikely(r !=3D 0)) { + return false; + } + + r =3D vhost_vdpa_dma_map(v, svq_addr.used_user_addr, device_size, + (void *)svq_addr.used_user_addr, false); + return r =3D=3D 0; +} + +static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, + VhostShadowVirtqueue *svq, + unsigned idx) +{ + uint16_t vq_index =3D dev->vq_index + idx; + struct vhost_vring_state s =3D { + .index =3D vq_index, + }; + int r; + bool ok; + + r =3D vhost_vdpa_set_dev_vring_base(dev, &s); + if (unlikely(r)) { + error_report("Can't set vring base (%d)", r); + return false; + } + + s.num =3D vhost_svq_get_num(svq); + r =3D vhost_vdpa_set_dev_vring_num(dev, &s); + if (unlikely(r)) { + error_report("Can't set vring num (%d)", r); + return false; + } + + ok =3D vhost_vdpa_svq_map_rings(dev, svq); + if (unlikely(!ok)) { + return false; + } + + r =3D vhost_vdpa_svq_set_fds(dev, svq, idx); return r =3D=3D 0; } =20 @@ -788,14 +881,24 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev= , bool started) if (started) { vhost_vdpa_host_notifiers_init(dev); for (unsigned i =3D 0; i < v->shadow_vqs->len; ++i) { + VirtQueue *vq =3D virtio_get_queue(dev->vdev, dev->vq_index + = i); VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs,= i); bool ok =3D vhost_vdpa_svq_setup(dev, svq, i); if (unlikely(!ok)) { return -1; } + vhost_svq_start(svq, dev->vdev, vq); } vhost_vdpa_set_vring_ready(dev); } else { + for (unsigned i =3D 0; i < v->shadow_vqs->len; ++i) { + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, + i); + bool ok =3D vhost_vdpa_svq_unmap_rings(dev, svq); + if (unlikely(!ok)) { + return -1; + } + } vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); } =20 --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798497838837.9829207526765; Fri, 21 Jan 2022 12:54:57 -0800 (PST) Received: from localhost ([::1]:37358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0vw-0008BJ-Ej for importer@patchew.org; Fri, 21 Jan 2022 15:54:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cB-0000Df-9I for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0c9-00054f-GV for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:30 -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-256-jVEWO3qyMzGRfJOQCuJw-g-1; Fri, 21 Jan 2022 15:34:25 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3DC01420E6; Fri, 21 Jan 2022 20:34:24 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15995E2C8; Fri, 21 Jan 2022 20:34:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797268; 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=Z288opq66qlQZL93foWxaq85NFVUQL9AlykAae/k0MU=; b=HVZNcombiV/wkVeNU3SI/51oMOcxjvxQ+R/BznzLDa2wYH3KlMDKAkm724F3gj3z2p9TkI txvEIk/1jv6UBXIEz8ygWOXPjO6llDOesQf7w3WCArvaI/jLQL4dWG/MrIzGNN1hiAxyzh U6t7jRr7gTgKIJtaUymCywmjSO3TB4g= X-MC-Unique: jVEWO3qyMzGRfJOQCuJw-g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 19/31] utils: Add internal DMAMap to iova-tree Date: Fri, 21 Jan 2022 21:27:21 +0100 Message-Id: <20220121202733.404989-20-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798501099100001 So we can store private data not accessible from outside. In this case, we will add intrusive linked list members so we can transverse it for allocation. Signed-off-by: Eugenio P=C3=A9rez --- util/iova-tree.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/util/iova-tree.c b/util/iova-tree.c index 23ea35b7a4..ac089101c4 100644 --- a/util/iova-tree.c +++ b/util/iova-tree.c @@ -12,13 +12,18 @@ #include "qemu/osdep.h" #include "qemu/iova-tree.h" =20 +typedef struct DMAMapInternal { + DMAMap map; +} DMAMapInternal; + struct IOVATree { GTree *tree; }; =20 static int iova_tree_compare(gconstpointer a, gconstpointer b, gpointer da= ta) { - const DMAMap *m1 =3D a, *m2 =3D b; + const DMAMapInternal *i1 =3D a, *i2 =3D b; + const DMAMap *m1 =3D &i1->map, *m2 =3D &i2->map; =20 if (m1->iova > m2->iova + m2->size) { return 1; @@ -42,9 +47,18 @@ IOVATree *iova_tree_new(void) return iova_tree; } =20 +static DMAMapInternal *iova_tree_find_internal(const IOVATree *tree, + const DMAMap *map) +{ + const DMAMapInternal map_internal =3D { .map =3D *map }; + + return g_tree_lookup(tree->tree, &map_internal); +} + const DMAMap *iova_tree_find(const IOVATree *tree, const DMAMap *map) { - return g_tree_lookup(tree->tree, map); + const DMAMapInternal *ret =3D iova_tree_find_internal(tree, map); + return &ret->map; } =20 const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova) @@ -54,7 +68,8 @@ const DMAMap *iova_tree_find_address(const IOVATree *tree= , hwaddr iova) return iova_tree_find(tree, &map); } =20 -static inline void iova_tree_insert_internal(GTree *gtree, DMAMap *range) +static inline void iova_tree_insert_internal(GTree *gtree, + DMAMapInternal *range) { /* Key and value are sharing the same range data */ g_tree_insert(gtree, range, range); @@ -62,7 +77,7 @@ static inline void iova_tree_insert_internal(GTree *gtree= , DMAMap *range) =20 int iova_tree_insert(IOVATree *tree, const DMAMap *map) { - DMAMap *new; + DMAMapInternal *new; =20 if (map->iova + map->size < map->iova || map->perm =3D=3D IOMMU_NONE) { return IOVA_ERR_INVALID; @@ -73,8 +88,8 @@ int iova_tree_insert(IOVATree *tree, const DMAMap *map) return IOVA_ERR_OVERLAP; } =20 - new =3D g_new0(DMAMap, 1); - memcpy(new, map, sizeof(*new)); + new =3D g_new0(DMAMapInternal, 1); + memcpy(&new->map, map, sizeof(new->map)); iova_tree_insert_internal(tree->tree, new); =20 return IOVA_OK; @@ -84,11 +99,11 @@ static gboolean iova_tree_traverse(gpointer key, gpoint= er value, gpointer data) { iova_tree_iterator iterator =3D data; - DMAMap *map =3D key; + DMAMapInternal *map =3D key; =20 g_assert(key =3D=3D value); =20 - return iterator(map); + return iterator(&map->map); } =20 void iova_tree_foreach(IOVATree *tree, iova_tree_iterator iterator) @@ -98,10 +113,10 @@ void iova_tree_foreach(IOVATree *tree, iova_tree_itera= tor iterator) =20 int iova_tree_remove(IOVATree *tree, const DMAMap *map) { - const DMAMap *overlap; + DMAMapInternal *overlap_internal; =20 - while ((overlap =3D iova_tree_find(tree, map))) { - g_tree_remove(tree->tree, overlap); + while ((overlap_internal =3D iova_tree_find_internal(tree, map))) { + g_tree_remove(tree->tree, overlap_internal); } =20 return IOVA_OK; --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799354205197.05903071649504; Fri, 21 Jan 2022 13:09:14 -0800 (PST) Received: from localhost ([::1]:35274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB19l-0000kC-4y for importer@patchew.org; Fri, 21 Jan 2022 16:09:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cJ-0000Hz-AU for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cG-00055c-HH for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:37 -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-572-Swp8W-6ZMpKdbnnsEdbOeg-1; Fri, 21 Jan 2022 15:34:31 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A2E446860; Fri, 21 Jan 2022 20:34:29 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 970B2167A8; Fri, 21 Jan 2022 20:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797276; 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=UXY13WrHKMeplYTVHN85eP6jeQoSwtEprvNFJ53nnMc=; b=BZDqleeV6MRPObVmikoOeAA+Ux7309nhLJc0pcsDz/N8giSLYIqKrP20h4wrgu3qVb8gkz iHaPNhlu2QVjhXM72RoqB0TCiYfgWLtTiiPWYnVl3fwayucgHNLMZ0JVTD80XYgJe9VAJ/ 5GM+Zd34Dpch/sEC0RcPJRY1l+RmvW0= X-MC-Unique: Swp8W-6ZMpKdbnnsEdbOeg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 20/31] util: Store DMA entries in a list Date: Fri, 21 Jan 2022 21:27:22 +0100 Message-Id: <20220121202733.404989-21-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799356317100001 SVQ need to allocate iova entries, traversing the list looking for holes. GLib offers methods to both transverse the list and look for entries upper than a key since version 2.68. However qemu may need to compile with earlier versions, so we replicate both methods here. Signed-off-by: Eugenio P=C3=A9rez --- util/iova-tree.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/util/iova-tree.c b/util/iova-tree.c index ac089101c4..5063a256dd 100644 --- a/util/iova-tree.c +++ b/util/iova-tree.c @@ -11,15 +11,44 @@ =20 #include "qemu/osdep.h" #include "qemu/iova-tree.h" +#include "qemu/queue.h" =20 typedef struct DMAMapInternal { DMAMap map; + QTAILQ_ENTRY(DMAMapInternal) entry; } DMAMapInternal; =20 struct IOVATree { GTree *tree; + QTAILQ_HEAD(, DMAMapInternal) list; }; =20 +/** + * Search function for the upper bound of a given needle. + * + * The upper bound is the first node that has its key strictly greater tha= n the + * searched key. + * + * TODO: A specialized function is available in GTree since Glib 2.68. Rep= lace + * when Glib minimal version is raised. + */ +static int iova_tree_compare_upper_bound(gconstpointer a, gconstpointer b) +{ + const DMAMapInternal *haystack =3D a, *needle =3D b, *prev; + + if (needle->map.iova >=3D haystack->map.iova) { + return 1; + } + + prev =3D QTAILQ_PREV(haystack, entry); + if (!prev || prev->map.iova < needle->map.iova) { + return 0; + } + + /* More data to the left or end of data */ + return -1; +} + static int iova_tree_compare(gconstpointer a, gconstpointer b, gpointer da= ta) { const DMAMapInternal *i1 =3D a, *i2 =3D b; @@ -43,6 +72,7 @@ IOVATree *iova_tree_new(void) =20 /* We don't have values actually, no need to free */ iova_tree->tree =3D g_tree_new_full(iova_tree_compare, NULL, g_free, N= ULL); + QTAILQ_INIT(&iova_tree->list); =20 return iova_tree; } @@ -77,7 +107,7 @@ static inline void iova_tree_insert_internal(GTree *gtre= e, =20 int iova_tree_insert(IOVATree *tree, const DMAMap *map) { - DMAMapInternal *new; + DMAMapInternal *new, *right; =20 if (map->iova + map->size < map->iova || map->perm =3D=3D IOMMU_NONE) { return IOVA_ERR_INVALID; @@ -92,6 +122,15 @@ int iova_tree_insert(IOVATree *tree, const DMAMap *map) memcpy(&new->map, map, sizeof(new->map)); iova_tree_insert_internal(tree->tree, new); =20 + /* Ordered insertion */ + right =3D g_tree_search(tree->tree, iova_tree_compare_upper_bound, new= ); + if (!right) { + /* Empty or bigger than any other entry */ + QTAILQ_INSERT_TAIL(&tree->list, new, entry); + } else { + QTAILQ_INSERT_BEFORE(right, new, entry); + } + return IOVA_OK; } =20 @@ -116,6 +155,7 @@ int iova_tree_remove(IOVATree *tree, const DMAMap *map) DMAMapInternal *overlap_internal; =20 while ((overlap_internal =3D iova_tree_find_internal(tree, map))) { + QTAILQ_REMOVE(&tree->list, overlap_internal, entry); g_tree_remove(tree->tree, overlap_internal); } =20 --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799855829474.6503421851635; Fri, 21 Jan 2022 13:17:35 -0800 (PST) Received: from localhost ([::1]:47734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1Hq-0000wt-JE for importer@patchew.org; Fri, 21 Jan 2022 16:17:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cM-0000Jz-6m for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cK-00055m-3S for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:41 -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-612-sbXyCH0cNxCJKFcaDvQ9kA-1; Fri, 21 Jan 2022 15:34:36 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D4ED946862; Fri, 21 Jan 2022 20:34:34 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4FE916A33; Fri, 21 Jan 2022 20:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797279; 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=VST6ydIDvy47Cx3pY2zc2TwGKNyubrTXRobXtdkSSmI=; b=ihkqz0I7SOYe3H46rTp8JFIYGPMPMfqWopsCOnStREu5poU4ofApLicpLsfKIjG1sh1/or BrRaQIVtFjlfnjelm1g35RhP2tRHuE5qZaUNIS+clVn6Yjqqv9ZQLmuGowEvh4wT8bMIv0 mBj2iTTjXWlkKmEyFvgeAm+ggfTutVU= X-MC-Unique: sbXyCH0cNxCJKFcaDvQ9kA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 21/31] util: Add iova_tree_alloc Date: Fri, 21 Jan 2022 21:27:23 +0100 Message-Id: <20220121202733.404989-22-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799857817100001 This iova tree function allows it to look for a hole in allocated regions and return a totally new translation for a given translated address. It's usage is mainly to allow devices to access qemu address space, remapping guest's one into a new iova space where qemu can add chunks of addresses. Signed-off-by: Eugenio P=C3=A9rez --- include/qemu/iova-tree.h | 17 ++++++++ util/iova-tree.c | 86 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h index 8249edd764..33f9b2e13f 100644 --- a/include/qemu/iova-tree.h +++ b/include/qemu/iova-tree.h @@ -29,6 +29,7 @@ #define IOVA_OK (0) #define IOVA_ERR_INVALID (-1) /* Invalid parameters */ #define IOVA_ERR_OVERLAP (-2) /* IOVA range overlapped */ +#define IOVA_ERR_NOMEM (-3) /* Cannot allocate */ =20 typedef struct IOVATree IOVATree; typedef struct DMAMap { @@ -119,6 +120,22 @@ const DMAMap *iova_tree_find_address(const IOVATree *t= ree, hwaddr iova); */ void iova_tree_foreach(IOVATree *tree, iova_tree_iterator iterator); =20 +/** + * iova_tree_alloc: + * + * @tree: the iova tree to allocate from + * @map: the new map (as translated addr & size) to allocate in iova region + * @iova_begin: the minimum address of the allocation + * @iova_end: the maximum addressable direction of the allocation + * + * Allocates a new region of a given size, between iova_min and iova_max. + * + * Return: Same as iova_tree_insert, but cannot overlap and can be out of + * free contiguous range. Caller can get the assigned iova in map->iova. + */ +int iova_tree_alloc(IOVATree *tree, DMAMap *map, hwaddr iova_begin, + hwaddr iova_end); + /** * iova_tree_destroy: * diff --git a/util/iova-tree.c b/util/iova-tree.c index 5063a256dd..1439fc9fe2 100644 --- a/util/iova-tree.c +++ b/util/iova-tree.c @@ -88,7 +88,7 @@ static DMAMapInternal *iova_tree_find_internal(const IOVA= Tree *tree, const DMAMap *iova_tree_find(const IOVATree *tree, const DMAMap *map) { const DMAMapInternal *ret =3D iova_tree_find_internal(tree, map); - return &ret->map; + return ret ? &ret->map : NULL; } =20 const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova) @@ -162,6 +162,90 @@ int iova_tree_remove(IOVATree *tree, const DMAMap *map) return IOVA_OK; } =20 +/** + * Check if there is at minimum "size" iova space between the end of "left= " and + * the start of "right". If some of them is NULL, iova_begin and iova_end = will + * be used. + */ +static bool iova_tree_alloc_map_in_hole(const DMAMapInternal *l, + const DMAMapInternal *r, + hwaddr iova_begin, hwaddr iova_las= t, + size_t size) +{ + const DMAMap *left =3D l ? &l->map : NULL; + const DMAMap *right =3D r ? &r->map : NULL; + uint64_t hole_start, hole_last; + + if (right && right->iova + right->size < iova_begin) { + return false; + } + + if (left && left->iova > iova_last) { + return false; + } + + hole_start =3D MAX(left ? left->iova + left->size + 1 : 0, iova_begin); + hole_last =3D MIN(right ? right->iova : HWADDR_MAX, iova_last); + + if (hole_last - hole_start > size) { + /* We found a valid hole. */ + return true; + } + + /* Keep iterating */ + return false; +} + +/** + * Allocates a new entry in the tree + * + * The caller specifies the size of the new entry with map->size. The new = iova + * address is returned in map->iova if allocation success. The map ownersh= ip is + * always of the caller as in iova_tree_insert. + * + * More contrains can be specified with iova_begin and iova_last. + * + * Returns the same as iova_tree_insert, but it can return IOVA_ERR_NOMEM = if + * cannot find a hole in iova range big enough. + */ +int iova_tree_alloc(IOVATree *tree, DMAMap *map, hwaddr iova_begin, + hwaddr iova_last) +{ + const DMAMapInternal *last, *i; + + assert(iova_begin < iova_last); + + /* + * Find a valid hole for the mapping + * + * TODO: Replace all this with g_tree_node_first/next/last when availa= ble + * (from glib since 2.68). Using a sepparated QTAILQ complicates code. + * + * Try to allocate first at the end of the list. + */ + last =3D QTAILQ_LAST(&tree->list); + if (iova_tree_alloc_map_in_hole(last, NULL, iova_begin, iova_last, + map->size)) { + goto alloc; + } + + /* Look for inner hole */ + last =3D NULL; + for (i =3D QTAILQ_FIRST(&tree->list); i; + last =3D i, i =3D QTAILQ_NEXT(i, entry)) { + if (iova_tree_alloc_map_in_hole(last, i, iova_begin, iova_last, + map->size)) { + goto alloc; + } + } + + return IOVA_ERR_NOMEM; + +alloc: + map->iova =3D last ? last->map.iova + last->map.size + 1 : iova_begin; + return iova_tree_insert(tree, map); +} + void iova_tree_destroy(IOVATree *tree) { g_tree_destroy(tree->tree); --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798971187413.84300669444235; Fri, 21 Jan 2022 13:02:51 -0800 (PST) Received: from localhost ([::1]:46262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB13Z-00062L-Vs for importer@patchew.org; Fri, 21 Jan 2022 16:02:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cQ-0000NN-UG for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cO-00056N-VD for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:46 -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-85-4F9Qnma4PGKTPtd6TFfZ9g-1; Fri, 21 Jan 2022 15:34:41 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 347E646861; Fri, 21 Jan 2022 20:34:40 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 413F916A31; Fri, 21 Jan 2022 20:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797284; 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=QVcCjMEA5sXXHxOLlAezD5eoMZnDS2qYR31Nbhq9Sns=; b=SMI4hPBvi1ku+yKc/YJa4IB2dRlD5ykXGlduBdedGCHCcOOvZikOgE0Ff/bpIdq7EoZmXh haUPviVLbvbyCMWKA7ufuPzT/BqeNWphErsZxuCvNETn2OJh9ygDdjqIEG8pjSISQhQshb 36/UnAfVJg+ZF6QXTRJt6JGGV/CIMXw= X-MC-Unique: 4F9Qnma4PGKTPtd6TFfZ9g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 22/31] vhost: Add VhostIOVATree Date: Fri, 21 Jan 2022 21:27:24 +0100 Message-Id: <20220121202733.404989-23-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798972871100001 This tree is able to look for a translated address from an IOVA address. At first glance it is similar to util/iova-tree. However, SVQ working on devices with limited IOVA space need more capabilities, like allocating IOVA chunks or performing reverse translations (qemu addresses to iova). The allocation capability, as "assign a free IOVA address to this chunk of memory in qemu's address space" allows shadow virtqueue to create a new address space that is not restricted by guest's addressable one, so we can allocate shadow vqs vrings outside of it. It duplicates the tree so it can search efficiently both directions, and it will signal overlap if iova or the translated address is present in any tree. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-iova-tree.h | 27 +++++++ hw/virtio/vhost-iova-tree.c | 157 ++++++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 2 +- 3 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/vhost-iova-tree.h create mode 100644 hw/virtio/vhost-iova-tree.c diff --git a/hw/virtio/vhost-iova-tree.h b/hw/virtio/vhost-iova-tree.h new file mode 100644 index 0000000000..610394eaf1 --- /dev/null +++ b/hw/virtio/vhost-iova-tree.h @@ -0,0 +1,27 @@ +/* + * vhost software live migration ring + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 + * SPDX-FileContributor: Author: Eugenio P=C3=A9rez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_VIRTIO_VHOST_IOVA_TREE_H +#define HW_VIRTIO_VHOST_IOVA_TREE_H + +#include "qemu/iova-tree.h" +#include "exec/memory.h" + +typedef struct VhostIOVATree VhostIOVATree; + +VhostIOVATree *vhost_iova_tree_new(uint64_t iova_first, uint64_t iova_last= ); +void vhost_iova_tree_delete(VhostIOVATree *iova_tree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostIOVATree, vhost_iova_tree_delete); + +const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *iova_tree, + const DMAMap *map); +int vhost_iova_tree_map_alloc(VhostIOVATree *iova_tree, DMAMap *map); +void vhost_iova_tree_remove(VhostIOVATree *iova_tree, const DMAMap *map); + +#endif diff --git a/hw/virtio/vhost-iova-tree.c b/hw/virtio/vhost-iova-tree.c new file mode 100644 index 0000000000..0021dbaf54 --- /dev/null +++ b/hw/virtio/vhost-iova-tree.c @@ -0,0 +1,157 @@ +/* + * vhost software live migration ring + * + * SPDX-FileCopyrightText: Red Hat, Inc. 2021 + * SPDX-FileContributor: Author: Eugenio P=C3=A9rez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/iova-tree.h" +#include "vhost-iova-tree.h" + +#define iova_min_addr qemu_real_host_page_size + +/** + * VhostIOVATree, able to: + * - Translate iova address + * - Reverse translate iova address (from translated to iova) + * - Allocate IOVA regions for translated range (potentially slow operatio= n) + * + * Note that it cannot remove nodes. + */ +struct VhostIOVATree { + /* First addresable iova address in the device */ + uint64_t iova_first; + + /* Last addressable iova address in the device */ + uint64_t iova_last; + + /* IOVA address to qemu memory maps. */ + IOVATree *iova_taddr_map; + + /* QEMU virtual memory address to iova maps */ + GTree *taddr_iova_map; +}; + +static gint vhost_iova_tree_cmp_taddr(gconstpointer a, gconstpointer b, + gpointer data) +{ + const DMAMap *m1 =3D a, *m2 =3D b; + + if (m1->translated_addr > m2->translated_addr + m2->size) { + return 1; + } + + if (m1->translated_addr + m1->size < m2->translated_addr) { + return -1; + } + + /* Overlapped */ + return 0; +} + +/** + * Create a new IOVA tree + * + * Returns the new IOVA tree + */ +VhostIOVATree *vhost_iova_tree_new(hwaddr iova_first, hwaddr iova_last) +{ + VhostIOVATree *tree =3D g_new(VhostIOVATree, 1); + + /* Some devices does not like 0 addresses */ + tree->iova_first =3D MAX(iova_first, iova_min_addr); + tree->iova_last =3D iova_last; + + tree->iova_taddr_map =3D iova_tree_new(); + tree->taddr_iova_map =3D g_tree_new_full(vhost_iova_tree_cmp_taddr, NU= LL, + NULL, g_free); + return tree; +} + +/** + * Delete an iova tree + */ +void vhost_iova_tree_delete(VhostIOVATree *iova_tree) +{ + iova_tree_destroy(iova_tree->iova_taddr_map); + g_tree_unref(iova_tree->taddr_iova_map); + g_free(iova_tree); +} + +/** + * Find the IOVA address stored from a memory address + * + * @tree The iova tree + * @map The map with the memory address + * + * Return the stored mapping, or NULL if not found. + */ +const DMAMap *vhost_iova_tree_find_iova(const VhostIOVATree *tree, + const DMAMap *map) +{ + return g_tree_lookup(tree->taddr_iova_map, map); +} + +/** + * Allocate a new mapping + * + * @tree The iova tree + * @map The iova map + * + * Returns: + * - IOVA_OK if the map fits in the container + * - IOVA_ERR_INVALID if the map does not make sense (like size overflow) + * - IOVA_ERR_OVERLAP if the tree already contains that map + * - IOVA_ERR_NOMEM if tree cannot allocate more space. + * + * It returns assignated iova in map->iova if return value is VHOST_DMA_MA= P_OK. + */ +int vhost_iova_tree_map_alloc(VhostIOVATree *tree, DMAMap *map) +{ + /* Some vhost devices does not like addr 0. Skip first page */ + hwaddr iova_first =3D tree->iova_first ?: qemu_real_host_page_size; + DMAMap *new; + int r; + + if (map->translated_addr + map->size < map->translated_addr || + map->perm =3D=3D IOMMU_NONE) { + return IOVA_ERR_INVALID; + } + + /* Check for collisions in translated addresses */ + if (vhost_iova_tree_find_iova(tree, map)) { + return IOVA_ERR_OVERLAP; + } + + /* Allocate a node in IOVA address */ + r =3D iova_tree_alloc(tree->iova_taddr_map, map, iova_first, + tree->iova_last); + if (r !=3D IOVA_OK) { + return r; + } + + /* Allocate node in qemu -> iova translations */ + new =3D g_malloc(sizeof(*new)); + memcpy(new, map, sizeof(*new)); + g_tree_insert(tree->taddr_iova_map, new, new); + return IOVA_OK; +} + +/** + * Remove existing mappings from iova tree + * + * @param iova_tree The vhost iova tree + * @param map The map to remove + */ +void vhost_iova_tree_remove(VhostIOVATree *iova_tree, const DMAMap *map) +{ + const DMAMap *overlap; + + iova_tree_remove(iova_tree->iova_taddr_map, map); + while ((overlap =3D vhost_iova_tree_find_iova(iova_tree, map))) { + g_tree_remove(iova_tree->taddr_iova_map, overlap); + } +} diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 2dc87613bc..6047670804 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-= stub.c')) =20 virtio_ss =3D ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backe= nd.c', 'vhost-shadow-virtqueue.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backe= nd.c', 'vhost-shadow-virtqueue.c', 'vhost-iova-tree.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloo= n.c')) --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642797836828257.17931498904034; Fri, 21 Jan 2022 12:43:56 -0800 (PST) Received: from localhost ([::1]:47924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0lH-0004Gh-Jt for importer@patchew.org; Fri, 21 Jan 2022 15:43:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cb-0000Ql-CG for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27649) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cX-00057D-Mj for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:56 -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-536-GwGGK_d6N6OhhlisZnwYYA-1; Fri, 21 Jan 2022 15:34:47 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A25141019982; Fri, 21 Jan 2022 20:34:45 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9096CE2C8; Fri, 21 Jan 2022 20:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797292; 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=V4QnG0VOwNLAPfh053MAe4HS4y023rWDHndE0ddtWeI=; b=TT1T4je0YpYUg6HuB2N6K9p17eMCgBpvEtruiNVi+9ZQ4UJejuhza/WiwaAuMwBBIVQLjl nbGELaYWVlOPzCuBhKtvmO4AoCqnlAakQ5n/G3h65Nusz9ar7rZFoeAI+7IYhk6TkQOWua B+2OvvXdbTMyKSm6afurAiRejL+SSAI= X-MC-Unique: GwGGK_d6N6OhhlisZnwYYA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 23/31] vdpa: Add custom IOTLB translations to SVQ Date: Fri, 21 Jan 2022 21:27:25 +0100 Message-Id: <20220121202733.404989-24-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642797837735100001 Use translations added in VhostIOVATree in SVQ. Only introduce usage here, not allocation and deallocation. As with previous patches, we use the dead code paths of shadow_vqs_enabled to avoid commiting too many changes at once. These are impossible to take at the moment. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 3 +- include/hw/virtio/vhost-vdpa.h | 3 + hw/virtio/vhost-shadow-virtqueue.c | 111 ++++++++++++++++---- hw/virtio/vhost-vdpa.c | 161 +++++++++++++++++++++++++---- 4 files changed, 238 insertions(+), 40 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index 19c934af49..c6f67d6f76 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -12,6 +12,7 @@ =20 #include "hw/virtio/vhost.h" #include "qemu/event_notifier.h" +#include "hw/virtio/vhost-iova-tree.h" =20 typedef struct VhostShadowVirtqueue VhostShadowVirtqueue; =20 @@ -37,7 +38,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODev= ice *vdev, VirtQueue *vq); void vhost_svq_stop(VhostShadowVirtqueue *svq); =20 -VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize); +VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_ma= p); =20 void vhost_svq_free(VhostShadowVirtqueue *vq); =20 diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 009a9f3b6b..cd2388b3be 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -14,6 +14,7 @@ =20 #include =20 +#include "hw/virtio/vhost-iova-tree.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" =20 @@ -30,6 +31,8 @@ typedef struct vhost_vdpa { MemoryListener listener; struct vhost_vdpa_iova_range iova_range; bool shadow_vqs_enabled; + /* IOVA mapping used by Shadow Virtqueue */ + VhostIOVATree *iova_tree; GPtrArray *shadow_vqs; struct vhost_dev *dev; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index a1a404f68f..c7888eb8cf 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -11,6 +11,7 @@ #include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/vhost-iova-tree.h" #include "standard-headers/linux/vhost_types.h" =20 #include "qemu/error-report.h" @@ -45,6 +46,9 @@ typedef struct VhostShadowVirtqueue { /* Virtio device */ VirtIODevice *vdev; =20 + /* IOVA mapping */ + VhostIOVATree *iova_tree; + /* Map for returning guest's descriptors */ VirtQueueElement **ring_id_maps; =20 @@ -97,13 +101,7 @@ bool vhost_svq_valid_device_features(uint64_t *dev_feat= ures) continue; =20 case VIRTIO_F_ACCESS_PLATFORM: - /* SVQ does not know how to translate addresses */ - if (*dev_features & BIT_ULL(b)) { - clear_bit(b, dev_features); - r =3D false; - } - break; - + /* SVQ trust in host's IOMMU to translate addresses */ case VIRTIO_F_VERSION_1: /* SVQ trust that guest vring is little endian */ if (!(*dev_features & BIT_ULL(b))) { @@ -205,7 +203,55 @@ static void vhost_svq_set_notification(VhostShadowVirt= queue *svq, bool enable) } } =20 +/** + * Translate addresses between qemu's virtual address and SVQ IOVA + * + * @svq Shadow VirtQueue + * @vaddr Translated IOVA addresses + * @iovec Source qemu's VA addresses + * @num Length of iovec and minimum length of vaddr + */ +static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq, + void **addrs, const struct iovec *iov= ec, + size_t num) +{ + size_t i; + + if (num =3D=3D 0) { + return true; + } + + for (i =3D 0; i < num; ++i) { + DMAMap needle =3D { + .translated_addr =3D (hwaddr)iovec[i].iov_base, + .size =3D iovec[i].iov_len, + }; + size_t off; + + const DMAMap *map =3D vhost_iova_tree_find_iova(svq->iova_tree, &n= eedle); + /* + * Map cannot be NULL since iova map contains all guest space and + * qemu already has a physical address mapped + */ + if (unlikely(!map)) { + error_report("Invalid address 0x%"HWADDR_PRIx" given by guest", + needle.translated_addr); + return false; + } + + /* + * Map->iova chunk size is ignored. What to do if descriptor + * (addr, size) does not fit is delegated to the device. + */ + off =3D needle.translated_addr - map->translated_addr; + addrs[i] =3D (void *)(map->iova + off); + } + + return true; +} + static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, + void * const *vaddr_sg, const struct iovec *iovec, size_t num, bool more_descs, bool writ= e) { @@ -224,7 +270,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueu= e *svq, } else { descs[i].flags =3D flags; } - descs[i].addr =3D cpu_to_le64((hwaddr)iovec[n].iov_base); + descs[i].addr =3D cpu_to_le64((hwaddr)vaddr_sg[n]); descs[i].len =3D cpu_to_le32(iovec[n].iov_len); =20 last =3D i; @@ -234,42 +280,60 @@ static void vhost_vring_write_descs(VhostShadowVirtqu= eue *svq, svq->free_head =3D le16_to_cpu(descs[last].next); } =20 -static unsigned vhost_svq_add_split(VhostShadowVirtqueue *svq, - VirtQueueElement *elem) +static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, + VirtQueueElement *elem, + unsigned *head) { - int head; unsigned avail_idx; vring_avail_t *avail =3D svq->vring.avail; + bool ok; + g_autofree void **sgs =3D g_new(void *, MAX(elem->out_num, elem->in_nu= m)); =20 - head =3D svq->free_head; + *head =3D svq->free_head; =20 /* We need some descriptors here */ assert(elem->out_num || elem->in_num); =20 - vhost_vring_write_descs(svq, elem->out_sg, elem->out_num, + ok =3D vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num); + if (unlikely(!ok)) { + return false; + } + vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num, elem->in_num > 0, false); - vhost_vring_write_descs(svq, elem->in_sg, elem->in_num, false, true); + + + ok =3D vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num); + if (unlikely(!ok)) { + return false; + } + + vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, tr= ue); =20 /* * Put entry in available array (but don't update avail->idx until they * do sync). */ avail_idx =3D svq->avail_idx_shadow & (svq->vring.num - 1); - avail->ring[avail_idx] =3D cpu_to_le16(head); + avail->ring[avail_idx] =3D cpu_to_le16(*head); svq->avail_idx_shadow++; =20 /* Update avail index after the descriptor is wrote */ smp_wmb(); avail->idx =3D cpu_to_le16(svq->avail_idx_shadow); =20 - return head; + return true; } =20 -static void vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) +static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) { - unsigned qemu_head =3D vhost_svq_add_split(svq, elem); + unsigned qemu_head; + bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); + if (unlikely(!ok)) { + return false; + } =20 svq->ring_id_maps[qemu_head] =3D elem; + return true; } =20 static void vhost_svq_kick(VhostShadowVirtqueue *svq) @@ -309,6 +373,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueu= e *svq) =20 while (true) { VirtQueueElement *elem; + bool ok; =20 if (svq->next_guest_avail_elem) { elem =3D g_steal_pointer(&svq->next_guest_avail_elem); @@ -337,7 +402,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtque= ue *svq) return; } =20 - vhost_svq_add(svq, elem); + ok =3D vhost_svq_add(svq, elem); + if (unlikely(!ok)) { + /* VQ is broken, just return and ignore any other kicks */ + return; + } vhost_svq_kick(svq); } =20 @@ -619,12 +688,13 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) * methods and file descriptors. * * @qsize Shadow VirtQueue size + * @iova_tree Tree to perform descriptors translations * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize) +VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize, VhostIOVATree *iova_tr= ee) { size_t desc_size =3D sizeof(vring_desc_t) * qsize; size_t device_size, driver_size; @@ -656,6 +726,7 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize) memset(svq->vring.desc, 0, driver_size); 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); event_notifier_set_handler(&svq->hdev_call, vhost_svq_handle_call); return g_steal_pointer(&svq); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 0e5c00ed7e..276a559649 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -209,6 +209,18 @@ static void vhost_vdpa_listener_region_add(MemoryListe= ner *listener, vaddr, section->readonly); =20 llsize =3D int128_sub(llend, int128_make64(iova)); + if (v->shadow_vqs_enabled) { + DMAMap mem_region =3D { + .translated_addr =3D (hwaddr)vaddr, + .size =3D int128_get64(llsize) - 1, + .perm =3D IOMMU_ACCESS_FLAG(true, section->readonly), + }; + + int r =3D vhost_iova_tree_map_alloc(v->iova_tree, &mem_region); + assert(r =3D=3D IOVA_OK); + + iova =3D mem_region.iova; + } =20 vhost_vdpa_iotlb_batch_begin_once(v); ret =3D vhost_vdpa_dma_map(v, iova, int128_get64(llsize), @@ -261,6 +273,20 @@ static void vhost_vdpa_listener_region_del(MemoryListe= ner *listener, =20 llsize =3D int128_sub(llend, int128_make64(iova)); =20 + if (v->shadow_vqs_enabled) { + const DMAMap *result; + const void *vaddr =3D memory_region_get_ram_ptr(section->mr) + + section->offset_within_region + + (iova - section->offset_within_address_space); + DMAMap mem_region =3D { + .translated_addr =3D (hwaddr)vaddr, + .size =3D int128_get64(llsize) - 1, + }; + + result =3D vhost_iova_tree_find_iova(v->iova_tree, &mem_region); + iova =3D result->iova; + vhost_iova_tree_remove(v->iova_tree, &mem_region); + } vhost_vdpa_iotlb_batch_begin_once(v); ret =3D vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize)); if (ret) { @@ -783,33 +809,70 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *d= ev, /** * Unmap SVQ area in the device */ -static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, hwaddr iova, - hwaddr size) +static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, + const DMAMap *needle) { + const DMAMap *result =3D vhost_iova_tree_find_iova(v->iova_tree, needl= e); + hwaddr size; int r; =20 - size =3D ROUND_UP(size, qemu_real_host_page_size); - r =3D vhost_vdpa_dma_unmap(v, iova, size); + if (unlikely(!result)) { + error_report("Unable to find SVQ address to unmap"); + return false; + } + + size =3D ROUND_UP(result->size, qemu_real_host_page_size); + r =3D vhost_vdpa_dma_unmap(v, result->iova, size); return r =3D=3D 0; } =20 static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, const VhostShadowVirtqueue *svq) { + DMAMap needle; struct vhost_vdpa *v =3D dev->opaque; struct vhost_vring_addr svq_addr; - size_t device_size =3D vhost_svq_device_area_size(svq); - size_t driver_size =3D vhost_svq_driver_area_size(svq); bool ok; =20 vhost_svq_get_vring_addr(svq, &svq_addr); =20 - ok =3D vhost_vdpa_svq_unmap_ring(v, svq_addr.desc_user_addr, driver_si= ze); + needle =3D (DMAMap) { + .translated_addr =3D svq_addr.desc_user_addr, + }; + ok =3D vhost_vdpa_svq_unmap_ring(v, &needle); if (unlikely(!ok)) { return false; } =20 - return vhost_vdpa_svq_unmap_ring(v, svq_addr.used_user_addr, device_si= ze); + needle =3D (DMAMap) { + .translated_addr =3D svq_addr.used_user_addr, + }; + return vhost_vdpa_svq_unmap_ring(v, &needle); +} + +/** + * Map SVQ area in the device + * + * @v Vhost-vdpa device + * @needle The area to search iova + * @readonly Permissions of the area + */ +static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, const DMAMap *ne= edle, + bool readonly) +{ + hwaddr off; + const DMAMap *result =3D vhost_iova_tree_find_iova(v->iova_tree, needl= e); + int r; + + if (unlikely(!result)) { + error_report("Can't locate SVQ ring"); + return false; + } + + off =3D needle->translated_addr - result->translated_addr; + r =3D vhost_vdpa_dma_map(v, result->iova + off, needle->size, + (void *)needle->translated_addr, readonly); + return r =3D=3D 0; } =20 /** @@ -821,23 +884,29 @@ static bool vhost_vdpa_svq_unmap_rings(struct vhost_d= ev *dev, static bool vhost_vdpa_svq_map_rings(struct vhost_dev *dev, const VhostShadowVirtqueue *svq) { + DMAMap needle; struct vhost_vdpa *v =3D dev->opaque; struct vhost_vring_addr svq_addr; size_t device_size =3D vhost_svq_device_area_size(svq); size_t driver_size =3D vhost_svq_driver_area_size(svq); - int r; + bool ok; =20 vhost_svq_get_vring_addr(svq, &svq_addr); =20 - r =3D vhost_vdpa_dma_map(v, svq_addr.desc_user_addr, driver_size, - (void *)svq_addr.desc_user_addr, true); - if (unlikely(r !=3D 0)) { + needle =3D (DMAMap) { + .translated_addr =3D svq_addr.desc_user_addr, + .size =3D driver_size, + }; + ok =3D vhost_vdpa_svq_map_ring(v, &needle, true); + if (unlikely(!ok)) { return false; } =20 - r =3D vhost_vdpa_dma_map(v, svq_addr.used_user_addr, device_size, - (void *)svq_addr.used_user_addr, false); - return r =3D=3D 0; + needle =3D (DMAMap) { + .translated_addr =3D svq_addr.used_user_addr, + .size =3D device_size, + }; + return vhost_vdpa_svq_map_ring(v, &needle, false); } =20 static bool vhost_vdpa_svq_setup(struct vhost_dev *dev, @@ -1006,6 +1075,23 @@ static int vhost_vdpa_set_owner(struct vhost_dev *de= v) return vhost_vdpa_call(dev, VHOST_SET_OWNER, NULL); } =20 +static bool vhost_vdpa_svq_get_vq_region(struct vhost_vdpa *v, + unsigned long long addr, + uint64_t *iova_addr) +{ + const DMAMap needle =3D { + .translated_addr =3D addr, + }; + const DMAMap *translation =3D vhost_iova_tree_find_iova(v->iova_tree, + &needle); + if (!translation) { + return false; + } + + *iova_addr =3D translation->iova + (addr - translation->translated_add= r); + return true; +} + static void vhost_vdpa_vq_get_guest_addr(struct vhost_vring_addr *addr, struct vhost_virtqueue *vq) { @@ -1023,10 +1109,23 @@ static int vhost_vdpa_vq_get_addr(struct vhost_dev = *dev, assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); =20 if (v->shadow_vqs_enabled) { + struct vhost_vring_addr svq_addr; int idx =3D vhost_vdpa_get_vq_index(dev, addr->index); VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, idx= ); =20 - vhost_svq_get_vring_addr(svq, addr); + vhost_svq_get_vring_addr(svq, &svq_addr); + if (!vhost_vdpa_svq_get_vq_region(v, svq_addr.desc_user_addr, + &addr->desc_user_addr)) { + return -1; + } + if (!vhost_vdpa_svq_get_vq_region(v, svq_addr.avail_user_addr, + &addr->avail_user_addr)) { + return -1; + } + if (!vhost_vdpa_svq_get_vq_region(v, svq_addr.used_user_addr, + &addr->used_user_addr)) { + return -1; + } } else { vhost_vdpa_vq_get_guest_addr(addr, vq); } @@ -1095,13 +1194,37 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hd= ev, struct vhost_vdpa *v, =20 shadow_vqs =3D g_ptr_array_new_full(hdev->nvqs, vhost_psvq_free); for (unsigned n =3D 0; n < hdev->nvqs; ++n) { - VhostShadowVirtqueue *svq =3D vhost_svq_new(qsize); - + DMAMap device_region, driver_region; + struct vhost_vring_addr addr; + VhostShadowVirtqueue *svq =3D vhost_svq_new(qsize, v->iova_tree); if (unlikely(!svq)) { error_setg(errp, "Cannot create svq %u", n); return -1; } - g_ptr_array_add(v->shadow_vqs, svq); + + vhost_svq_get_vring_addr(svq, &addr); + driver_region =3D (DMAMap) { + .translated_addr =3D (hwaddr)addr.desc_user_addr, + + /* + * DMAMAp.size include the last byte included in the range, wh= ile + * sizeof marks one past it. Substract one byte to make them m= atch. + */ + .size =3D vhost_svq_driver_area_size(svq) - 1, + .perm =3D VHOST_ACCESS_RO, + }; + device_region =3D (DMAMap) { + .translated_addr =3D (hwaddr)addr.used_user_addr, + .size =3D vhost_svq_device_area_size(svq) - 1, + .perm =3D VHOST_ACCESS_RW, + }; + + r =3D vhost_iova_tree_map_alloc(v->iova_tree, &driver_region); + assert(r =3D=3D IOVA_OK); + r =3D vhost_iova_tree_map_alloc(v->iova_tree, &device_region); + assert(r =3D=3D IOVA_OK); + + g_ptr_array_add(shadow_vqs, svq); } =20 out: --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799665520243.11683516558548; Fri, 21 Jan 2022 13:14:25 -0800 (PST) Received: from localhost ([::1]:43900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1El-0006ev-NC for importer@patchew.org; Fri, 21 Jan 2022 16:14:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0ca-0000Qh-Do for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:33504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cY-00057M-P2 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:34:56 -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-345-gB1H9M0HPpKd2edPQWtq4w-1; Fri, 21 Jan 2022 15:34:52 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B7B7193F560; Fri, 21 Jan 2022 20:34:51 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DD0116A31; Fri, 21 Jan 2022 20:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797294; 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=Peb2qYMHqs1yxVoiu5MR4UQKXcEu0CdYaTPh6BniDB4=; b=UXja6QQZe2VSyuafW2GpC0Lug7Dn9+du4XbmVQ7X+5lhjzYb8fbtfdG/77bypinb5V5t+c qWstD/i1dupx/Bg2R4JzH463VYJX8VpPdXaGvtvpJ2D2CN0roE7fundmY3Nxg+8Jvkdc8A LAKHpJ9EUTxOFNagD4yOvZVJczBX5U4= X-MC-Unique: gB1H9M0HPpKd2edPQWtq4w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 24/31] vhost: Add vhost_svq_get_last_used_idx Date: Fri, 21 Jan 2022 21:27:26 +0100 Message-Id: <20220121202733.404989-25-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799667427100001 This way SVQ queues can be migrated. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index c6f67d6f76..a2b0c6434d 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -30,6 +30,7 @@ const EventNotifier *vhost_svq_get_svq_call_notifier( const VhostShadowVirtqueue *= svq); void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, struct vhost_vring_addr *addr); +uint16_t vhost_svq_get_last_used_idx(const VhostShadowVirtqueue *svq); uint16_t vhost_svq_get_num(const VhostShadowVirtqueue *svq); size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq); size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index c7888eb8cf..eb0a3fcb80 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -574,6 +574,14 @@ void vhost_svq_get_vring_addr(const VhostShadowVirtque= ue *svq, addr->used_user_addr =3D (uint64_t)svq->vring.used; } =20 +/** + * Get the next index that SVQ is going to consume from SVQ used ring. + */ +uint16_t vhost_svq_get_last_used_idx(const VhostShadowVirtqueue *svq) +{ + return svq->last_used_idx; +} + uint16_t vhost_svq_get_num(const VhostShadowVirtqueue *svq) { return svq->vring.num; --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642800109949521.3879279800868; Fri, 21 Jan 2022 13:21:49 -0800 (PST) Received: from localhost ([::1]:51980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1Lw-0003td-PB for importer@patchew.org; Fri, 21 Jan 2022 16:21:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0ci-0000V8-9t for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21946) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cg-00058v-LE for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:03 -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-524-wqf65r4CMjGgXrsHl8P5jg-1; Fri, 21 Jan 2022 15:34:58 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0D9D46860; Fri, 21 Jan 2022 20:34:56 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69A5F16A31; Fri, 21 Jan 2022 20:34:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797301; 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=XLW2vuPxrcLhBXtl8ugt4z/aPwC32xSyVJfwdFddz+s=; b=T8PNwogTEvCmsGrNjUmTWOiJHca4XDRkttDpD+tcMpX0WJsGgmUmNwuCpIOFqGdOuz3ycl VG8idFThf/xXbNlri3NKkg+rMnYNwnJCtqjKOMIBbzvTdH/cBfW8uD//ZsM9AalBpJ4oMu zTV7WE2uE3iQ4fb/r6GWD655EpQebkY= X-MC-Unique: wqf65r4CMjGgXrsHl8P5jg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 25/31] vdpa: Adapt vhost_vdpa_get_vring_base to SVQ Date: Fri, 21 Jan 2022 21:27:27 +0100 Message-Id: <20220121202733.404989-26-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642800111759100001 This is needed to achieve migration, so destination can restore its index. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 276a559649..887857c177 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -716,8 +716,17 @@ static int vhost_vdpa_set_vring_base(struct vhost_dev = *dev, static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, struct vhost_vring_state *ring) { + struct vhost_vdpa *v =3D dev->opaque; int ret; =20 + if (v->shadow_vqs_enabled) { + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, + ring->index); + + ring->num =3D vhost_svq_get_last_used_idx(svq); + return 0; + } + ret =3D vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring); trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num); return ret; --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798300584324.8721074159031; Fri, 21 Jan 2022 12:51:40 -0800 (PST) Received: from localhost ([::1]:56530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0sl-0001tj-EX for importer@patchew.org; Fri, 21 Jan 2022 15:51:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0co-0000Vh-4N for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23109) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cl-0005bk-Ji for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:09 -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-46-yEC3F6q6P7S6lT-YMENfmA-1; Fri, 21 Jan 2022 15:35:03 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D055A46861; Fri, 21 Jan 2022 20:35:01 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id E98C0E2C1; Fri, 21 Jan 2022 20:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797306; 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=XmCwl6Nz8JRbyOedP3rUAJKjLtNcb8z/YRVGc+oGDNY=; b=Ym5BsZ3ZaIDjoZTc0N3EIhur3cp9woeCOueBpXelBGBpBpY+iVvR0XGwGGRpKVmzB9bwlG EX91IYNwPaOGNQSgdNV2C/cj+AK8N1Tm+gK6IcV1djYDiyIIf/iC+rMtFG1Wtr92XeY+H2 05K5zwjvI1xQZaRV/RzaBHiSVXGxLQA= X-MC-Unique: yEC3F6q6P7S6lT-YMENfmA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 26/31] vdpa: Clear VHOST_VRING_F_LOG at vhost_vdpa_set_vring_addr in SVQ Date: Fri, 21 Jan 2022 21:27:28 +0100 Message-Id: <20220121202733.404989-27-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798302068100001 Doing so would cause the device to export writes to SVQ addresses, which are not part of the guest's IOVA. Like the previous patch, this is currently not possible since SVQ does not run if the device exports VHOST_VRING_F_LOG. But it's needed to enable migration with SVQ. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 887857c177..ab729b3371 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -660,10 +660,16 @@ static int vhost_vdpa_set_log_base(struct vhost_dev *= dev, uint64_t base, static int vhost_vdpa_set_vring_addr(struct vhost_dev *dev, struct vhost_vring_addr *addr) { + struct vhost_vdpa *v =3D dev->opaque; + trace_vhost_vdpa_set_vring_addr(dev, addr->index, addr->flags, addr->desc_user_addr, addr->used_user_= addr, addr->avail_user_addr, addr->log_guest_addr); + + if (v->shadow_vqs_enabled) { + addr->flags &=3D ~BIT_ULL(VHOST_VRING_F_LOG); + } return vhost_vdpa_call(dev, VHOST_SET_VRING_ADDR, addr); } =20 --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642798488917777.6062265121758; Fri, 21 Jan 2022 12:54:48 -0800 (PST) Received: from localhost ([::1]:36758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB0vn-0007lj-9j for importer@patchew.org; Fri, 21 Jan 2022 15:54:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0dF-0000Yg-Bl for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42235) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0cq-0005t6-Me for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:14 -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-628-c5TJ-PHPMbi7MNkCAJUILg-1; Fri, 21 Jan 2022 15:35:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B8DB101999D; Fri, 21 Jan 2022 20:35:07 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A64EE2C1; Fri, 21 Jan 2022 20:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797312; 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=cmdxcA6W425ma8qs8Zilfh3tlyUiY7XWyQL5X5ASM2k=; b=YYkhr5q3pKdD1iE6H/jHxyQO4zx/BE18N/HmE6ab9LsbGFplxKBWcPEuTtmNdRJIBGbXsX YssZC7XbXZCKVbyADDPNYRf29oIcZD0+kiDIx7AlPH4METGCH415tqrRsyOw4EyMigo6rq JRFL3JvYR9NeW1CBw5eIximyCIS9OfE= X-MC-Unique: c5TJ-PHPMbi7MNkCAJUILg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 27/31] vdpa: Never set log_base addr if SVQ is enabled Date: Fri, 21 Jan 2022 21:27:29 +0100 Message-Id: <20220121202733.404989-28-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642798491209100001 Setting the log address would make the device start reporting invalid dirty memory because the SVQ vrings are located in qemu's memory. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index ab729b3371..fb0a338baa 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -648,7 +648,8 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev,= uint8_t *config, static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) { - if (vhost_vdpa_one_time_request(dev)) { + struct vhost_vdpa *v =3D dev->opaque; + if (v->shadow_vqs_enabled || vhost_vdpa_one_time_request(dev)) { return 0; } =20 --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799906646925.0999179570695; Fri, 21 Jan 2022 13:18:26 -0800 (PST) Received: from localhost ([::1]:49062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1Ie-0001sa-Uc for importer@patchew.org; Fri, 21 Jan 2022 16:18:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0dJ-0000ar-92 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0dF-0005tV-7d for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:35:39 -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-68-Ytj1KbFdOYG7ug1COfmKpQ-1; Fri, 21 Jan 2022 15:35:18 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDA998189CC; Fri, 21 Jan 2022 20:35:16 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82221194B9; Fri, 21 Jan 2022 20:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797321; 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=KqKu9gV12BSP7bp/DmZuehYWhm/L06WrJinEvvM6P9c=; b=TDhZ9+qzRZIdrHBp0lw8c99rdpet+NTJZPmSfNSeDg0hh6mTyua0qvjAo8SNzr6aPMc4KH A721StLkR7P7+2m7/+OhgySciMXzsK+3Zu4PufNzfDd4+v7Tg01EZq5yuSzTwx7z8Yulzm 8uKvz4x2rbmmsRB3gaWUYIzwOzscbLk= X-MC-Unique: Ytj1KbFdOYG7ug1COfmKpQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ Date: Fri, 21 Jan 2022 21:27:30 +0100 Message-Id: <20220121202733.404989-29-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799908773100001 SVQ is able to log the dirty bits by itself, so let's use it to not block migration. Also, ignore set and clear of VHOST_F_LOG_ALL on set_features if SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region. The log region is still allocated. Future changes might skip that, but this series is already long enough. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index fb0a338baa..75090d65e8 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *= dev, uint64_t *features) if (ret =3D=3D 0 && v->shadow_vqs_enabled) { /* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features(features); + + /* Add SVQ logging capabilities */ + *features |=3D BIT_ULL(VHOST_F_LOG_ALL); } =20 return ret; @@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev = *dev, =20 if (v->shadow_vqs_enabled) { uint64_t dev_features, svq_features, acked_features; + uint8_t status =3D 0; bool ok; =20 + ret =3D vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status); + if (unlikely(ret)) { + return ret; + } + + if (status & VIRTIO_CONFIG_S_DRIVER_OK) { + /* + * vhost is trying to enable or disable _F_LOG, and the device + * would report wrong dirty pages. SVQ handles it. + */ + return 0; + } + + /* We must not ack _F_LOG if SVQ is enabled */ + features &=3D ~BIT_ULL(VHOST_F_LOG_ALL); + ret =3D vhost_vdpa_get_dev_features(dev, &dev_features); if (ret !=3D 0) { error_report("Can't get vdpa device features, got (%d)", ret); --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642800234723304.63702451692825; Fri, 21 Jan 2022 13:23:54 -0800 (PST) Received: from localhost ([::1]:56598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1Nw-00078s-Vd for importer@patchew.org; Fri, 21 Jan 2022 16:23:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0ef-0002De-IA for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:37:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24984) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0eV-0006WW-GN for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:37:00 -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-90-CKtvwQ1YOSKjpk_6GAG7Kw-1; Fri, 21 Jan 2022 15:36:50 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D17C1091DA5; Fri, 21 Jan 2022 20:36:48 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B0E416A31; Fri, 21 Jan 2022 20:35:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797413; 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=1n9AQ37W0b14xZXad/BfVMGr5Wd3DU/6I9HeKxTuVj0=; b=NXIY+uhKkHmIZ+kRdqI9+aFCt5nINyqjkhZ59O7B32gbicRLW+8z73aaJ8jpVz2F5blExQ eOOtCVit1OQP4uadwypB8NS4/F7MYU7r8q8FDmqakvwnknKzvOYOspOgraJ+973D6Q908U EIErHi5DxLKmTjKZo6Pl3E+JmvEOwPo= X-MC-Unique: CKtvwQ1YOSKjpk_6GAG7Kw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 29/31] vdpa: Make ncs autofree Date: Fri, 21 Jan 2022 21:27:31 +0100 Message-Id: <20220121202733.404989-30-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642800237220100001 Simplifying memory management. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 4125d13118..4befba5cc7 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, { const NetdevVhostVDPAOptions *opts; int vdpa_device_fd; - NetClientState **ncs, *nc; + g_autofree NetClientState **ncs =3D NULL; + NetClientState *nc; int queue_pairs, i, has_cvq =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); @@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, goto err; } =20 - g_free(ncs); return 0; =20 err: @@ -310,7 +310,6 @@ err: qemu_del_net_client(ncs[0]); } qemu_close(vdpa_device_fd); - g_free(ncs); =20 return -1; } --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799232210549.3633817750888; Fri, 21 Jan 2022 13:07:12 -0800 (PST) Received: from localhost ([::1]:57844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB17n-0005Pt-7u for importer@patchew.org; Fri, 21 Jan 2022 16:07:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0fN-0003Uc-OW for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:37:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32411) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0fL-0006a2-O6 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:37:49 -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-402-KNv-7i2COu-QdJVZMNg_-w-1; Fri, 21 Jan 2022 15:37:46 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D3978145E1; Fri, 21 Jan 2022 20:37:44 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAADFE2D3; Fri, 21 Jan 2022 20:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797467; 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=TIMMZNZ/3FgLlCdpxCiJ5q46jj5saAuhvAUSPRz+8U0=; b=huxpWX1+QY5c0r9gMHMWCbMZtD+YJUqDUu4+5uMA2OlGlPoug/17dtAvDSWcQxwW3sfD2Q uo8Uc6nluj4Nlr6isz658TOWEUMBKQs4TJGnKHmgmhqL+p+9+msHvvFVnCiW8G+L5t4MIi 54dTxwbkTBXoJSIBGpEIOmVBY1BCv2k= X-MC-Unique: KNv-7i2COu-QdJVZMNg_-w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 30/31] vdpa: Move vhost_vdpa_get_iova_range to net/vhost-vdpa.c Date: Fri, 21 Jan 2022 21:27:32 +0100 Message-Id: <20220121202733.404989-31-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799233959100001 Since it's a device property, it can be done in net/. This helps SVQ to allocate the rings in vdpa device initialization, rather than delay that. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 15 --------------- net/vhost-vdpa.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 75090d65e8..2491c05d29 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -350,19 +350,6 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev= , uint8_t status) return 0; } =20 -static void vhost_vdpa_get_iova_range(struct vhost_vdpa *v) -{ - int ret =3D vhost_vdpa_call(v->dev, VHOST_VDPA_GET_IOVA_RANGE, - &v->iova_range); - if (ret !=3D 0) { - v->iova_range.first =3D 0; - v->iova_range.last =3D UINT64_MAX; - } - - trace_vhost_vdpa_get_iova_range(v->dev, v->iova_range.first, - v->iova_range.last); -} - static bool vhost_vdpa_one_time_request(struct vhost_dev *dev) { struct vhost_vdpa *v =3D dev->opaque; @@ -1295,8 +1282,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, voi= d *opaque, Error **errp) goto err; } =20 - vhost_vdpa_get_iova_range(v); - if (vhost_vdpa_one_time_request(dev)) { return 0; } diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 4befba5cc7..cc9cecf8d1 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -22,6 +22,7 @@ #include #include #include "standard-headers/linux/virtio_net.h" +#include "standard-headers/linux/vhost_types.h" #include "monitor/monitor.h" #include "hw/virtio/vhost.h" =20 @@ -187,13 +188,25 @@ static NetClientInfo net_vhost_vdpa_info =3D { .check_peer_type =3D vhost_vdpa_check_peer_type, }; =20 +static void vhost_vdpa_get_iova_range(int fd, + struct vhost_vdpa_iova_range *iova_r= ange) +{ + int ret =3D ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range); + + if (ret < 0) { + iova_range->first =3D 0; + iova_range->last =3D UINT64_MAX; + } +} + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, - const char *device, - const char *name, - int vdpa_device_fd, - int queue_pair_index, - int nvqs, - bool is_datapath) + const char *device, + const char *name, + int vdpa_device_fd, + int queue_pair_index, + int nvqs, + bool is_datapath, + struct vhost_vdpa_iova_range iova_r= ange) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -211,6 +224,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, =20 s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; + s->vhost_vdpa.iova_range =3D iova_range; ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); @@ -267,6 +281,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; int queue_pairs, i, has_cvq =3D 0; + struct vhost_vdpa_iova_range iova_range; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); opts =3D &netdev->u.vhost_vdpa; @@ -286,19 +301,20 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, qemu_close(vdpa_device_fd); return queue_pairs; } + vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); =20 ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); =20 for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true); + vdpa_device_fd, i, 2, true, iova_rang= e); if (!ncs[i]) goto err; } =20 if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false); + vdpa_device_fd, i, 1, false, iova_range); if (!nc) goto err; } --=20 2.27.0 From nobody Fri May 3 05:35:58 2024 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 1642799520050185.05845353698066; Fri, 21 Jan 2022 13:12:00 -0800 (PST) Received: from localhost ([::1]:38318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nB1CP-0002mi-Pb for importer@patchew.org; Fri, 21 Jan 2022 16:11:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0g6-0003tS-86 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:38:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37190) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nB0g3-00078s-VM for qemu-devel@nongnu.org; Fri, 21 Jan 2022 15:38:33 -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-496-Ftd5LJo0Mpm09sDyIJm2Dw-1; Fri, 21 Jan 2022 15:38:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB1238145E0; Fri, 21 Jan 2022 20:38:25 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3C07E2D3; Fri, 21 Jan 2022 20:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642797510; 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=4LGql8TZY0s6ZwIZaFQtscJKDocmuPbrDn2lBnqG4fU=; b=PoZ14edl49IFX+cq6gbHWB0fPpz16G8L9KQn0uezrjBABMzLdXY1lPbEE5e0sJaVTQESA7 VTAXtie9nwM9pLQJSBvypRKNMpVah53ru6SUXhLZy2f6RwUiSlcyh88HcE6mSSsSmqWbpY M4AKf1ka49IkJQTdw9vhISgewexqoao= X-MC-Unique: Ftd5LJo0Mpm09sDyIJm2Dw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Subject: [PATCH 31/31] vdpa: Add x-svq to NetdevVhostVDPAOptions Date: Fri, 21 Jan 2022 21:27:33 +0100 Message-Id: <20220121202733.404989-32-eperezma@redhat.com> In-Reply-To: <20220121202733.404989-1-eperezma@redhat.com> References: <20220121202733.404989-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 , Juan Quintela , Richard Henderson , Markus Armbruster , Gautam Dawar , virtualization@lists.linux-foundation.org, Eduardo Habkost , Harpreet Singh Anand , Xiao W Wang , Peter Xu , Stefan Hajnoczi , Eli Cohen , Paolo Bonzini , Zhu Lingshan , Eric Blake , Stefano Garzarella 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: 1642799521634100001 Finally offering the possibility to enable SVQ from the command line. Signed-off-by: Eugenio P=C3=A9rez --- qapi/net.json | 5 ++++- net/vhost-vdpa.c | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index 7fab2e7cd8..d243701527 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -445,12 +445,15 @@ # @queues: number of queues to be created for multiqueue vhost-vdpa # (default: 1) # +# @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.0) +# # Since: 5.1 ## { 'struct': 'NetdevVhostVDPAOptions', 'data': { '*vhostdev': 'str', - '*queues': 'int' } } + '*queues': 'int', + '*x-svq': 'bool' } } =20 ## # @NetClientDriver: diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index cc9cecf8d1..9e443fa715 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -128,7 +128,11 @@ err_init: static void vhost_vdpa_cleanup(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_dev *dev =3D s->vhost_vdpa.dev; =20 + if (dev && dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { + g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); + } if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); @@ -206,7 +210,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, int queue_pair_index, int nvqs, bool is_datapath, - struct vhost_vdpa_iova_range iova_r= ange) + bool svq, + struct vhost_vdpa_iova_range iova_r= ange, + VhostIOVATree *iova_tree) { NetClientState *nc =3D NULL; VhostVDPAState *s; @@ -225,6 +231,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientSta= te *peer, s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; s->vhost_vdpa.iova_range =3D iova_range; + s->vhost_vdpa.shadow_vqs_enabled =3D svq; + s->vhost_vdpa.iova_tree =3D iova_tree; ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); @@ -281,6 +289,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const cha= r *name, g_autofree NetClientState **ncs =3D NULL; NetClientState *nc; int queue_pairs, i, has_cvq =3D 0; + g_autoptr(VhostIOVATree) iova_tree =3D NULL; struct vhost_vdpa_iova_range iova_range; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); @@ -302,29 +311,41 @@ int net_init_vhost_vdpa(const Netdev *netdev, const c= har *name, return queue_pairs; } vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range); + if (opts->x_svq) { + if (has_cvq) { + error_setg(errp, "vdpa svq does not work with cvq"); + goto err_svq; + } + iova_tree =3D vhost_iova_tree_new(iova_range.first, iova_range.las= t); + } =20 ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); =20 for (i =3D 0; i < queue_pairs; i++) { ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 2, true, iova_rang= e); + vdpa_device_fd, i, 2, true, opts->x_s= vq, + iova_range, iova_tree); if (!ncs[i]) goto err; } =20 if (has_cvq) { nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, - vdpa_device_fd, i, 1, false, iova_range); + vdpa_device_fd, i, 1, false, opts->x_svq, + iova_range, iova_tree); if (!nc) goto err; } =20 + iova_tree =3D NULL; return 0; =20 err: if (i) { qemu_del_net_client(ncs[0]); } + +err_svq: qemu_close(vdpa_device_fd); =20 return -1; --=20 2.27.0