From nobody Tue May 7 00:02:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1564737831; cv=none; d=zoho.com; s=zohoarc; b=gmEO5VyMDZEc82GBIVuxjFdKBsrrkR6hLy7W9ResJAnxvzmQWnhAGHIDXl/CQyYGiwwEnwV55AIpJcV9ZRMn3C13BWprBwP1ITX+PWAerkPB2rFxlX0DnP4hqzWjuDBR+/FaMX08Lff2+uWntMKevFPLAXvYm91iVeSPcSZ9kkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564737831; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=9XXzbkY7kwRgDnaJRbUGCUCelTNHJsEMkmM0xULZTV8=; b=LIcPV63UTicRnxyFOR39swgEDMJOXHQNQorxJKwCeM9OVWh8s2UYgUrDuYjQRfTo1alQUotLr+6YO4kK8Q6X9a9CUnXb7EWsY5Ydb+eo70MOZwz6qdostDqsPvnuZy093TV5wT4v/hjDEmnqhRACiUjneYKfby8TQ5QaSOGsM2I= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1564737831666994.7737505540371; Fri, 2 Aug 2019 02:23:51 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htTlm-0007NR-7H; Fri, 02 Aug 2019 09:22:38 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htTll-0007NM-BJ for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 09:22:37 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0e1bc370-b507-11e9-9096-f78a72d0a99e; Fri, 02 Aug 2019 09:22:32 +0000 (UTC) X-Inumbo-ID: 0e1bc370-b507-11e9-9096-f78a72d0a99e Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: RrvRVlofppPDj91foRAgf39nLUABKsXePsBUzypcGRQrwSiq4NmiLtTDlyGfF0C0kRuNsPcr1Y 8zgFBavNpuG4RYA396L+6j7PqI0KIsRwXq04ONQ0Z7Bc704+TeiRXiyDAmGTAkcLlbEtbd5pMm kK+wvEB9ew1hbydkm+lQofUu7JB6bqhXePJm0wfLCuM/DeuB2m+++LjytBNaJoyWGJm8rajtur j5AUqjA+mK0bXMDaSWvNVHlT05Y7CBmgZBUBuBQ4mSo3oAKqnzRhNARQGWWupCb0PQ7rvjhYiL uOM= X-SBRS: 2.7 X-MesageID: 3929034 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,337,1559534400"; d="scan'208";a="3929034" From: Roger Pau Monne To: Date: Fri, 2 Aug 2019 11:22:27 +0200 Message-ID: <20190802092227.43058-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/iommu: remove usage of {set/clear}_identity_p2m_entry against PV domains X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Wei Liu , George Dunlap , Andrew Cooper , Roman Shaposhnik , Paul Durrant , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Switch rmrr_identity_mapping to use iommu_{un}map in order to establish RMRR mappings for PV domains, like it's done in arch_iommu_hwdom_init. This solves the issue of a PV hardware domain not getting RMRR mappings because {set/clear}_identity_p2m_entry was not properly updating the iommu page tables. As rmrr_identity_mapping was the last user of {set/clear}_identity_p2m_entry against PV domains modify the function so it's only usable against translated domains, as the other p2m related functions. Reported-by: Roman Shaposhnik Signed-off-by: Roger Pau Monn=C3=A9 --- Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: Kevin Tian Cc: Paul Durrant Cc: Roman Shaposhnik --- xen/arch/x86/mm/p2m.c | 11 ++++------- xen/drivers/passthrough/vtd/iommu.c | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index fef97c82f6..d36a58b1a6 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1341,10 +1341,8 @@ int set_identity_p2m_entry(struct domain *d, unsigne= d long gfn_l, =20 if ( !paging_mode_translate(p2m->domain) ) { - if ( !need_iommu_pt_sync(d) ) - return 0; - return iommu_legacy_map(d, _dfn(gfn_l), _mfn(gfn_l), PAGE_ORDER_4K, - IOMMUF_readable | IOMMUF_writable); + ASSERT_UNREACHABLE(); + return -ENXIO; } =20 gfn_lock(p2m, gfn, 0); @@ -1432,9 +1430,8 @@ int clear_identity_p2m_entry(struct domain *d, unsign= ed long gfn_l) =20 if ( !paging_mode_translate(d) ) { - if ( !need_iommu_pt_sync(d) ) - return 0; - return iommu_legacy_unmap(d, _dfn(gfn_l), PAGE_ORDER_4K); + ASSERT_UNREACHABLE(); + return -ENXIO; } =20 gfn_lock(p2m, gfn, 0); diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/= vtd/iommu.c index 5d72270c5b..62df5ca5aa 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1969,6 +1969,7 @@ static int rmrr_identity_mapping(struct domain *d, bo= ol_t map, unsigned long end_pfn =3D PAGE_ALIGN_4K(rmrr->end_address) >> PAGE_SHI= FT_4K; struct mapped_rmrr *mrmrr; struct domain_iommu *hd =3D dom_iommu(d); + unsigned int flush_flags =3D 0; =20 ASSERT(pcidevs_locked()); ASSERT(rmrr->base_address < rmrr->end_address); @@ -1982,7 +1983,7 @@ static int rmrr_identity_mapping(struct domain *d, bo= ol_t map, if ( mrmrr->base =3D=3D rmrr->base_address && mrmrr->end =3D=3D rmrr->end_address ) { - int ret =3D 0; + int ret =3D 0, err; =20 if ( map ) { @@ -1995,13 +1996,20 @@ static int rmrr_identity_mapping(struct domain *d, = bool_t map, =20 while ( base_pfn < end_pfn ) { - if ( clear_identity_p2m_entry(d, base_pfn) ) - ret =3D -ENXIO; + if ( paging_mode_translate(d) ) + ret =3D clear_identity_p2m_entry(d, base_pfn); + else + ret =3D iommu_unmap(d, _dfn(base_pfn), PAGE_ORDER_4K, + &flush_flags); base_pfn++; } =20 list_del(&mrmrr->list); xfree(mrmrr); + /* Keep the previous error code if there's one. */ + err =3D iommu_iotlb_flush_all(d, flush_flags); + if ( !ret ) + ret =3D err; return ret; } } @@ -2011,8 +2019,13 @@ static int rmrr_identity_mapping(struct domain *d, b= ool_t map, =20 while ( base_pfn < end_pfn ) { - int err =3D set_identity_p2m_entry(d, base_pfn, p2m_access_rw, fla= g); + int err; =20 + if ( paging_mode_translate(d) ) + err =3D set_identity_p2m_entry(d, base_pfn, p2m_access_rw, fla= g); + else + err =3D iommu_map(d, _dfn(base_pfn), _mfn(base_pfn), PAGE_ORDE= R_4K, + IOMMUF_readable | IOMMUF_writable, &flush_flag= s); if ( err ) return err; base_pfn++; @@ -2026,7 +2039,7 @@ static int rmrr_identity_mapping(struct domain *d, bo= ol_t map, mrmrr->count =3D 1; list_add_tail(&mrmrr->list, &hd->arch.mapped_rmrrs); =20 - return 0; + return iommu_iotlb_flush_all(d, flush_flags); } =20 static int intel_iommu_add_device(u8 devfn, struct pci_dev *pdev) --=20 2.20.1 (Apple Git-117) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel