From nobody Fri Apr 26 08:31:40 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=1562158320; cv=none; d=zoho.com; s=zohoarc; b=bs3AJvgFjjw2OnDFSvyyrd6QlP13ZC0xU1N9Cm6zn1Zk2i83uKvAwFfBGuDQMDascWM+EsxeeYrWcB4HzlbZIBx/oPa3Yz3laTLP9EIlxzGr3ee0cPa3aq1dEXee3RGIVj21ijk44RhyYkudaXaBhYYwUxFa2W7QrPyxjlRKOGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562158320; 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=o3ExTvt81EGbE2a9Bd0WEdcx7K1I317P1nNSC8Wftgc=; b=VnitD0nT2571+q/nAqT4R+7xfgxtHgyM+7L5HQegtzx6ErW9s5bBkz9u1qNKt9bUcM/OdobDXdGpNRGz5zJ1H45KfCGQy03AfySXzUn5d7J4CfT8m7Y4a15PYmPQ5rT3xdgUSZzKHw2IUIzU4Cz1GZVv2g0/TJlEdn65mV2pwP8= 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 156215832082773.45465681894586; Wed, 3 Jul 2019 05:52:00 -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 1hieiS-0003Gb-Qo; Wed, 03 Jul 2019 12:50:28 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hieiR-0003GW-3d for xen-devel@lists.xenproject.org; Wed, 03 Jul 2019 12:50:27 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (unknown [40.107.15.94]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1ed02f39-9d91-11e9-8980-bc764e045a96; Wed, 03 Jul 2019 12:50:24 +0000 (UTC) Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.106.11) by VI1PR0202MB2909.eurprd02.prod.outlook.com (10.171.102.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2032.20; Wed, 3 Jul 2019 12:50:18 +0000 Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dd50:3e97:1d64:5aa3]) by VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dd50:3e97:1d64:5aa3%4]) with mapi id 15.20.2032.019; Wed, 3 Jul 2019 12:50:18 +0000 X-Inumbo-ID: 1ed02f39-9d91-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector1-bitdefender-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tj41Fi4Z6qi/WL4Jwo+crhvra44EhMZum+W0rnWv6vs=; b=roddZf2SpSPEgxV9PlryvEoefwMg5zty/+Leb6i4smX+13p6VV+xZ+482R7lpszVmE6yEEF1kDGKynhRjuZmY8cxY9wIp0rTpqtQzbNxeOXPm7/B67DhdM5INK4Ld4yVMPwPyXXzN+6Yl6FvGC/vZ79xH9PzI3/eo4k9pZd8MLE= From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v2] x86/mm: Clean IOMMU flags from p2m-pt code Thread-Index: AQHVMZ3eVPiN3NnZMUe+cwMyPT0RlA== Date: Wed, 3 Jul 2019 12:50:18 +0000 Message-ID: <20190703125004.25451-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PR2PR09CA0023.eurprd09.prod.outlook.com (2603:10a6:101:16::35) To VI1PR0202MB2928.eurprd02.prod.outlook.com (2603:10a6:800:e3::11) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aisaila@bitdefender.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [91.199.104.6] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e8dd274d-3635-4da8-180d-08d6ffb50077 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:VI1PR0202MB2909; x-ms-traffictypediagnostic: VI1PR0202MB2909:|VI1PR0202MB2909: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3383; x-forefront-prvs: 00872B689F x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(396003)(136003)(376002)(366004)(39860400002)(199004)(189003)(54906003)(6506007)(52116002)(99286004)(53936002)(36756003)(102836004)(316002)(71190400001)(66946007)(478600001)(71200400001)(386003)(2501003)(476003)(107886003)(4326008)(6916009)(2906002)(66066001)(486006)(2351001)(6486002)(8936002)(81156014)(81166006)(86362001)(2616005)(1076003)(6436002)(66476007)(256004)(25786009)(5640700003)(6116002)(66446008)(14444005)(3846002)(64756008)(66556008)(68736007)(8676002)(5660300002)(305945005)(14454004)(6306002)(6512007)(186003)(50226002)(26005)(7736002)(73956011); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB2909; H:VI1PR0202MB2928.eurprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; 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 (protection.outlook.com: bitdefender.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: qIrtsVx7E3Owf1xZDD/UFrJBHW9lrGI/yhhrq8nYtBHCsYuw2z9/hEV3nS7oH5jIvtOEdKx5ERw6hHyMVAIsJxjamsYjdbiAoGWT/pOp7Lsm/Usk/SqAYksGlGG/BZSLxatBUkgCpgTTQFaJEHzszMT+6vVXsuWELbRcUZllCanZGx28X/44UY43STrQ7Fd6H21LrzZ91JWiAa2CjQjMFQ+lu4E1e1yvN1/XG732kBRTYBT4osZzOZcxvQCWVf37tT+dpwek+/LQu/O+g1e8CONn9bfcjVYa2GZb4vsLB8e3IZ3F2v62HNlwiRQGQYZxULFzgKNQkK62AhtdTRVncb4IWBhDtxcevt1I9SxCnCK60nsspx5oHnScjuMC8dB/41dUUMwE7bHfqxAEyyNR8demaZJ5nK/hjtTCi9Ycmr0= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8dd274d-3635-4da8-180d-08d6ffb50077 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jul 2019 12:50:18.5215 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 487baf29-f1da-469a-9221-243f830c36f3 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: aisaila@bbu.bitdefender.biz X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0202MB2909 Subject: [Xen-devel] [PATCH v2] 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: "wl@xen.org" , "george.dunlap@eu.citrix.com" , "andrew.cooper3@citrix.com" , "jbeulich@suse.com" , Alexandru Stefan ISAILA , "roger.pau@citrix.com" 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) At this moment IOMMU pt sharing is disabled by commit [1]. This patch aims to clear the IOMMU hap share support as it will not be used in the future. By doing this the IOMMU bits used in pte[52:58] can be used in other ways. [1] c2ba3db31ef2d9f1e40e7b6c16cf3be3d671d555 Suggested-by: George Dunlap Signed-off-by: Alexandru Isaila --- Changes since V1: - Rework commit message - Reflow comments - Move flags init to declaration in p2m_type_to_flags. --- xen/arch/x86/mm/p2m-pt.c | 96 +++------------------------------------- 1 file changed, 5 insertions(+), 91 deletions(-) diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c index cafc9f299b..3a0a500d66 100644 --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -24,7 +24,6 @@ * along with this program; If not, see . */ =20 -#include #include #include #include @@ -36,15 +35,13 @@ #include #include #include -#include =20 #include "mm-locks.h" =20 /* * We may store INVALID_MFN in PTEs. We need to clip this to avoid trampl= ing - * over higher-order bits (NX, p2m type, IOMMU flags). We seem to not need - * to unclip on the read path, as callers are concerned only with p2m type= in - * such cases. + * over higher-order bits (NX, p2m type). We seem to not need to unclip on= the + * read path, as callers are concerned only with p2m type in such cases. */ #define p2m_l1e_from_pfn(pfn, flags) \ l1e_from_pfn((pfn) & (PADDR_MASK >> PAGE_SHIFT), (flags)) @@ -71,13 +68,7 @@ static unsigned long p2m_type_to_flags(const struct p2m_= domain *p2m, mfn_t mfn, unsigned int level) { - unsigned long flags; - /* - * AMD IOMMU: When we share p2m table with iommu, bit 9 - bit 11 will = be - * used for iommu hardware to encode next io page level. Bit 59 - bit = 62 - * are used for iommu flags, We could not use these bits to store p2m = types. - */ - flags =3D (unsigned long)(t & 0x7f) << 12; + unsigned long flags =3D (unsigned long)(t & 0x7f) << 12; =20 switch(t) { @@ -165,16 +156,6 @@ p2m_free_entry(struct p2m_domain *p2m, l1_pgentry_t *p= 2m_entry, int page_order) // Returns 0 on error. // =20 -/* AMD IOMMU: Convert next level bits and r/w bits into 24 bits p2m flags = */ -#define iommu_nlevel_to_flags(nl, f) ((((nl) & 0x7) << 9 )|(((f) & 0x3) <<= 21)) - -static void p2m_add_iommu_flags(l1_pgentry_t *p2m_entry, - unsigned int nlevel, unsigned int flags) -{ - if ( iommu_hap_pt_share ) - l1e_add_flags(*p2m_entry, iommu_nlevel_to_flags(nlevel, flags)); -} - /* Returns: 0 for success, -errno for failure */ static int p2m_next_level(struct p2m_domain *p2m, void **table, @@ -203,7 +184,6 @@ p2m_next_level(struct p2m_domain *p2m, void **table, =20 new_entry =3D l1e_from_mfn(mfn, P2M_BASE_FLAGS | _PAGE_RW); =20 - p2m_add_iommu_flags(&new_entry, level, IOMMUF_readable|IOMMUF_writ= able); rc =3D p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, level = + 1); if ( rc ) goto error; @@ -242,13 +222,6 @@ p2m_next_level(struct p2m_domain *p2m, void **table, =20 l1_entry =3D map_domain_page(mfn); =20 - /* Inherit original IOMMU permissions, but update Next Level. */ - if ( iommu_hap_pt_share ) - { - flags &=3D ~iommu_nlevel_to_flags(~0, 0); - flags |=3D iommu_nlevel_to_flags(level - 1, 0); - } - for ( i =3D 0; i < (1u << PAGETABLE_ORDER); i++ ) { new_entry =3D l1e_from_pfn(pfn | (i << ((level - 1) * PAGETABL= E_ORDER)), @@ -264,8 +237,6 @@ p2m_next_level(struct p2m_domain *p2m, void **table, unmap_domain_page(l1_entry); =20 new_entry =3D l1e_from_mfn(mfn, P2M_BASE_FLAGS | _PAGE_RW); - p2m_add_iommu_flags(&new_entry, level, - IOMMUF_readable|IOMMUF_writable); rc =3D p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, level + 1); if ( rc ) @@ -470,9 +441,6 @@ static int do_recalc(struct p2m_domain *p2m, unsigned l= ong gfn) } =20 e =3D l1e_from_pfn(mfn, flags); - p2m_add_iommu_flags(&e, level, - (nt =3D=3D p2m_ram_rw) - ? IOMMUF_readable|IOMMUF_writable : 0); ASSERT(!needs_recalc(l1, e)); } else @@ -540,18 +508,7 @@ 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 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 int flags; unsigned long old_mfn =3D mfn_x(INVALID_MFN); =20 if ( !sve ) @@ -599,17 +556,9 @@ 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); @@ -619,9 +568,6 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mf= n_t mfn, : l3e_empty(); entry_content.l1 =3D l3e_content.l3; =20 - if ( entry_content.l1 !=3D 0 ) - p2m_add_iommu_flags(&entry_content, 0, iommu_pte_flags); - rc =3D p2m->write_p2m_entry(p2m, gfn, p2m_entry, entry_content, 3); /* NB: paging_write_p2m_entry() handles tlb flushes properly */ if ( rc ) @@ -648,9 +594,6 @@ 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), @@ -658,9 +601,6 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mf= n_t mfn, else entry_content =3D l1e_empty(); =20 - if ( entry_content.l1 !=3D 0 ) - p2m_add_iommu_flags(&entry_content, 0, iommu_pte_flags); - /* level 1 entry */ rc =3D p2m->write_p2m_entry(p2m, gfn, p2m_entry, entry_content, 1); /* NB: paging_write_p2m_entry() handles tlb flushes properly */ @@ -677,17 +617,9 @@ 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); @@ -697,9 +629,6 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mf= n_t mfn, : l2e_empty(); entry_content.l1 =3D l2e_content.l2; =20 - if ( entry_content.l1 !=3D 0 ) - p2m_add_iommu_flags(&entry_content, 0, iommu_pte_flags); - rc =3D p2m->write_p2m_entry(p2m, gfn, p2m_entry, entry_content, 2); /* NB: paging_write_p2m_entry() handles tlb flushes properly */ if ( rc ) @@ -711,24 +640,9 @@ 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 ( iommu_enabled && (iommu_old_flags !=3D iommu_pte_flags || - old_mfn !=3D mfn_x(mfn)) ) - { - ASSERT(rc =3D=3D 0); - - if ( need_iommu_pt_sync(p2m->domain) ) - 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); - else if ( iommu_use_hap_pt(d) && iommu_old_flags ) - amd_iommu_flush_pages(p2m->domain, gfn, page_order); - } - /* * Free old intermediate tables if necessary. This has to be the - * last thing we do, after removal from the IOMMU tables, so as to - * avoid a potential use-after-free. + * last thing we do 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.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel