From nobody Fri Oct 31 11:33:46 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 1756312896673780.330975087207; Wed, 27 Aug 2025 09:41:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1096549.1451237 (Exim 4.92) (envelope-from ) id 1urJDB-0006ZF-Kb; Wed, 27 Aug 2025 16:41:25 +0000 Received: by outflank-mailman (output) from mailman id 1096549.1451237; Wed, 27 Aug 2025 16:41:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1urJDB-0006Z5-Gf; Wed, 27 Aug 2025 16:41:25 +0000 Received: by outflank-mailman (input) for mailman id 1096549; Wed, 27 Aug 2025 16:41:24 +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 1urJDA-0004w9-2a for xen-devel@lists.xenproject.org; Wed, 27 Aug 2025 16:41:24 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id aa9a75c2-8364-11f0-aeb2-fb57b961d000; Wed, 27 Aug 2025 18:41:23 +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 5D2F8152B; Wed, 27 Aug 2025 09:41:14 -0700 (PDT) Received: from PWQ0QT7DJ1.arm.com (unknown [10.57.64.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 857B53F738; Wed, 27 Aug 2025 09:41:20 -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: aa9a75c2-8364-11f0-aeb2-fb57b961d000 From: Hari Limaye To: xen-devel@lists.xenproject.org Cc: luca.fancellu@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Penny Zheng , Wei Chen Subject: [PATCH v2 5/5] xen/arm: map static memory on demand Date: Wed, 27 Aug 2025 17:35:13 +0100 Message-ID: <6408f218f3075acd43f5563bff26165091d9f184.1756312498.git.hari.limaye@arm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1756312897768116600 Content-Type: text/plain; charset="utf-8" From: Penny Zheng In the function `init_staticmem_pages` we need to have mapped static memory banks for initialization. Unlike on an MMU system, we cannot map the entire RAM on an MPU system as we have a limited number of MPU memory regions. To solve this, transiently map the static memory banks for initialization. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Luca Fancellu Signed-off-by: Hari Limaye Reviewed-by: Michal Orzel --- xen/arch/arm/include/asm/mmu/mm.h | 3 +++ xen/arch/arm/include/asm/mpu/mm.h | 4 ++++ xen/arch/arm/mpu/setup.c | 11 +++++++++++ xen/include/xen/static-memory.h | 8 ++++++++ 4 files changed, 26 insertions(+) diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/m= mu/mm.h index 7f4d59137d..645a0ea3cb 100644 --- a/xen/arch/arm/include/asm/mmu/mm.h +++ b/xen/arch/arm/include/asm/mmu/mm.h @@ -110,6 +110,9 @@ void dump_pt_walk(paddr_t ttbr, paddr_t addr, extern void switch_ttbr(uint64_t ttbr); extern void relocate_and_switch_ttbr(uint64_t ttbr); =20 +static inline void map_staticmem_pages_to_xen(paddr_t start, paddr_t end) = {} +static inline void unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end= ) {} + #endif /* __ARM_MMU_MM_H__ */ =20 /* diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/m= pu/mm.h index efb0680e39..4cc769418e 100644 --- a/xen/arch/arm/include/asm/mpu/mm.h +++ b/xen/arch/arm/include/asm/mpu/mm.h @@ -123,6 +123,10 @@ void *map_mm_range(paddr_t base, paddr_t limit, unsign= ed int flags); */ void unmap_mm_range(paddr_t base); =20 +/* {un}map_staticmem_pages_to_xen used while initializing static memory ba= nks */ +void map_staticmem_pages_to_xen(paddr_t start, paddr_t end); +void unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end); + /* * Checks whether a given memory range is present in the provided table of * MPU protection regions. diff --git a/xen/arch/arm/mpu/setup.c b/xen/arch/arm/mpu/setup.c index 163573b932..dbc3107333 100644 --- a/xen/arch/arm/mpu/setup.c +++ b/xen/arch/arm/mpu/setup.c @@ -83,6 +83,17 @@ void * __init early_fdt_map(paddr_t fdt_paddr) return fdt_virt; } =20 +void __init map_staticmem_pages_to_xen(paddr_t start, paddr_t end) +{ + if ( !map_mm_range(start, end, PAGE_HYPERVISOR) ) + panic("Unable to map staticmem pages to Xen!"); +} + +void __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) +{ + unmap_mm_range(start); +} + /* * copy_from_paddr - copy data from a physical address * @dst: destination virtual address diff --git a/xen/include/xen/static-memory.h b/xen/include/xen/static-memor= y.h index e445aa8057..d99abac113 100644 --- a/xen/include/xen/static-memory.h +++ b/xen/include/xen/static-memory.h @@ -18,7 +18,15 @@ static inline void init_staticmem_bank(const struct memb= ank *bank) if ( mfn_x(bank_end) <=3D mfn_x(bank_start) ) return; =20 + /* Map temporarily before initialization */ + map_staticmem_pages_to_xen(mfn_to_maddr(bank_start), + mfn_to_maddr(bank_end)); + unprepare_staticmem_pages(mfn_to_page(bank_start), bank_pages, false); + + /* Unmap immediately after initialization */ + unmap_staticmem_pages_to_xen(mfn_to_maddr(bank_start), + mfn_to_maddr(bank_end)); } =20 void allocate_static_memory(struct domain *d, struct kernel_info *kinfo, --=20 2.34.1