From nobody Sun May 5 21:42:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1567068659; cv=none; d=zoho.com; s=zohoarc; b=L73lJcwmaNaaUYDaB0pHM+sAYIsRDtrK2BtJhE/W9eftkHudy2glfIkDo87v6Hj7aKDTCGSeuhslXWg32UZsMBq8cBX/Q+oGti7nT78W7t/qnCLBIj9F3DDzXBj1awl9qNkOCXPwamDKitSHSXk9JnJRLQ1bMQqtU6YRcnjS/mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567068659; 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=h6SHCOcSC6Vw2stRp7L+j5Oj5e2HlP4/eNx45l7ZMDk=; b=GMQfVTQ2PePbQG1yIgGX6eMidvOYxuYFxFE0CSr2nvdDHNotDs8TopEedxmbcg5VDrmufJKikr1euljNsp7VDaxfDHgzitLOUj6e0c3Pg9IrVDEqhHC3ZsSfubuTZjexP4IOm71E+eZyJ0DSRcjnRcFFNDhT0CaIjt4QERTBPJg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1567068659472167.47033113521172; Thu, 29 Aug 2019 01:50:59 -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 1i3G7m-0003Ea-U5; Thu, 29 Aug 2019 08:49:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i3G7l-0003EV-CD for xen-devel@lists.xenproject.org; Thu, 29 Aug 2019 08:49:45 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f21b9824-ca39-11e9-8980-bc764e2007e4; Thu, 29 Aug 2019 08:49:44 +0000 (UTC) X-Inumbo-ID: f21b9824-ca39-11e9-8980-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1567068583; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=sKcC0gdvsWkZJPlBBQsuSypnUnY1Dt1H043GO1Ab1d0=; b=EnPlAi5eTQ/SwcQlC8GHR41W9enxEjHtk0XyJ7NVuL6Jpq8Bm2UTcJpI FFnTQU8iGeftMHB+BJaoX/QCB8xf6wkkSPhV+i9dMFOPjll37Ao6ZRAb4 6qIpBk2QTea2hWVKSAxsacUTSy6wpTB/W1EjK6mKXHxCiUQ/qZWPw5zYq 4=; 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: O7WbXWYFO8sCxbJ43toiIh3ttS695yB3aXUJ2Yno56DsZnvErS0/ggKFUwzAOVWjh/l0j8JHYx oRffJz8WuxDtV36VungRzMFmjfxiZon9uiP8wK0nqG1MtrMeNU8D2vHFH532iJx+R6r8tVpoo+ gMgFXsW6yvT67QOdP2VjPmPaGLKeQlkLWdb3YT0jyV98/w/MmLvUWt8pbZHnwFY+ZXu5TYMgtL eCq27zzRLRHKZusXOJ/M6xbFfaFpJY7GCAoSfkFXDNxMKVpxYpJgcl6NdaNdtZZ2b67HSO4tsv X2E= X-SBRS: 2.7 X-MesageID: 5134594 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,442,1559534400"; d="scan'208";a="5134594" From: Roger Pau Monne To: Date: Thu, 29 Aug 2019 10:49:18 +0200 Message-ID: <20190829084918.89608-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] Partially revert "x86/mm: Clean IOMMU flags from p2m-pt code" 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: Wei Liu , George Dunlap , Andrew Cooper , Jan Beulich , Alexandru Stefan ISAILA , 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" X-ZohoMail-DKIM: fail (Header signature does not verify) This partially reverts commit 854a49a7486a02edae5b3e53617bace526e9c1b1 by re-adding the logic that propagates changes to the domain physmap done by p2m_pt_set_entry into the iommu page tables. Without this logic changes to the guest physmap are not propagated to the iommu, leaving stale iommu entries that can leak data, or failing to add new entries. Note that this commit doesn't re-introduce iommu flags to the cpu page table entries, since the logic to add/remove entries to the iommu page tables is based on the p2m type and the mfn. Fixes: 854a49a7486a02 ('x86/mm: Clean IOMMU flags from p2m-pt code') Signed-off-by: Roger Pau Monn=C3=A9 Acked-by: George Dunlap Reviewed-by: Alexandru Isaila Reviewed-by: Jan Beulich --- Cc: Alexandru Stefan ISAILA --- Changes since v1: - Remove the share-pt branch, there's no sharing on AMD hardware. --- xen/arch/x86/mm/p2m-pt.c | 42 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index 3a0a500d66..8483dc8142 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -508,7 +508,18 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, m= fn_t mfn, l2_pgentry_t l2e_content; l3_pgentry_t l3e_content; int rc; - unsigned int flags; + unsigned int iommu_pte_flags =3D p2m_get_iommu_flags(p2mt, mfn); + /* + * old_mfn and iommu_old_flags control possible flush/update needs on = the + * IOMMU: We need to flush when MFN or flags (i.e. permissions) change. + * iommu_old_flags being initialized to zero covers the case of the en= try + * getting replaced being a non-present (leaf or intermediate) one. For + * present leaf entries the real value will get calculated below, while + * for present intermediate entries ~0 (guaranteed !=3D iommu_pte_flag= s) + * will be used (to cover all cases of what the leaf entries underneath + * the intermediate one might be). + */ + unsigned int flags, iommu_old_flags =3D 0; unsigned long old_mfn =3D mfn_x(INVALID_MFN); =20 if ( !sve ) @@ -556,9 +567,17 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, m= fn_t mfn, if ( flags & _PAGE_PRESENT ) { if ( flags & _PAGE_PSE ) + { old_mfn =3D l1e_get_pfn(*p2m_entry); + iommu_old_flags =3D + p2m_get_iommu_flags(p2m_flags_to_type(flags), + _mfn(old_mfn)); + } else + { + iommu_old_flags =3D ~0; intermediate_entry =3D *p2m_entry; + } } =20 check_entry(mfn, p2mt, p2m_flags_to_type(flags), page_order); @@ -594,6 +613,9 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mf= n_t mfn, 0, L1_PAGETABLE_ENTRIES); ASSERT(p2m_entry); old_mfn =3D l1e_get_pfn(*p2m_entry); + iommu_old_flags =3D + p2m_get_iommu_flags(p2m_flags_to_type(l1e_get_flags(*p2m_entry= )), + _mfn(old_mfn)); =20 if ( mfn_valid(mfn) || p2m_allows_invalid_mfn(p2mt) ) entry_content =3D p2m_l1e_from_pfn(mfn_x(mfn), @@ -617,9 +639,17 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, m= fn_t mfn, if ( flags & _PAGE_PRESENT ) { if ( flags & _PAGE_PSE ) + { old_mfn =3D l1e_get_pfn(*p2m_entry); + iommu_old_flags =3D + p2m_get_iommu_flags(p2m_flags_to_type(flags), + _mfn(old_mfn)); + } else + { + iommu_old_flags =3D ~0; intermediate_entry =3D *p2m_entry; + } } =20 check_entry(mfn, p2mt, p2m_flags_to_type(flags), page_order); @@ -640,9 +670,17 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, m= fn_t mfn, && (gfn + (1UL << page_order) - 1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn =3D gfn + (1UL << page_order) - 1; =20 + if ( need_iommu_pt_sync(p2m->domain) && + (iommu_old_flags !=3D iommu_pte_flags || old_mfn !=3D mfn_x(mfn))= ) + rc =3D iommu_pte_flags ? + iommu_legacy_map(d, _dfn(gfn), mfn, page_order, + iommu_pte_flags) : + iommu_legacy_unmap(d, _dfn(gfn), page_order); + /* * Free old intermediate tables if necessary. This has to be the - * last thing we do so as to avoid a potential use-after-free. + * last thing we do, after removal from the IOMMU tables, so as to + * avoid a potential use-after-free. */ if ( l1e_get_flags(intermediate_entry) & _PAGE_PRESENT ) p2m_free_entry(p2m, &intermediate_entry, page_order); --=20 2.22.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel