From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125299; cv=none; d=zoho.com; s=zohoarc; b=ByfH21vedgGwrjVI10w2bEjdVbp9LbvyVg1sHVDAHFsjbNuZb2UmqqJTrxqGREGMLoDYh+JIli+s//qpbIcCWb7lVt7HDZwLbfHNJ8UoW00A4ULC6+1GbjWnVi8Iowogf2nINW9jyqEC4m8dHHMRULZMKmPc1FORmgu32jgsPeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125299; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0bqQbijfgv+DtHqG5cfgjQ4Vn94/7ZDbg/Qzwo04RT0=; b=EYmw6AinQM6nkexIvSmWUvrVsaVSENivQ8J8hJV3+dt8ib0DQZKnJiMFmHnRBj1QPIN2R1AtH9SFpwkOTbFEqG61ZWeU6uE6mEEmOGIRy6zjIJXU+5eAfOZ+5u55Hb6KLzXdrXJ8IhG3V2kOwCMyO0ky8qDuAkFnrnvmpjPxPN0= 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 1556125299130904.8606052852323; Wed, 24 Apr 2019 10:01:39 -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 1hJLFg-0007mq-3h; Wed, 24 Apr 2019 17:00:08 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFe-0007jX-S4 for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:06 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 68ce6a76-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:06 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D0FD0EBD; Wed, 24 Apr 2019 10:00:05 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B49AC3F557; Wed, 24 Apr 2019 10:00:04 -0700 (PDT) X-Inumbo-ID: 68ce6a76-66b2-11e9-92d7-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:44 +0100 Message-Id: <20190424165955.23718-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 01/12] xen/arm: lpae: Add a macro to generate offsets from an address 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" There are few places requiring to generate offsets from an address. Rather than open-coding everywhere, we can introduce a macro to do the job for us. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/p2m.c | 23 +++-------------------- xen/include/asm-arm/lpae.h | 9 +++++++++ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 92c2413f20..06fa342a8f 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -368,12 +368,7 @@ mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, p2m_type_t _t; =20 /* Convenience aliases */ - const unsigned int offsets[4] =3D { - zeroeth_table_offset(addr), - first_table_offset(addr), - second_table_offset(addr), - third_table_offset(addr) - }; + DECLARE_OFFSETS(offsets, addr); =20 ASSERT(p2m_is_locked(p2m)); BUILD_BUG_ON(THIRD_MASK !=3D PAGE_MASK); @@ -888,7 +883,6 @@ static int __p2m_set_entry(struct p2m_domain *p2m, p2m_type_t t, p2m_access_t a) { - paddr_t addr =3D gfn_to_gaddr(sgfn); unsigned int level =3D 0; unsigned int target =3D 3 - (page_order / LPAE_SHIFT); lpae_t *entry, *table, orig_pte; @@ -897,12 +891,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, bool removing_mapping =3D mfn_eq(smfn, INVALID_MFN); =20 /* Convenience aliases */ - const unsigned int offsets[4] =3D { - zeroeth_table_offset(addr), - first_table_offset(addr), - second_table_offset(addr), - third_table_offset(addr) - }; + DECLARE_OFFSETS(offsets, gfn_to_gaddr(sgfn)); =20 ASSERT(p2m_is_write_locked(p2m)); =20 @@ -1199,15 +1188,9 @@ bool p2m_resolve_translation_fault(struct domain *d,= gfn_t gfn) unsigned int level =3D 0; bool resolved =3D false; lpae_t entry, *table; - paddr_t addr =3D gfn_to_gaddr(gfn); =20 /* Convenience aliases */ - const unsigned int offsets[4] =3D { - zeroeth_table_offset(addr), - first_table_offset(addr), - second_table_offset(addr), - third_table_offset(addr) - }; + DECLARE_OFFSETS(offsets, gfn_to_gaddr(gfn)); =20 p2m_write_lock(p2m); =20 diff --git a/xen/include/asm-arm/lpae.h b/xen/include/asm-arm/lpae.h index 545b0c8f24..c22780f8f3 100644 --- a/xen/include/asm-arm/lpae.h +++ b/xen/include/asm-arm/lpae.h @@ -218,6 +218,15 @@ TABLE_OFFSET_HELPERS(64); #undef TABLE_OFFSET #undef TABLE_OFFSET_HELPERS =20 +/* Generate an array @var containing the offset for each level from @addr = */ +#define DECLARE_OFFSETS(var, addr) \ + const unsigned int var[4] =3D { \ + zeroeth_table_offset(addr), \ + first_table_offset(addr), \ + second_table_offset(addr), \ + third_table_offset(addr) \ + } + #endif /* __ASSEMBLY__ */ =20 /* --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125302; cv=none; d=zoho.com; s=zohoarc; b=KVUpYlKw4aEDeE2dw1lr2Wr7NzPPZZ5mKLHsQp6PKB3R0sQfNU/jm5bcfBTtGu9IFkNxKLIT3kd8t7aqg4ZknAhn3RZHFEaPvvCBD1r7AOy3uv3Go4fIs+C/JB/12YHgNZ2CbofgyaIA5lv6pEdXpR7R1L/1gZl+sMEL/f9ZPWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125302; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=8hguHsdSinYmO30SVyc5dThRBEseWvk43zMgI2E6Y+w=; b=jsd5h39uXmwdi/4CpMW372eGPta8xxw7NvjJJ2KSweXsy5RucGYBqYRFsRpFxq86TIFQWkQIsHiJ8ARLgNFy2CDuAUsAC7hReogKVUpdaBBm1+57MQTzjpGaEmhBt46ySC3v0A1JrVeZo73P5k0J22bMVeaouTLQhIbmU6BhGxQ= 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 1556125302668183.51499953080292; Wed, 24 Apr 2019 10:01:42 -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 1hJLFi-0007n2-CT; Wed, 24 Apr 2019 17:00:10 +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 1hJLFh-0007mw-4e for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:09 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 69ae0bec-66b2-11e9-9840-9b0330304ec4; Wed, 24 Apr 2019 17:00:07 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 38C5E15BE; Wed, 24 Apr 2019 10:00:07 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1E1143F557; Wed, 24 Apr 2019 10:00:05 -0700 (PDT) X-Inumbo-ID: 69ae0bec-66b2-11e9-9840-9b0330304ec4 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:45 +0100 Message-Id: <20190424165955.23718-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 02/12] xen/arm: mm: Rename create_xen_entries() to xen_pt_update() 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" create_xen_entries() is doing more than creating entries. It can also modify and remove entries. Rename the function to make clear what the function is actually doing. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index d6157c35d6..df2ec3a36b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -965,11 +965,11 @@ enum xenmap_operation { =20 static DEFINE_SPINLOCK(xen_pt_lock); =20 -static int create_xen_entries(enum xenmap_operation op, - unsigned long virt, - mfn_t mfn, - unsigned long nr_mfns, - unsigned int flags) +static int xen_pt_update(enum xenmap_operation op, + unsigned long virt, + mfn_t mfn, + unsigned long nr_mfns, + unsigned int flags) { int rc =3D 0; unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; @@ -1062,25 +1062,24 @@ int map_pages_to_xen(unsigned long virt, unsigned long nr_mfns, unsigned int flags) { - return create_xen_entries(INSERT, virt, mfn, nr_mfns, flags); + return xen_pt_update(INSERT, virt, mfn, nr_mfns, flags); } =20 int populate_pt_range(unsigned long virt, unsigned long nr_mfns) { - return create_xen_entries(RESERVE, virt, INVALID_MFN, nr_mfns, 0); + return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, 0); } =20 int destroy_xen_mappings(unsigned long v, unsigned long e) { ASSERT(v <=3D e); - return create_xen_entries(REMOVE, v, INVALID_MFN, (e - v) >> PAGE_SHIF= T, 0); + return xen_pt_update(REMOVE, v, INVALID_MFN, (e - v) >> PAGE_SHIFT, 0); } =20 int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int fla= gs) { ASSERT(s <=3D e); - return create_xen_entries(MODIFY, s, INVALID_MFN, (e - s) >> PAGE_SHIF= T, - flags); + return xen_pt_update(MODIFY, s, INVALID_MFN, (e - s) >> PAGE_SHIFT, fl= ags); } =20 enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125301; cv=none; d=zoho.com; s=zohoarc; b=ZdG4KYRWHTd7EELgPSrtFxzvwNg9ffu+fnMmVc+az9jPmuZZVFQXAuGoeK5XbRw4sNv4icISnP8G6g59ks3I6Wwuuk6Y8vdPedS+j0dPk4PKdYYngL/vG5io/1KMeeU/idw9mOcM0dFXxDeMMwHBSuPQ2XH6jLy1j2HKSMNATOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125301; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZNputk6QUdrZiTQcmoyAXdm73PJc4QX+zMHIMfURwWk=; b=i6m/pxpqL0RC0ut9rnM9vYeUTsP38MZmajxSuKRUFaROiNDvqzYND7HMcNqdvM8P+mNuP3lMyPTEn+btSYutkpDK7X6vS7nF5EA3gbc2eqSgthJ+xa4C9RpWhWRzSt/r4lgmI9XIA0uWgilIZOP/H4Y5lD/Ipn4kpU3Fh9J8Ll8= 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 1556125301324315.12315836517587; Wed, 24 Apr 2019 10:01:41 -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 1hJLFj-0007nH-LL; Wed, 24 Apr 2019 17:00:11 +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 1hJLFi-0007n1-BB for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:10 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 6a7fddf2-66b2-11e9-8188-4bb1fa585020; Wed, 24 Apr 2019 17:00:09 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 97A45374; Wed, 24 Apr 2019 10:00:08 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7B2593F557; Wed, 24 Apr 2019 10:00:07 -0700 (PDT) X-Inumbo-ID: 6a7fddf2-66b2-11e9-8188-4bb1fa585020 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:46 +0100 Message-Id: <20190424165955.23718-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In preparation of rework of the Xen PT, the logic to update an entry in moved out in a separate function. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 140 +++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index df2ec3a36b..6b1d41cfba 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -963,6 +963,76 @@ enum xenmap_operation { RESERVE }; =20 +static int xen_pt_update_entry(enum xenmap_operation op, unsigned long add= r, + mfn_t mfn, unsigned int flags) +{ + lpae_t pte, *entry; + lpae_t *third =3D NULL; + + entry =3D &xen_second[second_linear_offset(addr)]; + if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) + { + int rc =3D create_xen_table(entry); + if ( rc < 0 ) { + printk("%s: L2 failed\n", __func__); + return rc; + } + } + + BUG_ON(!lpae_is_valid(*entry)); + + third =3D mfn_to_virt(lpae_get_mfn(*entry)); + entry =3D &third[third_table_offset(addr)]; + + switch ( op ) { + case INSERT: + case RESERVE: + if ( lpae_is_valid(*entry) ) + { + printk("%s: trying to replace an existing mapping addr=3D%= lx mfn=3D%"PRI_mfn"\n", + __func__, addr, mfn_x(mfn)); + return -EINVAL; + } + if ( op =3D=3D RESERVE ) + break; + pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); + pte.pt.ro =3D PAGE_RO_MASK(flags); + pte.pt.xn =3D PAGE_XN_MASK(flags); + BUG_ON(!pte.pt.ro && !pte.pt.xn); + pte.pt.table =3D 1; + write_pte(entry, pte); + break; + case MODIFY: + case REMOVE: + if ( !lpae_is_valid(*entry) ) + { + printk("%s: trying to %s a non-existing mapping addr=3D%lx= \n", + __func__, op =3D=3D REMOVE ? "remove" : "modify", a= ddr); + return -EINVAL; + } + if ( op =3D=3D REMOVE ) + pte.bits =3D 0; + else + { + pte =3D *entry; + pte.pt.ro =3D PAGE_RO_MASK(flags); + pte.pt.xn =3D PAGE_XN_MASK(flags); + if ( !pte.pt.ro && !pte.pt.xn ) + { + printk("%s: Incorrect combination for addr=3D%lx\n", + __func__, addr); + return -EINVAL; + } + } + write_pte(entry, pte); + break; + default: + BUG(); + } + + return 0; +} + static DEFINE_SPINLOCK(xen_pt_lock); =20 static int xen_pt_update(enum xenmap_operation op, @@ -973,78 +1043,16 @@ static int xen_pt_update(enum xenmap_operation op, { int rc =3D 0; unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; - lpae_t pte, *entry; - lpae_t *third =3D NULL; =20 spin_lock(&xen_pt_lock); =20 for(; addr < addr_end; addr +=3D PAGE_SIZE, mfn =3D mfn_add(mfn, 1)) { - entry =3D &xen_second[second_linear_offset(addr)]; - if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) - { - rc =3D create_xen_table(entry); - if ( rc < 0 ) { - printk("%s: L2 failed\n", __func__); - goto out; - } - } - - BUG_ON(!lpae_is_valid(*entry)); - - third =3D mfn_to_virt(lpae_get_mfn(*entry)); - entry =3D &third[third_table_offset(addr)]; - - switch ( op ) { - case INSERT: - case RESERVE: - if ( lpae_is_valid(*entry) ) - { - printk("%s: trying to replace an existing mapping addr= =3D%lx mfn=3D%"PRI_mfn"\n", - __func__, addr, mfn_x(mfn)); - rc =3D -EINVAL; - goto out; - } - if ( op =3D=3D RESERVE ) - break; - pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - pte.pt.ro =3D PAGE_RO_MASK(flags); - pte.pt.xn =3D PAGE_XN_MASK(flags); - BUG_ON(!pte.pt.ro && !pte.pt.xn); - pte.pt.table =3D 1; - write_pte(entry, pte); - break; - case MODIFY: - case REMOVE: - if ( !lpae_is_valid(*entry) ) - { - printk("%s: trying to %s a non-existing mapping addr= =3D%lx\n", - __func__, op =3D=3D REMOVE ? "remove" : "modify= ", addr); - rc =3D -EINVAL; - goto out; - } - if ( op =3D=3D REMOVE ) - pte.bits =3D 0; - else - { - pte =3D *entry; - pte.pt.ro =3D PAGE_RO_MASK(flags); - pte.pt.xn =3D PAGE_XN_MASK(flags); - if ( !pte.pt.ro && !pte.pt.xn ) - { - printk("%s: Incorrect combination for addr=3D%lx\n= ", - __func__, addr); - rc =3D -EINVAL; - goto out; - } - } - write_pte(entry, pte); - break; - default: - BUG(); - } + rc =3D xen_pt_update_entry(op, addr, mfn, flags); + if ( rc ) + break; } -out: + /* * Flush the TLBs even in case of failure because we may have * partially modified the PT. This will prevent any unexpected --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125300; cv=none; d=zoho.com; s=zohoarc; b=AwWqxPCYEyahDM0niFUFSeejiuzFsE9ipIOKzZOzQsTt/5jEA4hq6MSubNQ0XcWXpvisyPEBUjltYLXdqtEpGeT+/8HomObqa3LslR5O36EnFh+FeC/n/RZeJc+xYH/Mrqp3yJbg/1MHm6WcmDtkxmCx3G2EbfYgI0UNkrB4sEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125300; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LpnIUsiNfWwPWKoaae1YH4QsdYC0swy4OnB3z1iHi1M=; b=mEtIMf2cDJI1Y7UmkGeYsO3/Y19qQHNtB5OkhlQamKYvSCjo03nxaInRC6ZGZxI9mTCypNLU2jB2DSS+3zPJj4uG3+tuEC6TmikqgnV+qje66E04fIxBxL8wOvMUUh+R+4HxJoAvQQu7zvqbJ+BFU+0lHegcYUJ5oFQtTMBk/i8= 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 1556125300521357.2590488011348; Wed, 24 Apr 2019 10:01:40 -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 1hJLFk-0007nS-Ux; Wed, 24 Apr 2019 17:00:12 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFj-0007nC-8v for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:11 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6b529442-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:10 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F363AEBD; Wed, 24 Apr 2019 10:00:09 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D87713F557; Wed, 24 Apr 2019 10:00:08 -0700 (PDT) X-Inumbo-ID: 6b529442-66b2-11e9-92d7-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:47 +0100 Message-Id: <20190424165955.23718-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 04/12] xen/arm: mm: Introduce _PAGE_PRESENT and _PAGE_POPULATE 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, the flags are not enough to describe what kind of update will done on the VA range. They need to be used in conjunction with the enum xenmap_operation. It would be more convenient to have all the information for the update in a single place. Two new flags are added to remove the relience on xenmap_operation: - _PAGE_PRESENT: Indicate whether we are adding/removing the mapping - _PAGE_POPULATE: Indicate whether we only populate page-tables Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 2 +- xen/include/asm-arm/page.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 6b1d41cfba..b61217abd0 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1075,7 +1075,7 @@ int map_pages_to_xen(unsigned long virt, =20 int populate_pt_range(unsigned long virt, unsigned long nr_mfns) { - return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, 0); + return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, _PAGE_POPULA= TE); } =20 int destroy_xen_mappings(unsigned long v, unsigned long e) diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h index 2bcdb0f1a5..caf2fac1ff 100644 --- a/xen/include/asm-arm/page.h +++ b/xen/include/asm-arm/page.h @@ -76,6 +76,8 @@ * * [0:2] Memory Attribute Index * [3:4] Permission flags + * [5] Present bit + * [6] Populate page table */ #define PAGE_AI_MASK(x) ((x) & 0x7U) =20 @@ -86,12 +88,15 @@ #define PAGE_XN_MASK(x) (((x) >> _PAGE_XN_BIT) & 0x1U) #define PAGE_RO_MASK(x) (((x) >> _PAGE_RO_BIT) & 0x1U) =20 +#define _PAGE_PRESENT (1U << 5) +#define _PAGE_POPULATE (1U << 6) + /* * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not * meant to be used outside of this header. */ -#define _PAGE_DEVICE _PAGE_XN -#define _PAGE_NORMAL MT_NORMAL +#define _PAGE_DEVICE (_PAGE_XN|_PAGE_PRESENT) +#define _PAGE_NORMAL (MT_NORMAL|_PAGE_PRESENT) =20 #define PAGE_HYPERVISOR_RO (_PAGE_NORMAL|_PAGE_RO|_PAGE_XN) #define PAGE_HYPERVISOR_RX (_PAGE_NORMAL|_PAGE_RO) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125299; cv=none; d=zoho.com; s=zohoarc; b=GzKzKK6UEuFEPURp3N/v0qIW0cKi6GaUffmt1SU1MeVil9RxJ2Hpm+VETP9CbHs5RKm1DGv9F+c+FIqdVdFFYTnzp6JM4MfcUR85KUpOU1mhwWN1hQtmDWvkhYCzgdAVN/jqd4covy5vjseiDlVWnF4k6CYWHG3bdYGSdcP9fx8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125299; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7igDFhkOrVPnO9OKdiiGnD56bNDkqOWtgF14/LjV8Jg=; b=dABPpITSW2DAG8vu4zGu4g7tZD3IZEX0qMAIANXu3upY7gJQAeJTF1PVWqrLlJq3390PFPO0mCdgaX20TothHCMCPC5dbN8NDKhngiKKFZRZspqXDJZE6s2us9XoFzC1Dp4GMzxWKGt3bwCGo19xHURRhtQ44dE4fqJ+u61KAxE= 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 155612529983120.151070079957435; Wed, 24 Apr 2019 10:01:39 -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 1hJLFl-0007nY-9o; Wed, 24 Apr 2019 17:00:13 +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 1hJLFk-0007nN-9Z for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:12 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 6c1ccaee-66b2-11e9-ace0-d3443eb28cba; Wed, 24 Apr 2019 17:00:11 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5A9E115BE; Wed, 24 Apr 2019 10:00:11 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3FD433F557; Wed, 24 Apr 2019 10:00:10 -0700 (PDT) X-Inumbo-ID: 6c1ccaee-66b2-11e9-ace0-d3443eb28cba From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:48 +0100 Message-Id: <20190424165955.23718-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 05/12] xen/arm: mm: Only increment mfn when valid in xen_pt_update 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, the MFN will be incremented even if it is invalid. This will result to have a valid MFN after the first iteration. While this is not a major problem today, this will be in the future if the code expect an invalid MFN at every iteration. Such behavior is prevented by avoiding to increment an invalid MFN. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b61217abd0..eee7122c88 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1046,11 +1046,14 @@ static int xen_pt_update(enum xenmap_operation op, =20 spin_lock(&xen_pt_lock); =20 - for(; addr < addr_end; addr +=3D PAGE_SIZE, mfn =3D mfn_add(mfn, 1)) + for( ; addr < addr_end; addr +=3D PAGE_SIZE ) { rc =3D xen_pt_update_entry(op, addr, mfn, flags); if ( rc ) break; + + if ( !mfn_eq(mfn, INVALID_MFN) ) + mfn =3D mfn_add(mfn, 1); } =20 /* --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125308; cv=none; d=zoho.com; s=zohoarc; b=HltfIO4q/h9UpxxHV7zRTcqbRcsH6OemBv+IYddDpvbzqCHTZyiFt1PvVBlnoucQ71FbA03RlkLYWcW7GcMSO9Wazk7DRf8zn32+PE3RJHKBvoQm+1WrBmvX2nXmN5oqIF6tcVJO1/jwm4TAA47qO3xvHNeqJA+6knl0mLxG7Ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125308; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lpedV1eiG5rJLQ2LjvVRzgM1eOhn2vZtAOxQCzzBEsQ=; b=gg2FfXRnBQGbywch7OVymPmMtl3/WQldvX/YpQvCWINk8l5kTX4Hh2IYdrhDd3cxmzkWtLl+FplDdqR+lynN5xhlYn6fEBJBguqcTRizEmKdN3JjHfPoTA0VnYCe6UNdQKTf4OFScA/S/AACG+TpkOyl/HIqPErlxnK+rEOoZfI= 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 1556125308047635.5253579236454; Wed, 24 Apr 2019 10:01:48 -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 1hJLFn-0007o1-Jr; Wed, 24 Apr 2019 17:00:15 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFm-0007ne-Fl for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:14 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6cdf9cf3-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:12 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B600F374; Wed, 24 Apr 2019 10:00:12 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9B6743F557; Wed, 24 Apr 2019 10:00:11 -0700 (PDT) X-Inumbo-ID: 6cdf9cf3-66b2-11e9-92d7-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:49 +0100 Message-Id: <20190424165955.23718-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 06/12] xen/arm: mm: Sanity check any update of Xen page tables 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The code handling Xen PT update has quite a few restrictions on what it can do. This is not a bad thing as it keeps the code simple. There are already a few checks scattered in current page table handling. However they are not sufficient as they could still allow to modify/remove entry with contiguous bit set. The checks are divided in two sets: - per entry check: They are gathered in a new function that will check whether an update is valid based on the flags passed and the current value of an entry. - global check: They are sanity check on xen_pt_update() parameters. Additionally to contiguous check, we also now check that the caller is not trying to modify the memory attributes of an entry. Lastly, it was probably a bit over the top to forbid removing an invalid mapping. This could just be ignored. The new behavior will be helpful in future changes. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 115 +++++++++++++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 97 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index eee7122c88..5eb6f47d74 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -50,6 +50,19 @@ struct domain *dom_xen, *dom_io, *dom_cow; #undef mfn_to_virt #define mfn_to_virt(mfn) __mfn_to_virt(mfn_x(mfn)) =20 +#ifdef NDEBUG +static inline void +__attribute__ ((__format__ (__printf__, 1, 2))) +mm_printk(const char *fmt, ...) {} +#else +#define mm_printk(fmt, args...) \ + do \ + { \ + dprintk(XENLOG_ERR, fmt, ## args); \ + WARN(); \ + } while (0); +#endif + /* Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching * to the CPUs own pagetables. @@ -963,12 +976,74 @@ enum xenmap_operation { RESERVE }; =20 +/* Sanity check of the entry */ +static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) +{ + /* Sanity check when modifying a page. */ + if ( (flags & _PAGE_PRESENT) && mfn_eq(mfn, INVALID_MFN) ) + { + /* We don't allow changing memory attributes. */ + if ( entry.pt.ai !=3D PAGE_AI_MASK(flags) ) + { + mm_printk("Modifying memory attributes is not allowed (0x%x ->= 0x%x).\n", + entry.pt.ai, PAGE_AI_MASK(flags)); + return false; + } + + /* We don't allow modifying entry with contiguous bit set. */ + if ( entry.pt.contig ) + { + mm_printk("Modifying entry with contiguous bit set is not allo= wed.\n"); + return false; + } + } + /* Sanity check when inserting a page */ + else if ( flags & _PAGE_PRESENT ) + { + /* We should be here with a valid MFN. */ + ASSERT(!mfn_eq(mfn, INVALID_MFN)); + + /* We don't allow replacing any valid entry. */ + if ( lpae_is_valid(entry) ) + { + mm_printk("Changing MFN for a valid entry is not allowed (%#"P= RI_mfn" -> %#"PRI_mfn").\n", + mfn_x(lpae_get_mfn(entry)), mfn_x(mfn)); + return false; + } + } + /* Sanity check when removing a page. */ + else if ( (flags & (_PAGE_PRESENT|_PAGE_POPULATE)) !=3D 0 ) + { + /* We should be here with an invalid MFN. */ + ASSERT(mfn_eq(mfn, INVALID_MFN)); + + /* We don't allow removing page with contiguous bit set. */ + if ( entry.pt.contig ) + { + mm_printk("Removing entry with contiguous bit set is not allow= ed.\n"); + return false; + } + } + /* Sanity check when populating the page-table. No check so far. */ + else + { + ASSERT(!(flags & _PAGE_POPULATE)); + /* We should be here with an invalid MFN */ + ASSERT(mfn_eq(mfn, INVALID_MFN)); + } + + return true; +} + static int xen_pt_update_entry(enum xenmap_operation op, unsigned long add= r, mfn_t mfn, unsigned int flags) { lpae_t pte, *entry; lpae_t *third =3D NULL; =20 + /* _PAGE_POPULATE and _PAGE_PRESENT should never be set together. */ + ASSERT((flags & (_PAGE_POPULATE|_PAGE_PRESENT)) !=3D (_PAGE_POPULATE|_= PAGE_PRESENT)); + entry =3D &xen_second[second_linear_offset(addr)]; if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) { @@ -984,15 +1059,12 @@ static int xen_pt_update_entry(enum xenmap_operation= op, unsigned long addr, third =3D mfn_to_virt(lpae_get_mfn(*entry)); entry =3D &third[third_table_offset(addr)]; =20 + if ( !xen_pt_check_entry(*entry, mfn, flags) ) + return -EINVAL; + switch ( op ) { case INSERT: case RESERVE: - if ( lpae_is_valid(*entry) ) - { - printk("%s: trying to replace an existing mapping addr=3D%= lx mfn=3D%"PRI_mfn"\n", - __func__, addr, mfn_x(mfn)); - return -EINVAL; - } if ( op =3D=3D RESERVE ) break; pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); @@ -1004,12 +1076,6 @@ static int xen_pt_update_entry(enum xenmap_operation= op, unsigned long addr, break; case MODIFY: case REMOVE: - if ( !lpae_is_valid(*entry) ) - { - printk("%s: trying to %s a non-existing mapping addr=3D%lx= \n", - __func__, op =3D=3D REMOVE ? "remove" : "modify", a= ddr); - return -EINVAL; - } if ( op =3D=3D REMOVE ) pte.bits =3D 0; else @@ -1017,12 +1083,6 @@ static int xen_pt_update_entry(enum xenmap_operation= op, unsigned long addr, pte =3D *entry; pte.pt.ro =3D PAGE_RO_MASK(flags); pte.pt.xn =3D PAGE_XN_MASK(flags); - if ( !pte.pt.ro && !pte.pt.xn ) - { - printk("%s: Incorrect combination for addr=3D%lx\n", - __func__, addr); - return -EINVAL; - } } write_pte(entry, pte); break; @@ -1044,6 +1104,25 @@ static int xen_pt_update(enum xenmap_operation op, int rc =3D 0; unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; =20 + /* + * The hardware was configured to forbid mapping both writeable and + * executable. + * When modifying/creating mapping (i.e _PAGE_PRESENT is set), + * prevent any update if this happen. + */ + if ( (flags & _PAGE_PRESENT) && !PAGE_RO_MASK(flags) && + !PAGE_XN_MASK(flags) ) + { + mm_printk("Mappings should not be both Writeable and Executable.\n= "); + return -EINVAL; + } + + if ( !IS_ALIGNED(virt, PAGE_SIZE) ) + { + mm_printk("The virtual address is not aligned to the page-size.\n"= ); + return -EINVAL; + } + spin_lock(&xen_pt_lock); =20 for( ; addr < addr_end; addr +=3D PAGE_SIZE ) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125300; cv=none; d=zoho.com; s=zohoarc; b=lX59Z6wo5XA1vmURyQJQLJSolYGxkIixOyrJD93XdoRqDoPBazPsu0k7f1TbZu/YcZelG3EeA0oWMn3QPZoNM0qvdYmHyMzOzcN+zcnFPcwsXBrYVt2xRGNhVCk8XsIdBcGoHpW52qgjFx8NxOqddxSMJDUFMtEqULXSSku4OMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125300; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SXAhvy1mk1PIBcnA6Oz00f9u41NJpRNQO0PISrzh9Ag=; b=hjdGH30SygeB8rLcRBkU1OLMWN8o4p8FJmU20i9vZAqHCzmW+uPxh/y6WbuB/AD6UuCi0mIjyQ95TCC3/PHG5YEj72bxChx6HIghcznglsAkteeD+GpPD73ate+vWw8hMZTUV2EJgQrbVYVzCD66Ufs8d7lOfEiKrHQNMJE3NzU= 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 1556125300368344.05185148758005; Wed, 24 Apr 2019 10:01:40 -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 1hJLFp-0007ob-1c; Wed, 24 Apr 2019 17:00:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFn-0007o4-OR for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:15 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6dc2e40a-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:14 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1DB67EBD; Wed, 24 Apr 2019 10:00:14 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 028153F557; Wed, 24 Apr 2019 10:00:12 -0700 (PDT) X-Inumbo-ID: 6dc2e40a-66b2-11e9-92d7-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:50 +0100 Message-Id: <20190424165955.23718-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 07/12] xen/arm: mm: Rework xen_pt_update_entry to avoid use xenmap_operation 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" With the newly introduced flags, it is now possible to know how the page will be updated through the flags. All the use of xenmap_operation are not replaced with the flags. At the same time, validity check are now removed as they are gathered in xen_pt_check_entry(). Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 5eb6f47d74..611ea53992 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1062,34 +1062,33 @@ static int xen_pt_update_entry(enum xenmap_operatio= n op, unsigned long addr, if ( !xen_pt_check_entry(*entry, mfn, flags) ) return -EINVAL; =20 - switch ( op ) { - case INSERT: - case RESERVE: - if ( op =3D=3D RESERVE ) - break; + /* If we are only populating page-table, then we are done. */ + if ( flags & _PAGE_POPULATE ) + return 0; + + /* We are removing the page */ + if ( !(flags & _PAGE_PRESENT) ) + memset(&pte, 0x00, sizeof(pte)); + else + { + /* We are inserting a mapping =3D> Create new pte. */ + if ( !mfn_eq(mfn, INVALID_MFN) ) + { pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - pte.pt.ro =3D PAGE_RO_MASK(flags); - pte.pt.xn =3D PAGE_XN_MASK(flags); - BUG_ON(!pte.pt.ro && !pte.pt.xn); + + /* Third level entries set pte.pt.table =3D 1 */ pte.pt.table =3D 1; - write_pte(entry, pte); - break; - case MODIFY: - case REMOVE: - if ( op =3D=3D REMOVE ) - pte.bits =3D 0; - else - { - pte =3D *entry; - pte.pt.ro =3D PAGE_RO_MASK(flags); - pte.pt.xn =3D PAGE_XN_MASK(flags); - } - write_pte(entry, pte); - break; - default: - BUG(); + } + else /* We are updating the permission =3D> Copy the current pte. = */ + pte =3D *entry; + + /* Set permission */ + pte.pt.ro =3D PAGE_RO_MASK(flags); + pte.pt.xn =3D PAGE_XN_MASK(flags); } =20 + write_pte(entry, pte); + return 0; } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125298; cv=none; d=zoho.com; s=zohoarc; b=DhIXHYU7w+AZ/2zHQFU7zxR9b/ziDu3UetlZ2dlAbyAKR3btZtv41r//7aP+PlkrZKRm8vIYDGewH322k1MgMeqphnAWqKXxjhv8iKWEl3YuxYvbDBRZNGiXUjPEo8A0sr+GbHRksUhTHItFoyBcxx5CWtrum+sGIaoW69ge3sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125298; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ufJGPF65hyJPA8b2qjto24PDzi2+yA54VwpoEX8bzlc=; b=fI5U2mix4gq98KmTDek3CrPsE16vrzi3wytWyXbXlogAKSl5nBDYVTurq5Wkroj+Dw8Kq9OUDh0IfvtlZKRf2BhSx1SiIv00GrplIlu9pBYTsxybEk8Kquj9WfIGGy6xtmNtW5nLPOZEMwEg0zbn02pjj86FoBwM1xD48aZLcg4= 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 1556125298920341.02863368775957; Wed, 24 Apr 2019 10:01:38 -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 1hJLFp-0007ol-CT; Wed, 24 Apr 2019 17:00:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFo-0007oY-Vy for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:17 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6e82a483-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:15 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 78DDD15BE; Wed, 24 Apr 2019 10:00:15 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5E7353F557; Wed, 24 Apr 2019 10:00:14 -0700 (PDT) X-Inumbo-ID: 6e82a483-66b2-11e9-92d7-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:51 +0100 Message-Id: <20190424165955.23718-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 08/12] xen/arm: mm: Remove enum xenmap_operation 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The enum xenmap_operation is not used anymore. So remove it. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 611ea53992..97e876d866 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -969,13 +969,6 @@ static int create_xen_table(lpae_t *entry) return 0; } =20 -enum xenmap_operation { - INSERT, - REMOVE, - MODIFY, - RESERVE -}; - /* Sanity check of the entry */ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) { @@ -1035,8 +1028,8 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mf= n, unsigned int flags) return true; } =20 -static int xen_pt_update_entry(enum xenmap_operation op, unsigned long add= r, - mfn_t mfn, unsigned int flags) +static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, + unsigned int flags) { lpae_t pte, *entry; lpae_t *third =3D NULL; @@ -1094,8 +1087,7 @@ static int xen_pt_update_entry(enum xenmap_operation = op, unsigned long addr, =20 static DEFINE_SPINLOCK(xen_pt_lock); =20 -static int xen_pt_update(enum xenmap_operation op, - unsigned long virt, +static int xen_pt_update(unsigned long virt, mfn_t mfn, unsigned long nr_mfns, unsigned int flags) @@ -1126,7 +1118,7 @@ static int xen_pt_update(enum xenmap_operation op, =20 for( ; addr < addr_end; addr +=3D PAGE_SIZE ) { - rc =3D xen_pt_update_entry(op, addr, mfn, flags); + rc =3D xen_pt_update_entry(addr, mfn, flags); if ( rc ) break; =20 @@ -1151,24 +1143,24 @@ int map_pages_to_xen(unsigned long virt, unsigned long nr_mfns, unsigned int flags) { - return xen_pt_update(INSERT, virt, mfn, nr_mfns, flags); + return xen_pt_update(virt, mfn, nr_mfns, flags); } =20 int populate_pt_range(unsigned long virt, unsigned long nr_mfns) { - return xen_pt_update(RESERVE, virt, INVALID_MFN, nr_mfns, _PAGE_POPULA= TE); + return xen_pt_update(virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); } =20 int destroy_xen_mappings(unsigned long v, unsigned long e) { ASSERT(v <=3D e); - return xen_pt_update(REMOVE, v, INVALID_MFN, (e - v) >> PAGE_SHIFT, 0); + return xen_pt_update(v, INVALID_MFN, (e - v) >> PAGE_SHIFT, 0); } =20 int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int fla= gs) { ASSERT(s <=3D e); - return xen_pt_update(MODIFY, s, INVALID_MFN, (e - s) >> PAGE_SHIFT, fl= ags); + return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); } =20 enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125300; cv=none; d=zoho.com; s=zohoarc; b=LIq5q2cGOenslhUmkQmGqNYXEb+C+n5dX14ku1mKdy8peeKL/oe4daIZsbzODy2dyZ9nAsXAgCTr5JSfYZ7h4asfwa0W7JzqbcVk4opGq6Dg66EM76qZoJdQOGMZ+gMHOm77WO8f70E1D2AXSMwVIz098CC1kjylrgpEJR9SCDI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125300; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=CVOwkPIQIV7WD0PjnnuTpAx04DTIUnAjo6Z3+BVP+34=; b=VIy474VmhIT2diSp/ZKi/nzaMkVxF5Glzj07cnOXUfwigDGwP71Ip2SM7olZymiyf1m4Zenr9Vtng21iH/F7K51fnh2st8DymAAre1KDWxolX0q1bXicDsimm3J4RIyo8P+7lUSALUlLDuCLqHlrtHLNh3X9apfT/DLUBHkMJHQ= 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 1556125300543194.44111152425353; Wed, 24 Apr 2019 10:01:40 -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 1hJLFr-0007pc-Mo; Wed, 24 Apr 2019 17:00:19 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJLFq-0007ou-7w for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:18 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6f5498a0-66b2-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 17:00:17 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D40E7374; Wed, 24 Apr 2019 10:00:16 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B99843F557; Wed, 24 Apr 2019 10:00:15 -0700 (PDT) X-Inumbo-ID: 6f5498a0-66b2-11e9-92d7-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:52 +0100 Message-Id: <20190424165955.23718-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 09/12] xen/arm: mm: Use {, un}map_domain_page() to map/unmap Xen page-tables 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, the virtual address of the 3rd level page-tables is obtained using mfn_to_virt(). On Arm32, mfn_to_virt can only work on xenheap page. While in practice all the page-tables updated will reside in xenheap, in practive the page-tables covering Xen memory (e.g xen_mapping) is part of Xen binary. Furthermore, a follow-up change will update xen_pt_update_entry() to walk all the levels and therefore be more generic. Some of the page-tables will also part of Xen memory and therefore will not be reachable using mfn_to_virt(). The easiest way to reach those pages is to use {, un}map_domain_page(). While on arm32 this means an extra mapping in the normal cases, this is not very important as xen page-tables are not updated often. In order to allow future change in the way Xen page-tables are mapped, two new helpers are introduced to map/unmap the page-tables. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 97e876d866..115e8340f1 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -969,6 +969,16 @@ static int create_xen_table(lpae_t *entry) return 0; } =20 +static lpae_t *xen_map_table(mfn_t mfn) +{ + return map_domain_page(mfn); +} + +static void xen_unmap_table(const lpae_t *table) +{ + unmap_domain_page(table); +} + /* Sanity check of the entry */ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) { @@ -1031,6 +1041,7 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mf= n, unsigned int flags) static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, unsigned int flags) { + int rc; lpae_t pte, *entry; lpae_t *third =3D NULL; =20 @@ -1049,15 +1060,17 @@ static int xen_pt_update_entry(unsigned long addr, = mfn_t mfn, =20 BUG_ON(!lpae_is_valid(*entry)); =20 - third =3D mfn_to_virt(lpae_get_mfn(*entry)); + third =3D xen_map_table(lpae_get_mfn(*entry)); entry =3D &third[third_table_offset(addr)]; =20 + rc =3D -EINVAL; if ( !xen_pt_check_entry(*entry, mfn, flags) ) - return -EINVAL; + goto out; =20 /* If we are only populating page-table, then we are done. */ + rc =3D 0; if ( flags & _PAGE_POPULATE ) - return 0; + goto out; =20 /* We are removing the page */ if ( !(flags & _PAGE_PRESENT) ) @@ -1082,7 +1095,12 @@ static int xen_pt_update_entry(unsigned long addr, m= fn_t mfn, =20 write_pte(entry, pte); =20 - return 0; + rc =3D 0; + +out: + xen_unmap_table(third); + + return rc; } =20 static DEFINE_SPINLOCK(xen_pt_lock); --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125305; cv=none; d=zoho.com; s=zohoarc; b=TQAZXtMbrDpFAXhvZ2vK+4MldS86/uv589zONlrwhI55pgUuFvbmPbqzNLZ8el8OQkYHQm5sr26EdbdZNEaxNwfn2xEKIoGDo6Mb/2vfiwJ2NRJHFY4uJwR9/LsLAbUIYfNnZ2QX0somEpWuZFNv/Al0m9PWEe9cVlDo4UCpdtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125305; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=YXcAIG4oObdlYQYj4+ikPZYdAa4sUe5JCoqRJj5pq0M=; b=RwXTPtSExOc7fclaDjWvhaH4YEM0LKz1j2KhyD3sFXGXOZ+2u/NfsucmqYobTCKB6cCwp9aWc9m/JDMcUBVYqfDaFa2w+RG29Z6rE3xhQMnH3BH3a5wdp5YH+WMdhCkhNMAfK9qA8yODyQ38ziveulzAc2Dp/J/W1c+NAaZ0U7E= 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 1556125305556933.7494595037629; Wed, 24 Apr 2019 10:01:45 -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 1hJLFt-0007pz-16; Wed, 24 Apr 2019 17:00:21 +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 1hJLFr-0007pX-HF for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:19 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 7037dc5e-66b2-11e9-9f38-6b2c9412e21c; Wed, 24 Apr 2019 17:00:18 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 49331EBD; Wed, 24 Apr 2019 10:00:18 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 209803F557; Wed, 24 Apr 2019 10:00:16 -0700 (PDT) X-Inumbo-ID: 7037dc5e-66b2-11e9-9f38-6b2c9412e21c From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:53 +0100 Message-Id: <20190424165955.23718-11-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 10/12] xen/arm: mm: Rework Xen page-tables walk during update 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, xen_pt_update_entry() is only able to update the region covered by xen_second (i.e 0 to 0x7fffffff). Because of the restriction we end to have multiple functions in mm.c modifying the page-tables differently. Furthermore, we never walked the page-tables fully. This means that any change in the layout may requires major rewrite of the page-tables code. Lastly, we have been quite lucky that no one ever tried to pass an address outside this range because it would have blown-up. xen_pt_update_entry() is reworked to walk over the page-tables every time. The logic has been borrowed from arch/arm/p2m.c and contain some limitations for the time being: - Superpage cannot be shattered - Only level 3 (i.e 4KB) can be done Note that the parameter 'addr' has been renamed to 'virt' to make clear we are dealing with a virtual address. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++---= ---- 1 file changed, 106 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 115e8340f1..022967ff9f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -979,6 +979,53 @@ static void xen_unmap_table(const lpae_t *table) unmap_domain_page(table); } =20 +#define XEN_TABLE_MAP_FAILED 0 +#define XEN_TABLE_SUPER_PAGE 1 +#define XEN_TABLE_NORMAL_PAGE 2 + +/* + * Take the currently mapped table, find the corresponding entry, + * and map the next table, if available. + * + * The read_only parameters indicates whether intermediate tables should + * be allocated when not present. + * + * Return values: + * XEN_TABLE_MAP_FAILED: Either read_only was set and the entry + * was empty, or allocating a new page failed. + * XEN_TABLE_NORMAL_PAGE: next level mapped normally + * XEN_TABLE_SUPER_PAGE: The next entry points to a superpage. + */ +static int xen_pt_next_level(bool read_only, unsigned int level, + lpae_t **table, unsigned int offset) +{ + lpae_t *entry; + int ret; + + entry =3D *table + offset; + + if ( !lpae_is_valid(*entry) ) + { + if ( read_only ) + return XEN_TABLE_MAP_FAILED; + + ret =3D create_xen_table(entry); + if ( ret ) + return XEN_TABLE_MAP_FAILED; + } + + ASSERT(lpae_is_valid(*entry)); + + /* The function xen_pt_next_level is never called at the 3rd level */ + if ( lpae_is_mapping(*entry, level) ) + return XEN_TABLE_SUPER_PAGE; + + xen_unmap_table(*table); + *table =3D xen_map_table(lpae_get_mfn(*entry)); + + return XEN_TABLE_NORMAL_PAGE; +} + /* Sanity check of the entry */ static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) { @@ -1038,30 +1085,65 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t = mfn, unsigned int flags) return true; } =20 -static int xen_pt_update_entry(unsigned long addr, mfn_t mfn, - unsigned int flags) +static int xen_pt_update_entry(mfn_t root, unsigned long virt, + mfn_t mfn, unsigned int flags) { int rc; + unsigned int level; + /* We only support 4KB mapping (i.e level 3) for now */ + unsigned int target =3D 3; + lpae_t *table; + /* + * The intermediate page tables are read-only when the MFN is not valid + * and we are not populating page table. + * This means we either modify permissions or remove an entry. + */ + bool read_only =3D mfn_eq(mfn, INVALID_MFN) && !(flags & _PAGE_POPULAT= E); lpae_t pte, *entry; - lpae_t *third =3D NULL; + + /* convenience aliases */ + DECLARE_OFFSETS(offsets, (paddr_t)virt); =20 /* _PAGE_POPULATE and _PAGE_PRESENT should never be set together. */ ASSERT((flags & (_PAGE_POPULATE|_PAGE_PRESENT)) !=3D (_PAGE_POPULATE|_= PAGE_PRESENT)); =20 - entry =3D &xen_second[second_linear_offset(addr)]; - if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) + table =3D xen_map_table(root); + for ( level =3D HYP_PT_ROOT_LEVEL; level < target; level++ ) { - int rc =3D create_xen_table(entry); - if ( rc < 0 ) { - printk("%s: L2 failed\n", __func__); - return rc; + rc =3D xen_pt_next_level(read_only, level, &table, offsets[level]); + if ( rc =3D=3D XEN_TABLE_MAP_FAILED ) + { + /* + * We are here because xen_pt_next_level has failed to map + * the intermediate page table (e.g the table does not exist + * and the pt is read-only). It is a valid case when + * removing a mapping as it may not exist in the page table. + * In this case, just ignore it. + */ + if ( flags & (_PAGE_PRESENT|_PAGE_POPULATE) ) + { + mm_printk("%s: Unable to map level %u\n", __func__, level); + rc =3D -ENOENT; + goto out; + } + else + { + rc =3D 0; + goto out; + } } + else if ( rc !=3D XEN_TABLE_NORMAL_PAGE ) + break; } =20 - BUG_ON(!lpae_is_valid(*entry)); + if ( level !=3D target ) + { + mm_printk("%s: Shattering superpage is not supported\n", __func__); + rc =3D -EOPNOTSUPP; + goto out; + } =20 - third =3D xen_map_table(lpae_get_mfn(*entry)); - entry =3D &third[third_table_offset(addr)]; + entry =3D table + offsets[level]; =20 rc =3D -EINVAL; if ( !xen_pt_check_entry(*entry, mfn, flags) ) @@ -1098,7 +1180,7 @@ static int xen_pt_update_entry(unsigned long addr, mf= n_t mfn, rc =3D 0; =20 out: - xen_unmap_table(third); + xen_unmap_table(table); =20 return rc; } @@ -1114,6 +1196,15 @@ static int xen_pt_update(unsigned long virt, unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; =20 /* + * For arm32, page-tables are different on each CPUs. Yet, they share + * some common mappings. It is assumed that only common mappings + * will be modified with this function. + * + * XXX: Add a check. + */ + const mfn_t root =3D virt_to_mfn(THIS_CPU_PGTABLE); + + /* * The hardware was configured to forbid mapping both writeable and * executable. * When modifying/creating mapping (i.e _PAGE_PRESENT is set), @@ -1134,9 +1225,9 @@ static int xen_pt_update(unsigned long virt, =20 spin_lock(&xen_pt_lock); =20 - for( ; addr < addr_end; addr +=3D PAGE_SIZE ) + for ( ; addr < addr_end; addr +=3D PAGE_SIZE ) { - rc =3D xen_pt_update_entry(addr, mfn, flags); + rc =3D xen_pt_update_entry(root, addr, mfn, flags); if ( rc ) break; =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125300; cv=none; d=zoho.com; s=zohoarc; b=TUHTTW9Fj1U4i1QqfpVDqrioij/nRRwb75ssWG2BYj5HNXthtPnPeLmDYLRMauc8S8BGbC00Ccbid5zH1KFD22PdK3ekmOctnmpOniDszChym9c497LSoBygrzXZNBiIKiktfsYP0R3WuJL3nerGMcBk66LEAJM81WScjjfI8tI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125300; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kGVrH3Kn+5uS2Ad5pkgcMxLuMSOBZq7zhjVLK9j1V3c=; b=k3kPZxcOrpNIoVZOPZgtWefekT3R3C6Xa2ZeA1iP0O8QUyyFxjffWeuunmUCL2t05eJL18k3wvNdXM1zwrJLmak6no3oHrAL1YFtjKeFGRHgAtyD1b1jmrhvXqPBUufMBt0vEEWaF3/k3L6XKVzIgmVZUmAVr8f0vas3bJZJU9Q= 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 1556125300896891.2149531027655; Wed, 24 Apr 2019 10:01:40 -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 1hJLFu-0007qj-Bt; Wed, 24 Apr 2019 17:00:22 +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 1hJLFs-0007pn-QE for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:20 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 70fe5c76-66b2-11e9-a695-fff1a3e162a4; Wed, 24 Apr 2019 17:00:19 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9609115BE; Wed, 24 Apr 2019 10:00:19 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7B9DD3F557; Wed, 24 Apr 2019 10:00:18 -0700 (PDT) X-Inumbo-ID: 70fe5c76-66b2-11e9-a695-fff1a3e162a4 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:54 +0100 Message-Id: <20190424165955.23718-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 11/12] xen/arm: mm: Don't open-code Xen PT update in {set, clear}_fixmap() 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" {set, clear}_fixmap() are currently open-coding update to the Xen page-tables. This can be avoided by using the generic helpers map_pages_to_xen() and destroy_xen_mappings(). Both function are not meant to fail for fixmap, hence the BUG_ON() checking the return. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 022967ff9f..7e6df9f877 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -343,19 +343,19 @@ static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsi= gned attr) /* Map a 4k page in a fixmap entry */ void set_fixmap(unsigned map, mfn_t mfn, unsigned int flags) { - lpae_t pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - pte.pt.table =3D 1; /* 4k mappings always have this bit set */ - pte.pt.xn =3D 1; - write_pte(xen_fixmap + third_table_offset(FIXMAP_ADDR(map)), pte); - flush_xen_tlb_range_va(FIXMAP_ADDR(map), PAGE_SIZE); + int res; + + res =3D map_pages_to_xen(FIXMAP_ADDR(map), mfn, 1, flags); + BUG_ON(res !=3D 0); } =20 /* Remove a mapping from a fixmap entry */ void clear_fixmap(unsigned map) { - lpae_t pte =3D {0}; - write_pte(xen_fixmap + third_table_offset(FIXMAP_ADDR(map)), pte); - flush_xen_tlb_range_va(FIXMAP_ADDR(map), PAGE_SIZE); + int res; + + res =3D destroy_xen_mappings(FIXMAP_ADDR(map), FIXMAP_ADDR(map) + PAGE= _SIZE); + BUG_ON(res !=3D 0); } =20 /* Create Xen's mappings of memory. --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu May 2 06:02:05 2024 Delivered-To: importer@patchew.org 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; 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=1556125302; cv=none; d=zoho.com; s=zohoarc; b=iapQR35idooWDsD4ELOeiDBOzPdO2z4vwAFiodzTtzLxdJw3iwGrV2OClOdrni9aruTcb42qC0KwPo8/DBwHoKn8fxf18B+mMMwmGnHo6yVAZQS2qXGmf4Kryq4IqpSNoCHF+tBWRKTUwuQUMF/1blp4NCpT3FuUUv+pIPb9eto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556125302; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=NlbK9HPyMEbbgtBdlomy8/Y3Jhvfacl6cJjNdD5yKCw=; b=hRvsQCnHZ4xi133SzgwMqVwW23HnsayaTYjvQbkIoZyF2VUEp7atBdeoMEt54ufn5xb8lKHWO+pV8QcZZ/F+1NV9JLR97vpCg0sU+s3FfDZZQwVJq4L049ZC+fblx9O1sjJ3DY6DkcwLzSvvokaDdkrGFkajwvyIJwm6ew9IGLI= 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 1556125302570642.7635508890686; Wed, 24 Apr 2019 10:01:42 -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 1hJLFu-0007qw-Ma; Wed, 24 Apr 2019 17:00:22 +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 1hJLFu-0007qV-22 for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 17:00:22 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 71db77c8-66b2-11e9-9fa8-dfc6e70f8e3d; Wed, 24 Apr 2019 17:00:21 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F1477374; Wed, 24 Apr 2019 10:00:20 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D6D073F557; Wed, 24 Apr 2019 10:00:19 -0700 (PDT) X-Inumbo-ID: 71db77c8-66b2-11e9-9fa8-dfc6e70f8e3d From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 24 Apr 2019 17:59:55 +0100 Message-Id: <20190424165955.23718-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com> References: <20190424165955.23718-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 12/12] xen/arm: mm: Remove set_pte_flags_on_range() 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , sstabellini@kernel.org, Andrii_Anisov@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" set_pte_flags_on_range() is yet another function that will open-code update to a specific range in the Xen page-tables. It can be completely dropped by using either modify_xen_mappings() or destroy_xen_mappings(). Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- xen/arch/arm/mm.c | 58 ++++++++++-----------------------------------------= ---- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7e6df9f877..5810d569ee 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1272,52 +1272,6 @@ int modify_xen_mappings(unsigned long s, unsigned lo= ng e, unsigned int flags) return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); } =20 -enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; -static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg= mg) -{ - lpae_t pte; - int i; - - ASSERT(is_kernel(p) && is_kernel(p + l)); - - /* Can only guard in page granularity */ - ASSERT(!((unsigned long) p & ~PAGE_MASK)); - ASSERT(!(l & ~PAGE_MASK)); - - for ( i =3D (p - _start) / PAGE_SIZE;=20 - i < (p + l - _start) / PAGE_SIZE;=20 - i++ ) - { - pte =3D xen_xenmap[i]; - switch ( mg ) - { - case mg_clear: - pte.pt.valid =3D 0; - break; - case mg_ro: - pte.pt.valid =3D 1; - pte.pt.pxn =3D 1; - pte.pt.xn =3D 1; - pte.pt.ro =3D 1; - break; - case mg_rw: - pte.pt.valid =3D 1; - pte.pt.pxn =3D 1; - pte.pt.xn =3D 1; - pte.pt.ro =3D 0; - break; - case mg_rx: - pte.pt.valid =3D 1; - pte.pt.pxn =3D 0; - pte.pt.xn =3D 0; - pte.pt.ro =3D 1; - break; - } - write_pte(xen_xenmap + i, pte); - } - flush_xen_tlb_local(); -} - /* Release all __init and __initdata ranges to be reused */ void free_init_memory(void) { @@ -1326,8 +1280,12 @@ void free_init_memory(void) uint32_t insn; unsigned int i, nr =3D len / sizeof(insn); uint32_t *p; + int rc; =20 - set_pte_flags_on_range(__init_begin, len, mg_rw); + rc =3D modify_xen_mappings((unsigned long)__init_begin, + (unsigned long)__init_end, PAGE_HYPERVISOR_RW= ); + if ( rc ) + panic("Unable to map RW the init section (rc =3D %d)", rc); =20 /* * From now on, init will not be used for execution anymore, @@ -1345,7 +1303,11 @@ void free_init_memory(void) for ( i =3D 0; i < nr; i++ ) *(p + i) =3D insn; =20 - set_pte_flags_on_range(__init_begin, len, mg_clear); + rc =3D destroy_xen_mappings((unsigned long)__init_begin, + (unsigned long)__init_end); + if ( rc ) + panic("Unable to remove the init section (rc =3D %d)", rc); + init_domheap_pages(pa, pa + len); printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>= 10); } --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel