From patchwork Fri Aug 2 09:22:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 11073023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7FBBD13A4 for ; Fri, 2 Aug 2019 09:24:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B38B287DE for ; Fri, 2 Aug 2019 09:24:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A7A3287E3; Fri, 2 Aug 2019 09:24:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D33B4287BA for ; Fri, 2 Aug 2019 09:24:29 +0000 (UTC) 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 X-Inumbo-ID: 0e1bc370-b507-11e9-9096-f78a72d0a99e 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) 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 (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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é --- 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, unsigned long gfn_l, 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; } gfn_lock(p2m, gfn, 0); @@ -1432,9 +1430,8 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l) 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; } 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, bool_t map, unsigned long end_pfn = PAGE_ALIGN_4K(rmrr->end_address) >> PAGE_SHIFT_4K; struct mapped_rmrr *mrmrr; struct domain_iommu *hd = dom_iommu(d); + unsigned int flush_flags = 0; ASSERT(pcidevs_locked()); ASSERT(rmrr->base_address < rmrr->end_address); @@ -1982,7 +1983,7 @@ static int rmrr_identity_mapping(struct domain *d, bool_t map, if ( mrmrr->base == rmrr->base_address && mrmrr->end == rmrr->end_address ) { - int ret = 0; + int ret = 0, err; if ( map ) { @@ -1995,13 +1996,20 @@ static int rmrr_identity_mapping(struct domain *d, bool_t map, while ( base_pfn < end_pfn ) { - if ( clear_identity_p2m_entry(d, base_pfn) ) - ret = -ENXIO; + if ( paging_mode_translate(d) ) + ret = clear_identity_p2m_entry(d, base_pfn); + else + ret = iommu_unmap(d, _dfn(base_pfn), PAGE_ORDER_4K, + &flush_flags); base_pfn++; } list_del(&mrmrr->list); xfree(mrmrr); + /* Keep the previous error code if there's one. */ + err = iommu_iotlb_flush_all(d, flush_flags); + if ( !ret ) + ret = err; return ret; } } @@ -2011,8 +2019,13 @@ static int rmrr_identity_mapping(struct domain *d, bool_t map, while ( base_pfn < end_pfn ) { - int err = set_identity_p2m_entry(d, base_pfn, p2m_access_rw, flag); + int err; + if ( paging_mode_translate(d) ) + err = set_identity_p2m_entry(d, base_pfn, p2m_access_rw, flag); + else + err = iommu_map(d, _dfn(base_pfn), _mfn(base_pfn), PAGE_ORDER_4K, + IOMMUF_readable | IOMMUF_writable, &flush_flags); if ( err ) return err; base_pfn++; @@ -2026,7 +2039,7 @@ static int rmrr_identity_mapping(struct domain *d, bool_t map, mrmrr->count = 1; list_add_tail(&mrmrr->list, &hd->arch.mapped_rmrrs); - return 0; + return iommu_iotlb_flush_all(d, flush_flags); } static int intel_iommu_add_device(u8 devfn, struct pci_dev *pdev)