From nobody Fri Apr 19 21:44:49 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=1557837152; cv=none; d=zoho.com; s=zohoarc; b=JOiW6y6c9ZpQLVkCKhW29OZfAND3VGRkX/URC2sfklVZ9gRGLxUo62lS5XVNHpV6Rv9+Tx0jA1LtDSbeg4RV8iA04zqC3LHWpNx4i2e4Ib5yDHsIxuW8XY887bK5k05NcBFpZdewJXzGB7xrVCSatmjyoKnC4SNWcWuGzfG7juk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837152; 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=KZfDxa9HDPTMdTvVn3yYmFaSRApeZAiwsNjCCCAspik=; b=oUEK9cQSe9IG6ID9H85m0sMGkAbH9D0W3h50nEtjeRDuacnEdw5TK4KyLn82BH75YIqGtHrflNA4/hnkBGgLGpZdWEGlyURD2HIeJ/Dz88gLJ0Bh5cCGR5afyFtyD7Z+mGwBuk2OY9ryMioChzZMI1k2ZVmX+DXszZ65XlbTais= 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 1557837152811641.8792469421171; Tue, 14 May 2019 05:32:32 -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 1hQWal-0005L3-6n; Tue, 14 May 2019 12:31:35 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWaj-0005Kr-Vd for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:34 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 34e55125-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:32 +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 B456815AB; Tue, 14 May 2019 05:31:32 -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 80F4A3F71E; Tue, 14 May 2019 05:31:31 -0700 (PDT) X-Inumbo-ID: 34e55125-7644-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:14 +0100 Message-Id: <20190514123125.29086-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 Acked-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- 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 Fri Apr 19 21:44:49 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=1557837144; cv=none; d=zoho.com; s=zohoarc; b=A6T7MAOVXdqazBBfg3P4pGsgP7dMU5O4IN87K9Amtw7Hk8sU/ti9gcJk/HWngACAl3j8QJRp1ixHtUc7UN08yl/PSXdQpubqUwQPT6Hztg0UffLaRzcHqaDPOG0/eBLT2NA2m4DcUYX/NQCM5Gsx7M6Ym037lnyAm85sGq9Y+Ws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837144; 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=DzCZSgyav+mtmOFNt5O6rV4PUjXSBF4b36MR1VD+oL8=; b=BqPK8DVyCysOk27ahQGqXVERk3Yb+dBo+EzN+ZGkpzu4hxc1JuQcS23BLhd2U6E3/QsncIurGu3JxExCIp6m4gxHcAYzwc05UMjyuc9mepASRTtHrdhVup1s17Z/eRx+szY69rGQvXTzS8RXK0oBjkzJiZzHuhH+YM+DTkU5gJk= 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 1557837144327970.5336468934179; Tue, 14 May 2019 05:32:24 -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 1hQWam-0005LE-Gh; Tue, 14 May 2019 12:31:36 +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 1hQWal-0005L9-P6 for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:35 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 35d8d544-7644-11e9-bbf8-af7ffef685ad; Tue, 14 May 2019 12:31:34 +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 318DC15AD; Tue, 14 May 2019 05:31:34 -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 F25383F71E; Tue, 14 May 2019 05:31:32 -0700 (PDT) X-Inumbo-ID: 35d8d544-7644-11e9-bbf8-af7ffef685ad From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:15 +0100 Message-Id: <20190514123125.29086-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 Acked-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- 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 b408de7c75..36e22fc9ad 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -970,11 +970,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; @@ -1067,25 +1067,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 Fri Apr 19 21:44:49 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=1557837147; cv=none; d=zoho.com; s=zohoarc; b=JObkOJWKrb1G6Eyzl1LlJV4FvDWTAKoVa8u8v6krBuKR+zySnAuJU75l3er1ArdxDguyEJbIv5Ra6o/RkMA250hFAysbj9dt2+AoIlvy6aFMZEpdxr1KtpWEsfYZ6jHxtI314QTr0rXv16V5oy2lX3IIjYXkKbJOjGmeLsIAP9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837147; 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=Sd5LlFTLrSwuH9XsPqTgL8PejG5Vyahgchhl9qG0fuk=; b=PzKicfsbmc1KP1TQchi8Y0eij4+4MxFotSfZ0/m4lKUCtYT46XEY59V8yGROe50mtHtIM5kX9xQ4vkkqbd3Q9vvSEDEQtfgG/9cEBiQZkaXaSQlMH+kNNP774icTKoUuKBEhFx4sOHbS8v3ajYjx+2nj8koX5yy5JPxP5xb+N88= 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 1557837147114967.7517917855666; Tue, 14 May 2019 05:32:27 -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 1hQWan-0005Lb-Q8; Tue, 14 May 2019 12:31:37 +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 1hQWan-0005LK-1a for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:37 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 36ade63a-7644-11e9-a640-97876d6490b5; Tue, 14 May 2019 12:31:36 +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 A2CC4341; Tue, 14 May 2019 05:31:35 -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 6FB0F3F71E; Tue, 14 May 2019 05:31:34 -0700 (PDT) X-Inumbo-ID: 36ade63a-7644-11e9-a640-97876d6490b5 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:16 +0100 Message-Id: <20190514123125.29086-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- 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 36e22fc9ad..f956aa6399 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -968,6 +968,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, @@ -978,78 +1048,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 Fri Apr 19 21:44:49 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=1557837147; cv=none; d=zoho.com; s=zohoarc; b=Xv6MM/Jp9OTL5mmKE9ELpgC5q4dZB3eJtROBpd9+p9YNZm6EfTagVZ7/rWdQ8yDE0PoCWD2Y5D7ikksm+q93BeuOqEDiIr8nOAQgboB5M6gGODOYvsunVVFIuUOYfl8zRzVX2HZHxGf3jElp/8f2Rs3m7yBmRdq0V0KJiUh7o3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837147; 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=C4BrL4lMuSUFy2yyQfrathgWRBWylzhjV7bD6DZgLuY=; b=Lws9I1cBqSY5FTKE7hTgW1YqU8VpZADEKhEMugMJx5VAE7rxeQNgrSr3sxrlBZ9ZLJItQBBz0aGGuRxDRzfMJB/VLHS6DpQOFIG2dH/E+GHGy2QGajoxFAj7zigQp/FoOkaP+xoRMUYCFDKcueIf2meY3dx5LS7hr8ZqLhWc81M= 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 1557837147460332.1525257603039; Tue, 14 May 2019 05:32:27 -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 1hQWap-0005MA-9c; Tue, 14 May 2019 12:31:39 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWao-0005Le-0o for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:38 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 377b0a74-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:37 +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 1FBEB15AB; Tue, 14 May 2019 05:31:37 -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 E08DF3F71E; Tue, 14 May 2019 05:31:35 -0700 (PDT) X-Inumbo-ID: 377b0a74-7644-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:17 +0100 Message-Id: <20190514123125.29086-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 04/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 , Stefano Stabellini , Andrii Anisov 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 --- Changes in v2: - Move the patch earlier on in the series - Add Andrii's reviewed-by --- 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 f956aa6399..9de2a1150f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1051,11 +1051,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 Fri Apr 19 21:44:49 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=1557837147; cv=none; d=zoho.com; s=zohoarc; b=B9a+F5hN4OFfL6xc2GEx6YGik4J3TuBy5SHIwkpser98Q6k49Hie1IcGd5c2Pouvvuh+mD+XhsCS85+h5n0F0kpWz4kGATfpeZLl2wvqVjBUIE0oSJoDn98mvXAcvWOa+F5Gth7NKpTvXoOg3U2o7f/q/x6lZbeolgMX3uBSBXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837147; 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=EoGUuu7rYiZT8b39UakCMSwcCzcEDBQRX+JSS26gZQM=; b=VdMch5hp5bQkI7siRh1cMQp1YSAxIvff7KUZvsM3u6aAxqMiFCCvoUQFvGapKz33mDHp1g6mgdqNR53R+1LaG17oiszee9EbMTaB4WRlxwIVbI3FmAPJTfIvfS6KEqsY1hU4U1QuVC3Oenbw0JwdHl3G78cZI1mHprn3xqS6h1M= 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 1557837147571991.2031325268507; Tue, 14 May 2019 05:32:27 -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 1hQWaq-0005Md-K4; Tue, 14 May 2019 12:31:40 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWaq-0005MN-3t for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:40 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3860fc25-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:38 +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 9137315AD; Tue, 14 May 2019 05:31:38 -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 5DFA63F71E; Tue, 14 May 2019 05:31:37 -0700 (PDT) X-Inumbo-ID: 3860fc25-7644-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:18 +0100 Message-Id: <20190514123125.29086-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 05/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 , Stefano Stabellini , Andrii Anisov 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 --- Changes in v2: - Add Andrii's reviewed-by --- 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 9de2a1150f..2192dede55 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1083,7 +1083,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 Fri Apr 19 21:44:49 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=1557837151; cv=none; d=zoho.com; s=zohoarc; b=MF3y6cGhfaykEHcvQ7I2IFgzhe/9TU/vloyLU8q2dIKMLGHlmOgcyWfF0AIH9Z98wEPlAKhwXiZRuEOKiBiylhuyMinwoofwJ7zPQzNemm4gfbaEqxQN1mMe1zUVg/0+9/0ci0MziOzxqexpO8dW5WQJ+PRHYLl8a2uz1W2TZJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837151; 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=rYohg+P0gAZ9Q0QlMGjYyMkis+pGx79Rxxhq+p8NUg0=; b=jIBQ1O7eTbF5J69fR/gVzHczYsOqt+LNl0WP0/moizUyCtbWnav/j0TA25vIQQTYJaSZBKWDrDa4WpUmYEkoJcuMrBB4zV1nV4R36tG5+9ij3/LcPSdKALWt1BNnupCRdvZOGUD5xS5ekEWmWUqBrpHBM6V1Da1Q/+8j8KeiD1Y= 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 1557837150923421.80877335315984; Tue, 14 May 2019 05:32:30 -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 1hQWar-0005N5-V0; Tue, 14 May 2019 12:31:41 +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 1hQWar-0005Mx-8b for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:41 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 39653716-7644-11e9-99f3-63d46a5efb4e; Tue, 14 May 2019 12:31:40 +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 0ED03341; Tue, 14 May 2019 05:31:40 -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 CF54E3F71E; Tue, 14 May 2019 05:31:38 -0700 (PDT) X-Inumbo-ID: 39653716-7644-11e9-99f3-63d46a5efb4e From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:19 +0100 Message-Id: <20190514123125.29086-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 --- Changes in v2: - Correctly detect the removal of a page - Fix ASSERT on flags in the else case - Add Andrii's reviewed-by --- 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 2192dede55..45a6f9287f 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 + #define DEFINE_PAGE_TABLES(name, nr) \ lpae_t __aligned(PAGE_SIZE) name[LPAE_ENTRIES * (nr)] =20 @@ -968,12 +981,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=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) ) { @@ -989,15 +1064,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)); @@ -1009,12 +1081,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 @@ -1022,12 +1088,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; @@ -1049,6 +1109,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 Fri Apr 19 21:44:49 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=1557837147; cv=none; d=zoho.com; s=zohoarc; b=Dqw1hqZcK4vmpInsk5dRQu8XsnrmFgFjnvpBxL4l668YWTZJ4AGmVxFHZc69hbTiZ163IGLZw7Iy6RvpI8NPG/zNX56APDSCvYcScqdqIS/Ya09Ds1s4aIZGnQstyvp3xoZ9OztJToRQrCYtmyy/cINSf+n/3qszrmusVHy/gHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837147; 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=636CpUsBf7lH75u4OaPdW//ylanrxAd2Ry/1iH7WNaQ=; b=Mheb9Iwca6WuYQMr2cb6H58d/aaZHrQJbGwmg9GRu56z9gG2pccq4V+qPadQw+dRYHLNQ773yQL1o213aqqbxT8UqfPdPu4eVZ+OmdSoRnrVAnmEBI8IwjrHQ2XNpSITh4Wn05UFMERBR5lox2bWVgIu5ymXLZDnbRszllArQ8g= 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 1557837147537511.68663898558293; Tue, 14 May 2019 05:32:27 -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 1hQWau-0005O8-91; Tue, 14 May 2019 12:31:44 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWat-0005NT-26 for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:43 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3a201512-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:41 +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 80C1315AB; Tue, 14 May 2019 05:31:41 -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 4CF8D3F71E; Tue, 14 May 2019 05:31:40 -0700 (PDT) X-Inumbo-ID: 3a201512-7644-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:20 +0100 Message-Id: <20190514123125.29086-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 now 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 Reviewed-by: Stefano Stabellini --- Changes in v2: - Fix typo in the commit message - Add Andrii's reviewed-by --- 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 45a6f9287f..86e1faeeb5 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1067,34 +1067,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 Fri Apr 19 21:44:49 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=1557837152; cv=none; d=zoho.com; s=zohoarc; b=ftn5TucY0s6FWSDwTuLJ2pgDkISQ8a3xnihxt1JyQbNCUkAouwxM4zBxz6kDF6DMa3smOuqucJf8fFbh0WtO68PeqEt6CubmZFBVctMeslBICBWx7NAlk3371dlY24rkJkNfL2Ej0WBxHPrnRgnX3KgfflgmksvrYbKLmTDCbhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837152; 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=ST9YiMniTUOihPYzALvzcZ7J/M2Kx93Y2ZytPcWb5jw=; b=SYeEL1nB111EqtUFqLq1cMd6pKLVcy40qPLrnOfqMDz1qMo83SGDapMb9a5DO3837j+CelE+MsaBOkFenFGSspWF+9YeVo/reCHwWKqz2MmoouPOz0Z81IvID8oVEwBDU/HNoiYmVYlsZGT/yl+SUVhoGZ4oo/02mvUzf8r2fRE= 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 1557837152181700.7047912523886; Tue, 14 May 2019 05:32:32 -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 1hQWav-0005QF-M7; Tue, 14 May 2019 12:31:45 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWau-0005O9-Ca for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:44 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3b0516d9-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:43 +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 F250415AD; Tue, 14 May 2019 05:31:42 -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 BEE743F71E; Tue, 14 May 2019 05:31:41 -0700 (PDT) X-Inumbo-ID: 3b0516d9-7644-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:21 +0100 Message-Id: <20190514123125.29086-9-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 Acked-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- 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 86e1faeeb5..651e296041 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -974,13 +974,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) { @@ -1040,8 +1033,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; @@ -1099,8 +1092,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) @@ -1131,7 +1123,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 @@ -1156,24 +1148,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 Fri Apr 19 21:44:49 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=1557837153; cv=none; d=zoho.com; s=zohoarc; b=Qu7ze92x9+3Ko90LA3hqSzp66jWnH42gd05hn80db/geYTp9Z9zK6X4Qh/VP+5jbL0NKLe43CJpMbSn+Wc0Xxb1XexV0JcqAchFEi0nmTkwmfalCocEs2080kceI5tjnPV6Hr61BlPGHpprGXfvA+81rAT0ikPK8SxNFhFywKQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837153; 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=asJQ6oXkvoubr6wNyHe0lSspww4TN4X8SItzDIZBE0Q=; b=UUCBEO8ZGtSTzoymCcc1xe4MbKNlz4i2uK3Qv8z/Eal4oSoNqvv4HeIv0vVwjWklz7yOrS0ybyCeJE0sq8fmyIHfL3la9qNNtEmXNd6xIfY3f1+lsdmu5/YEV9j8seDQgqvk8ymKFHclSlJo7RW/t3oCapxOqK/oPEc0wXu1GfE= 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 1557837153147716.7203679390115; Tue, 14 May 2019 05:32:33 -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 1hQWaw-0005Qu-55; Tue, 14 May 2019 12:31:46 +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 1hQWav-0005Q2-GG for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:45 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3be35306-7644-11e9-9745-a782c9656c67; Tue, 14 May 2019 12:31:44 +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 70476341; Tue, 14 May 2019 05:31:44 -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 3C40F3F71E; Tue, 14 May 2019 05:31:43 -0700 (PDT) X-Inumbo-ID: 3be35306-7644-11e9-9745-a782c9656c67 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:22 +0100 Message-Id: <20190514123125.29086-10-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 Acked-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- 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 651e296041..f5979f549b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -974,6 +974,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) { @@ -1036,6 +1046,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 @@ -1054,15 +1065,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) ) @@ -1087,7 +1100,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 Fri Apr 19 21:44:49 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=1557837148; cv=none; d=zoho.com; s=zohoarc; b=SAL+aBKwVKGRsZH4RFbqG/7tOmdH/39vv1qFUEDOm214RMeSfei8fwnmBFqj1E1m7qH6M954Uj78MhBxs9d6l7C7UeHuHNWTUlYihQH6j58dDwq19v/DxF9spqTvz/oRX36RCZf8vuWLH56suMWsblWdX0224xtYlZKjelt02Tg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837148; 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=APJzreMBZxF3B6yZ1frc+3ECyif+0gi/aTIo6kpCy18=; b=JgUO3YYlcyzq28jlDHIoVQQD2AbUjmoiSSb50Ry7U7o9fv9ZwED3sQC4xX2GK+Qt++wuJ27FAh5nUSFLOyRwF6hkYbmLuJvfCP9WA9z8vdgjDp3VJkx8a44eXAVsjohaar6AsMpxZ2fjQXeBcEh0Px7vmgsE7e3ci+khQDIMsak= 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 155783714872733.880519111271155; Tue, 14 May 2019 05:32:28 -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 1hQWay-0005UG-Nc; Tue, 14 May 2019 12:31:48 +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 1hQWax-0005Sd-CG for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:47 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3cc2bb54-7644-11e9-aba7-3fae97ee57bb; Tue, 14 May 2019 12:31:46 +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 E121015AB; Tue, 14 May 2019 05:31:45 -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 ADCC53F71E; Tue, 14 May 2019 05:31:44 -0700 (PDT) X-Inumbo-ID: 3cc2bb54-7644-11e9-aba7-3fae97ee57bb From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:23 +0100 Message-Id: <20190514123125.29086-11-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 --- Changes in v2: - Add Andrii's reviewed-by --- 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 f5979f549b..9a40754f44 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -984,6 +984,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) { @@ -1043,30 +1090,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) ) @@ -1103,7 +1185,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; } @@ -1119,6 +1201,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), @@ -1139,9 +1230,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 Fri Apr 19 21:44:49 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=1557837151; cv=none; d=zoho.com; s=zohoarc; b=UKQF5uIvVbxGXGuHoBJ7Nm3YU/IERz6ZQEOug0+lhtyIFqj10y21O2ttqwf8oKVmh6xRSqrOXEwFxsZah4H/fvx6mShfpW0kEn1lvibBJjuS26nQRIMIDx0cEqEcynDFo1NBXVGZ4KTC4ymvjcCl3KCTo7uOgCbxUE7uY9h7lzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837151; 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=q/5fO5w8i5zfDMpa1uLC2hOGVREryTjNX266uOdlSzI=; b=OKzCUe1YxxdlHcTD94H/S+llPiorIKGE2i5gvS+nDygz5CLKV9xFSwC/HUQbatKTeuH8cf8EqGKCOMo8s3AGDF6OIIrXMWpSejb7FpApUedd0a9g3wlodm/zeOrrh18prWEhyJwuBxdjQRK9K2XCxZ0p+p3nBelgG4/I8MsNpZY= 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 1557837151004152.62759946482674; Tue, 14 May 2019 05:32:31 -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 1hQWb0-0005Vt-3w; Tue, 14 May 2019 12:31:50 +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 1hQWay-0005U8-LN for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:48 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 3dba290c-7644-11e9-8b9c-93296919fc85; Tue, 14 May 2019 12:31:47 +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 5E11C341; Tue, 14 May 2019 05:31:47 -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 2ACDC3F71E; Tue, 14 May 2019 05:31:46 -0700 (PDT) X-Inumbo-ID: 3dba290c-7644-11e9-8b9c-93296919fc85 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:24 +0100 Message-Id: <20190514123125.29086-12-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 --- Changes in v2: - Add Andrii's reviewed-by --- 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 9a40754f44..23ca61e8f0 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -348,19 +348,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 Fri Apr 19 21:44:49 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=1557837153; cv=none; d=zoho.com; s=zohoarc; b=XB0Gj827DW3ZRcbPTkyAxLwapp+pRzo9/xwnGF8xzn3lTY290hVCqOGqntaThH6MZ9SzmDaiUNg0eFLSsQx4MVx6FgcB2YiigD4jxVd6sLAuEV2/3dn8RWxUZUbeWYaIDcGBm7Fghz/Qmiy04aJ1y70cEOScyLTHIVPh/opNv/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837153; 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=NYceLMcH0dnOtniPH4yWjGE7uP2ifN97Cb0B1oVMZOo=; b=IT+3hv03rKdiDG+3KsJdkZDZ9+DXCsMf87ylqxv9RL8dLXG6arUJerV3AxBq90vDPAl0hHjicot9gwhgZLuMZ6l7W/yWqduByeyHSdBbbbxxu1umeWhdCEXfWFV9smxFN5gDPjcrjOwoK5gfav933OPQzXADGpKLG4WTRkc7izc= 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 1557837153760519.564166791131; Tue, 14 May 2019 05:32:33 -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 1hQWb2-0005YQ-H5; Tue, 14 May 2019 12:31:52 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWb0-0005WX-OY for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:50 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3e86e24d-7644-11e9-8980-bc764e045a96; Tue, 14 May 2019 12:31:49 +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 CF7E115AD; Tue, 14 May 2019 05:31:48 -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 9BE8A3F71E; Tue, 14 May 2019 05:31:47 -0700 (PDT) X-Inumbo-ID: 3e86e24d-7644-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:25 +0100 Message-Id: <20190514123125.29086-13-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 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 , Stefano Stabellini , Andrii Anisov 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 --- Changes in v2: - Add missing newline in panic - Add Andrii's reviewed-by --- 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 23ca61e8f0..d74101bcd2 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1277,52 +1277,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) { @@ -1331,8 +1285,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)\n", rc); =20 /* * From now on, init will not be used for execution anymore, @@ -1350,7 +1308,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)\n", 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