From nobody Mon Nov 25 02:34:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717802127; cv=none; d=zohomail.com; s=zohoarc; b=Agr4ZXnZkoPIq7nc5sxgJf4WnrTjNDJCD6yg5kDoFKPPkTt7VzHErRUasq1So46jeXRnIJdbW9znqIB899w9WcCAyUg/byN/jH60QhLdZ4NVgE8MhkdLWeVu/wkA+33TyPdieU01H1Wt46dBznNpf6nLUcpe/kNJ/m2t4X21Ujc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717802127; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8m2kYAzpkGJ3Ey1H6NVbak4uUSK3PzHJop1nhkRKo+c=; b=I0xAFIZ1RlRalpVB+WRBzpS61NPTgCdVB9IaW/QA33zBkbDp8p4xD47AA+KVw1w9YrdOYX1vOUD/AaFUZuWaRegReD0mPbE+dHcC53tf6XQLT5P8IBe/i9/A6uIuB1/waMwF89+7E/876GIAQzPVSLCCXSFxnDaHf5Yo0Me1VpM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717802127107895.6596374091375; Fri, 7 Jun 2024 16:15:27 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFakc-00054p-1y; Fri, 07 Jun 2024 10:39:30 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFaka-0004rC-0L for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFakY-0003MS-J8 for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:27 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-jz2ezpk1MUmu6D9BnI5Uxw-1; Fri, 07 Jun 2024 10:39:22 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4D1EC1956063; Fri, 7 Jun 2024 14:39:21 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 481B61956048; Fri, 7 Jun 2024 14:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717771166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8m2kYAzpkGJ3Ey1H6NVbak4uUSK3PzHJop1nhkRKo+c=; b=AyYzPR0L5hvqIZhIks6ViO8YA10LmppVikCkiqfblIxRHBLkvJokbhlOynoL5zN6WQNU7z MpzySzJPH2Yp7RpPGFLwv0aY1AP1dHWxoPtVRH7rGs5g1cHN/S4+mrgPVFTadkFR8AxYuN Ld8i7jUfqjgjKffkM63fIzt7Gq92smY= X-MC-Unique: jz2ezpk1MUmu6D9BnI5Uxw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, imammedo@redhat.com, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [RFC v2 1/7] HostIOMMUDevice: Store the VFIO/VDPA agent Date: Fri, 7 Jun 2024 16:37:21 +0200 Message-ID: <20240607143905.765133-2-eric.auger@redhat.com> In-Reply-To: <20240607143905.765133-1-eric.auger@redhat.com> References: <20240607143905.765133-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717802127370100003 Content-Type: text/plain; charset="utf-8" Store the agent device (VFIO or VDPA) in the host IOMMU device. This will allow easy access to some of its resources. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan =20 --- include/sysemu/host_iommu_device.h | 1 + hw/vfio/container.c | 1 + hw/vfio/iommufd.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index a57873958b..3e5f058e7b 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -34,6 +34,7 @@ struct HostIOMMUDevice { Object parent_obj; =20 char *name; + void *agent; /* pointer to agent device, ie. VFIO or VDPA device */ HostIOMMUDeviceCaps caps; }; =20 diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 26e6f7fb4f..b728b978a2 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1145,6 +1145,7 @@ static bool hiod_legacy_vfio_realize(HostIOMMUDevice = *hiod, void *opaque, =20 hiod->name =3D g_strdup(vdev->name); hiod->caps.aw_bits =3D vfio_device_get_aw_bits(vdev); + hiod->agent =3D opaque; =20 return true; } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 409ed3dcc9..dbdae1adbb 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -631,6 +631,8 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *= hiod, void *opaque, struct iommu_hw_info_vtd vtd; } data; =20 + hiod->agent =3D opaque; + if (!iommufd_backend_get_device_info(vdev->iommufd, vdev->devid, &type, &data, sizeof(data), errp)= ) { return false; --=20 2.41.0 From nobody Mon Nov 25 02:34:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717804271; cv=none; d=zohomail.com; s=zohoarc; b=kuSaedgIQvLHpNyU0oIl3CQ44fExK5whnko1nTb8rpi8+YaWf5RVkELhupZN6z9ilKTAVCAoVBWKSlgh4/dDJnLQjHGEh5aqKKJQf8GfD9W72Gy/3eJD9rOHTs8zUwAsEcJMSqy7N/CwsN2aJFf/vmRXKF+zxdG+fr7L+t/9+HM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717804271; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sxoYtCwqn6c+3/9Ce6QALKIyPjypJJl1PydGzJDqgAc=; b=UW5RcbTXI6gAPzWxlVou2Sd2i/D+bBiZYyHxU/7woFMP9zfNmWYZBeoIMgxEwc3E3fs82UQi8VgYlKs/JyiyH2jYfEBzTUYcazDrJt+F5e+NDRCQhsWdg+o4oEY9zHtORYirCrhb9MAJugxIAmy0qHzf0pxdEuViAZvmXsF+33U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717804271568431.0485660040189; Fri, 7 Jun 2024 16:51:11 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFakj-0005kT-I8; Fri, 07 Jun 2024 10:39:37 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFaki-0005cy-Ky for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFakh-0003Oa-2i for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:36 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-JNvzNWrMMkeB4zzqKL3pMA-1; Fri, 07 Jun 2024 10:39:28 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A7D7D1955F36; Fri, 7 Jun 2024 14:39:26 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 81D1A1956050; Fri, 7 Jun 2024 14:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717771174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sxoYtCwqn6c+3/9Ce6QALKIyPjypJJl1PydGzJDqgAc=; b=AkOdpJlvTIHM3limNwW7n7xsOYYOme78iQbY9I1fbWjPYJwCwPajSVHUp5lNl6zdD8UFbB KqcNDbNZopG3h3Jqh766mI8o3JQcLV7pn1RRx5Vgqi1nTqd4xYoQJGkQH7x+mMxFt541Up ZrfFisQ94u47ZoD0NDjEbVZx2+re8eU= X-MC-Unique: JNvzNWrMMkeB4zzqKL3pMA-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, imammedo@redhat.com, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [RFC v2 2/7] virtio-iommu: Implement set|unset]_iommu_device() callbacks Date: Fri, 7 Jun 2024 16:37:22 +0200 Message-ID: <20240607143905.765133-3-eric.auger@redhat.com> In-Reply-To: <20240607143905.765133-1-eric.auger@redhat.com> References: <20240607143905.765133-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717804272126100001 Content-Type: text/plain; charset="utf-8" Implement PCIIOMMUOPs [set|unset]_iommu_device() callbacks. In set(), a VirtioHostIOMMUDevice is allocated which holds a reference to the HostIOMMUDevice. This object is stored in a hash table indexed by PCI BDF. The handle to the Host IOMMU device will allow to retrieve information related to the physical IOMMU. Signed-off-by: Eric Auger --- include/hw/virtio/virtio-iommu.h | 9 ++++ hw/virtio/virtio-iommu.c | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-io= mmu.h index 83a52cc446..4f664ea0c4 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -45,6 +45,14 @@ typedef struct IOMMUDevice { bool probe_done; } IOMMUDevice; =20 +typedef struct VirtioHostIOMMUDevice { + void *viommu; + PCIBus *bus; + uint8_t devfn; + HostIOMMUDevice *dev; + QLIST_ENTRY(VirtioHostIOMMUDevice) next; +} VirtioHostIOMMUDevice; + typedef struct IOMMUPciBus { PCIBus *bus; IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc= */ @@ -57,6 +65,7 @@ struct VirtIOIOMMU { struct virtio_iommu_config config; uint64_t features; GHashTable *as_by_busptr; + GHashTable *host_iommu_devices; IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX]; PCIBus *primary_bus; ReservedRegion *prop_resv_regions; diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 1326c6ec41..0680a357f0 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -28,6 +28,7 @@ #include "sysemu/kvm.h" #include "sysemu/reset.h" #include "sysemu/sysemu.h" +#include "sysemu/host_iommu_device.h" #include "qemu/reserved-region.h" #include "qemu/units.h" #include "qapi/error.h" @@ -69,6 +70,11 @@ typedef struct VirtIOIOMMUMapping { uint32_t flags; } VirtIOIOMMUMapping; =20 +struct hiod_key { + PCIBus *bus; + uint8_t devfn; +}; + static inline uint16_t virtio_iommu_get_bdf(IOMMUDevice *dev) { return PCI_BUILD_BDF(pci_bus_num(dev->bus), dev->devfn); @@ -462,8 +468,86 @@ static AddressSpace *virtio_iommu_find_add_as(PCIBus *= bus, void *opaque, return &sdev->as; } =20 +static gboolean hiod_equal(gconstpointer v1, gconstpointer v2) +{ + const struct hiod_key *key1 =3D v1; + const struct hiod_key *key2 =3D v2; + + return (key1->bus =3D=3D key2->bus) && (key1->devfn =3D=3D key2->devfn= ); +} + +static guint hiod_hash(gconstpointer v) +{ + const struct hiod_key *key =3D v; + guint value =3D (guint)(uintptr_t)key->bus; + + return (guint)(value << 8 | key->devfn); +} + +static VirtioHostIOMMUDevice * +get_host_iommu_device(VirtIOIOMMU *viommu, PCIBus *bus, int devfn) { + struct hiod_key key =3D { + .bus =3D bus, + .devfn =3D devfn, + }; + + return g_hash_table_lookup(viommu->host_iommu_devices, &key); +} + +static bool virtio_iommu_set_iommu_device(PCIBus *bus, void *opaque, int d= evfn, + HostIOMMUDevice *hiod, Error **e= rrp) +{ + VirtIOIOMMU *viommu =3D opaque; + VirtioHostIOMMUDevice *vhiod; + struct hiod_key *new_key; + + assert(hiod); + + vhiod =3D get_host_iommu_device(viommu, bus, devfn); + if (vhiod) { + error_setg(errp, "VirtioHostIOMMUDevice already exists"); + return false; + } + + vhiod =3D g_malloc0(sizeof(VirtioHostIOMMUDevice)); + vhiod->bus =3D bus; + vhiod->devfn =3D (uint8_t)devfn; + vhiod->viommu =3D viommu; + vhiod->dev =3D hiod; + + new_key =3D g_malloc(sizeof(*new_key)); + new_key->bus =3D bus; + new_key->devfn =3D devfn; + + object_ref(hiod); + g_hash_table_insert(viommu->host_iommu_devices, new_key, vhiod); + + return true; +} + +static void +virtio_iommu_unset_iommu_device(PCIBus *bus, void *opaque, int devfn) +{ + VirtIOIOMMU *viommu =3D opaque; + VirtioHostIOMMUDevice *vhiod; + struct hiod_key key =3D { + .bus =3D bus, + .devfn =3D devfn, + }; + + vhiod =3D g_hash_table_lookup(viommu->host_iommu_devices, &key); + if (!vhiod) { + return; + } + + g_hash_table_remove(viommu->host_iommu_devices, &key); + object_unref(vhiod->dev); +} + static const PCIIOMMUOps virtio_iommu_ops =3D { .get_address_space =3D virtio_iommu_find_add_as, + .set_iommu_device =3D virtio_iommu_set_iommu_device, + .unset_iommu_device =3D virtio_iommu_unset_iommu_device, }; =20 static int virtio_iommu_attach(VirtIOIOMMU *s, @@ -1357,6 +1441,9 @@ static void virtio_iommu_device_realize(DeviceState *= dev, Error **errp) =20 s->as_by_busptr =3D g_hash_table_new_full(NULL, NULL, NULL, g_free); =20 + s->host_iommu_devices =3D g_hash_table_new_full(hiod_hash, hiod_equal, + g_free, g_free); + if (s->primary_bus) { pci_setup_iommu(s->primary_bus, &virtio_iommu_ops, s); } else { --=20 2.41.0 From nobody Mon Nov 25 02:34:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717803012; cv=none; d=zohomail.com; s=zohoarc; b=SXX5f+dpP/EA2D25z1cyNZTOooQGkVhrZDKVBNMulx9Cvd8dZ0fQ/daIGQgskH7tjGL/CSn/TEUTNo3iizp1eAsPUt4/BvHYR/UmMFc29l7C8WfdXdUEzamZjRc+sCTx/zBltj0lXDuMZNStgSJcjPQ17MgO0Sx5CBRuTsHmGzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717803012; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eSM5FRhnse3Lv4Qk6nprGOWP6AKz6doiUgfqyn8MOXg=; b=XPKH47++eW0nBjUYfsyQjPJvqzJ/tiwNj80RSd5sR1uvyZsPvIQC2auBgrZ8DBa1t/vj2PztznB/1VwpYTcncx1YK/N9dyjnDpI036FeGNsgAsmZO6Y6g8dOg8/nllZ/e1u7eelzLbq5VZPYJqR/aAGope5OltMxTL5jMg5/1Lk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717803012314771.2268296566881; Fri, 7 Jun 2024 16:30:12 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFakn-00065X-AE; Fri, 07 Jun 2024 10:39:41 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFakl-00064L-GL for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFakk-0003Ot-0I for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:39 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-356-mSd1nHcBOq6ZPOvqG4jeSw-1; Fri, 07 Jun 2024 10:39:34 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9767719560B9; Fri, 7 Jun 2024 14:39:32 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 069D71956048; Fri, 7 Jun 2024 14:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717771177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eSM5FRhnse3Lv4Qk6nprGOWP6AKz6doiUgfqyn8MOXg=; b=VpHP7AjSb3SqyxbLlHeOFDbfzadhvZIsZhXLx7vJbB1xBVQbfqJNszNlbvvzjMunRxc8mE O/ZhqCa+YnI7vIq51cfOYixI8ZCc1ZerP85SvurXa6CGI0DcleG5SXzUA04CLZKKqpTtNn xHzo08JQ9OwNiyU14Rk+2DUz/IrkeWc= X-MC-Unique: mSd1nHcBOq6ZPOvqG4jeSw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, imammedo@redhat.com, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [RFC v2 3/7] HostIOMMUDevice: Introduce get_iova_ranges callback Date: Fri, 7 Jun 2024 16:37:23 +0200 Message-ID: <20240607143905.765133-4-eric.auger@redhat.com> In-Reply-To: <20240607143905.765133-1-eric.auger@redhat.com> References: <20240607143905.765133-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717803012741100001 Content-Type: text/plain; charset="utf-8" Introduce a new HostIOMMUDevice callback that allows to retrieve the usable IOVA ranges. Implement this callback in the legacy VFIO and IOMMUFD VFIO host iommu devices. This relies on the VFIODevice agent's base container iova_ranges resource. Signed-off-by: Eric Auger --- include/sysemu/host_iommu_device.h | 8 ++++++++ hw/vfio/container.c | 14 ++++++++++++++ hw/vfio/iommufd.c | 14 ++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/include/sysemu/host_iommu_device.h b/include/sysemu/host_iommu= _device.h index 3e5f058e7b..40e0fa13ef 100644 --- a/include/sysemu/host_iommu_device.h +++ b/include/sysemu/host_iommu_device.h @@ -80,6 +80,14 @@ struct HostIOMMUDeviceClass { * i.e., HOST_IOMMU_DEVICE_CAP_AW_BITS. */ int (*get_cap)(HostIOMMUDevice *hiod, int cap, Error **errp); + /** + * @get_iova_ranges: Return the list of usable iova_ranges along with + * @hiod Host IOMMU device + * + * @hiod: handle to the host IOMMU device + * @errp: error handle + */ + GList* (*get_iova_ranges)(HostIOMMUDevice *hiod, Error **errp); }; =20 /* diff --git a/hw/vfio/container.c b/hw/vfio/container.c index b728b978a2..edd0df6262 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -1164,12 +1164,26 @@ static int hiod_legacy_vfio_get_cap(HostIOMMUDevice= *hiod, int cap, } } =20 +static GList * +hiod_legacy_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) +{ + VFIODevice *vdev =3D hiod->agent; + GList *l =3D NULL; + + if (vdev && vdev->bcontainer) { + l =3D g_list_copy(vdev->bcontainer->iova_ranges); + } + + return l; +} + static void hiod_legacy_vfio_class_init(ObjectClass *oc, void *data) { HostIOMMUDeviceClass *hioc =3D HOST_IOMMU_DEVICE_CLASS(oc); =20 hioc->realize =3D hiod_legacy_vfio_realize; hioc->get_cap =3D hiod_legacy_vfio_get_cap; + hioc->get_iova_ranges =3D hiod_legacy_vfio_get_iova_ranges; }; =20 static const TypeInfo types[] =3D { diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index dbdae1adbb..1706784063 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -645,11 +645,25 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice= *hiod, void *opaque, return true; } =20 +static GList * +hiod_iommufd_vfio_get_iova_ranges(HostIOMMUDevice *hiod, Error **errp) +{ + VFIODevice *vdev =3D hiod->agent; + GList *l =3D NULL; + + if (vdev && vdev->bcontainer) { + l =3D g_list_copy(vdev->bcontainer->iova_ranges); + } + + return l; +} + static void hiod_iommufd_vfio_class_init(ObjectClass *oc, void *data) { HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_CLASS(oc); =20 hiodc->realize =3D hiod_iommufd_vfio_realize; + hiodc->get_iova_ranges =3D hiod_iommufd_vfio_get_iova_ranges; }; =20 static const TypeInfo types[] =3D { --=20 2.41.0 From nobody Mon Nov 25 02:34:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717804735; cv=none; d=zohomail.com; s=zohoarc; b=f+U0B7c8ThA/yKJjEANAu5SNmdRB5q38YFUm1LUBFR384VeLCXyieYMaCyd8xxW99bhAuw1oIP2SgY30epHiSvEnE6G1AcNgOFvzwsCsxwhz5qVoW+6InCQPT9bA8KW1A4Mad19Cwh2IfuCFgJ0/0F5OAobo/Ux0D57uDCc2XTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717804735; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ekL5HzvnxBYBoYa78c8HNqOALcdyf3GJNi8rKTmSLDs=; b=QMno6Qldc4e2jmiIYYB0ODhg+OEcV9vy0i+ObECd/Tz/FFFGLhD09ZRE4UHvb8OeHFZc0ghptXOW12qzU6LhAGCapzUBqGoyTocF2mz1w7u8dRtW80wCGrXdrNuGPhCxBAkdYTB7ez5miTf7GwvbEdlsseDDm0muBM/Cl/W/km8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717804735647942.0790994514754; Fri, 7 Jun 2024 16:58:55 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFakt-0006X8-SA; Fri, 07 Jun 2024 10:39:47 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFaks-0006Wd-Qq for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFakr-0003PH-7f for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:46 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-yCXr66ovN9KRrXCF4P8TGw-1; Fri, 07 Jun 2024 10:39:39 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CA2FA19560BA; Fri, 7 Jun 2024 14:39:37 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CF23E1956048; Fri, 7 Jun 2024 14:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717771184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ekL5HzvnxBYBoYa78c8HNqOALcdyf3GJNi8rKTmSLDs=; b=MKSJkHcwUhHntpOre17/KxGTLlMqf+66HN0Im0PWJayN/6G3pKOat1IGHxmD8BOPZTsyEe mbZ5FYPuJDlN5x44KejEWRG0KO8krmjx6pXoG42AkHJ+6FG7LBqlDUJMYa6/8E/J1vefGe HQJsTSE6mbaHFaEGl1EnFxHo+i2g0zU= X-MC-Unique: yCXr66ovN9KRrXCF4P8TGw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, imammedo@redhat.com, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [RFC v2 4/7] virtio-iommu: Compute host reserved regions Date: Fri, 7 Jun 2024 16:37:24 +0200 Message-ID: <20240607143905.765133-5-eric.auger@redhat.com> In-Reply-To: <20240607143905.765133-1-eric.auger@redhat.com> References: <20240607143905.765133-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717804736069100001 Content-Type: text/plain; charset="utf-8" Compute the host reserved regions in virtio_iommu_set_iommu_device(). The usable IOVA regions are retrieved from the HOSTIOMMUDevice. The virtio_iommu_set_host_iova_ranges() helper turns usable regions into complementary reserved regions while testing the inclusion into existing ones. virtio_iommu_set_host_iova_ranges() reuse the implementation of virtio_iommu_set_iova_ranges() which will be removed in subsequent patches. rebuild_resv_regions() is just moved. Signed-off-by: Eric Auger --- hw/virtio/virtio-iommu.c | 151 ++++++++++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 34 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 0680a357f0..33e9682b83 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -494,12 +494,114 @@ get_host_iommu_device(VirtIOIOMMU *viommu, PCIBus *b= us, int devfn) { return g_hash_table_lookup(viommu->host_iommu_devices, &key); } =20 +/** + * rebuild_resv_regions: rebuild resv regions with both the + * info of host resv ranges and property set resv ranges + */ +static int rebuild_resv_regions(IOMMUDevice *sdev) +{ + GList *l; + int i =3D 0; + + /* free the existing list and rebuild it from scratch */ + g_list_free_full(sdev->resv_regions, g_free); + sdev->resv_regions =3D NULL; + + /* First add host reserved regions if any, all tagged as RESERVED */ + for (l =3D sdev->host_resv_ranges; l; l =3D l->next) { + ReservedRegion *reg =3D g_new0(ReservedRegion, 1); + Range *r =3D (Range *)l->data; + + reg->type =3D VIRTIO_IOMMU_RESV_MEM_T_RESERVED; + range_set_bounds(®->range, range_lob(r), range_upb(r)); + sdev->resv_regions =3D resv_region_list_insert(sdev->resv_regions,= reg); + trace_virtio_iommu_host_resv_regions(sdev->iommu_mr.parent_obj.nam= e, i, + range_lob(®->range), + range_upb(®->range)); + i++; + } + /* + * then add higher priority reserved regions set by the machine + * through properties + */ + add_prop_resv_regions(sdev); + return 0; +} + +static int virtio_iommu_set_host_iova_ranges(VirtIOIOMMU *s, PCIBus *bus, + int devfn, GList *iova_ranges, + Error **errp) +{ + IOMMUPciBus *sbus =3D g_hash_table_lookup(s->as_by_busptr, bus); + IOMMUDevice *sdev; + GList *current_ranges; + GList *l, *tmp, *new_ranges =3D NULL; + int ret =3D -EINVAL; + + if (!sbus) { + error_report("%s no sbus", __func__); + } + + sdev =3D sbus->pbdev[devfn]; + + current_ranges =3D sdev->host_resv_ranges; + + if (sdev->probe_done) { + error_setg(errp, + "%s: Notified about new host reserved regions after pro= be", + __func__); + goto out; + } + + /* check that each new resv region is included in an existing one */ + if (sdev->host_resv_ranges) { + range_inverse_array(iova_ranges, + &new_ranges, + 0, UINT64_MAX); + + for (tmp =3D new_ranges; tmp; tmp =3D tmp->next) { + Range *newr =3D (Range *)tmp->data; + bool included =3D false; + + for (l =3D current_ranges; l; l =3D l->next) { + Range * r =3D (Range *)l->data; + + if (range_contains_range(r, newr)) { + included =3D true; + break; + } + } + if (!included) { + goto error; + } + } + /* all new reserved ranges are included in existing ones */ + ret =3D 0; + goto out; + } + + range_inverse_array(iova_ranges, + &sdev->host_resv_ranges, + 0, UINT64_MAX); + rebuild_resv_regions(sdev); + + return 0; +error: + error_setg(errp, "%s Conflicting host reserved ranges set!", + __func__); +out: + g_list_free_full(new_ranges, g_free); + return ret; +} + static bool virtio_iommu_set_iommu_device(PCIBus *bus, void *opaque, int d= evfn, HostIOMMUDevice *hiod, Error **e= rrp) { VirtIOIOMMU *viommu =3D opaque; VirtioHostIOMMUDevice *vhiod; + HostIOMMUDeviceClass *hiodc =3D HOST_IOMMU_DEVICE_GET_CLASS(hiod); struct hiod_key *new_key; + GList *host_iova_ranges =3D NULL; =20 assert(hiod); =20 @@ -509,6 +611,20 @@ static bool virtio_iommu_set_iommu_device(PCIBus *bus,= void *opaque, int devfn, return false; } =20 + if (hiodc->get_iova_ranges) { + int ret; + host_iova_ranges =3D hiodc->get_iova_ranges(hiod, errp); + if (!host_iova_ranges) { + return true; /* some old kernels may not support that capabili= ty */ + } + ret =3D virtio_iommu_set_host_iova_ranges(viommu, bus, devfn, + host_iova_ranges, errp); + if (ret) { + g_list_free_full(host_iova_ranges, g_free); + return false; + } + } + vhiod =3D g_malloc0(sizeof(VirtioHostIOMMUDevice)); vhiod->bus =3D bus; vhiod->devfn =3D (uint8_t)devfn; @@ -521,6 +637,7 @@ static bool virtio_iommu_set_iommu_device(PCIBus *bus, = void *opaque, int devfn, =20 object_ref(hiod); g_hash_table_insert(viommu->host_iommu_devices, new_key, vhiod); + g_list_free_full(host_iova_ranges, g_free); =20 return true; } @@ -1243,40 +1360,6 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemo= ryRegion *mr, return 0; } =20 -/** - * rebuild_resv_regions: rebuild resv regions with both the - * info of host resv ranges and property set resv ranges - */ -static int rebuild_resv_regions(IOMMUDevice *sdev) -{ - GList *l; - int i =3D 0; - - /* free the existing list and rebuild it from scratch */ - g_list_free_full(sdev->resv_regions, g_free); - sdev->resv_regions =3D NULL; - - /* First add host reserved regions if any, all tagged as RESERVED */ - for (l =3D sdev->host_resv_ranges; l; l =3D l->next) { - ReservedRegion *reg =3D g_new0(ReservedRegion, 1); - Range *r =3D (Range *)l->data; - - reg->type =3D VIRTIO_IOMMU_RESV_MEM_T_RESERVED; - range_set_bounds(®->range, range_lob(r), range_upb(r)); - sdev->resv_regions =3D resv_region_list_insert(sdev->resv_regions,= reg); - trace_virtio_iommu_host_resv_regions(sdev->iommu_mr.parent_obj.nam= e, i, - range_lob(®->range), - range_upb(®->range)); - i++; - } - /* - * then add higher priority reserved regions set by the machine - * through properties - */ - add_prop_resv_regions(sdev); - return 0; -} - /** * virtio_iommu_set_iova_ranges: Conveys the usable IOVA ranges * --=20 2.41.0 From nobody Mon Nov 25 02:34:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717804393; cv=none; d=zohomail.com; s=zohoarc; b=M6FckgcVQkrG5UqoqthSBW0hWsmnpJESQ68UAmXyLqhP+h0VjR/PKqi8JCDmjl0kRP+OHjOom417CGlP2d59PbUgvhvPtlb9TWxERZ0gX0vdiLZfXJX90yIJK78weWOgV2Lqay/4L1g9VOhbUl6aA7M3iw0d8hvS5zAf3ycP1hM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717804393; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NZxtuEQbwcSWkjTtgaPcpq0g8+TJ5S9KsG5IajnwesQ=; b=k5iBrsOItmyx6beB+9NeCeAVKQTMS5X98Zs6VgXr6wZPDK7ls4D1Zu+szm5xzoL7M8QIIMdwogsENmvD0rAzjTztp0nmUf/zvUYqH93R7q+ErfP4j59D+xa1E+C8D2X0FXP8tfue8VaY9Up0iaoPoSzOIQZw1qCSU5l4h4Nr9pY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717804393600407.4612262504884; Fri, 7 Jun 2024 16:53:13 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFal0-0006rZ-TS; Fri, 07 Jun 2024 10:39:54 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFaky-0006m4-Sp for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFakx-0003Pi-CP for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:52 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-133-gT1PyPkvOFaDGANimmSrCw-1; Fri, 07 Jun 2024 10:39:46 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 62E9E19560BB; Fri, 7 Jun 2024 14:39:44 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8B99F1956048; Fri, 7 Jun 2024 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717771190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZxtuEQbwcSWkjTtgaPcpq0g8+TJ5S9KsG5IajnwesQ=; b=ZMEaHJ142OvevFzBmTi+uHvScW70ygBuO33dJqOepZM7xIH2BET9fF62vXW97T425dKKvH N2Udf4pSd+spkOI39qroAIv78Uckz+Ha9yz/Xf8h7z6J+WSH1tvpQSryk4K5c3IsUvKzZi LrBR2dHtp4/CkOpgOF1htP5eYQySav8= X-MC-Unique: gT1PyPkvOFaDGANimmSrCw-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, imammedo@redhat.com, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [RFC v2 5/7] virtio-iommu: Remove the implementation of iommu_set_iova_range Date: Fri, 7 Jun 2024 16:37:25 +0200 Message-ID: <20240607143905.765133-6-eric.auger@redhat.com> In-Reply-To: <20240607143905.765133-1-eric.auger@redhat.com> References: <20240607143905.765133-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717804394504100001 Content-Type: text/plain; charset="utf-8" Now that we use PCIIOMMUOps to convey information about usable IOVA ranges we do not to implement the iommu_set_iova_ranges IOMMU MR callback. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan =20 --- hw/virtio/virtio-iommu.c | 67 ---------------------------------------- 1 file changed, 67 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 33e9682b83..643bbb060b 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -1360,72 +1360,6 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemo= ryRegion *mr, return 0; } =20 -/** - * virtio_iommu_set_iova_ranges: Conveys the usable IOVA ranges - * - * The function turns those into reserved ranges. Once some - * reserved ranges have been set, new reserved regions cannot be - * added outside of the original ones. - * - * @mr: IOMMU MR - * @iova_ranges: list of usable IOVA ranges - * @errp: error handle - */ -static int virtio_iommu_set_iova_ranges(IOMMUMemoryRegion *mr, - GList *iova_ranges, - Error **errp) -{ - IOMMUDevice *sdev =3D container_of(mr, IOMMUDevice, iommu_mr); - GList *current_ranges =3D sdev->host_resv_ranges; - GList *l, *tmp, *new_ranges =3D NULL; - int ret =3D -EINVAL; - - /* check that each new resv region is included in an existing one */ - if (sdev->host_resv_ranges) { - range_inverse_array(iova_ranges, - &new_ranges, - 0, UINT64_MAX); - - for (tmp =3D new_ranges; tmp; tmp =3D tmp->next) { - Range *newr =3D (Range *)tmp->data; - bool included =3D false; - - for (l =3D current_ranges; l; l =3D l->next) { - Range * r =3D (Range *)l->data; - - if (range_contains_range(r, newr)) { - included =3D true; - break; - } - } - if (!included) { - goto error; - } - } - /* all new reserved ranges are included in existing ones */ - ret =3D 0; - goto out; - } - - if (sdev->probe_done) { - warn_report("%s: Notified about new host reserved regions after pr= obe", - mr->parent_obj.name); - } - - range_inverse_array(iova_ranges, - &sdev->host_resv_ranges, - 0, UINT64_MAX); - rebuild_resv_regions(sdev); - - return 0; -error: - error_setg(errp, "IOMMU mr=3D%s Conflicting host reserved ranges set!", - mr->parent_obj.name); -out: - g_list_free_full(new_ranges, g_free); - return ret; -} - static void virtio_iommu_system_reset(void *opaque) { VirtIOIOMMU *s =3D opaque; @@ -1751,7 +1685,6 @@ static void virtio_iommu_memory_region_class_init(Obj= ectClass *klass, imrc->replay =3D virtio_iommu_replay; imrc->notify_flag_changed =3D virtio_iommu_notify_flag_changed; imrc->iommu_set_page_size_mask =3D virtio_iommu_set_page_size_mask; - imrc->iommu_set_iova_ranges =3D virtio_iommu_set_iova_ranges; } =20 static const TypeInfo virtio_iommu_info =3D { --=20 2.41.0 From nobody Mon Nov 25 02:34:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717800405; cv=none; d=zohomail.com; s=zohoarc; b=ZaHRHuxXfKr3115nWy0tY9nT8kwefN4CEkcFZ37SiHd2mtkRjnsT2ihPWmrt9wLWPKcapzFeocsA4PbZ8YdHu+6Qgib2zZpfviCqQ6RkNsSSHuKgDnrYctLAbZ9tbLPRaTMTE3lDUaOQCTiGcP0J9Iy7Qc3Uqm2x8/QeozRix98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717800405; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZuVDDqob31KAlDwmKxXvSjL1dLO0Pn1dcxk60z/nri8=; b=XrRpnIQODAvps5E1dhjqgFbL9GvRz6TaM0f6+G05u5Sj0uTMZb2sxDbyZsIOsGa6g5ToVit53tXyZ9wJ2J4O+pacpfxGwm5DD/qw3OEBUd0BeuCg1/T1wHJgx17FKpiO5Q8C3huBOArLlNrQhO1+Nmy3AKUURRpJESqR9dQLr48= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717800405581303.9175411919663; Fri, 7 Jun 2024 15:46:45 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFal4-0006uP-Iu; Fri, 07 Jun 2024 10:39:58 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFal3-0006rm-6V for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFal1-0003Q1-Om for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:39:56 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-WwWYGm_qMmqjPTaKL60Qeg-1; Fri, 07 Jun 2024 10:39:51 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6502819560B4; Fri, 7 Jun 2024 14:39:50 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C48731956048; Fri, 7 Jun 2024 14:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717771195; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZuVDDqob31KAlDwmKxXvSjL1dLO0Pn1dcxk60z/nri8=; b=HFyofKnDOd62bIJdUfwY4v/KbbdFkX+DfdsRPVdkZzopVCS4brrv4yE2i/B9GS92zRK/ad 6aYU1F/8R6bQomwuv1ModdtY7xl+e07rhsMdaVLfzuYfXyxRkrFHkSTBWE7gSxdY6xaypv iJa/xrVuzkd1IBf2I1cFPyPUFPcG1vI= X-MC-Unique: WwWYGm_qMmqjPTaKL60Qeg-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, imammedo@redhat.com, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [RFC v2 6/7] hw/vfio: Remove memory_region_iommu_set_iova_ranges() call Date: Fri, 7 Jun 2024 16:37:26 +0200 Message-ID: <20240607143905.765133-7-eric.auger@redhat.com> In-Reply-To: <20240607143905.765133-1-eric.auger@redhat.com> References: <20240607143905.765133-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717800406189100003 Content-Type: text/plain; charset="utf-8" As we have just removed the only implementation of iommu_set_iova_ranges IOMMU MR callback in the virtio-iommu, let's remove the call to the memory wrapper. Usable IOVA ranges are now conveyed through the PCIIOMMUOps in VFIO-PCI. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan =20 --- hw/vfio/common.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index f20a7b5bba..9e4c0cc95f 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -630,16 +630,6 @@ static void vfio_listener_region_add(MemoryListener *l= istener, goto fail; } =20 - if (bcontainer->iova_ranges) { - ret =3D memory_region_iommu_set_iova_ranges(giommu->iommu_mr, - bcontainer->iova_ran= ges, - &err); - if (ret) { - g_free(giommu); - goto fail; - } - } - ret =3D memory_region_register_iommu_notifier(section->mr, &giommu= ->n, &err); if (ret) { --=20 2.41.0 From nobody Mon Nov 25 02:34:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1717802728; cv=none; d=zohomail.com; s=zohoarc; b=MgXxs/HAtKbOL+iyGr32jvkrz6iwR5XtL478epq9zsWixscq4eZ8ty6nl1HIP75Wu+E6lShofItE1h2eNxnkrVrwDQpHm25s9P+sZEGZca2clg3Ls2hOakPDhNgNMnmjzzO70yRx5KVbg6Jlqhb6E3Sl12Kyq56eLCCbINXx5VU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717802728; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xK/OvgNzzcXSWIsdldMqiiYrOffSKwz7no1QQVoOC3M=; b=NHsqoUOQWuEznLs8sG1ZaZw01PBbLTSjP6ZvYkuKxqNCieClHXOJYXVrJtOiCkWV/WDApXknlVYBRlS29xDsz4eLiq/1NxgL+aZSmw8fh9SNLP69n9Yv5KYKRFyYnLOO2Mx8nPn9U7izTeFvUu0hhE2GpdJSROZK2p7JvosvD8I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717802728682326.13622369978975; Fri, 7 Jun 2024 16:25:28 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFalD-0007QT-Rs; Fri, 07 Jun 2024 10:40:07 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFalA-0007EV-6x for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:40:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFal8-0003Qs-Hz for qemu-devel@nongnu.org; Fri, 07 Jun 2024 10:40:03 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-300-pWgggVlZOBGnrh-8JtS-AQ-1; Fri, 07 Jun 2024 10:39:56 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8836E19560B9; Fri, 7 Jun 2024 14:39:55 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.191]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B50DA1956048; Fri, 7 Jun 2024 14:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717771201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xK/OvgNzzcXSWIsdldMqiiYrOffSKwz7no1QQVoOC3M=; b=fIlPZpW6YG4o+TEa2FAQqDGFRSZ13OCRN+jIHqlMViSOQ8kVTEmsrDom5ZQ+OgjMtcXouO UuqX+lxRINZu4ZRPjegeDI5kSc/kFlaGEr9xL6mgJQUwjz/KI0EUFEUoYNl3eKrAFbBE+h /f3X4sKAvJunDx7qFIcDvBATrTJ6QUU= X-MC-Unique: pWgggVlZOBGnrh-8JtS-AQ-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com, jean-philippe@linaro.org, imammedo@redhat.com, peter.maydell@linaro.org, clg@redhat.com, yanghliu@redhat.com, zhenzhong.duan@intel.com Cc: alex.williamson@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, berrange@redhat.com Subject: [RFC v2 7/7] memory: Remove IOMMU MR iommu_set_iova_range API Date: Fri, 7 Jun 2024 16:37:27 +0200 Message-ID: <20240607143905.765133-8-eric.auger@redhat.com> In-Reply-To: <20240607143905.765133-1-eric.auger@redhat.com> References: <20240607143905.765133-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717802729777100003 Content-Type: text/plain; charset="utf-8" Since the host IOVA ranges are now passed through the PCIIOMMUOps set_host_resv_regions and we have removed the only implementation of iommu_set_iova_range() in the virtio-iommu and the only call site in vfio/common, let's retire the IOMMU MR API and its memory wrapper. Signed-off-by: Eric Auger Reviewed-by: Zhenzhong Duan =20 --- include/exec/memory.h | 32 -------------------------------- system/memory.c | 13 ------------- 2 files changed, 45 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 9cdd64e9c6..35d772e52b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -530,26 +530,6 @@ struct IOMMUMemoryRegionClass { int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu, uint64_t page_size_mask, Error **errp); - /** - * @iommu_set_iova_ranges: - * - * Propagate information about the usable IOVA ranges for a given IOMMU - * memory region. Used for example to propagate host physical device - * reserved memory region constraints to the virtual IOMMU. - * - * Optional method: if this method is not provided, then the default I= OVA - * aperture is used. - * - * @iommu: the IOMMUMemoryRegion - * - * @iova_ranges: list of ordered IOVA ranges (at least one range) - * - * Returns 0 on success, or a negative error. In case of failure, the = error - * object must be created. - */ - int (*iommu_set_iova_ranges)(IOMMUMemoryRegion *iommu, - GList *iova_ranges, - Error **errp); }; =20 typedef struct RamDiscardListener RamDiscardListener; @@ -1945,18 +1925,6 @@ int memory_region_iommu_set_page_size_mask(IOMMUMemo= ryRegion *iommu_mr, uint64_t page_size_mask, Error **errp); =20 -/** - * memory_region_iommu_set_iova_ranges - Set the usable IOVA ranges - * for a given IOMMU MR region - * - * @iommu: IOMMU memory region - * @iova_ranges: list of ordered IOVA ranges (at least one range) - * @errp: pointer to Error*, to store an error if it happens. - */ -int memory_region_iommu_set_iova_ranges(IOMMUMemoryRegion *iommu, - GList *iova_ranges, - Error **errp); - /** * memory_region_name: get a memory region's name * diff --git a/system/memory.c b/system/memory.c index 9540caa8a1..248d514f83 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1914,19 +1914,6 @@ int memory_region_iommu_set_page_size_mask(IOMMUMemo= ryRegion *iommu_mr, return ret; } =20 -int memory_region_iommu_set_iova_ranges(IOMMUMemoryRegion *iommu_mr, - GList *iova_ranges, - Error **errp) -{ - IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); - int ret =3D 0; - - if (imrc->iommu_set_iova_ranges) { - ret =3D imrc->iommu_set_iova_ranges(iommu_mr, iova_ranges, errp); - } - return ret; -} - int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp) { --=20 2.41.0