From nobody Wed Nov 27 14:33:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1698317425; cv=none; d=zohomail.com; s=zohoarc; b=K2ZsN1UG2pDdsYVseHVCWjIeuTtelm6u+4bEfN/zsfi/nTFJcznW825Rn+YxIcv/nv4mYCWAuJZ0cXG5rdlV+GkYkjSL5sHzsetVZplTtejjcum0dwzdNaNFpQV4KLRJomEFh7TJ55T9npDpOt6DfpelrBz3Iyf1kie0qbNcywQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698317425; 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=pV+Aa2A6X47y04VcKhb0kM7bPAPadsiODq2e4eh7Z7c=; b=n5fGR7+c8O7yhV8SpeibfbbQlQQ1s2zKoFqmjuyjENrSG9Y8wAaDePiZS9FKyw2pQPFFHQ3cKELcyajtc9Ag90TRIlZAuMDDPwatFLDr0fsXh3YlQWeMJTv5QJ1ZsI6xJApCSXntqK6osryO6TitHF6L2/YDD3/c8ozHO4EPuQU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=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 169831742522946.753522761871864; Thu, 26 Oct 2023 03:50:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvxus-0002dA-Sy; Thu, 26 Oct 2023 06:48:43 -0400 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 1qvxuL-0002EB-Nw; Thu, 26 Oct 2023 06:48:16 -0400 Received: from mgamail.intel.com ([134.134.136.126]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvxu9-0001PR-Hs; Thu, 26 Oct 2023 06:48:01 -0400 Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2023 03:47:31 -0700 Received: from duan-server-s2600bt.bj.intel.com ([10.240.192.147]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2023 03:47:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698317277; x=1729853277; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cgs1UlOu9KSvDtr3cTTJNPXjMQDSb8lNfbQ0g80dHeA=; b=SMg0b3+I3WpEqesLkb6Q9bYTdx8gVI0m+sqUe48xYaoz1z1JnXdSjnUa YSJeWXVvPnSvMW4bB091JiwEuHH5j9phjDnVVqjDYOcWp/OHpr4WtM9GL KMURxw9lSYkObV5Knb8EpZE1XkikVlnzooN7fELjNVGwNPNowru8Z1orR N4hdiPELfxXaMy/OYL7Fl7R+6FbQ4gwx5ClPLmxkVDYwFoKb0CL6vbZ8i cP7e3CfTlqB5Y7cyYYbTt9mhI4bEVXXEDAL4VSZOdqw9WssUjRd03vmLl 5ijVLyNvOy9rzv3syPdPfI4xcNZUR7ilU7TtFZBdtf7QBLZraOdtF1WBE w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="372563560" X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="372563560" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="463727" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, eric.auger@redhat.com, peterx@redhat.com, jasowang@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, yi.y.sun@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Nicholas Piggin , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , qemu-ppc@nongnu.org (open list:sPAPR (pseries)) Subject: [PATCH v3 20/37] vfio/spapr: switch to spapr IOMMU BE add/del_section_window Date: Thu, 26 Oct 2023 18:30:47 +0800 Message-Id: <20231026103104.1686921-21-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026103104.1686921-1-zhenzhong.duan@intel.com> References: <20231026103104.1686921-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 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=134.134.136.126; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1698317427108100007 Content-Type: text/plain; charset="utf-8" No fucntional change intended. Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-common.h | 5 ----- include/hw/vfio/vfio-container-base.h | 5 +++++ hw/vfio/common.c | 8 ++------ hw/vfio/container-base.c | 23 ++++++++++++++++++++++- hw/vfio/spapr.c | 22 ++++++++++++++++------ 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index a74e60e677..1489b49d71 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -177,11 +177,6 @@ typedef struct VFIOIOMMUSpaprOps { MemoryRegionSection *section); } VFIOIOMMUSpaprOps; =20 -int vfio_container_add_section_window(VFIOContainer *container, - MemoryRegionSection *section, - Error **errp); -void vfio_container_del_section_window(VFIOContainer *container, - MemoryRegionSection *section); bool vfio_spapr_container_init(VFIOContainer *container, Error **errp); void vfio_spapr_container_deinit(VFIOContainer *container); =20 diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 1e1854d24f..88463bcf24 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -91,6 +91,11 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer, int vfio_container_dma_unmap(VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb); +int vfio_container_add_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp); +void vfio_container_del_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start); int vfio_container_query_dirty_bitmap(VFIOContainerBase *bcontainer, diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 64565b4ae9..41a5609e33 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -571,8 +571,6 @@ static void vfio_listener_region_add(MemoryListener *li= stener, { VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); - VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, - bcontainer); hwaddr iova, end; Int128 llend, llsize; void *vaddr; @@ -596,7 +594,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, return; } =20 - if (vfio_container_add_section_window(container, section, &err)) { + if (vfio_container_add_section_window(bcontainer, section, &err)) { goto fail; } =20 @@ -739,8 +737,6 @@ static void vfio_listener_region_del(MemoryListener *li= stener, { VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); - VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, - bcontainer); hwaddr iova, end; Int128 llend, llsize; int ret; @@ -820,7 +816,7 @@ static void vfio_listener_region_del(MemoryListener *li= stener, =20 memory_region_unref(section->mr); =20 - vfio_container_del_section_window(container, section); + vfio_container_del_section_window(bcontainer, section); } =20 typedef struct VFIODirtyRanges { diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 6363ed3552..2efb26cfe4 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -24,7 +24,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/error-report.h" -#include "hw/vfio/vfio-container-base.h" +#include "hw/vfio/vfio-common.h" =20 int vfio_container_dma_map(VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, @@ -48,6 +48,27 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontain= er, return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb); } =20 +int vfio_container_add_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp) +{ + if (!bcontainer->spapr_ops || !bcontainer->spapr_ops->add_window) { + return 0; + } + + return bcontainer->spapr_ops->add_window(bcontainer, section, errp); +} + +void vfio_container_del_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section) +{ + if (!bcontainer->spapr_ops || !bcontainer->spapr_ops->del_window) { + return; + } + + return bcontainer->spapr_ops->del_window(bcontainer, section); +} + int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start) { diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 3739004151..43e32e544b 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -302,10 +302,13 @@ static int vfio_spapr_create_window(VFIOContainer *co= ntainer, return 0; } =20 -int vfio_container_add_section_window(VFIOContainer *container, - MemoryRegionSection *section, - Error **errp) +static int +vfio_spapr_container_add_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp) { + VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, + bcontainer); VFIOHostDMAWindow *hostwin; hwaddr pgsize =3D 0; int ret; @@ -370,9 +373,13 @@ int vfio_container_add_section_window(VFIOContainer *c= ontainer, return 0; } =20 -void vfio_container_del_section_window(VFIOContainer *container, - MemoryRegionSection *section) +static void +vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section) { + VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, + bcontainer); + if (container->iommu_type !=3D VFIO_SPAPR_TCE_v2_IOMMU) { return; } @@ -388,7 +395,10 @@ void vfio_container_del_section_window(VFIOContainer *= container, } } =20 -const VFIOIOMMUSpaprOps vfio_iommu_spapr_ops; +const VFIOIOMMUSpaprOps vfio_iommu_spapr_ops =3D { + .add_window =3D vfio_spapr_container_add_section_window, + .del_window =3D vfio_spapr_container_del_section_window, +}; =20 bool vfio_spapr_container_init(VFIOContainer *container, Error **errp) { --=20 2.34.1