From nobody Thu Jan 30 06:07:47 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 1731667870121603.4611437778595; Fri, 15 Nov 2024 02:51:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.837072.1252987 (Exim 4.92) (envelope-from ) id 1tBtud-0000n4-QR; Fri, 15 Nov 2024 10:50:51 +0000 Received: by outflank-mailman (output) from mailman id 837072.1252987; Fri, 15 Nov 2024 10:50:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBtud-0000mR-LE; Fri, 15 Nov 2024 10:50:51 +0000 Received: by outflank-mailman (input) for mailman id 837072; Fri, 15 Nov 2024 10:50:51 +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 1tBtud-0000jy-1B for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 10:50:51 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 786ddaff-a33f-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 11:50:47 +0100 (CET) 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 A7CDF176A; Fri, 15 Nov 2024 02:51:16 -0800 (PST) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 013113F6A8; Fri, 15 Nov 2024 02:50:45 -0800 (PST) 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: 786ddaff-a33f-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6Ijc4NmRkYWZmLWEzM2YtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjY3ODQ3LjY1OTI1LCJzZW5kZXIiOiJsdWNhLmZhbmNlbGx1QGFybS5jb20iLCJyZWNpcGllbnQiOiJ4ZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcifQ== From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP Date: Fri, 15 Nov 2024 10:50:32 +0000 Message-Id: <20241115105036.218418-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241115105036.218418-1-luca.fancellu@arm.com> References: <20241115105036.218418-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1731667872085116600 Content-Type: text/plain; charset="utf-8" When HAS_VMAP is disabled, the xv{malloc,zalloc,...} functions should fall back to the simple x{malloc,zalloc,...} variant, implement that because MPU systems won't have virtual memory. Additionally remove VMAP_VIRT_START from vmap.h guards since MPU systems won't have it defined and move iounmap function to the vmap.c file, because it uses the vunmap function that won't be compiled in when !HAS_VMAP. Signed-off-by: Luca Fancellu --- This is a rework of this one: https://patchwork.kernel.org/project/xen-deve= l/patch/20230626033443.2943270-16-Penny.Zheng@arm.com/ where I hope I've understood correctly what Jan Beulich was suggesting here: https://patchwork.kernel.org/project/xen-devel/patch/20230626033443.2943270= -16-Penny.Zheng@arm.com/#25409119 --- xen/common/vmap.c | 7 +++++++ xen/include/xen/vmap.h | 9 ++------- xen/include/xen/xvmalloc.h | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/xen/common/vmap.c b/xen/common/vmap.c index 47225fecc067..294280dcd08c 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -426,3 +426,10 @@ void *_xvrealloc(void *va, size_t size, unsigned int a= lign) =20 return ptr; } + +void iounmap(void __iomem *va) +{ + unsigned long addr =3D (unsigned long)(void __force *)va; + + vunmap((void *)(addr & PAGE_MASK)); +} diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index c1dd7ac22f30..9e1d794c2548 100644 --- a/xen/include/xen/vmap.h +++ b/xen/include/xen/vmap.h @@ -5,7 +5,7 @@ * purpose area (VMAP_DEFAULT) and a livepatch-specific area (VMAP_XEN). T= he * latter is used when loading livepatches and the former for everything e= lse. */ -#if !defined(__XEN_VMAP_H__) && defined(VMAP_VIRT_START) +#if !defined(__XEN_VMAP_H__) #define __XEN_VMAP_H__ =20 #include @@ -128,12 +128,7 @@ void __iomem *ioremap(paddr_t pa, size_t len); unsigned int vmap_size(const void *va); =20 /* Analogous to vunmap(), but for IO memory mapped via ioremap() */ -static inline void iounmap(void __iomem *va) -{ - unsigned long addr =3D (unsigned long)(void __force *)va; - - vunmap((void *)(addr & PAGE_MASK)); -} +void iounmap(void __iomem *va); =20 /* Pointer to 1 octet past the end of the VMAP_DEFAULT virtual area */ void *arch_vmap_virt_end(void); diff --git a/xen/include/xen/xvmalloc.h b/xen/include/xen/xvmalloc.h index 440d85a284bb..802be6687085 100644 --- a/xen/include/xen/xvmalloc.h +++ b/xen/include/xen/xvmalloc.h @@ -40,20 +40,46 @@ ((typeof(ptr))_xvrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ __alignof__(typeof(*(ptr))))) =20 +#if defined(CONFIG_HAS_VMAP) + /* Free any of the above. */ void xvfree(void *va); =20 +/* Underlying functions */ +void *_xvmalloc(size_t size, unsigned int align); +void *_xvzalloc(size_t size, unsigned int align); +void *_xvrealloc(void *va, size_t size, unsigned int align); + +#else + +static inline void xvfree(void *va) +{ + xfree(va); +} + +void *_xvmalloc(size_t size, unsigned int align) +{ + return _xmalloc(size, align); +} + +void *_xvzalloc(size_t size, unsigned int align) +{ + return _xzalloc(size, align); +} + +void *_xvrealloc(void *va, size_t size, unsigned int align) +{ + return _xrealloc(va, size, align); +} + +#endif + /* Free an allocation, and zero the pointer to it. */ #define XVFREE(p) do { \ xvfree(p); \ (p) =3D NULL; \ } while ( false ) =20 -/* Underlying functions */ -void *_xvmalloc(size_t size, unsigned int align); -void *_xvzalloc(size_t size, unsigned int align); -void *_xvrealloc(void *va, size_t size, unsigned int align); - static inline void *_xvmalloc_array( size_t size, unsigned int align, unsigned long num) { --=20 2.34.1 From nobody Thu Jan 30 06:07:47 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 173166787769358.4588036908724; Fri, 15 Nov 2024 02:51:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.837073.1253002 (Exim 4.92) (envelope-from ) id 1tBtue-0001EC-US; Fri, 15 Nov 2024 10:50:52 +0000 Received: by outflank-mailman (output) from mailman id 837073.1253002; Fri, 15 Nov 2024 10:50:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBtue-0001E5-RU; Fri, 15 Nov 2024 10:50:52 +0000 Received: by outflank-mailman (input) for mailman id 837073; Fri, 15 Nov 2024 10:50:51 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBtud-0000kJ-R0 for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 10:50:51 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 79161f42-a33f-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 11:50:48 +0100 (CET) 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 BB8C21A00; Fri, 15 Nov 2024 02:51:17 -0800 (PST) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EED023F6A8; Fri, 15 Nov 2024 02:50:46 -0800 (PST) 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: 79161f42-a33f-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6Ijc5MTYxZjQyLWEzM2YtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjY3ODQ4LjU2ODY4NCwic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH 2/5] arm/setup: Move MMU specific extern declarations to mmu/mm.h Date: Fri, 15 Nov 2024 10:50:33 +0000 Message-Id: <20241115105036.218418-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241115105036.218418-1-luca.fancellu@arm.com> References: <20241115105036.218418-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1731667879886116600 Content-Type: text/plain; charset="utf-8" Move some extern declarations related to MMU structures and define from asm/setup.h to asm/mm.h, in order to increase encapsulation and allow the MPU part to build, since it has no clue about them. Signed-off-by: Luca Fancellu --- xen/arch/arm/include/asm/mmu/mm.h | 11 +++++++++++ xen/arch/arm/include/asm/setup.h | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/m= mu/mm.h index c5e03a66bf9e..69b72d671012 100644 --- a/xen/arch/arm/include/asm/mmu/mm.h +++ b/xen/arch/arm/include/asm/mmu/mm.h @@ -12,6 +12,17 @@ extern vaddr_t directmap_virt_start; extern unsigned long directmap_base_pdx; #endif =20 +extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES]; + +#ifdef CONFIG_ARM_64 +extern lpae_t boot_first[XEN_PT_LPAE_ENTRIES]; +extern lpae_t boot_first_id[XEN_PT_LPAE_ENTRIES]; +#endif +extern lpae_t boot_second[XEN_PT_LPAE_ENTRIES]; +extern lpae_t boot_second_id[XEN_PT_LPAE_ENTRIES]; +extern lpae_t boot_third[XEN_PT_LPAE_ENTRIES * XEN_NR_ENTRIES(2)]; +extern lpae_t boot_third_id[XEN_PT_LPAE_ENTRIES]; + #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) =20 /* diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 64c227d171fc..3f5c6cf9a08b 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -65,17 +65,6 @@ int map_irq_to_domain(struct domain *d, unsigned int irq, int map_range_to_domain(const struct dt_device_node *dev, uint64_t addr, uint64_t len, void *data); =20 -extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES]; - -#ifdef CONFIG_ARM_64 -extern lpae_t boot_first[XEN_PT_LPAE_ENTRIES]; -extern lpae_t boot_first_id[XEN_PT_LPAE_ENTRIES]; -#endif -extern lpae_t boot_second[XEN_PT_LPAE_ENTRIES]; -extern lpae_t boot_second_id[XEN_PT_LPAE_ENTRIES]; -extern lpae_t boot_third[XEN_PT_LPAE_ENTRIES * XEN_NR_ENTRIES(2)]; -extern lpae_t boot_third_id[XEN_PT_LPAE_ENTRIES]; - /* Find where Xen will be residing at runtime and return a PT entry */ lpae_t pte_of_xenaddr(vaddr_t va); =20 --=20 2.34.1 From nobody Thu Jan 30 06:07:47 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 1731667873027402.13466687996606; Fri, 15 Nov 2024 02:51:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.837074.1253007 (Exim 4.92) (envelope-from ) id 1tBtuf-0001H5-79; Fri, 15 Nov 2024 10:50:53 +0000 Received: by outflank-mailman (output) from mailman id 837074.1253007; Fri, 15 Nov 2024 10:50:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBtuf-0001GJ-2P; Fri, 15 Nov 2024 10:50:53 +0000 Received: by outflank-mailman (input) for mailman id 837074; Fri, 15 Nov 2024 10:50:52 +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 1tBtue-0000jy-1O for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 10:50:52 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 79cd26b4-a33f-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 11:50:49 +0100 (CET) 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 E99751A25; Fri, 15 Nov 2024 02:51:18 -0800 (PST) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0EB213F6A8; Fri, 15 Nov 2024 02:50:47 -0800 (PST) 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: 79cd26b4-a33f-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6Ijc5Y2QyNmI0LWEzM2YtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjY3ODQ5Ljc4MjA0Nywic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH 3/5] xen/arm: only map the init text section RW in free_init_memory Date: Fri, 15 Nov 2024 10:50:34 +0000 Message-Id: <20241115105036.218418-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241115105036.218418-1-luca.fancellu@arm.com> References: <20241115105036.218418-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1731667873943116600 Content-Type: text/plain; charset="utf-8" From: Penny Zheng In free_init_memory, we do not need to map the whole init section RW, as only init text section is mapped RO in boot time. Signed-off-by: Luca Fancellu --- This is this one: https://patchwork.kernel.org/project/xen-devel/patch/2023= 0626033443.2943270-19-Penny.Zheng@arm.com/ --- xen/arch/arm/mmu/setup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 9664e85ee6c0..1b1d302c8788 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include #include @@ -309,16 +310,17 @@ void *__init arch_vmap_virt_end(void) void free_init_memory(void) { paddr_t pa =3D virt_to_maddr(__init_begin); + unsigned long inittext_end =3D round_pgup((unsigned long)_einittext); unsigned long len =3D __init_end - __init_begin; uint32_t insn; unsigned int i, nr =3D len / sizeof(insn); uint32_t *p; int rc; =20 - rc =3D modify_xen_mappings((unsigned long)__init_begin, - (unsigned long)__init_end, PAGE_HYPERVISOR_RW= ); + rc =3D modify_xen_mappings((unsigned long)__init_begin, inittext_end, + PAGE_HYPERVISOR_RW); if ( rc ) - panic("Unable to map RW the init section (rc =3D %d)\n", rc); + panic("Unable to map RW the init text section (rc =3D %d)\n", rc); =20 /* * From now on, init will not be used for execution anymore, --=20 2.34.1 From nobody Thu Jan 30 06:07:47 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 1731667876338943.4756719590423; Fri, 15 Nov 2024 02:51:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.837075.1253022 (Exim 4.92) (envelope-from ) id 1tBtug-0001iN-GU; Fri, 15 Nov 2024 10:50:54 +0000 Received: by outflank-mailman (output) from mailman id 837075.1253022; Fri, 15 Nov 2024 10:50:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBtug-0001hz-CA; Fri, 15 Nov 2024 10:50:54 +0000 Received: by outflank-mailman (input) for mailman id 837075; Fri, 15 Nov 2024 10:50:53 +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 1tBtuf-0000jy-6x for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 10:50:53 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7a876618-a33f-11ef-a0c7-8be0dac302b0; Fri, 15 Nov 2024 11:50:50 +0100 (CET) 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 3F34E1A2D; Fri, 15 Nov 2024 02:51:20 -0800 (PST) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3E8143F6A8; Fri, 15 Nov 2024 02:50:49 -0800 (PST) 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: 7a876618-a33f-11ef-a0c7-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6IjdhODc2NjE4LWEzM2YtMTFlZi1hMGM3LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxNjY3ODUxLjE4MTYzNiwic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Ross Lagerwall Subject: [PATCH 4/5] xen/arm: Use vmap_contig instead of __vmap where it's possible Date: Fri, 15 Nov 2024 10:50:35 +0000 Message-Id: <20241115105036.218418-5-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241115105036.218418-1-luca.fancellu@arm.com> References: <20241115105036.218418-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1731667877816116600 Content-Type: text/plain; charset="utf-8" Currently the arm code uses __vmap function in few parts to map physically contiguous pages, vmap_contig was introduced recently and does the same because it's a wrapper for __vmap, so use the latter instead of the direct __vmap function. Signed-off-by: Luca Fancellu Acked-by: Julien Grall --- xen/arch/arm/alternative.c | 3 +-- xen/arch/arm/cpuerrata.c | 5 ++--- xen/arch/arm/kernel.c | 2 +- xen/arch/arm/livepatch.c | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index d99b5070937d..fec7dbd2cde9 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -209,8 +209,7 @@ void __init apply_alternatives_all(void) * The text and inittext section are read-only. So re-map Xen to * be able to patch the code. */ - xenmap =3D __vmap(&xen_mfn, 1U << xen_order, 1, 1, PAGE_HYPERVISOR, - VMAP_DEFAULT); + xenmap =3D vmap_contig(xen_mfn, 1U << xen_order); /* Re-mapping Xen is not expected to fail during boot. */ BUG_ON(!xenmap); =20 diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c index eef9c0ea0e21..17cf134f1b0d 100644 --- a/xen/arch/arm/cpuerrata.c +++ b/xen/arch/arm/cpuerrata.c @@ -61,9 +61,8 @@ static bool copy_hyp_vect_bpi(unsigned int slot, const ch= ar *hyp_vec_start, * Vectors are part of the text that are mapped read-only. So re-map * the vector table to be able to update vectors. */ - dst_remapped =3D __vmap(&dst_mfn, - 1UL << get_order_from_bytes(VECTOR_TABLE_SIZE), - 1, 1, PAGE_HYPERVISOR, VMAP_DEFAULT); + dst_remapped =3D vmap_contig(dst_mfn, + 1UL << get_order_from_bytes(VECTOR_TABLE_SI= ZE)); if ( !dst_remapped ) return false; =20 diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 669d143cee1b..293d7efaed9c 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -211,7 +211,7 @@ static __init int kernel_decompress(struct bootmodule *= mod, uint32_t offset) return -ENOMEM; } mfn =3D page_to_mfn(pages); - output =3D __vmap(&mfn, 1 << kernel_order_out, 1, 1, PAGE_HYPERVISOR, = VMAP_DEFAULT); + output =3D vmap_contig(mfn, 1 << kernel_order_out); =20 rc =3D perform_gunzip(output, input, size); clean_dcache_va_range(output, output_size); diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index 037746d9528d..3805b2974663 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -39,8 +39,7 @@ int arch_livepatch_quiesce(void) * The text section is read-only. So re-map Xen to be able to patch * the code. */ - vmap_of_xen_text =3D __vmap(&text_mfn, 1U << text_order, 1, 1, PAGE_HY= PERVISOR, - VMAP_DEFAULT); + vmap_of_xen_text =3D vmap_contig(text_mfn, 1U << text_order); =20 if ( !vmap_of_xen_text ) { --=20 2.34.1 From nobody Thu Jan 30 06:07:48 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 1731667883237617.3750701944361; Fri, 15 Nov 2024 02:51:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.837076.1253032 (Exim 4.92) (envelope-from ) id 1tBtui-00023g-TB; Fri, 15 Nov 2024 10:50:56 +0000 Received: by outflank-mailman (output) from mailman id 837076.1253032; Fri, 15 Nov 2024 10:50:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBtui-00023X-Pt; Fri, 15 Nov 2024 10:50:56 +0000 Received: by outflank-mailman (input) for mailman id 837076; Fri, 15 Nov 2024 10:50:55 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tBtuh-0000kJ-GY for xen-devel@lists.xenproject.org; Fri, 15 Nov 2024 10:50:55 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7b422713-a33f-11ef-99a3-01e77a169b0f; Fri, 15 Nov 2024 11:50:52 +0100 (CET) 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 6DBD61476; Fri, 15 Nov 2024 02:51:21 -0800 (PST) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 86DA23F6A8; Fri, 15 Nov 2024 02:50:50 -0800 (PST) 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: 7b422713-a33f-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6IjdiNDIyNzEzLWEzM2YtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxNjY3ODUyLjMzNzcwMywic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH 5/5] xen/arm: do not give memory back to static heap Date: Fri, 15 Nov 2024 10:50:36 +0000 Message-Id: <20241115105036.218418-6-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241115105036.218418-1-luca.fancellu@arm.com> References: <20241115105036.218418-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1731667883965116600 Content-Type: text/plain; charset="utf-8" From: Penny Zheng If Xenheap is statically configured in Device Tree, its size is definite. So, the memory shall not be given back into static heap, like it's normally done in free_init_memory, etc, once the initialization is finished. Extract static_heap flag from init data bootinfo, as it will be needed after destroying the init data section. Introduce a new helper xen_is_using_staticheap() to tell whether Xenheap is statically configured in the Device Tree. Signed-off-by: Luca Fancellu --- This is a rebase of this one: https://patchwork.kernel.org/project/xen-deve= l/patch/20230626033443.2943270-18-Penny.Zheng@arm.com/ --- xen/arch/arm/arm32/mmu/mm.c | 4 ++-- xen/arch/arm/kernel.c | 3 ++- xen/arch/arm/mmu/setup.c | 8 ++++++-- xen/arch/arm/setup.c | 27 ++++++++++++++------------- xen/common/device-tree/bootfdt.c | 2 +- xen/common/device-tree/bootinfo.c | 2 +- xen/common/device-tree/device-tree.c | 3 +++ xen/include/xen/bootfdt.h | 11 ++++++++++- 8 files changed, 39 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/arm32/mmu/mm.c b/xen/arch/arm/arm32/mmu/mm.c index 063611412be0..b7ca7c94c9ca 100644 --- a/xen/arch/arm/arm32/mmu/mm.c +++ b/xen/arch/arm/arm32/mmu/mm.c @@ -199,7 +199,7 @@ void __init setup_mm(void) =20 total_pages =3D ram_size >> PAGE_SHIFT; =20 - if ( bootinfo.static_heap ) + if ( xen_is_using_staticheap() ) { const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(= ); =20 @@ -246,7 +246,7 @@ void __init setup_mm(void) =20 do { - e =3D bootinfo.static_heap ? + e =3D xen_is_using_staticheap() ? fit_xenheap_in_static_heap(pfn_to_paddr(xenheap_pages), MB(32)= ) : consider_modules(ram_start, ram_end, pfn_to_paddr(xenheap_pages), diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 293d7efaed9c..a4a99607b668 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -247,7 +247,8 @@ static __init int kernel_decompress(struct bootmodule *= mod, uint32_t offset) * Free the original kernel, update the pointers to the * decompressed kernel */ - fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0); + if ( !xen_is_using_staticheap() ) + fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0); =20 return 0; } diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 1b1d302c8788..d0775793f4b4 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -343,8 +343,12 @@ void free_init_memory(void) if ( rc ) panic("Unable to remove the init section (rc =3D %d)\n", rc); =20 - init_domheap_pages(pa, pa + len); - printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>= 10); + if ( !xen_is_using_staticheap() ) + { + init_domheap_pages(pa, pa + len); + printk("Freed %ldkB init memory.\n", + (long)(__init_end-__init_begin) >> 10); + } } =20 /** diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 71ebaa77ca94..91340d5dc201 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -206,24 +206,25 @@ void __init discard_initial_modules(void) struct bootmodules *mi =3D &bootinfo.modules; int i; =20 - for ( i =3D 0; i < mi->nr_mods; i++ ) + if ( !xen_is_using_staticheap() ) { - paddr_t s =3D mi->module[i].start; - paddr_t e =3D s + PAGE_ALIGN(mi->module[i].size); - - if ( mi->module[i].kind =3D=3D BOOTMOD_XEN ) - continue; + for ( i =3D 0; i < mi->nr_mods; i++ ) + { + paddr_t s =3D mi->module[i].start; + paddr_t e =3D s + PAGE_ALIGN(mi->module[i].size); =20 - if ( !mfn_valid(maddr_to_mfn(s)) || - !mfn_valid(maddr_to_mfn(e)) ) - continue; + if ( mi->module[i].kind =3D=3D BOOTMOD_XEN ) + continue; =20 - fw_unreserved_regions(s, e, init_domheap_pages, 0); - } + if ( !mfn_valid(maddr_to_mfn(s)) || + !mfn_valid(maddr_to_mfn(e)) ) + continue; =20 - mi->nr_mods =3D 0; + fw_unreserved_regions(s, e, init_domheap_pages, 0); + } =20 - remove_early_mappings(); + mi->nr_mods =3D 0; + } } =20 /* Relocate the FDT in Xen heap */ diff --git a/xen/common/device-tree/bootfdt.c b/xen/common/device-tree/boot= fdt.c index 927f59c64b0d..ccb150b34a63 100644 --- a/xen/common/device-tree/bootfdt.c +++ b/xen/common/device-tree/bootfdt.c @@ -403,7 +403,7 @@ static int __init process_chosen_node(const void *fdt, = int node, if ( rc ) return rc; =20 - bootinfo.static_heap =3D true; + static_heap =3D true; } =20 printk("Checking for initrd in /chosen\n"); diff --git a/xen/common/device-tree/bootinfo.c b/xen/common/device-tree/boo= tinfo.c index f2e6a1145b7c..1e83d5172938 100644 --- a/xen/common/device-tree/bootinfo.c +++ b/xen/common/device-tree/bootinfo.c @@ -386,7 +386,7 @@ void __init populate_boot_allocator(void) const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); paddr_t s, e; =20 - if ( bootinfo.static_heap ) + if ( xen_is_using_staticheap() ) { for ( i =3D 0 ; i < reserved_mem->nr_banks; i++ ) { diff --git a/xen/common/device-tree/device-tree.c b/xen/common/device-tree/= device-tree.c index d0528c582565..22b69c49171b 100644 --- a/xen/common/device-tree/device-tree.c +++ b/xen/common/device-tree/device-tree.c @@ -25,6 +25,9 @@ #include #include =20 +/* Flag saved when Xen is using the static heap feature (xen,static-heap) = */ +bool __read_mostly static_heap; + const void *device_tree_flattened; dt_irq_xlate_func dt_irq_xlate; /* Host device tree */ diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index 16fa05f38f38..0015a4babde7 100644 --- a/xen/include/xen/bootfdt.h +++ b/xen/include/xen/bootfdt.h @@ -132,7 +132,6 @@ struct bootinfo { #ifdef CONFIG_STATIC_SHM struct shared_meminfo shmem; #endif - bool static_heap; }; =20 #ifdef CONFIG_ACPI @@ -156,6 +155,7 @@ struct bootinfo { } =20 extern struct bootinfo bootinfo; +extern bool static_heap; =20 bool check_reserved_regions_overlap(paddr_t region_start, paddr_t region_size); @@ -206,4 +206,13 @@ static inline struct shmem_membank_extra *bootinfo_get= _shmem_extra(void) } #endif =20 +static inline bool xen_is_using_staticheap(void) +{ +#ifdef CONFIG_STATIC_MEMORY + return static_heap; +#else + return false; +#endif +} + #endif /* XEN_BOOTFDT_H */ --=20 2.34.1