From nobody Thu Oct 23 00:47:02 2025 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; 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; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168775085576778.81521242503345; Sun, 25 Jun 2023 20:40:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.555072.866769 (Exim 4.92) (envelope-from ) id 1qDd5S-0007NK-P5; Mon, 26 Jun 2023 03:40:22 +0000 Received: by outflank-mailman (output) from mailman id 555072.866769; Mon, 26 Jun 2023 03:40:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDd5S-0007ML-Fb; Mon, 26 Jun 2023 03:40:22 +0000 Received: by outflank-mailman (input) for mailman id 555072; Mon, 26 Jun 2023 03:40:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDd2B-0007ej-Bm for xen-devel@lists.xenproject.org; Mon, 26 Jun 2023 03:36:59 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id b41595ed-13d2-11ee-b237-6b7b168915f2; Mon, 26 Jun 2023 05:36:58 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C69601FB; Sun, 25 Jun 2023 20:37:41 -0700 (PDT) Received: from a011292.shanghai.arm.com (a011292.shanghai.arm.com [10.169.190.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2ACB33F64C; Sun, 25 Jun 2023 20:36:54 -0700 (PDT) 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" X-Inumbo-ID: b41595ed-13d2-11ee-b237-6b7b168915f2 From: Penny Zheng To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng , Wei Chen Subject: [PATCH v3 35/52] xen/arm: map static memory on demand Date: Mon, 26 Jun 2023 11:34:26 +0800 Message-Id: <20230626033443.2943270-36-Penny.Zheng@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230626033443.2943270-1-Penny.Zheng@arm.com> References: <20230626033443.2943270-1-Penny.Zheng@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1687750856174100001 Content-Type: text/plain; charset="utf-8" In function init_staticmem_pages, we need the access to static memory for proper initialization. It is not a problem in MMU system, as Xen map the whole RAM in setup_mm(). However, with limited MPU memory regions, it is too luxury to map the whole RAM. As a result, we follow the rule of "map on demand", to map static memory temporarily before its initialization, and unmap immediately after its initialization. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen --- v3: - new commit --- xen/arch/arm/include/asm/mm.h | 2 ++ xen/arch/arm/mmu/mm.c | 10 ++++++++++ xen/arch/arm/mpu/mm.c | 10 ++++++++++ xen/arch/arm/setup.c | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 66d98b9a29..cffbf8a595 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -224,6 +224,8 @@ extern void mm_init_secondary_cpu(void); extern void setup_frametable_mappings(paddr_t ps, paddr_t pe); /* map a physical range in virtual memory */ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int attribu= tes); +extern int map_staticmem_pages_to_xen(paddr_t start, paddr_t end); +extern int unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end); =20 static inline void __iomem *ioremap_nocache(paddr_t start, size_t len) { diff --git a/xen/arch/arm/mmu/mm.c b/xen/arch/arm/mmu/mm.c index 2f29cb53fe..4196a55c32 100644 --- a/xen/arch/arm/mmu/mm.c +++ b/xen/arch/arm/mmu/mm.c @@ -1113,6 +1113,16 @@ int populate_pt_range(unsigned long virt, unsigned l= ong nr_mfns) return xen_pt_update(virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); } =20 +int __init map_staticmem_pages_to_xen(paddr_t start, paddr_t end) +{ + return 0; +} + +int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) +{ + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index a40055ae5e..9d5c1da39c 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -614,6 +614,16 @@ void __init setup_frametable_mappings(paddr_t ps, padd= r_t pe) frametable_size - (nr_pdxs * sizeof(struct page_info))); } =20 +int __init map_staticmem_pages_to_xen(paddr_t start, paddr_t end) +{ + return xen_mpumap_update(start, end, PAGE_HYPERVISOR | _PAGE_TRANSIENT= ); +} + +int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) +{ + return xen_mpumap_update(start, end, 0); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index f42b53d17b..c21d1db763 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -637,12 +637,33 @@ void __init init_staticmem_pages(void) mfn_t bank_start =3D _mfn(PFN_UP(bootinfo.reserved_mem.bank[ba= nk].start)); unsigned long bank_pages =3D PFN_DOWN(bootinfo.reserved_mem.ba= nk[bank].size); mfn_t bank_end =3D mfn_add(bank_start, bank_pages); + int res; =20 if ( mfn_x(bank_end) <=3D mfn_x(bank_start) ) return; =20 + /* Map temporarily before initialization */ + res =3D map_staticmem_pages_to_xen(mfn_to_maddr(bank_start), + mfn_to_maddr(bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to map static memory to Xen: %d\= n", + res); + return; + } + unprepare_staticmem_pages(mfn_to_page(bank_start), bank_pages, false); + + /* Unmap immediately after initialization */ + res =3D unmap_staticmem_pages_to_xen(mfn_to_maddr(bank_start), + mfn_to_maddr(bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to unmap static memory to Xen: %= d\n", + res); + return; + } } } #endif --=20 2.25.1