From nobody Wed Nov 27 00:21:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 1703012295277411.00524668152923; Tue, 19 Dec 2023 10:58:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFfHv-0002C2-T1; Tue, 19 Dec 2023 13:57:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rFfHu-00027j-V8 for qemu-devel@nongnu.org; Tue, 19 Dec 2023 13:57:54 -0500 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rFfHs-00072E-Fh for qemu-devel@nongnu.org; Tue, 19 Dec 2023 13:57:54 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4SvmCy3h0Xz4xPh; Wed, 20 Dec 2023 05:57:50 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SvmCs6Frgz4xCp; Wed, 20 Dec 2023 05:57:45 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Eric Auger , Zhenzhong Duan , Peter Maydell , Richard Henderson , Nicholas Piggin , Harsh Prateek Bora , Thomas Huth , Eric Farman , Alex Williamson , Matthew Rosato , Yi Liu , Yi Sun , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 10/47] vfio/container: Move pgsizes and dma_max_mappings to base container Date: Tue, 19 Dec 2023 19:56:06 +0100 Message-ID: <20231219185643.725448-11-clg@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231219185643.725448-1-clg@redhat.com> References: <20231219185643.725448-1-clg@redhat.com> MIME-Version: 1.0 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=2404:9400:2221:ea00::3; envelope-from=SRS0=7/MV=H6=redhat.com=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1703012297465100002 From: Eric Auger No functional change intended. Signed-off-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 2 -- include/hw/vfio/vfio-container-base.h | 2 ++ hw/vfio/common.c | 17 +++++++++-------- hw/vfio/container-base.c | 1 + hw/vfio/container.c | 11 +++++------ hw/vfio/spapr.c | 10 ++++++---- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index bc67e1316ceeaf4439aa9dd71d8c35cc5f34366c..d3dc2f9dcbde9abf57fa1592604= f60caa3cb0137 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -85,8 +85,6 @@ typedef struct VFIOContainer { bool initialized; uint64_t dirty_pgsizes; uint64_t max_dirty_bitmap_size; - unsigned long pgsizes; - unsigned int dma_max_mappings; QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; QLIST_HEAD(, VFIOGroup) group_list; QLIST_HEAD(, VFIORamDiscardListener) vrdl_list; diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 709096249642c7c597aa789264a09389e53664f3..85ec7e1a561af641ae2261c7753= 32afb8e76c838 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -36,6 +36,8 @@ typedef struct VFIOAddressSpace { typedef struct VFIOContainerBase { const VFIOIOMMUOps *ops; VFIOAddressSpace *space; + unsigned long pgsizes; + unsigned int dma_max_mappings; bool dirty_pages_supported; QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; QLIST_ENTRY(VFIOContainerBase) next; diff --git a/hw/vfio/common.c b/hw/vfio/common.c index cf6618f6ed3d16a4c76d641d7bdb4958dd2bd8ef..1cb53d369e871090b4d58dc6d5d= d4d6cdfe455c4 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -401,6 +401,7 @@ static int vfio_ram_discard_notify_populate(RamDiscardL= istener *rdl, static void vfio_register_ram_discard_listener(VFIOContainer *container, MemoryRegionSection *sectio= n) { + VFIOContainerBase *bcontainer =3D &container->bcontainer; RamDiscardManager *rdm =3D memory_region_get_ram_discard_manager(secti= on->mr); VFIORamDiscardListener *vrdl; =20 @@ -419,8 +420,8 @@ static void vfio_register_ram_discard_listener(VFIOCont= ainer *container, section->m= r); =20 g_assert(vrdl->granularity && is_power_of_2(vrdl->granularity)); - g_assert(container->pgsizes && - vrdl->granularity >=3D 1ULL << ctz64(container->pgsizes)); + g_assert(bcontainer->pgsizes && + vrdl->granularity >=3D 1ULL << ctz64(bcontainer->pgsizes)); =20 ram_discard_listener_init(&vrdl->listener, vfio_ram_discard_notify_populate, @@ -441,7 +442,7 @@ static void vfio_register_ram_discard_listener(VFIOCont= ainer *container, * number of sections in the address space we could have over time, * also consuming DMA mappings. */ - if (container->dma_max_mappings) { + if (bcontainer->dma_max_mappings) { unsigned int vrdl_count =3D 0, vrdl_mappings =3D 0, max_memslots = =3D 512; =20 #ifdef CONFIG_KVM @@ -462,11 +463,11 @@ static void vfio_register_ram_discard_listener(VFIOCo= ntainer *container, } =20 if (vrdl_mappings + max_memslots - vrdl_count > - container->dma_max_mappings) { + bcontainer->dma_max_mappings) { warn_report("%s: possibly running out of DMA mappings. E.g., t= ry" " increasing the 'block-size' of virtio-mem devies= ." " Maximum possible DMA mappings: %d, Maximum possi= ble" - " memslots: %d", __func__, container->dma_max_mapp= ings, + " memslots: %d", __func__, bcontainer->dma_max_map= pings, max_memslots); } } @@ -626,7 +627,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, iommu_idx); =20 ret =3D memory_region_iommu_set_page_size_mask(giommu->iommu_mr, - container->pgsizes, + bcontainer->pgsizes, &err); if (ret) { g_free(giommu); @@ -675,7 +676,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, llsize =3D int128_sub(llend, int128_make64(iova)); =20 if (memory_region_is_ram_device(section->mr)) { - hwaddr pgmask =3D (1ULL << ctz64(container->pgsizes)) - 1; + hwaddr pgmask =3D (1ULL << ctz64(bcontainer->pgsizes)) - 1; =20 if ((iova & pgmask) || (int128_get64(llsize) & pgmask)) { trace_vfio_listener_region_add_no_dma_map( @@ -777,7 +778,7 @@ static void vfio_listener_region_del(MemoryListener *li= stener, if (memory_region_is_ram_device(section->mr)) { hwaddr pgmask; =20 - pgmask =3D (1ULL << ctz64(container->pgsizes)) - 1; + pgmask =3D (1ULL << ctz64(bcontainer->pgsizes)) - 1; try_unmap =3D !((iova & pgmask) || (int128_get64(llsize) & pgmask)= ); } else if (memory_region_has_ram_discard_manager(section->mr)) { vfio_unregister_ram_discard_listener(container, section); diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 5d654ae17233fe06c235d33d981eb8fa92128536..dcce111349f9ded6beb72efc7a4= ddd86ab7df184 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -52,6 +52,7 @@ void vfio_container_init(VFIOContainerBase *bcontainer, V= FIOAddressSpace *space, bcontainer->ops =3D ops; bcontainer->space =3D space; bcontainer->dirty_pages_supported =3D false; + bcontainer->dma_max_mappings =3D 0; QLIST_INIT(&bcontainer->giommu_list); } =20 diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 7bd81eab09008530294757a81429bfea1b147815..c5a62628826c6426e8cd67ff53e= 73c502d7f73ba 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -154,7 +154,7 @@ static int vfio_legacy_dma_unmap(VFIOContainerBase *bco= ntainer, hwaddr iova, if (errno =3D=3D EINVAL && unmap.size && !(unmap.iova + unmap.size= ) && container->iommu_type =3D=3D VFIO_TYPE1v2_IOMMU) { trace_vfio_legacy_dma_unmap_overflow_workaround(); - unmap.size -=3D 1ULL << ctz64(container->pgsizes); + unmap.size -=3D 1ULL << ctz64(bcontainer->pgsizes); continue; } error_report("VFIO_UNMAP_DMA failed: %s", strerror(errno)); @@ -559,7 +559,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, container =3D g_malloc0(sizeof(*container)); container->fd =3D fd; container->error =3D NULL; - container->dma_max_mappings =3D 0; container->iova_ranges =3D NULL; QLIST_INIT(&container->vrdl_list); bcontainer =3D &container->bcontainer; @@ -589,13 +588,13 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, } =20 if (info->flags & VFIO_IOMMU_INFO_PGSIZES) { - container->pgsizes =3D info->iova_pgsizes; + bcontainer->pgsizes =3D info->iova_pgsizes; } else { - container->pgsizes =3D qemu_real_host_page_size(); + bcontainer->pgsizes =3D qemu_real_host_page_size(); } =20 - if (!vfio_get_info_dma_avail(info, &container->dma_max_mappings)) { - container->dma_max_mappings =3D 65535; + if (!vfio_get_info_dma_avail(info, &bcontainer->dma_max_mappings))= { + bcontainer->dma_max_mappings =3D 65535; } =20 vfio_get_info_iova_range(info, container); diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 83da2f7ec213dab2acca9b96a1d07a22a49d22c4..4f76bdd3cadfd282b7f2a01c19e= e772be5627068 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -226,6 +226,7 @@ static int vfio_spapr_create_window(VFIOContainer *cont= ainer, hwaddr *pgsize) { int ret =3D 0; + VFIOContainerBase *bcontainer =3D &container->bcontainer; IOMMUMemoryRegion *iommu_mr =3D IOMMU_MEMORY_REGION(section->mr); uint64_t pagesize =3D memory_region_iommu_get_min_page_size(iommu_mr),= pgmask; unsigned entries, bits_total, bits_per_level, max_levels; @@ -239,13 +240,13 @@ static int vfio_spapr_create_window(VFIOContainer *co= ntainer, if (pagesize > rampagesize) { pagesize =3D rampagesize; } - pgmask =3D container->pgsizes & (pagesize | (pagesize - 1)); + pgmask =3D bcontainer->pgsizes & (pagesize | (pagesize - 1)); pagesize =3D pgmask ? (1ULL << (63 - clz64(pgmask))) : 0; if (!pagesize) { error_report("Host doesn't support page size 0x%"PRIx64 ", the supported mask is 0x%lx", memory_region_iommu_get_min_page_size(iommu_mr), - container->pgsizes); + bcontainer->pgsizes); return -EINVAL; } =20 @@ -421,6 +422,7 @@ void vfio_container_del_section_window(VFIOContainer *c= ontainer, =20 int vfio_spapr_container_init(VFIOContainer *container, Error **errp) { + VFIOContainerBase *bcontainer =3D &container->bcontainer; struct vfio_iommu_spapr_tce_info info; bool v2 =3D container->iommu_type =3D=3D VFIO_SPAPR_TCE_v2_IOMMU; int ret, fd =3D container->fd; @@ -461,7 +463,7 @@ int vfio_spapr_container_init(VFIOContainer *container,= Error **errp) } =20 if (v2) { - container->pgsizes =3D info.ddw.pgsizes; + bcontainer->pgsizes =3D info.ddw.pgsizes; /* * There is a default window in just created container. * To make region_add/del simpler, we better remove this @@ -476,7 +478,7 @@ int vfio_spapr_container_init(VFIOContainer *container,= Error **errp) } } else { /* The default table uses 4K pages */ - container->pgsizes =3D 0x1000; + bcontainer->pgsizes =3D 0x1000; vfio_host_win_add(container, info.dma32_window_start, info.dma32_window_start + info.dma32_window_size - 1, --=20 2.43.0