From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048651; cv=none; d=zohomail.com; s=zohoarc; b=mTRVM2AIqL5lsvVejfV3aMEAi/m3j1NaaO3CfSD5RG8bOtBhM+ymYHRP7fowsA33PngKy9+ORsTJPlwDw1fAB1txxuOI9z68gb6B5RV5/D6GujfUV1ySFjfc8JvN3/q2eVJjHBoVsnK0oEvhHnEKmCEDOzQfge06o87M+wiKa6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048651; h=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; bh=bZGPX4hXWWtjiKuU1/G3tIZ/8HOIH6yjg6x6XxicNi4=; b=m2RK2i/BQpTVsUZ/TTd3Zi/5iQ0rF68fPE3u+5XvoCBEHn798uQv/X+kSJi20i93tnORtE+cGie+5aVoqfvu6pUo6Ulis+KfTvVN9qDzO5VO3RaT8VH2dYRvAQlifzJpAK0uFUZ9+Jr3AOPkvZ4Kw4JRpmL8sohyKvBQPiRYYp8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048651218832.0329200464113; Fri, 20 May 2022 05:10:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333898.557823 (Exim 4.92) (envelope-from ) id 1ns1Sc-0005PE-5D; Fri, 20 May 2022 12:10:26 +0000 Received: by outflank-mailman (output) from mailman id 333898.557823; Fri, 20 May 2022 12:10:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sc-0005P7-1Y; Fri, 20 May 2022 12:10:26 +0000 Received: by outflank-mailman (input) for mailman id 333898; Fri, 20 May 2022 12:10:25 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sb-0005Hy-9I for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:25 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sa-0005m7-V3; Fri, 20 May 2022 12:10:24 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sa-0001lI-JW; Fri, 20 May 2022 12:10:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=bZGPX4hXWWtjiKuU1/G3tIZ/8HOIH6yjg6x6XxicNi4=; b=NDIly0hgLKDaJXvQhwtnoWQMU0 kv5OKALIHsTD2RNWd11IEAkRLYEo8HFEV2c6RnyXP8gK1U8HpdPytmPJaVZV6ALuW0IFEuMNLJ+kp 0rBswn0mHO/CMrm/d3Oxflk3KHFzLNhVRgGmC5wgNCkGoJE8VYu6ZFahH0cjYNImNtoM=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall , Hongda Deng Subject: [PATCH 01/16] xen/arm: mm: Allow other mapping size in xen_pt_update_entry() Date: Fri, 20 May 2022 13:09:22 +0100 Message-Id: <20220520120937.28925-2-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048651827100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, xen_pt_update_entry() only supports mapping at level 3 (i.e 4KB mapping). While this is fine for most of the runtime helper, the boot code will require to use superpage mapping. We don't want to allow superpage mapping by default as some of the callers may expect small mappings (i.e populate_pt_range()) or even expect to unmap only a part of a superpage. To keep the code simple, a new flag _PAGE_BLOCK is introduced to allow the caller to enable superpage mapping. As the code doesn't support all the combinations, xen_pt_check_entry() is extended to take into account the cases we don't support when using block mapping: - Replacing a table with a mapping. This may happen if region was first mapped with 4KB mapping and then later on replaced with a 2MB (or 1GB mapping). - Removing/modifying a table. This may happen if a caller try to remove a region with _PAGE_BLOCK set when it was created without it. Note that the current restriction means that the caller must ensure that _PAGE_BLOCK is consistently set/cleared across all the updates on a given virtual region. This ought to be fine with the expected use-cases. More rework will be necessary if we wanted to remove the restrictions. Note that nr_mfns is now marked const as it is used for flushing the TLBs and we don't want it to be modified. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Hongda Deng Reviewed-by: Stefano Stabellini --- Changes in v4: - Add Hongda's reviewed-by - Add a comment why nr_mfns is const - Open-code pfn_to_paddr() Changes in v3: - Fix clash after prefixing the PT macros with XEN_PT_ - Fix typoes in the commit message - Support superpage mappings even if nr is not suitably aligned - Move the logic to find the level in a separate function Changes in v2: - Pass the target level rather than the order to xen_pt_update_entry() - Update some comments - Open-code paddr_to_pfn() - Add my AWS signed-off-by --- xen/arch/arm/include/asm/page.h | 4 ++ xen/arch/arm/mm.c | 109 ++++++++++++++++++++++++++------ 2 files changed, 95 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/include/asm/page.h b/xen/arch/arm/include/asm/pag= e.h index c6f9fb0d4e0c..07998df47bac 100644 --- a/xen/arch/arm/include/asm/page.h +++ b/xen/arch/arm/include/asm/page.h @@ -69,6 +69,7 @@ * [3:4] Permission flags * [5] Page present * [6] Only populate page tables + * [7] Superpage mappings is allowed */ #define PAGE_AI_MASK(x) ((x) & 0x7U) =20 @@ -82,6 +83,9 @@ #define _PAGE_PRESENT (1U << 5) #define _PAGE_POPULATE (1U << 6) =20 +#define _PAGE_BLOCK_BIT 7 +#define _PAGE_BLOCK (1U << _PAGE_BLOCK_BIT) + /* * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not * meant to be used outside of this header. diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7b1f2f49060d..be2ac302d731 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1078,9 +1078,10 @@ static int xen_pt_next_level(bool read_only, unsigne= d int level, } =20 /* Sanity check of the entry */ -static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int flags) +static bool xen_pt_check_entry(lpae_t entry, mfn_t mfn, unsigned int level, + unsigned int flags) { - /* Sanity check when modifying a page. */ + /* Sanity check when modifying an entry. */ if ( (flags & _PAGE_PRESENT) && mfn_eq(mfn, INVALID_MFN) ) { /* We don't allow modifying an invalid entry. */ @@ -1090,6 +1091,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t m= fn, unsigned int flags) return false; } =20 + /* We don't allow modifying a table entry */ + if ( !lpae_is_mapping(entry, level) ) + { + mm_printk("Modifying a table entry is not allowed.\n"); + return false; + } + /* We don't allow changing memory attributes. */ if ( entry.pt.ai !=3D PAGE_AI_MASK(flags) ) { @@ -1105,7 +1113,7 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t mf= n, unsigned int flags) return false; } } - /* Sanity check when inserting a page */ + /* Sanity check when inserting a mapping */ else if ( flags & _PAGE_PRESENT ) { /* We should be here with a valid MFN. */ @@ -1114,18 +1122,28 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t = mfn, unsigned int flags) /* 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)); + if ( lpae_is_mapping(entry, level) ) + mm_printk("Changing MFN for a valid entry is not allowed (= %#"PRI_mfn" -> %#"PRI_mfn").\n", + mfn_x(lpae_get_mfn(entry)), mfn_x(mfn)); + else + mm_printk("Trying to replace a table with a mapping.\n"); return false; } } - /* Sanity check when removing a page. */ + /* Sanity check when removing a mapping. */ else if ( (flags & (_PAGE_PRESENT|_PAGE_POPULATE)) =3D=3D 0 ) { /* We should be here with an invalid MFN. */ ASSERT(mfn_eq(mfn, INVALID_MFN)); =20 - /* We don't allow removing page with contiguous bit set. */ + /* We don't allow removing a table */ + if ( lpae_is_table(entry, level) ) + { + mm_printk("Removing a table is not allowed.\n"); + return false; + } + + /* We don't allow removing a mapping with contiguous bit set. */ if ( entry.pt.contig ) { mm_printk("Removing entry with contiguous bit set is not allow= ed.\n"); @@ -1143,13 +1161,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t = mfn, unsigned int flags) return true; } =20 +/* Update an entry at the level @target. */ static int xen_pt_update_entry(mfn_t root, unsigned long virt, - mfn_t mfn, unsigned int flags) + mfn_t mfn, unsigned int target, + 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 @@ -1204,7 +1222,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned l= ong virt, entry =3D table + offsets[level]; =20 rc =3D -EINVAL; - if ( !xen_pt_check_entry(*entry, mfn, flags) ) + if ( !xen_pt_check_entry(*entry, mfn, level, flags) ) goto out; =20 /* If we are only populating page-table, then we are done. */ @@ -1222,8 +1240,11 @@ static int xen_pt_update_entry(mfn_t root, unsigned = long virt, { pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); =20 - /* Third level entries set pte.pt.table =3D 1 */ - pte.pt.table =3D 1; + /* + * First and second level pages set pte.pt.table =3D 0, but + * third level entries set pte.pt.table =3D 1. + */ + pte.pt.table =3D (level =3D=3D 3); } else /* We are updating the permission =3D> Copy the current pte. = */ pte =3D *entry; @@ -1243,15 +1264,57 @@ out: return rc; } =20 +/* Return the level where mapping should be done */ +static int xen_pt_mapping_level(unsigned long vfn, mfn_t mfn, unsigned lon= g nr, + unsigned int flags) +{ + unsigned int level; + unsigned long mask; + + /* + * Don't take into account the MFN when removing mapping (i.e + * MFN_INVALID) to calculate the correct target order. + * + * Per the Arm Arm, `vfn` and `mfn` must be both superpage aligned. + * They are or-ed together and then checked against the size of + * each level. + * + * `left` is not included and checked separately to allow + * superpage mapping even if it is not properly aligned (the + * user may have asked to map 2MB + 4k). + */ + mask =3D !mfn_eq(mfn, INVALID_MFN) ? mfn_x(mfn) : 0; + mask |=3D vfn; + + /* + * Always use level 3 mapping unless the caller request block + * mapping. + */ + if ( likely(!(flags & _PAGE_BLOCK)) ) + level =3D 3; + else if ( !(mask & (BIT(FIRST_ORDER, UL) - 1)) && + (nr >=3D BIT(FIRST_ORDER, UL)) ) + level =3D 1; + else if ( !(mask & (BIT(SECOND_ORDER, UL) - 1)) && + (nr >=3D BIT(SECOND_ORDER, UL)) ) + level =3D 2; + else + level =3D 3; + + return level; +} + static DEFINE_SPINLOCK(xen_pt_lock); =20 static int xen_pt_update(unsigned long virt, mfn_t mfn, - unsigned long nr_mfns, + /* const on purpose as it is used for TLB flush */ + const unsigned long nr_mfns, unsigned int flags) { int rc =3D 0; - unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; + unsigned long vfn =3D virt >> PAGE_SHIFT; + unsigned long left =3D nr_mfns; =20 /* * For arm32, page-tables are different on each CPUs. Yet, they share @@ -1283,14 +1346,24 @@ static int xen_pt_update(unsigned long virt, =20 spin_lock(&xen_pt_lock); =20 - for ( ; addr < addr_end; addr +=3D PAGE_SIZE ) + while ( left ) { - rc =3D xen_pt_update_entry(root, addr, mfn, flags); + unsigned int order, level; + + level =3D xen_pt_mapping_level(vfn, mfn, left, flags); + order =3D XEN_PT_LEVEL_ORDER(level); + + ASSERT(left >=3D BIT(order, UL)); + + rc =3D xen_pt_update_entry(root, vfn << PAGE_SHIFT, mfn, level, fl= ags); if ( rc ) break; =20 + vfn +=3D 1U << order; if ( !mfn_eq(mfn, INVALID_MFN) ) - mfn =3D mfn_add(mfn, 1); + mfn =3D mfn_add(mfn, 1U << order); + + left -=3D (1U << order); } =20 /* --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048652; cv=none; d=zohomail.com; s=zohoarc; b=hSVtDRVwF1Y9w9VemwPtgq81KHpGTHV7jT0p9g2VjaT1iqaJtx431uG1rkd7J4TaNBbddajXGdlwsUJfSvsCaXRgu86/vrArrkOqunS3AFJ+eWvEd3vr6uDnpdbFy3ySSH32bKpEnNAV7Og37/DwGpdQp7uld6doE5hQ6HM0rxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048652; h=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; bh=G/yN/MMtss1f4FLjXsFIcnhjFW34XkVIM7A866pB5UU=; b=a8gmugZ6+VIJ7fGIVvsMVAsrsSUALaIM4gFHN+frZldudih982iru7l+gwiqnQ7dJLoHiGOqtZ3GghtmKyq987Lw729akDn6x4kSIughyrMGUPdWJ5R1//pa7XxWYmLXzKTSQ4I6n8W8UPa6X3G2px1Lyv38Y0yKHYUS/6PF3Ck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048652963862.3725951862118; Fri, 20 May 2022 05:10:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333899.557833 (Exim 4.92) (envelope-from ) id 1ns1Sd-0005fH-F7; Fri, 20 May 2022 12:10:27 +0000 Received: by outflank-mailman (output) from mailman id 333899.557833; Fri, 20 May 2022 12:10:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sd-0005es-Ah; Fri, 20 May 2022 12:10:27 +0000 Received: by outflank-mailman (input) for mailman id 333899; Fri, 20 May 2022 12:10:26 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sc-0005Sb-A9 for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:26 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sc-0005n7-2i; Fri, 20 May 2022 12:10:26 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sb-0001lI-RB; Fri, 20 May 2022 12:10:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=G/yN/MMtss1f4FLjXsFIcnhjFW34XkVIM7A866pB5UU=; b=269d0/n+a5ZxknKGNjRNIHkykk ai0vXTeeOTqJUDLP2r/QRjhi54o7qkt8Rj9oncohm+yT7uow6nHpFMLeaHmbAG5S7cfGxfh3tJjhM 0DuQNlMIq3tBOW9rbRqshKDt28Cy+H2vPRG35KnPVM1X5+nw5ppchRD0URig3DQBXc/Y=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Hongda Deng Subject: [PATCH 02/16] xen/arm: mm: Add support for the contiguous bit Date: Fri, 20 May 2022 13:09:23 +0100 Message-Id: <20220520120937.28925-3-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048653648100004 Content-Type: text/plain; charset="utf-8" From: Julien Grall In follow-up patches, we will use xen_pt_update() (or its callers) to handle large mappings (e.g. frametable, xenheap). They are also not going to be modified once created. The page-table entries have an hint to indicate that whether an entry is contiguous to another 16 entries (assuming 4KB). When the processor support the hint, one TLB entry will be created per contiguous region. For now this is tied to _PAGE_BLOCK. We can untie it in the future if there are use-cases where we may want to use _PAGE_BLOCK without setting the contiguous (couldn't think of any yet). Note that to avoid extra complexity, mappings with the contiguous bit set cannot be removed. Given the expected use, this restriction ought to be fine. Signed-off-by: Julien Grall Reviewed-by: Hongda Deng Reviewed-by: Stefano Stabellini --- Changes in v4: - Add Hongda and Stefano's reviewed-by - Exit the outer loop as soon as there is an error. Changes in v3: - New patch --- xen/arch/arm/include/asm/page.h | 4 ++ xen/arch/arm/mm.c | 83 +++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/include/asm/page.h b/xen/arch/arm/include/asm/pag= e.h index 07998df47bac..e7cd62190c7f 100644 --- a/xen/arch/arm/include/asm/page.h +++ b/xen/arch/arm/include/asm/page.h @@ -70,6 +70,7 @@ * [5] Page present * [6] Only populate page tables * [7] Superpage mappings is allowed + * [8] Set contiguous bit (internal flag) */ #define PAGE_AI_MASK(x) ((x) & 0x7U) =20 @@ -86,6 +87,9 @@ #define _PAGE_BLOCK_BIT 7 #define _PAGE_BLOCK (1U << _PAGE_BLOCK_BIT) =20 +#define _PAGE_CONTIG_BIT 8 +#define _PAGE_CONTIG (1U << _PAGE_CONTIG_BIT) + /* * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not * meant to be used outside of this header. diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index be2ac302d731..c4487dd7fc46 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1252,6 +1252,8 @@ static int xen_pt_update_entry(mfn_t root, unsigned l= ong virt, /* Set permission */ pte.pt.ro =3D PAGE_RO_MASK(flags); pte.pt.xn =3D PAGE_XN_MASK(flags); + /* Set contiguous bit */ + pte.pt.contig =3D !!(flags & _PAGE_CONTIG); } =20 write_pte(entry, pte); @@ -1304,6 +1306,51 @@ static int xen_pt_mapping_level(unsigned long vfn, m= fn_t mfn, unsigned long nr, return level; } =20 +#define XEN_PT_4K_NR_CONTIG 16 + +/* + * Check whether the contiguous bit can be set. Return the number of + * contiguous entry allowed. If not allowed, return 1. + */ +static unsigned int xen_pt_check_contig(unsigned long vfn, mfn_t mfn, + unsigned int level, unsigned long = left, + unsigned int flags) +{ + unsigned long nr_contig; + + /* + * Allow the contiguous bit to set when the caller requests block + * mapping. + */ + if ( !(flags & _PAGE_BLOCK) ) + return 1; + + /* + * We don't allow to remove mapping with the contiguous bit set. + * So shortcut the logic and directly return 1. + */ + if ( mfn_eq(mfn, INVALID_MFN) ) + return 1; + + /* + * The number of contiguous entries varies depending on the page + * granularity used. The logic below assumes 4KB. + */ + BUILD_BUG_ON(PAGE_SIZE !=3D SZ_4K); + + /* + * In order to enable the contiguous bit, we should have enough entries + * to map left and both the virtual and physical address should be + * aligned to the size of 16 translation tables entries. + */ + nr_contig =3D BIT(XEN_PT_LEVEL_ORDER(level), UL) * XEN_PT_4K_NR_CONTIG; + + if ( (left < nr_contig) || ((mfn_x(mfn) | vfn) & (nr_contig - 1)) ) + return 1; + + return XEN_PT_4K_NR_CONTIG; +} + static DEFINE_SPINLOCK(xen_pt_lock); =20 static int xen_pt_update(unsigned long virt, @@ -1338,6 +1385,12 @@ static int xen_pt_update(unsigned long virt, return -EINVAL; } =20 + if ( flags & _PAGE_CONTIG ) + { + mm_printk("_PAGE_CONTIG is an internal only flag.\n"); + return -EINVAL; + } + if ( !IS_ALIGNED(virt, PAGE_SIZE) ) { mm_printk("The virtual address is not aligned to the page-size.\n"= ); @@ -1348,22 +1401,36 @@ static int xen_pt_update(unsigned long virt, =20 while ( left ) { - unsigned int order, level; + unsigned int order, level, nr_contig, new_flags; =20 level =3D xen_pt_mapping_level(vfn, mfn, left, flags); order =3D XEN_PT_LEVEL_ORDER(level); =20 ASSERT(left >=3D BIT(order, UL)); =20 - rc =3D xen_pt_update_entry(root, vfn << PAGE_SHIFT, mfn, level, fl= ags); - if ( rc ) - break; + /* + * Check if we can set the contiguous mapping and update the + * flags accordingly. + */ + nr_contig =3D xen_pt_check_contig(vfn, mfn, level, left, flags); + new_flags =3D flags | ((nr_contig > 1) ? _PAGE_CONTIG : 0); =20 - vfn +=3D 1U << order; - if ( !mfn_eq(mfn, INVALID_MFN) ) - mfn =3D mfn_add(mfn, 1U << order); + for ( ; nr_contig > 0; nr_contig-- ) + { + rc =3D xen_pt_update_entry(root, vfn << PAGE_SHIFT, mfn, level, + new_flags); + if ( rc ) + break; + + vfn +=3D 1U << order; + if ( !mfn_eq(mfn, INVALID_MFN) ) + mfn =3D mfn_add(mfn, 1U << order); =20 - left -=3D (1U << order); + left -=3D (1U << order); + } + + if ( rc ) + break; } =20 /* --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048652; cv=none; d=zohomail.com; s=zohoarc; b=PNDk6BYRflWGs/ITx1EtD7weTa0kG9Eh4DnXc0r2x7g82z6C6lQjCHy2x242Klhxaa3ZdlwcrD5FKyiA0Xs9lwsDykm+zwiBBDKKs+lYbNksbYSK6lyOkx9I+UyEG2KpYDwDsGdLT2wBb4fypwM20rai8/XmdY1y0bIfCOPeRDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048652; h=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; bh=cXnFYR1s5Y1jTbUV7oiOEy9M5vJYn4ZOPU2cNphW9n8=; b=VmbnzEHaxStRyGYJvBctrrtb//258W1hDMBqylqDvsd+jWD0FD/5jsZR9s9eoeQhMv8aja6Hvf5lVKro+/U+EOAelxMZ5pizrjtt4qdrcMdfnJ9ZTbHEgVLaeVsRKzfmzn4BnfeolfyeY6l9VcAcLCa9hlS8xDGsW1f3kUFFETI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048652254854.6108577054243; Fri, 20 May 2022 05:10:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333900.557845 (Exim 4.92) (envelope-from ) id 1ns1Se-0005x9-Ro; Fri, 20 May 2022 12:10:28 +0000 Received: by outflank-mailman (output) from mailman id 333900.557845; Fri, 20 May 2022 12:10:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Se-0005wQ-LS; Fri, 20 May 2022 12:10:28 +0000 Received: by outflank-mailman (input) for mailman id 333900; Fri, 20 May 2022 12:10:27 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sd-0005fF-Bv for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:27 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sd-0005o0-4E; Fri, 20 May 2022 12:10:27 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sc-0001lI-SC; Fri, 20 May 2022 12:10:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=cXnFYR1s5Y1jTbUV7oiOEy9M5vJYn4ZOPU2cNphW9n8=; b=IgB6/e2OpHBYymW363eOT6isR8 2ydHpuICXzkkbxiAC84pf2WJBrTBqgAGsd1CkUUupwhrlXwN2fabRLA8cnJAYeeKhFAXo5+Qg2cld wFlGWGnlQgfFqDDf4j6exrdOECLtgq4PzFaaGpidkEWaLdPyKeAqbbPjWft5fl7kvGqQ=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 03/16] xen/arm: mm: Avoid flushing the TLBs when mapping are inserted Date: Fri, 20 May 2022 13:09:24 +0100 Message-Id: <20220520120937.28925-4-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048653640100003 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, the function xen_pt_update() will flush the TLBs even when the mappings are inserted. This is a bit wasteful because we don't allow mapping replacement. Even if we were, the flush would need to happen earlier because mapping replacement should use Break-Before-Make when updating the entry. A single call to xen_pt_update() can perform a single action. IOW, it is not possible to, for instance, mix inserting and removing mappings. Therefore, we can use `flags` to determine what action is performed. This change will be particularly help to limit the impact of switching boot time mapping to use xen_pt_update(). Signed-off-by: Julien Grall Reviewed-by: Luca Fancellu Reviewed-by: Stefano Stabellini Tested-by: Luca Fancellu --- Changes in v4: - Switch the check to a different expression that will still result to the same truth table. Changes in v2: - New patch --- xen/arch/arm/mm.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index c4487dd7fc46..747083d820dd 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1119,7 +1119,13 @@ static bool xen_pt_check_entry(lpae_t entry, mfn_t m= fn, unsigned int level, /* We should be here with a valid MFN. */ ASSERT(!mfn_eq(mfn, INVALID_MFN)); =20 - /* We don't allow replacing any valid entry. */ + /* + * We don't allow replacing any valid entry. + * + * Note that the function xen_pt_update() relies on this + * assumption and will skip the TLB flush. The function will need + * to be updated if the check is relaxed. + */ if ( lpae_is_valid(entry) ) { if ( lpae_is_mapping(entry, level) ) @@ -1434,11 +1440,16 @@ static int xen_pt_update(unsigned long virt, } =20 /* - * Flush the TLBs even in case of failure because we may have + * The TLBs flush can be safely skipped when a mapping is inserted + * as we don't allow mapping replacement (see xen_pt_check_entry()). + * + * For all the other cases, the TLBs will be flushed unconditionally + * even if the mapping has failed. This is because we may have * partially modified the PT. This will prevent any unexpected * behavior afterwards. */ - flush_xen_tlb_range_va(virt, PAGE_SIZE * nr_mfns); + if ( !((flags & _PAGE_PRESENT) && !mfn_eq(mfn, INVALID_MFN)) ) + flush_xen_tlb_range_va(virt, PAGE_SIZE * nr_mfns); =20 spin_unlock(&xen_pt_lock); =20 --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048653; cv=none; d=zohomail.com; s=zohoarc; b=J/pMsLPGnCAkktwcWJkqcv9jmTMYxZZnod/xeeWyJFBbBD7xRyhbTqbWIJjgN55bsHNA2RTTX4pCifmShJF8jAbEarYtt+sX4wrxDilwfAHyfN6hM75pmX1NnarCkMnv44VjTnvbNY0Y8j3VmjEjFuP8ihmK5izfc59UNEvNtAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048653; h=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; bh=noAFzbg7XMXNKcoQy6EbRQkG8IRrJ9Zy042sIzuyylk=; b=G7ZNDhspvkqMVfrQeGIQdWgxofTvVCYXVPxoZRdkQLBm57HzRP/rN8WI0OKFfYdDuCnpaZoRfIr6b/ace5yJW8eJBypoK6axB90IFlY6v4dQ3lH3E5vXv8B9dbZv4plccVhC5ai7n25XrGsIKV1dcNuuikKE/QLtFDP25B1VfsM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048653970230.05511929512807; Fri, 20 May 2022 05:10:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333901.557856 (Exim 4.92) (envelope-from ) id 1ns1Sg-0006Fs-9T; Fri, 20 May 2022 12:10:30 +0000 Received: by outflank-mailman (output) from mailman id 333901.557856; Fri, 20 May 2022 12:10:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sg-0006Fl-4S; Fri, 20 May 2022 12:10:30 +0000 Received: by outflank-mailman (input) for mailman id 333901; Fri, 20 May 2022 12:10:28 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Se-0005v8-Hk for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:28 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Se-0005oM-BP; Fri, 20 May 2022 12:10:28 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Se-0001lI-3Z; Fri, 20 May 2022 12:10:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=noAFzbg7XMXNKcoQy6EbRQkG8IRrJ9Zy042sIzuyylk=; b=JMmHBQf30UDfDEGdAOJclsCP2F MfBJ0ImN4oLdOXiZZmlAYP361G0+BY+p+TKwEIwLRK4yddh+z4yP/tcYuOt7yxiUAsGsf3XQBPwCv 9psvqC+wV5F5oe89mmB5JgLAhP+9RHy7QpMCX/jHvaDZoW7Ev1S0nszbujx5CneafAA8=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall , Hongda Deng Subject: [PATCH 04/16] xen/arm: mm: Don't open-code Xen PT update in remove_early_mappings() Date: Fri, 20 May 2022 13:09:25 +0100 Message-Id: <20220520120937.28925-5-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048655813100003 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that xen_pt_update_entry() is able to deal with different mapping size, we can replace the open-coding of the page-tables update by a call to modify_xen_mappings(). As the function is not meant to fail, a BUG_ON() is added to check the return. Note that we don't use destroy_xen_mappings() because the helper doesn't allow us to pass a flags. In theory we could add an extra parameter to the function, however there are no other expected users. Hence why modify_xen_mappings() is used. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Hongda Deng Reviewed-by: Stefano Stabellini --- Changes in v4: - Add Hongda's reviewed-by - Add a comment to explain what modify_xen_mappings() does. - Clarify in the commit message hwy modify_xen_mappings() is used rather than destroy_xen_mappings(). Changes in v2: - Stay consistent with how function name are used in the commit message - Add my AWS signed-off-by --- xen/arch/arm/mm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 747083d820dd..64a79d45b38c 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -614,11 +614,12 @@ void * __init early_fdt_map(paddr_t fdt_paddr) =20 void __init remove_early_mappings(void) { - lpae_t pte =3D {0}; - write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START), pte); - write_pte(xen_second + second_table_offset(BOOT_FDT_VIRT_START + SZ_2M= ), - pte); - flush_xen_tlb_range_va(BOOT_FDT_VIRT_START, BOOT_FDT_SLOT_SIZE); + int rc; + + /* destroy the _PAGE_BLOCK mapping */ + rc =3D modify_xen_mappings(BOOT_FDT_VIRT_START, BOOT_FDT_VIRT_END, + _PAGE_BLOCK); + BUG_ON(rc); } =20 /* --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048653; cv=none; d=zohomail.com; s=zohoarc; b=MUAjGlx2dau5qxeUcnzGprdXyhdifsKMFxLzJkU95KL879th2DfjKuVLVfrjs2mNSIHa/rxEMN67FuSt+Ddzzu29iFGTlLp/YBq5GFU6eNMi98+2+4KPEeZ06Fmy1m6UYmDft5Rou8+TsBKCn8wGV0Bh8MPO8rXUgm5hCTmmpdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048653; h=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; bh=cJm41f6bVbuh9BtVBTWvTK9jtgSvHumHceiTZgvegME=; b=HALgDufhbOEgvHvZ1plTtVj/MAm/CD2kVBRhwUZGKk7IVRm0AZeVgOiXuInCH2pYHG6dKfVb5tdtdCzcBCiKEqhklQw5TO+6m/t0DXYutGwCJpKH3AXYRaJCRTTxArr5iSdn3kYb73oCCfej4SZ/zoa9FpyFsYVCCmQIoWqhzQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048653653251.81934051335134; Fri, 20 May 2022 05:10:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333902.557867 (Exim 4.92) (envelope-from ) id 1ns1Sh-0006Wn-In; Fri, 20 May 2022 12:10:31 +0000 Received: by outflank-mailman (output) from mailman id 333902.557867; Fri, 20 May 2022 12:10:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sh-0006Vv-Do; Fri, 20 May 2022 12:10:31 +0000 Received: by outflank-mailman (input) for mailman id 333902; Fri, 20 May 2022 12:10:29 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sf-0006BN-MN for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:29 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sf-0005oi-J4; Fri, 20 May 2022 12:10:29 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sf-0001lI-BC; Fri, 20 May 2022 12:10:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=cJm41f6bVbuh9BtVBTWvTK9jtgSvHumHceiTZgvegME=; b=kWMwtARSZEDeCPKM84SONgQCxm zSwLU3CORC3yppW+MV/MuXvyEq4yqQc09qGooh3xSJowT3/Rn+GB/LwJtWD53sn1o6CWX55Mvruh6 ukX8KEqaHtb/wQ2WkfgC0bjMLOB4+SdMVpp/VEb0Z4Nlxd5fERjFys57PmV9G8P+Xy+Y=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall , Hongda Deng Subject: [PATCH 05/16] xen/arm: mm: Re-implement early_fdt_map() using map_pages_to_xen() Date: Fri, 20 May 2022 13:09:26 +0100 Message-Id: <20220520120937.28925-6-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048655719100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() calls by map_pages_to_xen() calls. The mapping can also be marked read-only as Xen should not modify the host Device Tree during boot. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Hongda Deng Reviewed-by: Stefano Stabellini --- Changes in v4: - Fix typo in the commit message - Add Hongda's reviewed-by Changes in v2: - Add my AWS signed-off-by - Fix typo in the commit message --- xen/arch/arm/mm.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 64a79d45b38c..03f970e4d10b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -574,6 +574,7 @@ void * __init early_fdt_map(paddr_t fdt_paddr) paddr_t offset; void *fdt_virt; uint32_t size; + int rc; =20 /* * Check whether the physical FDT address is set and meets the minimum @@ -589,8 +590,12 @@ void * __init early_fdt_map(paddr_t fdt_paddr) /* The FDT is mapped using 2MB superpage */ BUILD_BUG_ON(BOOT_FDT_VIRT_START % SZ_2M); =20 - create_mappings(xen_second, BOOT_FDT_VIRT_START, paddr_to_pfn(base_pad= dr), - SZ_2M >> PAGE_SHIFT, SZ_2M); + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START, maddr_to_mfn(base_paddr), + SZ_2M >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO | _PAGE_BLOCK); + if ( rc ) + panic("Unable to map the device-tree.\n"); + =20 offset =3D fdt_paddr % SECOND_SIZE; fdt_virt =3D (void *)BOOT_FDT_VIRT_START + offset; @@ -604,9 +609,12 @@ void * __init early_fdt_map(paddr_t fdt_paddr) =20 if ( (offset + size) > SZ_2M ) { - create_mappings(xen_second, BOOT_FDT_VIRT_START + SZ_2M, - paddr_to_pfn(base_paddr + SZ_2M), - SZ_2M >> PAGE_SHIFT, SZ_2M); + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START + SZ_2M, + maddr_to_mfn(base_paddr + SZ_2M), + SZ_2M >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO | _PAGE_BLOCK); + if ( rc ) + panic("Unable to map the device-tree\n"); } =20 return fdt_virt; --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048657; cv=none; d=zohomail.com; s=zohoarc; b=L83fI6G5VEFQA17z5yzoQj4dDIgOW9sFVn+qx0ZoyrqvloqgPiEbEIOGuLGDXyhB0n3GOT1Ek0R1bhd27oDy3ZsIPYxNRb4j91iJ1VSC/QsU1p6s3veAYObfqbtQYiwdNLdJ29NPB1DOObIj2NC1eYBXC1poABImkWju2+0mZ6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048657; h=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; bh=x8Bsa7TYWnNoGQK+pARdRdk5x9L3RhzgU3aFf8j8hqY=; b=PpXJxubB0cM94zYnJzrnqwp+6yeyukteOG2yFkCxBP0tyt+qMQQCT8h+K6MVu3Nw25fOy5Al3kJ3mByT/k/uBGvDUswNQ2yFHRsXzQZpHOLgOAI6e87YfKTi+mpVOGUAxFLBVMLtdnvtUu/hkX74UnOur/qVFxzuAE2gG7DQ1Jc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 165304865714046.32572946927644; Fri, 20 May 2022 05:10:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333903.557879 (Exim 4.92) (envelope-from ) id 1ns1Si-0006pt-Uh; Fri, 20 May 2022 12:10:32 +0000 Received: by outflank-mailman (output) from mailman id 333903.557879; Fri, 20 May 2022 12:10:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Si-0006on-Mv; Fri, 20 May 2022 12:10:32 +0000 Received: by outflank-mailman (input) for mailman id 333903; Fri, 20 May 2022 12:10:30 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sg-0006RM-RJ for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:30 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sg-0005p1-Jx; Fri, 20 May 2022 12:10:30 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sg-0001lI-CD; Fri, 20 May 2022 12:10:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=x8Bsa7TYWnNoGQK+pARdRdk5x9L3RhzgU3aFf8j8hqY=; b=rJ+xL3CzsAOPOmH5sEymKxEf41 Um7SI/EwztZBDG1lYa6DyX//+Zc4HQZ1V3wikCCqwDs2Hk6ZTwnlG/QMeooADUZWIrEQC6JmbjbeR S4fVs3EF0ODBNb2SzJMbQHhpfhJ4hWGBKu7gUS3rU4WLh0DafZOUOaz5P17/slZecjMg=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 06/16] xen/arm32: mm: Re-implement setup_xenheap_mappings() using map_pages_to_xen() Date: Fri, 20 May 2022 13:09:27 +0100 Message-Id: <20220520120937.28925-7-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048657663100009 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() call by map_pages_to_xen() call. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v4: - Add Stefano's reviewed-by Changes in v3: - Fix build when CONFIG_DEBUG=3Dy Changes in v2: - New patch --- xen/arch/arm/mm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 03f970e4d10b..47c2111c36a4 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -825,7 +825,12 @@ void mmu_init_secondary_cpu(void) void __init setup_xenheap_mappings(unsigned long base_mfn, unsigned long nr_mfns) { - create_mappings(xen_second, XENHEAP_VIRT_START, base_mfn, nr_mfns, MB(= 32)); + int rc; + + rc =3D map_pages_to_xen(XENHEAP_VIRT_START, _mfn(base_mfn), nr_mfns, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the xenheap mappings.\n"); =20 /* Record where the xenheap is, for translation routines. */ xenheap_virt_end =3D XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048653; cv=none; d=zohomail.com; s=zohoarc; b=cF5EtSEbhbNYwAc1iC96HolE7XY/R3Sct5AI0DyVZ06fVZrjBgleJJDeu+L2x6T8dzzZ5IOrM9QNXKG4jUM9zu0eZTjt8VDe1FXvL+Kho8PEJiBa7QO9wyonGeaOgi9H8dGtH9KE33s9I8ZZ4VsAgVpUn3f9Vba937cDy808k+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048653; h=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; bh=P+NWrrFhs3KxS6dDexgzIQNemrzeLTVuO4hodlzBMxc=; b=Q2tAahdY01gBK+QsTdKI1HWKzW3DYO3z+6+naj4OFXR0CcTfronPYepuJEjLIE9SABkQmRNYZm9n7430sOk7ZDryDegHqsro99OQkDA7WAykLOSDuz9VN5sEQPEeWTWrfA6J6ORo0S/mT+kLSdNJHMoVkYBVphLvcgpUXMeYCgs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 165304865374039.7148590542281; Fri, 20 May 2022 05:10:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333904.557882 (Exim 4.92) (envelope-from ) id 1ns1Sj-0006uT-D5; Fri, 20 May 2022 12:10:33 +0000 Received: by outflank-mailman (output) from mailman id 333904.557882; Fri, 20 May 2022 12:10:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sj-0006sQ-16; Fri, 20 May 2022 12:10:33 +0000 Received: by outflank-mailman (input) for mailman id 333904; Fri, 20 May 2022 12:10:31 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sh-0006dX-SG for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:31 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sh-0005pF-L3; Fri, 20 May 2022 12:10:31 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sh-0001lI-DD; Fri, 20 May 2022 12:10:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=P+NWrrFhs3KxS6dDexgzIQNemrzeLTVuO4hodlzBMxc=; b=zpjOljw9eKfhAEkzKFoZ951lxC Lsinhm3LjaJqyo4Goz9AVjTRs64vMfo4jrGxslDEQIJxWNutHUQyzjHDO3hV09Ngp0NhBITbRafrt TiyAFlXDMbz93Yx3biv7GJXzfYXus1p+7GYdgi31lWg5fZilsgWfirwNXOk3sWsJ6fzY=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 07/16] xen/arm: mm: Allocate xen page tables in domheap rather than xenheap Date: Fri, 20 May 2022 13:09:28 +0100 Message-Id: <20220520120937.28925-8-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048655719100002 Content-Type: text/plain; charset="utf-8" From: Julien Grall xen_{un,}map_table() already uses the helper to map/unmap pages on-demand (note this is currently a NOP on arm64). So switching to domheap don't have any disavantage. But this as the benefit: - to keep the page tables unmapped if an arch decided to do so - reduce xenheap use on arm32 which can be pretty small Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v3: - Add Stefano's acked-by Changes in v2: - New patch --- xen/arch/arm/mm.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 47c2111c36a4..252114d67df5 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -988,21 +988,6 @@ void *ioremap(paddr_t pa, size_t len) return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE); } =20 -static int create_xen_table(lpae_t *entry) -{ - void *p; - lpae_t pte; - - p =3D alloc_xenheap_page(); - if ( p =3D=3D NULL ) - return -ENOMEM; - clear_page(p); - pte =3D mfn_to_xen_entry(virt_to_mfn(p), MT_NORMAL); - pte.pt.table =3D 1; - write_pte(entry, pte); - return 0; -} - static lpae_t *xen_map_table(mfn_t mfn) { /* @@ -1043,6 +1028,27 @@ static void xen_unmap_table(const lpae_t *table) unmap_domain_page(table); } =20 +static int create_xen_table(lpae_t *entry) +{ + struct page_info *pg; + void *p; + lpae_t pte; + + pg =3D alloc_domheap_page(NULL, 0); + if ( pg =3D=3D NULL ) + return -ENOMEM; + + p =3D xen_map_table(page_to_mfn(pg)); + clear_page(p); + xen_unmap_table(p); + + pte =3D mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte.pt.table =3D 1; + write_pte(entry, pte); + + return 0; +} + #define XEN_TABLE_MAP_FAILED 0 #define XEN_TABLE_SUPER_PAGE 1 #define XEN_TABLE_NORMAL_PAGE 2 --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048656; cv=none; d=zohomail.com; s=zohoarc; b=SwuG/9Sg62nnLAn+Kr0FeWj+D/c74BOn9xhOQM1eaRUXhRj7DwmTpkjh7wRs7eXY2kZNzfwK7/+bGsvKNO4FIKEthg9dgYU3rwOKOcoQzi+2U4mX1yjyr9ehhHnq8QG1mLf+Yq4jDCX2uQemOdLwVdXN/hoa5ZCJ8fDNId0/vaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048656; h=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; bh=gimEip3VkLJRKnHAXm3TnqTrnKrLjfGvOIOXBXVQdRQ=; b=Vy4aXhJJvI6S39xnxnSNUWAV/bN+K9mb+wPqDf+VFfhXi2WdnLngwY3CBQNYfFZnKtrdcVevtdUEjmi5n0w2Wy5Bcc6GKK44cceRZZAVbehiZiTiX9pO656PSE+e1p+VEWJ4Fd8rbWCh4qgzVWScnfniXddsv1vpH+M0TeZctCk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048656775286.9933042520672; Fri, 20 May 2022 05:10:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333905.557896 (Exim 4.92) (envelope-from ) id 1ns1Sk-0007J8-M2; Fri, 20 May 2022 12:10:34 +0000 Received: by outflank-mailman (output) from mailman id 333905.557896; Fri, 20 May 2022 12:10:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sk-0007Hy-CW; Fri, 20 May 2022 12:10:34 +0000 Received: by outflank-mailman (input) for mailman id 333905; Fri, 20 May 2022 12:10:33 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Si-0006rd-Vd for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:32 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Si-0005pW-PB; Fri, 20 May 2022 12:10:32 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Si-0001lI-HX; Fri, 20 May 2022 12:10:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=gimEip3VkLJRKnHAXm3TnqTrnKrLjfGvOIOXBXVQdRQ=; b=0Z94Mp5HwfpHEQTToAgWAdkw0B dl3gC1Pt7J4lRQn0guwGshH858PED22AWw97r9tRaPTJfwE71z0V3E2AIYSKwZx8dEhCkSBbwlEeW JVZ1usC0K8n8o8kgTOd0QR51IWhSsa3Ut81N1erIFaf7IVvvfSoydJkiKrfnkp8yy6IU=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH 08/16] xen/arm: mm: Allow page-table allocation from the boot allocator Date: Fri, 20 May 2022 13:09:29 +0100 Message-Id: <20220520120937.28925-9-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048657666100010 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, page-table can only be allocated from domheap. This means it is not possible to create mapping in the page-tables via map_pages_to_xen() if page-table needs to be allocated. In order to avoid open-coding page-tables update in early boot, we need to be able to allocate page-tables much earlier. Thankfully, we have the boot allocator for those cases. create_xen_table() is updated to cater early boot allocation by using alloc_boot_pages(). Note, this is not sufficient to bootstrap the page-tables (i.e mapping before any memory is actually mapped). This will be addressed separately. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v4: - Add Stefano's reviewed-by Changes in v2: - New patch --- xen/arch/arm/mm.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 252114d67df5..6b7b72de27fe 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1030,19 +1030,27 @@ static void xen_unmap_table(const lpae_t *table) =20 static int create_xen_table(lpae_t *entry) { - struct page_info *pg; + mfn_t mfn; void *p; lpae_t pte; =20 - pg =3D alloc_domheap_page(NULL, 0); - if ( pg =3D=3D NULL ) - return -ENOMEM; + if ( system_state !=3D SYS_STATE_early_boot ) + { + struct page_info *pg =3D alloc_domheap_page(NULL, 0); + + if ( pg =3D=3D NULL ) + return -ENOMEM; + + mfn =3D page_to_mfn(pg); + } + else + mfn =3D alloc_boot_pages(1, 1); =20 - p =3D xen_map_table(page_to_mfn(pg)); + p =3D xen_map_table(mfn); clear_page(p); xen_unmap_table(p); =20 - pte =3D mfn_to_xen_entry(page_to_mfn(pg), MT_NORMAL); + pte =3D mfn_to_xen_entry(mfn, MT_NORMAL); pte.pt.table =3D 1; write_pte(entry, pte); =20 --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048657; cv=none; d=zohomail.com; s=zohoarc; b=fwyPw9ccWYEtRDBGax/xJgqLqnxTJ+kJ6BBVZ6T1rL+WOnCKKzLKdUIj6QjrTV9zNXro2QLRbYMreN8lSZUnYbJmWcDfL4aA+EdOhaEaGPxMHM8lJPBPkZ3L7lniOBH/wK9RoUG3utXU+Mo4Uc0e8p44XSv7/2EPdAFSonjon6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048657; h=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; bh=kU92uCk+wpW7sogs8vL65U0R39Ihu48YVjWuEhMIJGI=; b=KuS/8CUtzMXPurj3AXZXvnvX+4l1xD+wYOOstxAUh2v+i1YY/WPTNw/wlX63H5kiDWt76HvJxA2oV6ltnnZim6hcJVEUYaWiwngo5A0dYH3pSGD7FK9A4k6QT9QlDbmG0I80xCbKh6oHclnG3p1j185HklehFfSOTKNxPnQRiFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048657520954.3496763070899; Fri, 20 May 2022 05:10:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333906.557909 (Exim 4.92) (envelope-from ) id 1ns1Sm-0007jB-BH; Fri, 20 May 2022 12:10:36 +0000 Received: by outflank-mailman (output) from mailman id 333906.557909; Fri, 20 May 2022 12:10:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sm-0007hO-3t; Fri, 20 May 2022 12:10:36 +0000 Received: by outflank-mailman (input) for mailman id 333906; Fri, 20 May 2022 12:10:34 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sk-0007Ji-HT for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:10:34 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Sk-0005pq-7b; Fri, 20 May 2022 12:10:34 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sj-0001lI-Vp; Fri, 20 May 2022 12:10:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=kU92uCk+wpW7sogs8vL65U0R39Ihu48YVjWuEhMIJGI=; b=ST0W8BXPufeABbx+NK2KIQ+a6D zZcLC2rI2uMKWUsWCFa3NCw8HODlm/LgTvSccCSKGbsd6QiyneZEjRbTQcxIIUC1eVtEe1vIe9rQB dFGCv0GyNGIkWafmiRAT25afqbw6Vb1de+xDeBeqwGaT5wBK69tY9aY04FSO3A8gmHbk=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH 09/16] xen/arm: Move fixmap definitions in a separate header Date: Fri, 20 May 2022 13:09:30 +0100 Message-Id: <20220520120937.28925-10-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048659735100013 Content-Type: text/plain; charset="utf-8" From: Julien Grall To use properly the fixmap definitions, their user would need also new to include . This is not very great when the user itself is not meant to directly use ACPI definitions. Including in is not option because the latter header is included by everyone. So move out the fixmap entries definition in a new header. Take the opportunity to also move {set, clear}_fixmap() prototypes in the new header. Note that most of the definitions in now need to be surrounded with #ifndef __ASSEMBLY__ because will be used in assembly (see EARLY_UART_VIRTUAL_ADDRESS). The split will become more helpful in a follow-up patch where new fixmap entries will be defined. Signed-off-by: Julien Grall Acked-by: Jan Beulich Acked-by: Stefano Stabellini --- There was some disagreement with Stefano on whether fixmap.h should include acpi.h or this should be the other way around. I chose the former because each components should decide how much entries in the fixmap they need and also because this is the current behavior on x86. We should stay consitent between arch to avoid any headers mess. Jan acked this patch, so I am assuming he is happy with this approach. I would be OK to rework it if others agree with Stefano's view. Changes in v4: - Add Jan's acked-by - Record Stefano's disagreement on the approach Changes in v3: - Patch added --- xen/arch/arm/acpi/lib.c | 2 ++ xen/arch/arm/include/asm/config.h | 6 ------ xen/arch/arm/include/asm/early_printk.h | 1 + xen/arch/arm/include/asm/fixmap.h | 24 ++++++++++++++++++++++++ xen/arch/arm/include/asm/mm.h | 4 ---- xen/arch/arm/kernel.c | 1 + xen/arch/arm/mm.c | 1 + xen/include/xen/acpi.h | 18 +++++++++++------- 8 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 xen/arch/arm/include/asm/fixmap.h diff --git a/xen/arch/arm/acpi/lib.c b/xen/arch/arm/acpi/lib.c index a59cc4074cfb..41d521f720ac 100644 --- a/xen/arch/arm/acpi/lib.c +++ b/xen/arch/arm/acpi/lib.c @@ -25,6 +25,8 @@ #include #include =20 +#include + static bool fixmap_inuse; =20 char *__acpi_map_table(paddr_t phys, unsigned long size) diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/c= onfig.h index b25c9d39bb32..3e2a55a91058 100644 --- a/xen/arch/arm/include/asm/config.h +++ b/xen/arch/arm/include/asm/config.h @@ -169,12 +169,6 @@ =20 #endif =20 -/* Fixmap slots */ -#define FIXMAP_CONSOLE 0 /* The primary UART */ -#define FIXMAP_MISC 1 /* Ephemeral mappings of hardware */ -#define FIXMAP_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ -#define FIXMAP_ACPI_END (FIXMAP_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1)= /* End mappings of ACPI tables */ - #define NR_hypercalls 64 =20 #define STACK_ORDER 3 diff --git a/xen/arch/arm/include/asm/early_printk.h b/xen/arch/arm/include= /asm/early_printk.h index 8dc911cf48a3..c5149b2976da 100644 --- a/xen/arch/arm/include/asm/early_printk.h +++ b/xen/arch/arm/include/asm/early_printk.h @@ -11,6 +11,7 @@ #define __ARM_EARLY_PRINTK_H__ =20 #include +#include =20 #ifdef CONFIG_EARLY_PRINTK =20 diff --git a/xen/arch/arm/include/asm/fixmap.h b/xen/arch/arm/include/asm/f= ixmap.h new file mode 100644 index 000000000000..1cee51e52ab9 --- /dev/null +++ b/xen/arch/arm/include/asm/fixmap.h @@ -0,0 +1,24 @@ +/* + * fixmap.h: compile-time virtual memory allocation + */ +#ifndef __ASM_FIXMAP_H +#define __ASM_FIXMAP_H + +#include + +/* Fixmap slots */ +#define FIXMAP_CONSOLE 0 /* The primary UART */ +#define FIXMAP_MISC 1 /* Ephemeral mappings of hardware */ +#define FIXMAP_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ +#define FIXMAP_ACPI_END (FIXMAP_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1)= /* End mappings of ACPI tables */ + +#ifndef __ASSEMBLY__ + +/* Map a page in a fixmap entry */ +extern void set_fixmap(unsigned map, mfn_t mfn, unsigned attributes); +/* Remove a mapping from a fixmap entry */ +extern void clear_fixmap(unsigned map); + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_FIXMAP_H */ diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 424aaf28230b..045a8ba4bb63 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -191,10 +191,6 @@ extern void mmu_init_secondary_cpu(void); extern void setup_xenheap_mappings(unsigned long base_mfn, unsigned long n= r_mfns); /* Map a frame table to cover physical addresses ps through pe */ extern void setup_frametable_mappings(paddr_t ps, paddr_t pe); -/* Map a 4k page in a fixmap entry */ -extern void set_fixmap(unsigned map, mfn_t mfn, unsigned attributes); -/* Remove a mapping from a fixmap entry */ -extern void clear_fixmap(unsigned map); /* map a physical range in virtual memory */ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned attributes); =20 diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 8f43caa1866d..25ded1c056d9 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -15,6 +15,7 @@ #include =20 #include +#include #include #include =20 diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 6b7b72de27fe..52b2a0394047 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -41,6 +41,7 @@ #include #include =20 +#include #include =20 /* Override macros from asm/page.h to make them work with mfn_t */ diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h index 39d51fcd01dd..1b9c75e68fc4 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -28,6 +28,15 @@ #define _LINUX #endif =20 +/* + * Fixmap pages to reserve for ACPI boot-time tables (see + * arch/x86/include/asm/fixmap.h or arch/arm/include/asm/fixmap.h), + * 64 pages(256KB) is large enough for most cases.) + */ +#define NUM_FIXMAP_ACPI_PAGES 64 + +#ifndef __ASSEMBLY__ + #include =20 #include @@ -39,13 +48,6 @@ #define ACPI_MADT_GET_POLARITY(inti) ACPI_MADT_GET_(POLARITY, inti) #define ACPI_MADT_GET_TRIGGER(inti) ACPI_MADT_GET_(TRIGGER, inti) =20 -/* - * Fixmap pages to reserve for ACPI boot-time tables (see - * arch/x86/include/asm/fixmap.h or arch/arm/include/asm/config.h, - * 64 pages(256KB) is large enough for most cases.) - */ -#define NUM_FIXMAP_ACPI_PAGES 64 - #define BAD_MADT_ENTRY(entry, end) ( = \ (!(entry)) || (unsigned long)(entry) + sizeof(*(entry)) > = (end) || \ (entry)->header.length < sizeof(*(entry))) @@ -207,4 +209,6 @@ void acpi_reboot(void); void acpi_dmar_zap(void); void acpi_dmar_reinstate(void); =20 +#endif /* __ASSEMBLY__ */ + #endif /*_LINUX_ACPI_H*/ --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048907; cv=none; d=zohomail.com; s=zohoarc; b=W+LsnTMElQzGrqmZe4/lV4fufT13ZHU9n2njuDjzcTg40rC18zHiLzD5MDNk6Ae25cr8WS71H2Yc40hLG00RqbhV6Lk3vlGziDeUCPgKHgRoo1mvBazYkfKhcN3m2uMLVSeWRThQINphhh/9F8WfS5Ux7doA4Dg9ne82JIdaPZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048907; 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; bh=xXyiaAqaXOE8UjksPYWndQvCCsS0jnjjnrlX2Gok8p4=; b=AHGHchL9QhpJt600HWubM88Mq+ubvjq0U+X5D9S3kGW7R4XVNJysYBJer1IvNe0v7Az8lAnezvjPKEmMDX+/4qrTW8QztHGBPUf9YtlZEz2MfhTq1fY3d9/fFuZ70rZLzauc3u84vPyD/C4cFWBEfH/4nfuYyaUGvTWeVI9vAJ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048907494918.835356265069; Fri, 20 May 2022 05:15:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333990.557961 (Exim 4.92) (envelope-from ) id 1ns1Wo-0003o1-AC; Fri, 20 May 2022 12:14:46 +0000 Received: by outflank-mailman (output) from mailman id 333990.557961; Fri, 20 May 2022 12:14:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wn-0003ji-Sm; Fri, 20 May 2022 12:14:45 +0000 Received: by outflank-mailman (input) for mailman id 333990; Fri, 20 May 2022 12:14:43 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0003NV-SG for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:14:43 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0005wS-IR; Fri, 20 May 2022 12:14:43 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sl-0001lI-Nm; Fri, 20 May 2022 12:10:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=xXyiaAqaXOE8UjksPYWndQvCCsS0jnjjnrlX2Gok8p4=; b=xkgAUx/nd4GGJbbvcAtEElB/+V ZOrrVNlIN7mSVaB1/vbRHaovXTkHyRSNQKsmcT+4u9Y1HcZ3KxKZwkDsnkHe5l4l4MYYzXX7cfL5e 7tC996Az2c/Dw7GUKuajB29F3rPAwQSOEXcB+gJWDbrI4awHqt+jBXC7iESLGFQ50/bM=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Wei Liu , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , George Dunlap , Hongyan Xia , Julien Grall , Jan Beulich , Wei Liu , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 10/16] xen/arm: add Persistent Map (PMAP) infrastructure Date: Fri, 20 May 2022 13:09:31 +0100 Message-Id: <20220520120937.28925-11-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048908863100007 From: Wei Liu The basic idea is like Persistent Kernel Map (PKMAP) in Linux. We pre-populate all the relevant page tables before the system is fully set up. We will need it on Arm in order to rework the arm64 version of xenheap_setup_mappings() as we may need to use pages allocated from the boot allocator before they are effectively mapped. This infrastructure is not lock-protected therefore can only be used before smpboot. After smpboot, map_domain_page() has to be used. This is based on the x86 version [1] that was originally implemented by Wei Liu. The PMAP infrastructure is implemented in common code with some arch helpers to set/clear the page-table entries and convertion between a fixmap slot to a virtual address... As mfn_to_xen_entry() now needs to be exported, take the opportunity to swich the parameter attr from unsigned to unsigned int. [1] Signed-off-by: Wei Liu Signed-off-by: Hongyan Xia [julien: Adapted for Arm] Signed-off-by: Julien Grall Reviewed-by: Luca Fancellu Reviewed-by: Stefano Stabellini Tested-by: Luca Fancellu --- Changes in v4: - Move xen_fixmap in fixmap.h and add a comment about its usage. - Update comments - Use DECLARE_BITMAP() - Replace local_irq_{enable, disable} with an ASSERT() as there should be no user of pmap() in interrupt context. Changes in v3: - s/BITS_PER_LONG/BITS_PER_BYTE/ - Move pmap to common code Changes in v2: - New patch Cc: Jan Beulich Cc: Wei Liu Cc: Andrew Cooper Cc: Roger Pau Monn=C3=A9 --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/include/asm/fixmap.h | 24 +++++++++++ xen/arch/arm/include/asm/lpae.h | 8 ++++ xen/arch/arm/include/asm/pmap.h | 32 ++++++++++++++ xen/arch/arm/mm.c | 7 +-- xen/common/Kconfig | 3 ++ xen/common/Makefile | 1 + xen/common/pmap.c | 72 +++++++++++++++++++++++++++++++ xen/include/xen/pmap.h | 16 +++++++ 9 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 xen/arch/arm/include/asm/pmap.h create mode 100644 xen/common/pmap.c create mode 100644 xen/include/xen/pmap.h diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ecfa6822e4d3..a89a67802aa9 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -14,6 +14,7 @@ config ARM select HAS_DEVICE_TREE select HAS_PASSTHROUGH select HAS_PDX + select HAS_PMAP select IOMMU_FORCE_PT_SHARE =20 config ARCH_DEFCONFIG diff --git a/xen/arch/arm/include/asm/fixmap.h b/xen/arch/arm/include/asm/f= ixmap.h index 1cee51e52ab9..365a2385a087 100644 --- a/xen/arch/arm/include/asm/fixmap.h +++ b/xen/arch/arm/include/asm/fixmap.h @@ -5,20 +5,44 @@ #define __ASM_FIXMAP_H =20 #include +#include =20 /* Fixmap slots */ #define FIXMAP_CONSOLE 0 /* The primary UART */ #define FIXMAP_MISC 1 /* Ephemeral mappings of hardware */ #define FIXMAP_ACPI_BEGIN 2 /* Start mappings of ACPI tables */ #define FIXMAP_ACPI_END (FIXMAP_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1)= /* End mappings of ACPI tables */ +#define FIXMAP_PMAP_BEGIN (FIXMAP_ACPI_END + 1) /* Start of PMAP */ +#define FIXMAP_PMAP_END (FIXMAP_PMAP_BEGIN + NUM_FIX_PMAP - 1) /* End of P= MAP */ + +#define FIXMAP_LAST FIXMAP_PMAP_END + +#define FIXADDR_START FIXMAP_ADDR(0) +#define FIXADDR_TOP FIXMAP_ADDR(FIXMAP_LAST) =20 #ifndef __ASSEMBLY__ =20 +/* + * Direct access to xen_fixmap[] should only happen when {set, + * clear}_fixmap() is unusable (e.g. where we would end up to + * recursively call the helpers). + */ +extern lpae_t xen_fixmap[XEN_PT_LPAE_ENTRIES]; + /* Map a page in a fixmap entry */ extern void set_fixmap(unsigned map, mfn_t mfn, unsigned attributes); /* Remove a mapping from a fixmap entry */ extern void clear_fixmap(unsigned map); =20 +#define fix_to_virt(slot) ((void *)FIXMAP_ADDR(slot)) + +static inline unsigned int virt_to_fix(vaddr_t vaddr) +{ + BUG_ON(vaddr >=3D FIXADDR_TOP || vaddr < FIXADDR_START); + + return ((vaddr - FIXADDR_START) >> PAGE_SHIFT); +} + #endif /* __ASSEMBLY__ */ =20 #endif /* __ASM_FIXMAP_H */ diff --git a/xen/arch/arm/include/asm/lpae.h b/xen/arch/arm/include/asm/lpa= e.h index aecb320dec45..fc19cbd84772 100644 --- a/xen/arch/arm/include/asm/lpae.h +++ b/xen/arch/arm/include/asm/lpae.h @@ -4,6 +4,7 @@ #ifndef __ASSEMBLY__ =20 #include +#include =20 /* * WARNING! Unlike the x86 pagetable code, where l1 is the lowest level a= nd @@ -168,6 +169,13 @@ static inline bool lpae_is_superpage(lpae_t pte, unsig= ned int level) third_table_offset(addr) \ } =20 +/* + * Standard entry type that we'll use to build Xen's own pagetables. + * We put the same permissions at every level, because they're ignored + * by the walker in non-leaf entries. + */ +lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr); + #endif /* __ASSEMBLY__ */ =20 /* diff --git a/xen/arch/arm/include/asm/pmap.h b/xen/arch/arm/include/asm/pma= p.h new file mode 100644 index 000000000000..74398b4c4fe6 --- /dev/null +++ b/xen/arch/arm/include/asm/pmap.h @@ -0,0 +1,32 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include + +#include + +static inline void arch_pmap_map(unsigned int slot, mfn_t mfn) +{ + lpae_t *entry =3D &xen_fixmap[slot]; + lpae_t pte; + + ASSERT(!lpae_is_valid(*entry)); + + pte =3D mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pt.table =3D 1; + write_pte(entry, pte); +} + +static inline void arch_pmap_unmap(unsigned int slot) +{ + lpae_t pte =3D {}; + + write_pte(&xen_fixmap[slot], pte); + + flush_xen_tlb_range_va_local(FIXMAP_ADDR(slot), PAGE_SIZE); +} + +void arch_pmap_map_slot(unsigned int slot, mfn_t mfn); +void arch_pmap_clear_slot(void *ptr); + +#endif /* __ASM_PMAP_H__ */ diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 52b2a0394047..bd1348a99716 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -305,12 +305,7 @@ void dump_hyp_walk(vaddr_t addr) dump_pt_walk(ttbr, addr, HYP_PT_ROOT_LEVEL, 1); } =20 -/* - * Standard entry type that we'll use to build Xen's own pagetables. - * We put the same permissions at every level, because they're ignored - * by the walker in non-leaf entries. - */ -static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned attr) +lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr) { lpae_t e =3D (lpae_t) { .pt =3D { diff --git a/xen/common/Kconfig b/xen/common/Kconfig index d921c74d615e..5b6b2406c028 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -49,6 +49,9 @@ config HAS_KEXEC config HAS_PDX bool =20 +config HAS_PMAP + bool + config HAS_SCHED_GRANULARITY bool =20 diff --git a/xen/common/Makefile b/xen/common/Makefile index b1e076c30b81..3baf83d527d8 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -29,6 +29,7 @@ obj-y +=3D notifier.o obj-y +=3D page_alloc.o obj-$(CONFIG_HAS_PDX) +=3D pdx.o obj-$(CONFIG_PERF_COUNTERS) +=3D perfc.o +obj-bin-$(CONFIG_HAS_PMAP) +=3D pmap.init.o obj-y +=3D preempt.o obj-y +=3D random.o obj-y +=3D rangeset.o diff --git a/xen/common/pmap.c b/xen/common/pmap.c new file mode 100644 index 000000000000..9355cacb7373 --- /dev/null +++ b/xen/common/pmap.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#include +#include + +/* + * Simple mapping infrastructure to map / unmap pages in fixed map. + * This is used to set the page table before the map domain page infrastru= cture + * is initialized. + * + * This structure is not protected by any locks, so it must not be used af= ter + * smp bring-up. + */ + +/* Bitmap to track which slot is used */ +static __initdata DECLARE_BITMAP(inuse, NUM_FIX_PMAP); + +void *__init pmap_map(mfn_t mfn) +{ + unsigned int idx; + unsigned int slot; + + ASSERT(system_state < SYS_STATE_smp_boot); + ASSERT(!in_irq()); + + idx =3D find_first_zero_bit(inuse, NUM_FIX_PMAP); + if ( idx =3D=3D NUM_FIX_PMAP ) + panic("Out of PMAP slots\n"); + + __set_bit(idx, inuse); + + slot =3D idx + FIXMAP_PMAP_BEGIN; + ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + + /* + * We cannot use set_fixmap() here. We use PMAP when the domain map + * page infrastructure is not yet initialized, so map_pages_to_xen() c= alled + * by set_fixmap() needs to map pages on demand, which then calls pmap= () + * again, resulting in a loop. Modify the PTEs directly instead. The s= ame + * is true for pmap_unmap(). + */ + arch_pmap_map(slot, mfn); + + return fix_to_virt(slot); +} + +void __init pmap_unmap(const void *p) +{ + unsigned int idx; + unsigned int slot =3D virt_to_fix((unsigned long)p); + + ASSERT(system_state < SYS_STATE_smp_boot); + ASSERT(slot >=3D FIXMAP_PMAP_BEGIN && slot <=3D FIXMAP_PMAP_END); + ASSERT(in_irq()); + + idx =3D slot - FIXMAP_PMAP_BEGIN; + + __clear_bit(idx, inuse); + arch_pmap_unmap(slot); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/pmap.h b/xen/include/xen/pmap.h new file mode 100644 index 000000000000..93e61b10870e --- /dev/null +++ b/xen/include/xen/pmap.h @@ -0,0 +1,16 @@ +#ifndef __XEN_PMAP_H__ +#define __XEN_PMAP_H__ + +/* Large enough for mapping 5 levels of page tables with some headroom */ +#define NUM_FIX_PMAP 8 + +#ifndef __ASSEMBLY__ + +#include + +void *pmap_map(mfn_t mfn); +void pmap_unmap(const void *p); + +#endif /* __ASSEMBLY__ */ + +#endif /* __XEN_PMAP_H__ */ --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048905; cv=none; d=zohomail.com; s=zohoarc; b=VIfX+vhYWBL3VZFf/9BLiYP0R6Y9X94t3jTSTRpPVpUI1NtzADaNkxdESOtShL8tw6aJOlsiPZWvo11ObQVwgbdMOOqQmZtzZClo1SY/XAUDVoA7kJhE4YEG+og9iKATyo3/sp42pJg6Q4xy2T1KhDBrfhRmEfvaezKydLh1Bes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048905; h=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; bh=HwmRtt4otl1crmQ3IgjCxj/lVWCzBdIkM8zTQonw0lU=; b=eJZ8GseXHixqNv+T8dlR8pJXZKLhEx5n+S99C6QGFxKvxKH07EE5oglCefFWSW0Tec+VCl88yHaQcdKs91ngx57KqO7exFCbw8NzZKgpTLBHorquwMSG29zLaoxQZXyRyzebyUEh6a+cEPGg5lc206VEZ+DPzSM0YGoCVzoIOI4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048905394259.8262723288333; Fri, 20 May 2022 05:15:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333988.557943 (Exim 4.92) (envelope-from ) id 1ns1Wn-0003Y5-AG; Fri, 20 May 2022 12:14:45 +0000 Received: by outflank-mailman (output) from mailman id 333988.557943; Fri, 20 May 2022 12:14:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wn-0003WA-5W; Fri, 20 May 2022 12:14:45 +0000 Received: by outflank-mailman (input) for mailman id 333988; Fri, 20 May 2022 12:14:43 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0003NP-R9 for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:14:43 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0005wW-Li; Fri, 20 May 2022 12:14:43 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sm-0001lI-S2; Fri, 20 May 2022 12:10:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=HwmRtt4otl1crmQ3IgjCxj/lVWCzBdIkM8zTQonw0lU=; b=EiJ687OV4u5psb86gk5OSHYba4 gE5eOTcNprJA0+yjr3EcYZo+FUl/WEp+BWKB+Xz9owRPWsmeK6yZQz+y+7V+kIjhLXlPySjjEH4Qt +M7dZYhOx8bgcih8R1K/0YRJJKsbLBgy6DgZdCkI9YhC7Kl5vry0Ob7hKk4bU5PrzS4M=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 11/16] xen/arm: mm: Clean-up the includes and order them Date: Fri, 20 May 2022 13:09:32 +0100 Message-Id: <20220520120937.28925-12-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048906816100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall The numbers of includes in mm.c has been growing quite a lot. However some of them (e.g. xen/device_tree.h, xen/softirq.h) doesn't look to be directly used by the file or other will be included by larger headers (e.g asm/flushtlb.h will be included by xen/mm.h). So trim down the number of includes. Take the opportunity to order them with the xen headers first, then asm headers and last public headers. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini --- Changes in v4: - Add Stefano's acked-by Changes in v3: - Patch added --- xen/arch/arm/mm.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index bd1348a99716..d40dd4e6c9e6 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -17,33 +17,26 @@ * GNU General Public License for more details. */ =20 -#include -#include -#include -#include -#include -#include +#include #include #include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include +#include +#include #include + #include -#include -#include -#include =20 #include #include =20 +#include + /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048907; cv=none; d=zohomail.com; s=zohoarc; b=YiIFY8u98Gh4HAywam5xs91e6wvD7WRf9pgt+deuFNtkj15YrkPJndjYhHjuj6DVYOi3CexFVMoh6DGSNfQZr9bOX1HOIpGAjHRe8PQNUgLaqxkDdtiM/aBbBrCjrhlP6I9LsiZGWOdkYsYt9pzipsMRq49u/N71RLr9qsdrISc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048907; h=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; bh=QrMX+f1B9/uCnIONfcNrd5IjXpsYHLALKUn/Mv7SupA=; b=VND+35ipXyJxhX9IMFg7970IMQaYLY346tfz0lu8r7RpiZ975oRqQQatnCiW/v0JGgr/qrM7xsP2dNtK6eLzOxvHzOnF8yRDxrIHYTVlcMlQgA/2Gm6W1vwUQ5ALJDAs6+We25u9tJQ+iANUia8d3RpKcU/xHG/VcE17hqyjSYA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048907169800.8087590835846; Fri, 20 May 2022 05:15:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333992.557977 (Exim 4.92) (envelope-from ) id 1ns1Wp-0004BU-EL; Fri, 20 May 2022 12:14:47 +0000 Received: by outflank-mailman (output) from mailman id 333992.557977; Fri, 20 May 2022 12:14:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wo-00047E-Vu; Fri, 20 May 2022 12:14:46 +0000 Received: by outflank-mailman (input) for mailman id 333992; Fri, 20 May 2022 12:14:44 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0003NZ-TR for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:14:43 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0005wU-K9; Fri, 20 May 2022 12:14:43 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sn-0001lI-T1; Fri, 20 May 2022 12:10:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=QrMX+f1B9/uCnIONfcNrd5IjXpsYHLALKUn/Mv7SupA=; b=6Up0ZDUUnV7j3M6/hSXLAhP30w JjdnUfUG1voWCIHjL4TOnQyYZFkX4i1J0w1x10XhV5yAe10ZeDXQigwv4OK11+YZkzQAVyhIur8ED QEDfrRXcCTkokXAVlBrpuvsBzcin/bcjIgkl1EJciGHxzTMy4kC6TWq6k6y64nJ78Efk=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 12/16] xen/arm: mm: Use the PMAP helpers in xen_{,un}map_table() Date: Fri, 20 May 2022 13:09:33 +0100 Message-Id: <20220520120937.28925-13-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048908811100005 Content-Type: text/plain; charset="utf-8" From: Julien Grall During early boot, it is not possible to use xen_{,un}map_table() if the page tables are not residing the Xen binary. This is a blocker to switch some of the helpers to use xen_pt_update() as we may need to allocate extra page tables and access them before the domheap has been initialized (see setup_xenheap_mappings()). xen_{,un}map_table() are now updated to use the PMAP helpers for early boot map/unmap. Note that the special case for page-tables residing in Xen binary has been dropped because it is "complex" and was only added as a workaround in 8d4f1b8878e0 ("xen/arm: mm: Allow generic xen page-tables helpers to be called early"). Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v4: - Add Stefano's reviewed-by Changes in v2: - New patch --- xen/arch/arm/mm.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index d40dd4e6c9e6..b019e4b35b55 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -980,27 +981,11 @@ void *ioremap(paddr_t pa, size_t len) static lpae_t *xen_map_table(mfn_t mfn) { /* - * We may require to map the page table before map_domain_page() is - * useable. The requirements here is it must be useable as soon as - * page-tables are allocated dynamically via alloc_boot_pages(). - * - * We need to do the check on physical address rather than virtual - * address to avoid truncation on Arm32. Therefore is_kernel() cannot - * be used. + * During early boot, map_domain_page() may be unusable. Use the + * PMAP to map temporarily a page-table. */ if ( system_state =3D=3D SYS_STATE_early_boot ) - { - if ( is_xen_fixed_mfn(mfn) ) - { - /* - * It is fine to demote the type because the size of Xen - * will always fit in vaddr_t. - */ - vaddr_t offset =3D mfn_to_maddr(mfn) - virt_to_maddr(&_start); - - return (lpae_t *)(XEN_VIRT_START + offset); - } - } + return pmap_map(mfn); =20 return map_domain_page(mfn); } @@ -1009,12 +994,12 @@ static void xen_unmap_table(const lpae_t *table) { /* * During early boot, xen_map_table() will not use map_domain_page() - * for page-tables residing in Xen binary. So skip the unmap part. + * but the PMAP. */ - if ( system_state =3D=3D SYS_STATE_early_boot && is_kernel(table) ) - return; - - unmap_domain_page(table); + if ( system_state =3D=3D SYS_STATE_early_boot ) + pmap_unmap(table); + else + unmap_domain_page(table); } =20 static int create_xen_table(lpae_t *entry) --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048906; cv=none; d=zohomail.com; s=zohoarc; b=Ti1mJEddWY1dfpkme4eUMERQRIRDTsNzvQHoDQcold3brpnOmk6cZ405a2vqobsk8y5En1eJYI1knJQqzuZWObNzwgHFSl/1Q+CjNwL5q5fw5YHsK9b6gRVuat6fMjBfZeOXwH9ONso6/s7ZqzuoMMB8VZTpYnCso3M2IPsb2bA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048906; h=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; bh=mOn3zp5wUGYujSQe5FrNT0Pt6XF+4/RdAAfK0S+9m+Y=; b=fsVOaTjBG+ZDmtLumjFq3aP+yiXadbpmDvhtHqrhhic/S6yd8AH9YqCuB8rInbVwNSSbCmDFiPzTYvS+RATjgxws6ilZI5P7TTbL+o2aI1qgKLHrEZM30Wme1rSK2hFRSvDmM+LB9yS/lVTSq5fOlZs7Yj8AkJ8uB5sbHdttZ5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048906562626.3338242859369; Fri, 20 May 2022 05:15:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333987.557937 (Exim 4.92) (envelope-from ) id 1ns1Wm-0003Qb-VY; Fri, 20 May 2022 12:14:44 +0000 Received: by outflank-mailman (output) from mailman id 333987.557937; Fri, 20 May 2022 12:14:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wm-0003Po-SF; Fri, 20 May 2022 12:14:44 +0000 Received: by outflank-mailman (input) for mailman id 333987; Fri, 20 May 2022 12:14:43 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0003NG-Od for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:14:43 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0005wO-FC; Fri, 20 May 2022 12:14:43 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1So-0001lI-U1; Fri, 20 May 2022 12:10:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=mOn3zp5wUGYujSQe5FrNT0Pt6XF+4/RdAAfK0S+9m+Y=; b=cbG95IzqZm/2Lgg6aseyQY31Zd NlLO/aB0E6nWqkJ7QtRqxCA62EP19nQ6MA901oF2mCR+tRSTrLliDccxFa/oS1VwKUcvCTRrBnucP tocIDpjaz4VaPd1JbJPa7b2pUe2WURB4Tng+8mkJqFCcWVFFg3jhhUlmLd7qeihrrWSI=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 13/16] xen/arm32: setup: Move out the code to populate the boot allocator Date: Fri, 20 May 2022 13:09:34 +0100 Message-Id: <20220520120937.28925-14-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048906880100003 Content-Type: text/plain; charset="utf-8" From: Julien Grall In a follow-up patch, we will want to populate the boot allocator separately for arm64. The code will end up to be very similar to the one on arm32. So move out the code in a new helper populate_boot_allocator(). For now the code is still protected by CONFIG_ARM_32 to avoid any build failure on arm64. Take the opportunity to replace mfn_add(xen_mfn_start, xenheap_pages) with xenheap_mfn_end as they are equivalent. Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis Reviewed-by: Michal Orzel Reviewed-by: Stefano Stabellini --- Changes in v4: - Patch added --- xen/arch/arm/setup.c | 90 +++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index d5d0792ed48a..3d5a2283d4ef 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -637,10 +637,58 @@ static void __init init_staticmem_pages(void) } =20 #ifdef CONFIG_ARM_32 +/* + * Populate the boot allocator. All the RAM but the following regions + * will be added: + * - Modules (e.g., Xen, Kernel) + * - Reserved regions + * - Xenheap + */ +static void __init populate_boot_allocator(void) +{ + unsigned int i; + const struct meminfo *banks =3D &bootinfo.mem; + + for ( i =3D 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank =3D &banks->bank[i]; + paddr_t bank_end =3D bank->start + bank->size; + paddr_t s, e; + + s =3D bank->start; + while ( s < bank_end ) + { + paddr_t n =3D bank_end; + + e =3D next_module(s, &n); + + if ( e =3D=3D ~(paddr_t)0 ) + e =3D n =3D bank_end; + + /* + * Module in a RAM bank other than the one which we are + * not dealing with here. + */ + if ( e > bank_end ) + e =3D bank_end; + + /* Avoid the xenheap */ + if ( s < mfn_to_maddr(xenheap_mfn_end) && + mfn_to_maddr(xenheap_mfn_start) < e ) + { + e =3D mfn_to_maddr(xenheap_mfn_start); + n =3D mfn_to_maddr(xenheap_mfn_end); + } + + fw_unreserved_regions(s, e, init_boot_pages, 0); + s =3D n; + } + } +} + static void __init setup_mm(void) { - paddr_t ram_start, ram_end, ram_size; - paddr_t s, e; + paddr_t ram_start, ram_end, ram_size, e; unsigned long ram_pages; unsigned long heap_pages, xenheap_pages, domheap_pages; int i; @@ -718,43 +766,7 @@ static void __init setup_mm(void) setup_xenheap_mappings((e >> PAGE_SHIFT) - xenheap_pages, xenheap_page= s); =20 /* Add non-xenheap memory */ - for ( i =3D 0; i < bootinfo.mem.nr_banks; i++ ) - { - paddr_t bank_start =3D bootinfo.mem.bank[i].start; - paddr_t bank_end =3D bank_start + bootinfo.mem.bank[i].size; - - s =3D bank_start; - while ( s < bank_end ) - { - paddr_t n =3D bank_end; - - e =3D next_module(s, &n); - - if ( e =3D=3D ~(paddr_t)0 ) - { - e =3D n =3D ram_end; - } - - /* - * Module in a RAM bank other than the one which we are - * not dealing with here. - */ - if ( e > bank_end ) - e =3D bank_end; - - /* Avoid the xenheap */ - if ( s < mfn_to_maddr(mfn_add(xenheap_mfn_start, xenheap_pages= )) - && mfn_to_maddr(xenheap_mfn_start) < e ) - { - e =3D mfn_to_maddr(xenheap_mfn_start); - n =3D mfn_to_maddr(mfn_add(xenheap_mfn_start, xenheap_page= s)); - } - - fw_unreserved_regions(s, e, init_boot_pages, 0); - - s =3D n; - } - } + populate_boot_allocator(); =20 /* Frame table covers all of RAM region, including holes */ setup_frametable_mappings(ram_start, ram_end); --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048908; cv=none; d=zohomail.com; s=zohoarc; b=fuFUmq/hJHT5ChgVfR43FQSVaNpEntgjXo1CBqHIymw3pzKNZsrM6YzVJW47OyiasbfLCGiP0qIQ/JvMHE8zNBiCCjFk6bJxQNJe/xyyDA1S5E0KKzOO0adWQf9UmQxmbc14Wp/rbcMdShlvO8jkad0NRwxJ7+lzuBxffpVdbB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048908; h=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; bh=/p4UF49sOqtR4ILsBBu0AgkjXqEpW9beFbXzPB2vh14=; b=c6xtcNiqxxe+SZxmOI/YXld2RBfrUDmpiufc8pv4vI4gvSPkZmhyAZzj7gBfbdJUhaQycDdhfMDZM9H2nHTy+31ibH7EPnl0FmI/ea6Hrr47swQf/9sEY9f057F4gS8bLfXoKqFwBSW1wDKgb59JxUqUT9nlNSVyEWVbUGDmgBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048908371772.6238788189287; Fri, 20 May 2022 05:15:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333989.557948 (Exim 4.92) (envelope-from ) id 1ns1Wn-0003f7-LY; Fri, 20 May 2022 12:14:45 +0000 Received: by outflank-mailman (output) from mailman id 333989.557948; Fri, 20 May 2022 12:14:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wn-0003c3-FI; Fri, 20 May 2022 12:14:45 +0000 Received: by outflank-mailman (input) for mailman id 333989; Fri, 20 May 2022 12:14:43 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0003NU-S7 for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:14:43 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0005wY-NE; Fri, 20 May 2022 12:14:43 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sp-0001lI-V2; Fri, 20 May 2022 12:10:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=/p4UF49sOqtR4ILsBBu0AgkjXqEpW9beFbXzPB2vh14=; b=RqVcFZF6NOBVK1/WkZJeoI26DI KjGigIBdadzMlNjOeFHlUxYSOA4GqqHVuYh4RYON/Zew2s28W4WPqgZFlbArO5ZqEvhFrfZv1QEK/ dIJGEL6krsspXyYMhrNhKLKfPpfI2gg26QDRiumPAdCX567ojsYK1djN0jqTD/itkY1k=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 14/16] xen/arm64: mm: Add memory to the boot allocator first Date: Fri, 20 May 2022 13:09:35 +0100 Message-Id: <20220520120937.28925-15-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048908819100006 Content-Type: text/plain; charset="utf-8" From: Julien Grall Currently, memory is added to the boot allocator after the xenheap mappings are done. This will break if the first mapping is more than 512GB of RAM. In addition to that, a follow-up patch will rework setup_xenheap_mappings() to use smaller mappings (e.g. 2MB, 4KB). So it will be necessary to have memory in the boot allocator earlier. Only free memory (e.g. not reserved or modules) can be added to the boot allocator. It might be possible that some regions (including the first one) will have no free memory. So we need to add all the free memory to the boot allocator first and then add do the mappings. Populating the boot allocator is nearly the same between arm32 and arm64. The only difference is on the former we need to exclude the xenheap for the boot allocator. Gate the difference with CONFIG_ARM_32 so the code be re-used on arm64. Signed-off-by: Julien Grall Reviewed-by: Luca Fancellu Reviewed-by: Stefano Stabellini Tested-by: Luca Fancellu --- Changes in v4: - The implementation of populate_boot_allocator() has been moved in a separate patch. - Fix typo Changes in v3: - Patch added --- xen/arch/arm/setup.c | 55 +++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 3d5a2283d4ef..db1768c03f03 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -636,13 +636,12 @@ static void __init init_staticmem_pages(void) #endif } =20 -#ifdef CONFIG_ARM_32 /* * Populate the boot allocator. All the RAM but the following regions * will be added: * - Modules (e.g., Xen, Kernel) * - Reserved regions - * - Xenheap + * - Xenheap (arm32 only) */ static void __init populate_boot_allocator(void) { @@ -672,6 +671,7 @@ static void __init populate_boot_allocator(void) if ( e > bank_end ) e =3D bank_end; =20 +#ifdef CONFIG_ARM_32 /* Avoid the xenheap */ if ( s < mfn_to_maddr(xenheap_mfn_end) && mfn_to_maddr(xenheap_mfn_start) < e ) @@ -679,6 +679,7 @@ static void __init populate_boot_allocator(void) e =3D mfn_to_maddr(xenheap_mfn_start); n =3D mfn_to_maddr(xenheap_mfn_end); } +#endif =20 fw_unreserved_regions(s, e, init_boot_pages, 0); s =3D n; @@ -686,6 +687,7 @@ static void __init populate_boot_allocator(void) } } =20 +#ifdef CONFIG_ARM_32 static void __init setup_mm(void) { paddr_t ram_start, ram_end, ram_size, e; @@ -781,45 +783,36 @@ static void __init setup_mm(void) #else /* CONFIG_ARM_64 */ static void __init setup_mm(void) { + const struct meminfo *banks =3D &bootinfo.mem; paddr_t ram_start =3D ~0; paddr_t ram_end =3D 0; paddr_t ram_size =3D 0; - int bank; + unsigned int i; =20 init_pdx(); =20 - total_pages =3D 0; - for ( bank =3D 0 ; bank < bootinfo.mem.nr_banks; bank++ ) - { - paddr_t bank_start =3D bootinfo.mem.bank[bank].start; - paddr_t bank_size =3D bootinfo.mem.bank[bank].size; - paddr_t bank_end =3D bank_start + bank_size; - paddr_t s, e; - - ram_size =3D ram_size + bank_size; - ram_start =3D min(ram_start,bank_start); - ram_end =3D max(ram_end,bank_end); - - setup_xenheap_mappings(bank_start>>PAGE_SHIFT, bank_size>>PAGE_SHI= FT); - - s =3D bank_start; - while ( s < bank_end ) - { - paddr_t n =3D bank_end; + /* + * We need some memory to allocate the page-tables used for the xenheap + * mappings. But some regions may contain memory already allocated + * for other uses (e.g. modules, reserved-memory...). + * + * For simplicity, add all the free regions in the boot allocator. + */ + populate_boot_allocator(); =20 - e =3D next_module(s, &n); + total_pages =3D 0; =20 - if ( e =3D=3D ~(paddr_t)0 ) - { - e =3D n =3D bank_end; - } + for ( i =3D 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank =3D &banks->bank[i]; + paddr_t bank_end =3D bank->start + bank->size; =20 - if ( e > bank_end ) - e =3D bank_end; + ram_size =3D ram_size + bank->size; + ram_start =3D min(ram_start, bank->start); + ram_end =3D max(ram_end, bank_end); =20 - fw_unreserved_regions(s, e, init_boot_pages, 0); - s =3D n; - } + setup_xenheap_mappings(PFN_DOWN(bank->start), + PFN_DOWN(bank->size)); } =20 total_pages +=3D ram_size >> PAGE_SHIFT; --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048911; cv=none; d=zohomail.com; s=zohoarc; b=i3kmYEjIogqUDKQZSKTWfUd3Akq4oWUKnqhPLGhhDg7xCLWGc1YJCotBGnaskMliEAInIJEAzYAeKAVqQ+B1+T8W1c365l7hlIq8JdKXoXGOQqe23kD+7To8eUcgNd/XK9kdjAkatjpl1BRxYoPoUook0LtrQXqwWnvSoHCnQFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048911; h=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; bh=41WjXhbveDV5dmNCQg1PHVgqE6S+lfA5Dgi2tBRYmT0=; b=m04CyJnv3+8SsJe12lFD65xhG3yC8iOnERO/6v3BBNksxjuH9HLBhecLYCkD77/FPhAz9NKmZURMpky/T8z8240+LJHoglFqciU6RT+Tnr1CLrKZrdfcIpppfPRsZD8sn9+ve8IxSmOJ6DUYsBjxmHpwisuhC8Wictz6eJSqZgg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048911414571.970396486531; Fri, 20 May 2022 05:15:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333991.557968 (Exim 4.92) (envelope-from ) id 1ns1Wo-0003yz-S2; Fri, 20 May 2022 12:14:46 +0000 Received: by outflank-mailman (output) from mailman id 333991.557968; Fri, 20 May 2022 12:14:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wo-0003vf-EY; Fri, 20 May 2022 12:14:46 +0000 Received: by outflank-mailman (input) for mailman id 333991; Fri, 20 May 2022 12:14:43 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0003Nd-Tk for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:14:43 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0005we-Oq; Fri, 20 May 2022 12:14:43 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Sr-0001lI-38; Fri, 20 May 2022 12:10:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=41WjXhbveDV5dmNCQg1PHVgqE6S+lfA5Dgi2tBRYmT0=; b=sZoYCpyBcFzHWZlYss8ssgcJBg ZCC9jzSuNV0zXOmMwhY6dEB7lqRhdIJuoWSebGFUDYQGwbVbq1NKe0tpccxEASdhs/B7XKNDv5d26 1PJsLbQ+CVjSrKVjX54SZdXZe5AyZ6LUcfJeXIXviwddedkf4qOKLwAKdRQZLlIStO7A=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH 15/16] xen/arm: mm: Rework setup_xenheap_mappings() Date: Fri, 20 May 2022 13:09:36 +0100 Message-Id: <20220520120937.28925-16-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048912824100013 Content-Type: text/plain; charset="utf-8" From: Julien Grall The current implementation of setup_xenheap_mappings() is using 1GB mappings. This can lead to unexpected result because the mapping may alias a non-cachable region (such as device or reserved regions). For more details see B2.8 in ARM DDI 0487H.a. map_pages_to_xen() was recently reworked to allow superpage mappings, support contiguous mapping and deal with the use of page-tables before they are mapped. Most of the code in setup_xenheap_mappings() is now replaced with a single call to map_pages_to_xen(). Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v4: - Fix typo - Add Stefano's reviewed-by Changes in v3: - Don't use 1GB mapping - Re-order code in setup_mm() in a separate patch Changes in v2: - New patch --- xen/arch/arm/mm.c | 87 ++++++++++------------------------------------- 1 file changed, 18 insertions(+), 69 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b019e4b35b55..65af44f42232 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -138,17 +138,6 @@ static DEFINE_PAGE_TABLE(cpu0_pgtable); static DEFINE_PAGE_TABLES(cpu0_dommap, DOMHEAP_SECOND_PAGES); #endif =20 -#ifdef CONFIG_ARM_64 -/* The first page of the first level mapping of the xenheap. The - * subsequent xenheap first level pages are dynamically allocated, but - * we need this one to bootstrap ourselves. */ -static DEFINE_PAGE_TABLE(xenheap_first_first); -/* The zeroeth level slot which uses xenheap_first_first. Used because - * setup_xenheap_mappings otherwise relies on mfn_to_virt which isn't - * valid for a non-xenheap mapping. */ -static __initdata int xenheap_first_first_slot =3D -1; -#endif - /* Common pagetable leaves */ /* Second level page tables. * @@ -831,77 +820,37 @@ void __init setup_xenheap_mappings(unsigned long base= _mfn, void __init setup_xenheap_mappings(unsigned long base_mfn, unsigned long nr_mfns) { - lpae_t *first, pte; - unsigned long mfn, end_mfn; - vaddr_t vaddr; - - /* Align to previous 1GB boundary */ - mfn =3D base_mfn & ~((FIRST_SIZE>>PAGE_SHIFT)-1); + int rc; =20 /* First call sets the xenheap physical and virtual offset. */ if ( mfn_eq(xenheap_mfn_start, INVALID_MFN) ) { + unsigned long mfn_gb =3D base_mfn & ~((FIRST_SIZE >> PAGE_SHIFT) -= 1); + xenheap_mfn_start =3D _mfn(base_mfn); xenheap_base_pdx =3D mfn_to_pdx(_mfn(base_mfn)); + /* + * The base address may not be aligned to the first level + * size (e.g. 1GB when using 4KB pages). This would prevent + * superpage mappings for all the regions because the virtual + * address and machine address should both be suitably aligned. + * + * Prevent that by offsetting the start of the xenheap virtual + * address. + */ xenheap_virt_start =3D DIRECTMAP_VIRT_START + - (base_mfn - mfn) * PAGE_SIZE; + (base_mfn - mfn_gb) * PAGE_SIZE; } =20 if ( base_mfn < mfn_x(xenheap_mfn_start) ) panic("cannot add xenheap mapping at %lx below heap start %lx\n", base_mfn, mfn_x(xenheap_mfn_start)); =20 - end_mfn =3D base_mfn + nr_mfns; - - /* - * Virtual address aligned to previous 1GB to match physical - * address alignment done above. - */ - vaddr =3D (vaddr_t)__mfn_to_virt(base_mfn) & FIRST_MASK; - - while ( mfn < end_mfn ) - { - int slot =3D zeroeth_table_offset(vaddr); - lpae_t *p =3D &xen_pgtable[slot]; - - if ( p->pt.valid ) - { - /* mfn_to_virt is not valid on the 1st 1st mfn, since it - * is not within the xenheap. */ - first =3D slot =3D=3D xenheap_first_first_slot ? - xenheap_first_first : mfn_to_virt(lpae_get_mfn(*p)); - } - else if ( xenheap_first_first_slot =3D=3D -1) - { - /* Use xenheap_first_first to bootstrap the mappings */ - first =3D xenheap_first_first; - - pte =3D pte_of_xenaddr((vaddr_t)xenheap_first_first); - pte.pt.table =3D 1; - write_pte(p, pte); - - xenheap_first_first_slot =3D slot; - } - else - { - mfn_t first_mfn =3D alloc_boot_pages(1, 1); - - clear_page(mfn_to_virt(first_mfn)); - pte =3D mfn_to_xen_entry(first_mfn, MT_NORMAL); - pte.pt.table =3D 1; - write_pte(p, pte); - first =3D mfn_to_virt(first_mfn); - } - - pte =3D mfn_to_xen_entry(_mfn(mfn), MT_NORMAL); - /* TODO: Set pte.pt.contig when appropriate. */ - write_pte(&first[first_table_offset(vaddr)], pte); - - mfn +=3D FIRST_SIZE>>PAGE_SHIFT; - vaddr +=3D FIRST_SIZE; - } - - flush_xen_tlb_local(); + rc =3D map_pages_to_xen((vaddr_t)__mfn_to_virt(base_mfn), + _mfn(base_mfn), nr_mfns, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the xenheap mappings.\n"); } #endif =20 --=20 2.32.0 From nobody Tue May 14 06:34:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1653048909; cv=none; d=zohomail.com; s=zohoarc; b=R0MR2WKxyIEQGjmD8yx2Qs/UAjwXoGvF0gX/fvJ1dLQlAJN3YvcpcjW+uIu5K5ciY4kcJfmwxAVROkLklbhV0OiZoa7A+iG+bC+LnWjI0kR57KLKoX2Ie+KMGl1gZGxfSZqaxR0Q/WcU1DqnF9UOlDZf6B+/Wqb+ZhspYKCoLvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653048909; h=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; bh=7kkcUtTj63g7Kwg1pXZqqsSOsowp6Vr0NeH5tERRvKE=; b=MptepxEopYm67sKhFXe9HP5A4U+lVRtRQXwFrmihUevBUAJKiaVMf8S7OvO7aYB+taipHUb5tjAWiInNbES8PYyh7DidLW7YGZ4Hinvf5HX99gKGov0ILulQ2K3V80y+Fp6Xp2MSVYVfGfB1twowLw8bACUk/jV2WegyRskZz0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1653048909276481.0702520102508; Fri, 20 May 2022 05:15:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.333986.557932 (Exim 4.92) (envelope-from ) id 1ns1Wm-0003O4-ML; Fri, 20 May 2022 12:14:44 +0000 Received: by outflank-mailman (output) from mailman id 333986.557932; Fri, 20 May 2022 12:14:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wm-0003Nx-JZ; Fri, 20 May 2022 12:14:44 +0000 Received: by outflank-mailman (input) for mailman id 333986; Fri, 20 May 2022 12:14:43 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0003NF-Od for xen-devel@lists.xenproject.org; Fri, 20 May 2022 12:14:43 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ns1Wl-0005wQ-Gq; Fri, 20 May 2022 12:14:43 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ns1Ss-0001lI-7T; Fri, 20 May 2022 12:10:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=7kkcUtTj63g7Kwg1pXZqqsSOsowp6Vr0NeH5tERRvKE=; b=Y/a0/6lqiOd+ENWCW26KMos1CT IaBH4JCumNkQJzAc5WJwRhRuYudmnr30I+g1PGh1IbPw6S5ql5Jyur0RS7RrTsGnnCCUugQmf58F0 zp+VjvgR9JrglKY39gKq8IQgbAvetjSL8qW//zW1WX3mjX9E7s3R7x5prKh+NnG5VgLQ=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Julien Grall Subject: [PATCH 16/16] xen/arm: mm: Re-implement setup_frame_table_mappings() with map_pages_to_xen() Date: Fri, 20 May 2022 13:09:37 +0100 Message-Id: <20220520120937.28925-17-julien@xen.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520120937.28925-1-julien@xen.org> References: <20220520120937.28925-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1653048910891100011 Content-Type: text/plain; charset="utf-8" From: Julien Grall Now that map_pages_to_xen() has been extended to support 2MB mappings, we can replace the create_mappings() call by map_pages_to_xen() call. This has the advantage to remove the differences between 32-bit and 64-bit code. Lastly remove create_mappings() as there is no more callers. Signed-off-by: Julien Grall Signed-off-by: Julien Grall Reviewed-by: Luca Fancellu Reviewed-by: Stefano Stabellini Tested-by: Luca Fancellu --- Changes in v4: - Add missing _PAGE_BLOCK Changes in v3: - Fix typo in the commit message - Remove the TODO regarding contiguous bit Changes in v2: - New patch --- xen/arch/arm/mm.c | 64 +++++------------------------------------------ 1 file changed, 6 insertions(+), 58 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 65af44f42232..be37176a4725 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -369,40 +369,6 @@ void clear_fixmap(unsigned map) BUG_ON(res !=3D 0); } =20 -/* Create Xen's mappings of memory. - * Mapping_size must be either 2MB or 32MB. - * Base and virt must be mapping_size aligned. - * Size must be a multiple of mapping_size. - * second must be a contiguous set of second level page tables - * covering the region starting at virt_offset. */ -static void __init create_mappings(lpae_t *second, - unsigned long virt_offset, - unsigned long base_mfn, - unsigned long nr_mfns, - unsigned int mapping_size) -{ - unsigned long i, count; - const unsigned long granularity =3D mapping_size >> PAGE_SHIFT; - lpae_t pte, *p; - - ASSERT((mapping_size =3D=3D MB(2)) || (mapping_size =3D=3D MB(32))); - ASSERT(!((virt_offset >> PAGE_SHIFT) % granularity)); - ASSERT(!(base_mfn % granularity)); - ASSERT(!(nr_mfns % granularity)); - - count =3D nr_mfns / XEN_PT_LPAE_ENTRIES; - p =3D second + second_linear_offset(virt_offset); - pte =3D mfn_to_xen_entry(_mfn(base_mfn), MT_NORMAL); - if ( granularity =3D=3D 16 * XEN_PT_LPAE_ENTRIES ) - pte.pt.contig =3D 1; /* These maps are in 16-entry contiguous chu= nks. */ - for ( i =3D 0; i < count; i++ ) - { - write_pte(p + i, pte); - pte.pt.base +=3D 1 << XEN_PT_LPAE_SHIFT; - } - flush_xen_tlb_local(); -} - #ifdef CONFIG_DOMAIN_PAGE void *map_domain_page_global(mfn_t mfn) { @@ -862,36 +828,18 @@ void __init setup_frametable_mappings(paddr_t ps, pad= dr_t pe) unsigned long frametable_size =3D nr_pdxs * sizeof(struct page_info); mfn_t base_mfn; const unsigned long mapping_size =3D frametable_size < MB(32) ? MB(2) = : MB(32); -#ifdef CONFIG_ARM_64 - lpae_t *second, pte; - unsigned long nr_second; - mfn_t second_base; - int i; -#endif + int rc; =20 frametable_base_pdx =3D mfn_to_pdx(maddr_to_mfn(ps)); /* Round up to 2M or 32M boundary, as appropriate. */ frametable_size =3D ROUNDUP(frametable_size, mapping_size); base_mfn =3D alloc_boot_pages(frametable_size >> PAGE_SHIFT, 32<<(20-1= 2)); =20 -#ifdef CONFIG_ARM_64 - /* Compute the number of second level pages. */ - nr_second =3D ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT; - second_base =3D alloc_boot_pages(nr_second, 1); - second =3D mfn_to_virt(second_base); - for ( i =3D 0; i < nr_second; i++ ) - { - clear_page(mfn_to_virt(mfn_add(second_base, i))); - pte =3D mfn_to_xen_entry(mfn_add(second_base, i), MT_NORMAL); - pte.pt.table =3D 1; - write_pte(&xen_first[first_table_offset(FRAMETABLE_VIRT_START)+i],= pte); - } - create_mappings(second, 0, mfn_x(base_mfn), frametable_size >> PAGE_SH= IFT, - mapping_size); -#else - create_mappings(xen_second, FRAMETABLE_VIRT_START, mfn_x(base_mfn), - frametable_size >> PAGE_SHIFT, mapping_size); -#endif + rc =3D map_pages_to_xen(FRAMETABLE_VIRT_START, base_mfn, + frametable_size >> PAGE_SHIFT, + PAGE_HYPERVISOR_RW | _PAGE_BLOCK); + if ( rc ) + panic("Unable to setup the frametable mappings.\n"); =20 memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); memset(&frame_table[nr_pdxs], -1, --=20 2.32.0