From nobody Thu Dec 26 10:59: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; 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 1732871644015191.42018836185616; Fri, 29 Nov 2024 01:14:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.845798.1261139 (Exim 4.92) (envelope-from ) id 1tGx4M-0004xc-Go; Fri, 29 Nov 2024 09:13:46 +0000 Received: by outflank-mailman (output) from mailman id 845798.1261139; Fri, 29 Nov 2024 09:13: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 1tGx4M-0004vn-Ar; Fri, 29 Nov 2024 09:13:46 +0000 Received: by outflank-mailman (input) for mailman id 845798; Fri, 29 Nov 2024 09:13:45 +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 1tGx4L-0004rr-88 for xen-devel@lists.xenproject.org; Fri, 29 Nov 2024 09:13:45 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 39e0a437-ae32-11ef-a0cf-8be0dac302b0; Fri, 29 Nov 2024 10:13:41 +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 A8D611424; Fri, 29 Nov 2024 01:14:10 -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 625203F58B; Fri, 29 Nov 2024 01:13:40 -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: 39e0a437-ae32-11ef-a0cf-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6IjM5ZTBhNDM3LWFlMzItMTFlZi1hMGNmLThiZTBkYWMzMDJiMCIsInRzIjoxNzMyODcxNjIxLjg2OTYzMSwic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v3 1/5] common/vmap: Fall back to simple allocator when !HAS_VMAP Date: Fri, 29 Nov 2024 09:12:33 +0000 Message-Id: <20241129091237.3409304-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241129091237.3409304-1-luca.fancellu@arm.com> References: <20241129091237.3409304-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1732871646213019100 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. Signed-off-by: Luca Fancellu --- Changes from v2: - Don't protect declarations. Changes from v1: - put back static inline iounmap - changed commit message - hide not used declaration for system with !HAS_VMAP - correct function declared in xvmalloc.h to be static inline - prefer '#ifdef' instead of '#if defined' where possible --- --- xen/include/xen/vmap.h | 2 +- xen/include/xen/xvmalloc.h | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index c1dd7ac22f30..26c831757a11 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) +#ifndef __XEN_VMAP_H__ #define __XEN_VMAP_H__ =20 #include diff --git a/xen/include/xen/xvmalloc.h b/xen/include/xen/xvmalloc.h index 440d85a284bb..e97a30f61e96 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 +#ifdef 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 /* !CONFIG_HAS_VMAP */ + +static inline void xvfree(void *va) +{ + xfree(va); +} + +static inline void *_xvmalloc(size_t size, unsigned int align) +{ + return _xmalloc(size, align); +} + +static inline void *_xvzalloc(size_t size, unsigned int align) +{ + return _xzalloc(size, align); +} + +static inline void *_xvrealloc(void *va, size_t size, unsigned int align) +{ + return _xrealloc(va, size, align); +} + +#endif /* CONFIG_HAS_VMAP */ + /* 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 Dec 26 10:59: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; 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 1732871640592241.50905073575086; Fri, 29 Nov 2024 01:14:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.845799.1261152 (Exim 4.92) (envelope-from ) id 1tGx4N-0005L7-MD; Fri, 29 Nov 2024 09:13:47 +0000 Received: by outflank-mailman (output) from mailman id 845799.1261152; Fri, 29 Nov 2024 09:13: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 1tGx4N-0005Kv-Ii; Fri, 29 Nov 2024 09:13:47 +0000 Received: by outflank-mailman (input) for mailman id 845799; Fri, 29 Nov 2024 09:13:46 +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 1tGx4M-0004tF-Em for xen-devel@lists.xenproject.org; Fri, 29 Nov 2024 09:13:46 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 3a86a8ad-ae32-11ef-99a3-01e77a169b0f; Fri, 29 Nov 2024 10:13:42 +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 B97601C00; Fri, 29 Nov 2024 01:14:11 -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 5AD073F58B; Fri, 29 Nov 2024 01:13:41 -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: 3a86a8ad-ae32-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6IjNhODZhOGFkLWFlMzItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyODcxNjIzLjE0NjE5Niwic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 2/5] arm/setup: Move MMU specific extern declarations to mmu/setup.h Date: Fri, 29 Nov 2024 09:12:34 +0000 Message-Id: <20241129091237.3409304-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241129091237.3409304-1-luca.fancellu@arm.com> References: <20241129091237.3409304-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1732871642131019100 Content-Type: text/plain; charset="utf-8" Move some extern declarations related to MMU structures and define from asm/setup.h to asm/mmu/setup.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 Acked-by: Julien Grall --- Changes from v2: - No changes Changes from v1: - Moved extern to mmu/setup.h instead of mmu/mm.h - moved also pte_of_xenaddr() --- --- xen/arch/arm/include/asm/mmu/setup.h | 31 ++++++++++++++++++++++++++++ xen/arch/arm/include/asm/setup.h | 20 ++++++------------ 2 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 xen/arch/arm/include/asm/mmu/setup.h diff --git a/xen/arch/arm/include/asm/mmu/setup.h b/xen/arch/arm/include/as= m/mmu/setup.h new file mode 100644 index 000000000000..3fe752b04c63 --- /dev/null +++ b/xen/arch/arm/include/asm/mmu/setup.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __ARM_MMU_SETUP_H__ +#define __ARM_MMU_SETUP_H__ + +#include +#include + +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); + +#endif /* __ARM_MMU_SETUP_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 64c227d171fc..a5a80d9b477f 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -6,6 +6,12 @@ #include #include =20 +#if defined(CONFIG_MMU) +# include +#elif !defined(CONFIG_MPU) +# error "Unknown memory management layout" +#endif + #define MAX_FDT_SIZE SZ_2M =20 struct map_range_data @@ -65,20 +71,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); - extern const char __ro_after_init_start[], __ro_after_init_end[]; =20 struct init_info --=20 2.34.1 From nobody Thu Dec 26 10:59: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; 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 1732871644319778.9226233270227; Fri, 29 Nov 2024 01:14:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.845800.1261162 (Exim 4.92) (envelope-from ) id 1tGx4O-0005aU-UT; Fri, 29 Nov 2024 09:13:48 +0000 Received: by outflank-mailman (output) from mailman id 845800.1261162; Fri, 29 Nov 2024 09:13:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGx4O-0005aJ-Pn; Fri, 29 Nov 2024 09:13:48 +0000 Received: by outflank-mailman (input) for mailman id 845800; Fri, 29 Nov 2024 09:13:47 +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 1tGx4N-0004tF-Ff for xen-devel@lists.xenproject.org; Fri, 29 Nov 2024 09:13:47 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 3b5ece71-ae32-11ef-99a3-01e77a169b0f; Fri, 29 Nov 2024 10:13:44 +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 26F0A1C01; Fri, 29 Nov 2024 01:14:13 -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 6E26C3F58B; Fri, 29 Nov 2024 01:13:42 -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: 3b5ece71-ae32-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6IjNiNWVjZTcxLWFlMzItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyODcxNjI0LjUxNDM2Nywic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= 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 , Julien Grall Subject: [PATCH v3 3/5] xen/arm: Use vmap_contig instead of __vmap where it's possible Date: Fri, 29 Nov 2024 09:12:35 +0000 Message-Id: <20241129091237.3409304-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241129091237.3409304-1-luca.fancellu@arm.com> References: <20241129091237.3409304-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1732871646197019100 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 Acked-by: Roger Pau Monn=C3=A9 --- Changes from v2: - Add ack-by Roger Changes from v1: - Add ack-by Julien --- --- 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 Dec 26 10:59: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; 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 17328716443261016.569156136658; Fri, 29 Nov 2024 01:14:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.845801.1261172 (Exim 4.92) (envelope-from ) id 1tGx4Q-0005rb-7E; Fri, 29 Nov 2024 09:13:50 +0000 Received: by outflank-mailman (output) from mailman id 845801.1261172; Fri, 29 Nov 2024 09:13:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGx4Q-0005r0-1d; Fri, 29 Nov 2024 09:13:50 +0000 Received: by outflank-mailman (input) for mailman id 845801; Fri, 29 Nov 2024 09:13:48 +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 1tGx4O-0004rr-EO for xen-devel@lists.xenproject.org; Fri, 29 Nov 2024 09:13:48 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 3c4ba90b-ae32-11ef-a0cf-8be0dac302b0; Fri, 29 Nov 2024 10:13:45 +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 BCCF112FC; Fri, 29 Nov 2024 01:14:14 -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 CFF783F58B; Fri, 29 Nov 2024 01:13:43 -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: 3c4ba90b-ae32-11ef-a0cf-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6IjNjNGJhOTBiLWFlMzItMTFlZi1hMGNmLThiZTBkYWMzMDJiMCIsInRzIjoxNzMyODcxNjI2LjA2ODgzMSwic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Jan Beulich , Penny Zheng , Wei Chen Subject: [PATCH v3 4/5] xen/arm: Check for Static Heap feature when freeing resources Date: Fri, 29 Nov 2024 09:12:36 +0000 Message-Id: <20241129091237.3409304-5-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241129091237.3409304-1-luca.fancellu@arm.com> References: <20241129091237.3409304-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1732871646317019100 Content-Type: text/plain; charset="utf-8" From: Penny Zheng If the Xen heap is statically configured in Device Tree, its size is definite, so only the defined memory shall be given to the boot allocator. Have a check where init_domheap_pages() is called which takes into account if static heap feature is used. Extract static_heap flag from init data bootinfo, as it will be needed after destroying the init data section. Introduce a new helper using_static_heap() to tell whether Xen Heap is statically configured in the Device Tree. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Luca Fancellu --- Changes from v2: - Change xen_is_using_staticheap() to using_static_heap() - Move declaration of static_heap and using_static_heap() to xen/mm.h - Reprased first part of the commit message and title Changes from v1: - moved static_heap to common/page_alloc.c - protect static_heap access with CONFIG_STATIC_MEMORY - update comment in arm/kernel.c kernel_decompress() --- --- xen/arch/arm/arm32/mmu/mm.c | 4 ++-- xen/arch/arm/kernel.c | 7 ++++--- xen/arch/arm/mmu/setup.c | 8 ++++++-- xen/arch/arm/setup.c | 27 ++++++++++++++------------- xen/common/device-tree/bootfdt.c | 4 +++- xen/common/device-tree/bootinfo.c | 2 +- xen/common/page_alloc.c | 5 +++++ xen/include/xen/bootfdt.h | 1 - xen/include/xen/mm.h | 13 +++++++++++++ 9 files changed, 48 insertions(+), 23 deletions(-) diff --git a/xen/arch/arm/arm32/mmu/mm.c b/xen/arch/arm/arm32/mmu/mm.c index 063611412be0..905565e1b528 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 ( using_static_heap() ) { 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 using_static_heap() ? 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..5dc367951113 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -244,10 +244,11 @@ static __init int kernel_decompress(struct bootmodule= *mod, uint32_t offset) size +=3D offset; =20 /* - * Free the original kernel, update the pointers to the - * decompressed kernel + * In case Xen is not using the static heap feature, free the original + * kernel, update the pointers to the decompressed kernel */ - fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0); + if ( !using_static_heap() ) + 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 9664e85ee6c0..36d0efd16c29 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -341,8 +341,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 ( !using_static_heap() ) + { + 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..46689d13072e 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 ( !using_static_heap() ) { - 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 480644b4b421..4ba283de2da9 100644 --- a/xen/common/device-tree/bootfdt.c +++ b/xen/common/device-tree/bootfdt.c @@ -403,7 +403,9 @@ static int __init process_chosen_node(const void *fdt, = int node, if ( rc ) return rc; =20 - bootinfo.static_heap =3D true; +#ifdef CONFIG_STATIC_MEMORY + static_heap =3D true; +#endif } =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 3738eb57ff52..04cd90d2ab4b 100644 --- a/xen/common/device-tree/bootinfo.c +++ b/xen/common/device-tree/bootinfo.c @@ -388,7 +388,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 ( using_static_heap() ) { for ( i =3D 0 ; i < reserved_mem->nr_banks; i++ ) { diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 92abed6514b4..e614984a129b 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -165,6 +165,11 @@ #define PGT_TYPE_INFO_INITIALIZER 0 #endif =20 +#ifdef CONFIG_STATIC_MEMORY +/* Flag saved when Xen is using the static heap feature (xen,static-heap) = */ +bool __ro_after_init static_heap; +#endif + unsigned long __read_mostly max_page; unsigned long __read_mostly total_pages; paddr_t __ro_after_init mem_hotplug; diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index 16fa05f38f38..ba24bf8fd574 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 diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index d7dcf0f06330..65ce6818ba2a 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -72,6 +72,19 @@ =20 struct page_info; =20 +#ifdef CONFIG_STATIC_MEMORY +extern bool static_heap; +#endif + +static inline bool using_static_heap(void) +{ +#ifdef CONFIG_STATIC_MEMORY + return static_heap; +#else + return false; +#endif +} + void put_page(struct page_info *page); bool __must_check get_page(struct page_info *page, const struct domain *domain); --=20 2.34.1 From nobody Thu Dec 26 10:59: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; 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 173287164821620.822980662788154; Fri, 29 Nov 2024 01:14:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.845803.1261182 (Exim 4.92) (envelope-from ) id 1tGx4S-0006A9-DQ; Fri, 29 Nov 2024 09:13:52 +0000 Received: by outflank-mailman (output) from mailman id 845803.1261182; Fri, 29 Nov 2024 09:13: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 1tGx4S-00069y-AI; Fri, 29 Nov 2024 09:13:52 +0000 Received: by outflank-mailman (input) for mailman id 845803; Fri, 29 Nov 2024 09:13:50 +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 1tGx4Q-0004tF-8g for xen-devel@lists.xenproject.org; Fri, 29 Nov 2024 09:13:50 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 3cf176b8-ae32-11ef-99a3-01e77a169b0f; Fri, 29 Nov 2024 10:13:46 +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 CFAF41424; Fri, 29 Nov 2024 01:14:15 -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 70AE93F58B; Fri, 29 Nov 2024 01:13: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: 3cf176b8-ae32-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6IjNjZjE3NmI4LWFlMzItMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMyODcxNjI3LjEzMjUwMywic2VuZGVyIjoibHVjYS5mYW5jZWxsdUBhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 5/5] xen/arm: Move setup_frametable_mappings to arm/mmu Date: Fri, 29 Nov 2024 09:12:37 +0000 Message-Id: <20241129091237.3409304-6-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241129091237.3409304-1-luca.fancellu@arm.com> References: <20241129091237.3409304-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1732871650319019100 Content-Type: text/plain; charset="utf-8" Move the current setup_frametable_mappings implementation to arm/mmu under a new file mm.c, this implementation depends on virtual memory and won't be used as it is for MPU systems. Take the occasion to fix code style issues related to the line length. Moved also frametable_virt_end since it is used only on MMU systems. Signed-off-by: Luca Fancellu --- Changes to v2: - New patch --- --- xen/arch/arm/mm.c | 40 ------------------------- xen/arch/arm/mmu/Makefile | 1 + xen/arch/arm/mmu/mm.c | 61 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 40 deletions(-) create mode 100644 xen/arch/arm/mmu/mm.c diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index def939172cc5..a56e20ba2bdc 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -22,7 +22,6 @@ #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) =20 unsigned long frametable_base_pdx __read_mostly; -unsigned long frametable_virt_end __read_mostly; =20 void flush_page_to_ram(unsigned long mfn, bool sync_icache) { @@ -43,45 +42,6 @@ void flush_page_to_ram(unsigned long mfn, bool sync_icac= he) invalidate_icache(); } =20 -/* Map a frame table to cover physical addresses ps through pe */ -void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) -{ - unsigned long nr_pdxs =3D mfn_to_pdx(mfn_add(maddr_to_mfn(pe), -1)) - - mfn_to_pdx(maddr_to_mfn(ps)) + 1; - 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); - int rc; - - /* - * The size of paddr_t should be sufficient for the complete range of - * physical address. - */ - BUILD_BUG_ON((sizeof(paddr_t) * BITS_PER_BYTE) < PADDR_BITS); - BUILD_BUG_ON(sizeof(struct page_info) !=3D PAGE_INFO_SIZE); - - if ( frametable_size > FRAMETABLE_SIZE ) - panic("The frametable cannot cover the physical region %#"PRIpaddr= " - %#"PRIpaddr"\n", - ps, pe); - - 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)); - - 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"); - - memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); - memset(&frame_table[nr_pdxs], -1, - frametable_size - (nr_pdxs * sizeof(struct page_info))); - - frametable_virt_end =3D FRAMETABLE_VIRT_START + (nr_pdxs * sizeof(stru= ct page_info)); -} - int steal_page( struct domain *d, struct page_info *page, unsigned int memflags) { diff --git a/xen/arch/arm/mmu/Makefile b/xen/arch/arm/mmu/Makefile index 2cb44b857dd2..1c89602947de 100644 --- a/xen/arch/arm/mmu/Makefile +++ b/xen/arch/arm/mmu/Makefile @@ -1,3 +1,4 @@ +obj-y +=3D mm.o obj-y +=3D p2m.o obj-y +=3D pt.o obj-y +=3D setup.o diff --git a/xen/arch/arm/mmu/mm.c b/xen/arch/arm/mmu/mm.c new file mode 100644 index 000000000000..aefec908b7f2 --- /dev/null +++ b/xen/arch/arm/mmu/mm.c @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include +#include +#include +#include + +unsigned long frametable_virt_end __read_mostly; + +/* Map a frame table to cover physical addresses ps through pe */ +void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) +{ + unsigned long nr_pdxs =3D mfn_to_pdx(mfn_add(maddr_to_mfn(pe), -1)) - + mfn_to_pdx(maddr_to_mfn(ps)) + 1; + 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); + int rc; + + /* + * The size of paddr_t should be sufficient for the complete range of + * physical address. + */ + BUILD_BUG_ON((sizeof(paddr_t) * BITS_PER_BYTE) < PADDR_BITS); + BUILD_BUG_ON(sizeof(struct page_info) !=3D PAGE_INFO_SIZE); + + if ( frametable_size > FRAMETABLE_SIZE ) + panic("The frametable cannot cover the physical region %#"PRIpaddr= " - %#"PRIpaddr"\n", + ps, pe); + + 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)); + + 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"); + + memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); + memset(&frame_table[nr_pdxs], -1, + frametable_size - (nr_pdxs * sizeof(struct page_info))); + + frametable_virt_end =3D FRAMETABLE_VIRT_START + (nr_pdxs * + sizeof(struct page_info= )); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.34.1