From nobody Fri May 17 04:59:56 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 1713425837956251.16505141548953; Thu, 18 Apr 2024 00:37:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708011.1106535 (Exim 4.92) (envelope-from ) id 1rxMKR-0004LE-8U; Thu, 18 Apr 2024 07:37:07 +0000 Received: by outflank-mailman (output) from mailman id 708011.1106535; Thu, 18 Apr 2024 07:37:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKR-0004L7-59; Thu, 18 Apr 2024 07:37:07 +0000 Received: by outflank-mailman (input) for mailman id 708011; Thu, 18 Apr 2024 07:37:06 +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 1rxMKP-00046V-Td for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:05 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 72b1bec8-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:03 +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 BA219DA7; Thu, 18 Apr 2024 00:37:30 -0700 (PDT) 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 CCE7B3F64C; Thu, 18 Apr 2024 00:37:01 -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: 72b1bec8-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v3 01/12] xen/arm: remove stale addr_cells/size_cells in assign_shared_memory Date: Thu, 18 Apr 2024 08:36:41 +0100 Message-Id: <20240418073652.3622828-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425839687100001 Content-Type: text/plain; charset="utf-8" From: Penny Zheng Function parameters {addr_cells,size_cells} are stale parameters in assign_shared_memory, so we shall remove them. Signed-off-by: Penny Zheng Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v2: - no change v1: - This is this patch: https://patchwork.kernel.org/project/xen-devel/patch= /20231206090623.1932275-2-Penny.Zheng@arm.com/ --- --- xen/arch/arm/static-shmem.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 9097bc8b1511..cb268cd2edf1 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -90,7 +90,6 @@ static mfn_t __init acquire_shared_memory_bank(struct dom= ain *d, } =20 static int __init assign_shared_memory(struct domain *d, - uint32_t addr_cells, uint32_t size_= cells, paddr_t pbase, paddr_t psize, paddr_t gbase) { @@ -252,7 +251,6 @@ int __init process_shm(struct domain *d, struct kernel_= info *kinfo, * specified, so they should be assigned to dom_io. */ ret =3D assign_shared_memory(owner_dom_io ? dom_io : d, - addr_cells, size_cells, pbase, psize, gbase); if ( ret ) return ret; --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425849370855.5419467438005; Thu, 18 Apr 2024 00:37:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708012.1106545 (Exim 4.92) (envelope-from ) id 1rxMKS-0004al-EK; Thu, 18 Apr 2024 07:37:08 +0000 Received: by outflank-mailman (output) from mailman id 708012.1106545; Thu, 18 Apr 2024 07:37:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKS-0004aa-B6; Thu, 18 Apr 2024 07:37:08 +0000 Received: by outflank-mailman (input) for mailman id 708012; Thu, 18 Apr 2024 07:37:07 +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 1rxMKR-00046V-2u for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:07 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 73a43654-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:04 +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 4CC021576; Thu, 18 Apr 2024 00:37:32 -0700 (PDT) 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 5F1313F64C; Thu, 18 Apr 2024 00:37:03 -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: 73a43654-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v3 02/12] xen/arm: avoid repetitive checking in process_shm_node Date: Thu, 18 Apr 2024 08:36:42 +0100 Message-Id: <20240418073652.3622828-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425849672100001 Content-Type: text/plain; charset="utf-8" From: Penny Zheng Putting overlap and overflow checking in the loop is causing repetitive operation, so this commit extracts both checking outside the loop. Signed-off-by: Penny Zheng Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v2: - add Michal R-by v1: - Rework of https://patchwork.kernel.org/project/xen-devel/patch/202312060= 90623.1932275-3-Penny.Zheng@arm.com/ - use strncmp to match the branch above - drop Michal R-by given the change --- --- xen/arch/arm/static-shmem.c | 39 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index cb268cd2edf1..40a0e860c79d 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -349,7 +349,7 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, { const struct fdt_property *prop, *prop_id, *prop_role; const __be32 *cell; - paddr_t paddr, gaddr, size; + paddr_t paddr, gaddr, size, end; struct meminfo *mem =3D &bootinfo.reserved_mem; unsigned int i; int len; @@ -422,6 +422,13 @@ int __init process_shm_node(const void *fdt, int node,= uint32_t address_cells, return -EINVAL; } =20 + end =3D paddr + size; + if ( end <=3D paddr ) + { + printk("fdt: static shared memory region %s overflow\n", shm_id); + return -EINVAL; + } + for ( i =3D 0; i < mem->nr_banks; i++ ) { /* @@ -441,30 +448,13 @@ int __init process_shm_node(const void *fdt, int node= , uint32_t address_cells, return -EINVAL; } } + else if ( strncmp(shm_id, mem->bank[i].shm_id, MAX_SHM_ID_LENGTH) = !=3D 0 ) + continue; else { - paddr_t end =3D paddr + size; - paddr_t bank_end =3D mem->bank[i].start + mem->bank[i].size; - - if ( (end <=3D paddr) || (bank_end <=3D mem->bank[i].start) ) - { - printk("fdt: static shared memory region %s overflow\n", s= hm_id); - return -EINVAL; - } - - if ( check_reserved_regions_overlap(paddr, size) ) - return -EINVAL; - else - { - if ( strcmp(shm_id, mem->bank[i].shm_id) !=3D 0 ) - continue; - else - { - printk("fdt: different shared memory region could not = share the same shm ID %s\n", - shm_id); - return -EINVAL; - } - } + printk("fdt: different shared memory region could not share th= e same shm ID %s\n", + shm_id); + return -EINVAL; } } =20 @@ -472,6 +462,9 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, { if ( i < NR_MEM_BANKS ) { + if ( check_reserved_regions_overlap(paddr, size) ) + return -EINVAL; + /* Static shared memory shall be reserved from any other use. = */ safe_strcpy(mem->bank[mem->nr_banks].shm_id, shm_id); mem->bank[mem->nr_banks].start =3D paddr; --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425847589312.8768909167926; Thu, 18 Apr 2024 00:37:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708013.1106555 (Exim 4.92) (envelope-from ) id 1rxMKT-0004qw-Rt; Thu, 18 Apr 2024 07:37:09 +0000 Received: by outflank-mailman (output) from mailman id 708013.1106555; Thu, 18 Apr 2024 07:37:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKT-0004qi-Ox; Thu, 18 Apr 2024 07:37:09 +0000 Received: by outflank-mailman (input) for mailman id 708013; Thu, 18 Apr 2024 07:37:08 +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 1rxMKS-00046V-E9 for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:08 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 74634cd5-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:05 +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 93C08339; Thu, 18 Apr 2024 00:37:33 -0700 (PDT) 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 E51DC3F64C; Thu, 18 Apr 2024 00:37:04 -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: 74634cd5-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 03/12] xen/arm: Pass struct kernel_info parameter to make_{resv,shm}_memory_node Date: Thu, 18 Apr 2024 08:36:43 +0100 Message-Id: <20240418073652.3622828-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425849679100002 Content-Type: text/plain; charset="utf-8" The struct domain parameter is not used in make_resv_memory_node and in its called function make_shm_memory_node, so drop it from both functions, also, take the occasion to pass directly struct kernel_info, from which we can infer other parameters passed to the functions and drop them as well. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3: - Fix commit title/msg, add Michal R-by v2: - new patch --- --- xen/arch/arm/dom0less-build.c | 3 +-- xen/arch/arm/domain_build.c | 3 +-- xen/arch/arm/include/asm/static-shmem.h | 9 ++++----- xen/arch/arm/static-shmem.c | 16 +++++++++------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index fb63ec6fd111..0edc5357caef 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -645,8 +645,7 @@ static int __init prepare_dtb_domU(struct domain *d, st= ruct kernel_info *kinfo) if ( ret ) goto err; =20 - ret =3D make_resv_memory_node(d, kinfo->fdt, addrcells, sizecells, - &kinfo->shm_mem); + ret =3D make_resv_memory_node(kinfo, addrcells, sizecells); if ( ret ) goto err; =20 diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 54232ed4cb9d..11d4e7d0b1ea 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1769,8 +1769,7 @@ static int __init handle_node(struct domain *d, struc= t kernel_info *kinfo, return res; } =20 - res =3D make_resv_memory_node(d, kinfo->fdt, addrcells, sizecells, - &kinfo->shm_mem); + res =3D make_resv_memory_node(kinfo, addrcells, sizecells); if ( res ) return res; } diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include= /asm/static-shmem.h index 1536ff18b895..680594b6843d 100644 --- a/xen/arch/arm/include/asm/static-shmem.h +++ b/xen/arch/arm/include/asm/static-shmem.h @@ -7,8 +7,8 @@ =20 #ifdef CONFIG_STATIC_SHM =20 -int make_resv_memory_node(const struct domain *d, void *fdt, int addrcells, - int sizecells, const struct meminfo *mem); +int make_resv_memory_node(const struct kernel_info *kinfo, int addrcells, + int sizecells); =20 int process_shm(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node); @@ -26,9 +26,8 @@ int process_shm_node(const void *fdt, int node, uint32_t = address_cells, =20 #else /* !CONFIG_STATIC_SHM */ =20 -static inline int make_resv_memory_node(const struct domain *d, void *fdt, - int addrcells, int sizecells, - const struct meminfo *mem) +static inline int make_resv_memory_node(const struct kernel_info *kinfo, + int addrcells, int sizecells) { return 0; } diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 40a0e860c79d..349b85667684 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -277,10 +277,11 @@ int __init process_shm(struct domain *d, struct kerne= l_info *kinfo, return 0; } =20 -static int __init make_shm_memory_node(const struct domain *d, void *fdt, - int addrcells, int sizecells, - const struct meminfo *mem) +static int __init make_shm_memory_node(const struct kernel_info *kinfo, + int addrcells, int sizecells) { + const struct meminfo *mem =3D &kinfo->shm_mem; + void *fdt =3D kinfo->fdt; unsigned int i =3D 0; int res =3D 0; =20 @@ -488,10 +489,11 @@ int __init process_shm_node(const void *fdt, int node= , uint32_t address_cells, return 0; } =20 -int __init make_resv_memory_node(const struct domain *d, void *fdt, - int addrcells, int sizecells, - const struct meminfo *mem) +int __init make_resv_memory_node(const struct kernel_info *kinfo, int addr= cells, + int sizecells) { + const struct meminfo *mem =3D &kinfo->shm_mem; + void *fdt =3D kinfo->fdt; int res =3D 0; /* Placeholder for reserved-memory\0 */ const char resvbuf[16] =3D "reserved-memory"; @@ -518,7 +520,7 @@ int __init make_resv_memory_node(const struct domain *d= , void *fdt, if ( res ) return res; =20 - res =3D make_shm_memory_node(d, fdt, addrcells, sizecells, mem); + res =3D make_shm_memory_node(kinfo, addrcells, sizecells); if ( res ) return res; =20 --=20 2.34.1 From nobody Fri May 17 04:59:56 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 171342586112148.471680418955316; Thu, 18 Apr 2024 00:37:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708016.1106585 (Exim 4.92) (envelope-from ) id 1rxMKX-0005cl-Tx; Thu, 18 Apr 2024 07:37:13 +0000 Received: by outflank-mailman (output) from mailman id 708016.1106585; Thu, 18 Apr 2024 07:37:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKX-0005cM-LX; Thu, 18 Apr 2024 07:37:13 +0000 Received: by outflank-mailman (input) for mailman id 708016; Thu, 18 Apr 2024 07:37:11 +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 1rxMKV-00046V-K2 for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:11 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 753bb806-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:07 +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 283FDDA7; Thu, 18 Apr 2024 00:37:35 -0700 (PDT) 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 3ABA03F64C; Thu, 18 Apr 2024 00:37:06 -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: 753bb806-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 04/12] xen/arm: Introduce a generic way to access memory bank structures Date: Thu, 18 Apr 2024 08:36:44 +0100 Message-Id: <20240418073652.3622828-5-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425861749100009 Content-Type: text/plain; charset="utf-8" Currently the 'struct meminfo' is defining a static defined array of 'struct membank' of NR_MEM_BANKS elements, some features like shared memory don't require such amount of memory allocation but might want to reuse existing code to manipulate this kind of structure that is just as 'struct meminfo' but less bulky. For this reason introduce a generic way to access this kind of structure using a new structure 'struct membanks', which implements all the fields needed by a structure related to memory banks without the need to specify at build time the size of the 'struct membank' array, using a flexible array member. Modify 'struct meminfo' to implement the field related to the new introduced structure, given the change all usage of this structure are updated in this way: - code accessing bootinfo.{mem,reserved_mem,acpi} field now uses 3 new introduced static inline helpers to access the new field of 'struct meminfo' named 'common'. - code accessing 'struct kernel_info *' member 'mem' now use the new introduced macro 'kernel_info_get_mem(...)' to access the new field of 'struct meminfo' named 'common'. - introduced KERNEL_INFO_INIT and BOOTINFO_INIT that from now on will be used to initialize 'struct kernel_info' and 'struct bootinfo' respectively, in order to initialize their 'struct meminfo' .common.max_banks members. Constify pointers where needed. Suggested-by: Julien Grall Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3: - mention KERNEL_INFO_INIT and BOOTINFO_INIT in the commit msg, back to the macro for struct kernel_info as in v1 because the static inline solution needed two different static inline to handle 'struct kernel_info *kinfo' and 'const struct kernel_info *kinfo'. - add Michal R-by v2: - Fixed typos in commit message and mention flexible array member - Add static assert for struct membanks - use static inline for the kernel_info structure instead of macro - use xzalloc_flex_struct inside make_hypervisor_node instead of xzalloc - Fix trailing backslash style v1: - new patch --- --- xen/arch/arm/acpi/domain_build.c | 6 +- xen/arch/arm/arm32/mmu/mm.c | 44 +++++----- xen/arch/arm/arm64/mmu/mm.c | 2 +- xen/arch/arm/bootfdt.c | 39 ++++++--- xen/arch/arm/dom0less-build.c | 16 ++-- xen/arch/arm/domain_build.c | 103 +++++++++++++----------- xen/arch/arm/efi/efi-boot.h | 8 +- xen/arch/arm/efi/efi-dom0.c | 13 +-- xen/arch/arm/include/asm/domain_build.h | 2 +- xen/arch/arm/include/asm/kernel.h | 8 ++ xen/arch/arm/include/asm/setup.h | 40 ++++++++- xen/arch/arm/kernel.c | 12 +-- xen/arch/arm/setup.c | 58 +++++++------ xen/arch/arm/static-memory.c | 27 ++++--- xen/arch/arm/static-shmem.c | 34 ++++---- 15 files changed, 249 insertions(+), 163 deletions(-) diff --git a/xen/arch/arm/acpi/domain_build.c b/xen/arch/arm/acpi/domain_bu= ild.c index b58389ce9e9f..ed895dd8f926 100644 --- a/xen/arch/arm/acpi/domain_build.c +++ b/xen/arch/arm/acpi/domain_build.c @@ -444,14 +444,14 @@ static int __init acpi_create_fadt(struct domain *d, = struct membank tbl_add[]) } =20 static int __init estimate_acpi_efi_size(struct domain *d, - struct kernel_info *kinfo) + const struct kernel_info *kinfo) { size_t efi_size, acpi_size, madt_size; u64 addr; struct acpi_table_rsdp *rsdp_tbl; struct acpi_table_header *table; =20 - efi_size =3D estimate_efi_size(kinfo->mem.nr_banks); + efi_size =3D estimate_efi_size(kernel_info_get_mem(kinfo)->nr_banks); =20 acpi_size =3D ROUNDUP(sizeof(struct acpi_table_fadt), 8); acpi_size +=3D ROUNDUP(sizeof(struct acpi_table_stao), 8); @@ -546,7 +546,7 @@ int __init prepare_acpi(struct domain *d, struct kernel= _info *kinfo) =20 acpi_map_other_tables(d); acpi_create_efi_system_table(d, tbl_add); - acpi_create_efi_mmap_table(d, &kinfo->mem, tbl_add); + acpi_create_efi_mmap_table(d, kernel_info_get_mem(kinfo), tbl_add); =20 /* Map the EFI and ACPI tables to Dom0 */ rc =3D map_regions_p2mt(d, diff --git a/xen/arch/arm/arm32/mmu/mm.c b/xen/arch/arm/arm32/mmu/mm.c index 0ab6ae52a63b..84c89da909bf 100644 --- a/xen/arch/arm/arm32/mmu/mm.c +++ b/xen/arch/arm/arm32/mmu/mm.c @@ -42,6 +42,7 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t= e, uint32_t size, paddr_t align, int first_mod) { + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); const struct bootmodules *mi =3D &bootinfo.modules; int i; int nr; @@ -100,15 +101,14 @@ static paddr_t __init consider_modules(paddr_t s, pad= dr_t e, * possible kinds of bootmodules. * * When retrieving the corresponding reserved-memory addresses, we - * need to index the bootinfo.reserved_mem bank starting from 0, and - * only counting the reserved-memory modules. Hence, we need to use - * i - nr. + * need to index the reserved_mem bank starting from 0, and only count= ing + * the reserved-memory modules. Hence, we need to use i - nr. */ nr +=3D mi->nr_mods; - for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ ) + for ( ; i - nr < reserved_mem->nr_banks; i++ ) { - paddr_t r_s =3D bootinfo.reserved_mem.bank[i - nr].start; - paddr_t r_e =3D r_s + bootinfo.reserved_mem.bank[i - nr].size; + paddr_t r_s =3D reserved_mem->bank[i - nr].start; + paddr_t r_e =3D r_s + reserved_mem->bank[i - nr].size; =20 if ( s < r_e && r_s < e ) { @@ -129,17 +129,18 @@ static paddr_t __init consider_modules(paddr_t s, pad= dr_t e, */ static paddr_t __init fit_xenheap_in_static_heap(uint32_t size, paddr_t al= ign) { + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); unsigned int i; paddr_t end =3D 0, aligned_start, aligned_end; paddr_t bank_start, bank_size, bank_end; =20 - for ( i =3D 0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + for ( i =3D 0 ; i < reserved_mem->nr_banks; i++ ) { - if ( bootinfo.reserved_mem.bank[i].type !=3D MEMBANK_STATIC_HEAP ) + if ( reserved_mem->bank[i].type !=3D MEMBANK_STATIC_HEAP ) continue; =20 - bank_start =3D bootinfo.reserved_mem.bank[i].start; - bank_size =3D bootinfo.reserved_mem.bank[i].size; + bank_start =3D reserved_mem->bank[i].start; + bank_size =3D reserved_mem->bank[i].size; bank_end =3D bank_start + bank_size; =20 if ( bank_size < size ) @@ -162,13 +163,14 @@ static paddr_t __init fit_xenheap_in_static_heap(uint= 32_t size, paddr_t align) =20 void __init setup_mm(void) { + const struct membanks *mem =3D bootinfo_get_mem(); paddr_t ram_start, ram_end, ram_size, e, bank_start, bank_end, bank_si= ze; paddr_t static_heap_end =3D 0, static_heap_size =3D 0; unsigned long heap_pages, xenheap_pages, domheap_pages; unsigned int i; const uint32_t ctr =3D READ_CP32(CTR); =20 - if ( !bootinfo.mem.nr_banks ) + if ( !mem->nr_banks ) panic("No memory bank\n"); =20 /* We only supports instruction caches implementing the IVIPT extensio= n. */ @@ -177,14 +179,14 @@ void __init setup_mm(void) =20 init_pdx(); =20 - ram_start =3D bootinfo.mem.bank[0].start; - ram_size =3D bootinfo.mem.bank[0].size; + ram_start =3D mem->bank[0].start; + ram_size =3D mem->bank[0].size; ram_end =3D ram_start + ram_size; =20 - for ( i =3D 1; i < bootinfo.mem.nr_banks; i++ ) + for ( i =3D 1; i < mem->nr_banks; i++ ) { - bank_start =3D bootinfo.mem.bank[i].start; - bank_size =3D bootinfo.mem.bank[i].size; + bank_start =3D mem->bank[i].start; + bank_size =3D mem->bank[i].size; bank_end =3D bank_start + bank_size; =20 ram_size =3D ram_size + bank_size; @@ -196,13 +198,15 @@ void __init setup_mm(void) =20 if ( bootinfo.static_heap ) { - for ( i =3D 0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(= ); + + for ( i =3D 0 ; i < reserved_mem->nr_banks; i++ ) { - if ( bootinfo.reserved_mem.bank[i].type !=3D MEMBANK_STATIC_HE= AP ) + if ( reserved_mem->bank[i].type !=3D MEMBANK_STATIC_HEAP ) continue; =20 - bank_start =3D bootinfo.reserved_mem.bank[i].start; - bank_size =3D bootinfo.reserved_mem.bank[i].size; + bank_start =3D reserved_mem->bank[i].start; + bank_size =3D reserved_mem->bank[i].size; bank_end =3D bank_start + bank_size; =20 static_heap_size +=3D bank_size; diff --git a/xen/arch/arm/arm64/mmu/mm.c b/xen/arch/arm/arm64/mmu/mm.c index d2651c948698..f8aaf4ac18be 100644 --- a/xen/arch/arm/arm64/mmu/mm.c +++ b/xen/arch/arm/arm64/mmu/mm.c @@ -194,7 +194,7 @@ static void __init setup_directmap_mappings(unsigned lo= ng base_mfn, =20 void __init setup_mm(void) { - const struct meminfo *banks =3D &bootinfo.mem; + const struct membanks *banks =3D bootinfo_get_mem(); paddr_t ram_start =3D INVALID_PADDR; paddr_t ram_end =3D 0; paddr_t ram_size =3D 0; diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 35dbdf3384cb..4c80962f79d4 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -17,6 +17,18 @@ #include #include =20 +static void __init __maybe_unused build_assertions(void) +{ + /* + * Check that no padding is between struct membanks "bank" flexible ar= ray + * member and struct meminfo "bank" member + */ + BUILD_BUG_ON((offsetof(struct membanks, bank) !=3D + offsetof(struct meminfo, bank))); + /* Ensure "struct membanks" is 8-byte aligned */ + BUILD_BUG_ON(alignof(struct membanks) !=3D 8); +} + static bool __init device_tree_node_is_available(const void *fdt, int node) { const char *status; @@ -107,14 +119,14 @@ void __init device_tree_get_reg(const __be32 **cell, = uint32_t address_cells, static int __init device_tree_get_meminfo(const void *fdt, int node, const char *prop_name, u32 address_cells, u32 size_cell= s, - void *data, enum membank_type ty= pe) + struct membanks *mem, + enum membank_type type) { const struct fdt_property *prop; unsigned int i, banks; const __be32 *cell; u32 reg_cells =3D address_cells + size_cells; paddr_t start, size; - struct meminfo *mem =3D data; =20 if ( !device_tree_node_is_available(fdt, node) ) return 0; @@ -133,10 +145,10 @@ static int __init device_tree_get_meminfo(const void = *fdt, int node, cell =3D (const __be32 *)prop->data; banks =3D fdt32_to_cpu(prop->len) / (reg_cells * sizeof (u32)); =20 - for ( i =3D 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ ) + for ( i =3D 0; i < banks && mem->nr_banks < mem->max_banks; i++ ) { device_tree_get_reg(&cell, address_cells, size_cells, &start, &siz= e); - if ( mem =3D=3D &bootinfo.reserved_mem && + if ( mem =3D=3D bootinfo_get_reserved_mem() && check_reserved_regions_overlap(start, size) ) return -EINVAL; /* Some DT may describe empty bank, ignore them */ @@ -231,10 +243,10 @@ int __init device_tree_for_each_node(const void *fdt,= int node, static int __init process_memory_node(const void *fdt, int node, const char *name, int depth, u32 address_cells, u32 size_cells, - void *data) + struct membanks *mem) { return device_tree_get_meminfo(fdt, node, "reg", address_cells, size_c= ells, - data, MEMBANK_DEFAULT); + mem, MEMBANK_DEFAULT); } =20 static int __init process_reserved_memory_node(const void *fdt, int node, @@ -259,7 +271,7 @@ static int __init process_reserved_memory(const void *f= dt, int node, { return device_tree_for_each_node(fdt, node, process_reserved_memory_node, - &bootinfo.reserved_mem); + bootinfo_get_reserved_mem()); } =20 static void __init process_multiboot_node(const void *fdt, int node, @@ -358,7 +370,7 @@ static int __init process_chosen_node(const void *fdt, = int node, =20 rc =3D device_tree_get_meminfo(fdt, node, "xen,static-heap", address_cells, size_cells, - &bootinfo.reserved_mem, + bootinfo_get_reserved_mem(), MEMBANK_STATIC_HEAP); if ( rc ) return rc; @@ -420,7 +432,7 @@ static int __init process_domain_node(const void *fdt, = int node, return 0; =20 return device_tree_get_meminfo(fdt, node, "xen,static-mem", address_ce= lls, - size_cells, &bootinfo.reserved_mem, + size_cells, bootinfo_get_reserved_mem(), MEMBANK_STATIC_DOMAIN); } =20 @@ -438,7 +450,7 @@ static int __init early_scan_node(const void *fdt, if ( !efi_enabled(EFI_BOOT) && device_tree_node_matches(fdt, node, "memory") ) rc =3D process_memory_node(fdt, node, name, depth, - address_cells, size_cells, &bootinfo.mem); + address_cells, size_cells, bootinfo_get_m= em()); else if ( depth =3D=3D 1 && !dt_node_cmp(name, "reserved-memory") ) rc =3D process_reserved_memory(fdt, node, name, depth, address_cells, size_cells); @@ -459,8 +471,8 @@ static int __init early_scan_node(const void *fdt, =20 static void __init early_print_info(void) { - struct meminfo *mi =3D &bootinfo.mem; - struct meminfo *mem_resv =3D &bootinfo.reserved_mem; + const struct membanks *mi =3D bootinfo_get_mem(); + const struct membanks *mem_resv =3D bootinfo_get_reserved_mem(); struct bootmodules *mods =3D &bootinfo.modules; struct bootcmdlines *cmds =3D &bootinfo.cmdlines; unsigned int i, j; @@ -537,6 +549,7 @@ static void __init swap_memory_node(void *_a, void *_b,= size_t size) */ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) { + struct membanks *mem =3D bootinfo_get_mem(); int ret; =20 ret =3D fdt_check_header(fdt); @@ -554,7 +567,7 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t pa= ddr) * bank in memory first. There is no requirement that the DT will prov= ide * the banks sorted in ascending order. So sort them through. */ - sort(bootinfo.mem.bank, bootinfo.mem.nr_banks, sizeof(struct membank), + sort(mem->bank, mem->nr_banks, sizeof(struct membank), cmp_memory_node, swap_memory_node); =20 early_print_info(); diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 0edc5357caef..51cf03221d56 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -50,6 +50,7 @@ bool __init is_dom0less_mode(void) =20 static void __init allocate_memory(struct domain *d, struct kernel_info *k= info) { + struct membanks *mem =3D kernel_info_get_mem(kinfo); unsigned int i; paddr_t bank_size; =20 @@ -57,7 +58,7 @@ static void __init allocate_memory(struct domain *d, stru= ct kernel_info *kinfo) /* Don't want format this as PRIpaddr (16 digit hex) */ (unsigned long)(kinfo->unassigned_mem >> 20), d); =20 - kinfo->mem.nr_banks =3D 0; + mem->nr_banks =3D 0; bank_size =3D MIN(GUEST_RAM0_SIZE, kinfo->unassigned_mem); if ( !allocate_bank_memory(d, kinfo, gaddr_to_gfn(GUEST_RAM0_BASE), bank_size) ) @@ -71,15 +72,15 @@ static void __init allocate_memory(struct domain *d, st= ruct kernel_info *kinfo) if ( kinfo->unassigned_mem ) goto fail; =20 - for( i =3D 0; i < kinfo->mem.nr_banks; i++ ) + for( i =3D 0; i < mem->nr_banks; i++ ) { printk(XENLOG_INFO "%pd BANK[%d] %#"PRIpaddr"-%#"PRIpaddr" (%ldMB)= \n", d, i, - kinfo->mem.bank[i].start, - kinfo->mem.bank[i].start + kinfo->mem.bank[i].size, + mem->bank[i].start, + mem->bank[i].start + mem->bank[i].size, /* Don't want format this as PRIpaddr (16 digit hex) */ - (unsigned long)(kinfo->mem.bank[i].size >> 20)); + (unsigned long)(mem->bank[i].size >> 20)); } =20 return; @@ -641,7 +642,8 @@ static int __init prepare_dtb_domU(struct domain *d, st= ruct kernel_info *kinfo) if ( ret ) goto err; =20 - ret =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kinfo->= mem); + ret =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, + kernel_info_get_mem(kinfo)); if ( ret ) goto err; =20 @@ -740,7 +742,7 @@ static int __init alloc_xenstore_evtchn(struct domain *= d) static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { - struct kernel_info kinfo =3D {}; + struct kernel_info kinfo =3D KERNEL_INFO_INIT; const char *dom0less_enhanced; int rc; u64 mem; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 11d4e7d0b1ea..02e4dcafe78f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -141,6 +141,7 @@ static bool __init insert_11_bank(struct domain *d, struct page_info *pg, unsigned int order) { + struct membanks *mem =3D kernel_info_get_mem(kinfo); unsigned int i; int res; mfn_t smfn; @@ -157,9 +158,9 @@ static bool __init insert_11_bank(struct domain *d, (unsigned long)(kinfo->unassigned_mem >> 20), order); =20 - if ( kinfo->mem.nr_banks > 0 && + if ( mem->nr_banks > 0 && size < MB(128) && - start + size < kinfo->mem.bank[0].start ) + start + size < mem->bank[0].start ) { D11PRINT("Allocation below bank 0 is too small, not using\n"); goto fail; @@ -171,17 +172,17 @@ static bool __init insert_11_bank(struct domain *d, =20 kinfo->unassigned_mem -=3D size; =20 - if ( kinfo->mem.nr_banks =3D=3D 0 ) + if ( mem->nr_banks =3D=3D 0 ) { - kinfo->mem.bank[0].start =3D start; - kinfo->mem.bank[0].size =3D size; - kinfo->mem.nr_banks =3D 1; + mem->bank[0].start =3D start; + mem->bank[0].size =3D size; + mem->nr_banks =3D 1; return true; } =20 - for( i =3D 0; i < kinfo->mem.nr_banks; i++ ) + for( i =3D 0; i < mem->nr_banks; i++ ) { - struct membank *bank =3D &kinfo->mem.bank[i]; + struct membank *bank =3D &mem->bank[i]; =20 /* If possible merge new memory into the start of the bank */ if ( bank->start =3D=3D start+size ) @@ -204,24 +205,24 @@ static bool __init insert_11_bank(struct domain *d, * could have inserted the memory into/before we would already * have done so, so this must be the right place. */ - if ( start + size < bank->start && kinfo->mem.nr_banks < NR_MEM_BA= NKS ) + if ( start + size < bank->start && mem->nr_banks < mem->max_banks ) { memmove(bank + 1, bank, - sizeof(*bank) * (kinfo->mem.nr_banks - i)); - kinfo->mem.nr_banks++; + sizeof(*bank) * (mem->nr_banks - i)); + mem->nr_banks++; bank->start =3D start; bank->size =3D size; return true; } } =20 - if ( i =3D=3D kinfo->mem.nr_banks && kinfo->mem.nr_banks < NR_MEM_BANK= S ) + if ( i =3D=3D mem->nr_banks && mem->nr_banks < mem->max_banks ) { - struct membank *bank =3D &kinfo->mem.bank[kinfo->mem.nr_banks]; + struct membank *bank =3D &mem->bank[mem->nr_banks]; =20 bank->start =3D start; bank->size =3D size; - kinfo->mem.nr_banks++; + mem->nr_banks++; return true; } =20 @@ -293,6 +294,7 @@ static void __init allocate_memory_11(struct domain *d, const unsigned int min_low_order =3D get_order_from_bytes(min_t(paddr_t, dom0_mem, MB(128))); const unsigned int min_order =3D get_order_from_bytes(MB(4)); + struct membanks *mem =3D kernel_info_get_mem(kinfo); struct page_info *pg; unsigned int order =3D get_allocation_size(kinfo->unassigned_mem); unsigned int i; @@ -311,7 +313,7 @@ static void __init allocate_memory_11(struct domain *d, /* Don't want format this as PRIpaddr (16 digit hex) */ (unsigned long)(kinfo->unassigned_mem >> 20)); =20 - kinfo->mem.nr_banks =3D 0; + mem->nr_banks =3D 0; =20 /* * First try and allocate the largest thing we can as low as @@ -349,7 +351,7 @@ static void __init allocate_memory_11(struct domain *d, * continue allocating from above the lowmem and fill in banks. */ order =3D get_allocation_size(kinfo->unassigned_mem); - while ( kinfo->unassigned_mem && kinfo->mem.nr_banks < NR_MEM_BANKS ) + while ( kinfo->unassigned_mem && mem->nr_banks < mem->max_banks ) { pg =3D alloc_domheap_pages(d, order, lowmem ? MEMF_bits(lowmem_bitsize) : 0); @@ -373,7 +375,7 @@ static void __init allocate_memory_11(struct domain *d, =20 if ( !insert_11_bank(d, kinfo, pg, order) ) { - if ( kinfo->mem.nr_banks =3D=3D NR_MEM_BANKS ) + if ( mem->nr_banks =3D=3D mem->max_banks ) /* Nothing more we can do. */ break; =20 @@ -403,14 +405,14 @@ static void __init allocate_memory_11(struct domain *= d, panic("Failed to allocate requested dom0 memory. %ldMB unallocated= \n", (unsigned long)kinfo->unassigned_mem >> 20); =20 - for( i =3D 0; i < kinfo->mem.nr_banks; i++ ) + for( i =3D 0; i < mem->nr_banks; i++ ) { printk("BANK[%d] %#"PRIpaddr"-%#"PRIpaddr" (%ldMB)\n", i, - kinfo->mem.bank[i].start, - kinfo->mem.bank[i].start + kinfo->mem.bank[i].size, + mem->bank[i].start, + mem->bank[i].start + mem->bank[i].size, /* Don't want format this as PRIpaddr (16 digit hex) */ - (unsigned long)(kinfo->mem.bank[i].size >> 20)); + (unsigned long)(mem->bank[i].size >> 20)); } } =20 @@ -418,6 +420,7 @@ static void __init allocate_memory_11(struct domain *d, bool __init allocate_bank_memory(struct domain *d, struct kernel_info *kin= fo, gfn_t sgfn, paddr_t tot_size) { + struct membanks *mem =3D kernel_info_get_mem(kinfo); int res; struct page_info *pg; struct membank *bank; @@ -431,7 +434,7 @@ bool __init allocate_bank_memory(struct domain *d, stru= ct kernel_info *kinfo, if ( tot_size =3D=3D 0 ) return true; =20 - bank =3D &kinfo->mem.bank[kinfo->mem.nr_banks]; + bank =3D &mem->bank[mem->nr_banks]; bank->start =3D gfn_to_gaddr(sgfn); bank->size =3D tot_size; =20 @@ -471,7 +474,7 @@ bool __init allocate_bank_memory(struct domain *d, stru= ct kernel_info *kinfo, tot_size -=3D (1ULL << (PAGE_SHIFT + order)); } =20 - kinfo->mem.nr_banks++; + mem->nr_banks++; kinfo->unassigned_mem -=3D bank->size; =20 return true; @@ -756,7 +759,7 @@ int __init domain_fdt_begin_node(void *fdt, const char = *name, uint64_t unit) int __init make_memory_node(const struct domain *d, void *fdt, int addrcells, int sizecells, - struct meminfo *mem) + const struct membanks *mem) { unsigned int i; int res, reg_size =3D addrcells + sizecells; @@ -816,12 +819,12 @@ int __init make_memory_node(const struct domain *d, static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data) { - struct meminfo *ext_regions =3D data; + struct membanks *ext_regions =3D data; paddr_t start, size; paddr_t s =3D pfn_to_paddr(s_gfn); paddr_t e =3D pfn_to_paddr(e_gfn); =20 - if ( ext_regions->nr_banks >=3D ARRAY_SIZE(ext_regions->bank) ) + if ( ext_regions->nr_banks >=3D ext_regions->max_banks ) return 0; =20 /* @@ -863,9 +866,11 @@ static int __init add_ext_regions(unsigned long s_gfn,= unsigned long e_gfn, * - grant table space */ static int __init find_unallocated_memory(const struct kernel_info *kinfo, - struct meminfo *ext_regions) + struct membanks *ext_regions) { - const struct meminfo *assign_mem =3D &kinfo->mem; + const struct membanks *kinfo_mem =3D kernel_info_get_mem(kinfo); + const struct membanks *mem =3D bootinfo_get_mem(); + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); struct rangeset *unalloc_mem; paddr_t start, end; unsigned int i; @@ -878,10 +883,10 @@ static int __init find_unallocated_memory(const struc= t kernel_info *kinfo, return -ENOMEM; =20 /* Start with all available RAM */ - for ( i =3D 0; i < bootinfo.mem.nr_banks; i++ ) + for ( i =3D 0; i < mem->nr_banks; i++ ) { - start =3D bootinfo.mem.bank[i].start; - end =3D bootinfo.mem.bank[i].start + bootinfo.mem.bank[i].size; + start =3D mem->bank[i].start; + end =3D mem->bank[i].start + mem->bank[i].size; res =3D rangeset_add_range(unalloc_mem, PFN_DOWN(start), PFN_DOWN(end - 1)); if ( res ) @@ -893,10 +898,10 @@ static int __init find_unallocated_memory(const struc= t kernel_info *kinfo, } =20 /* Remove RAM assigned to Dom0 */ - for ( i =3D 0; i < assign_mem->nr_banks; i++ ) + for ( i =3D 0; i < kinfo_mem->nr_banks; i++ ) { - start =3D assign_mem->bank[i].start; - end =3D assign_mem->bank[i].start + assign_mem->bank[i].size; + start =3D kinfo_mem->bank[i].start; + end =3D kinfo_mem->bank[i].start + kinfo_mem->bank[i].size; res =3D rangeset_remove_range(unalloc_mem, PFN_DOWN(start), PFN_DOWN(end - 1)); if ( res ) @@ -908,11 +913,10 @@ static int __init find_unallocated_memory(const struc= t kernel_info *kinfo, } =20 /* Remove reserved-memory regions */ - for ( i =3D 0; i < bootinfo.reserved_mem.nr_banks; i++ ) + for ( i =3D 0; i < reserved_mem->nr_banks; i++ ) { - start =3D bootinfo.reserved_mem.bank[i].start; - end =3D bootinfo.reserved_mem.bank[i].start + - bootinfo.reserved_mem.bank[i].size; + start =3D reserved_mem->bank[i].start; + end =3D reserved_mem->bank[i].start + reserved_mem->bank[i].size; res =3D rangeset_remove_range(unalloc_mem, PFN_DOWN(start), PFN_DOWN(end - 1)); if ( res ) @@ -990,7 +994,7 @@ static int __init handle_pci_range(const struct dt_devi= ce_node *dev, * - PCI aperture */ static int __init find_memory_holes(const struct kernel_info *kinfo, - struct meminfo *ext_regions) + struct membanks *ext_regions) { struct dt_device_node *np; struct rangeset *mem_holes; @@ -1080,19 +1084,20 @@ out: } =20 static int __init find_domU_holes(const struct kernel_info *kinfo, - struct meminfo *ext_regions) + struct membanks *ext_regions) { unsigned int i; uint64_t bankend; const uint64_t bankbase[] =3D GUEST_RAM_BANK_BASES; const uint64_t banksize[] =3D GUEST_RAM_BANK_SIZES; + const struct membanks *kinfo_mem =3D kernel_info_get_mem(kinfo); int res =3D -ENOENT; =20 for ( i =3D 0; i < GUEST_RAM_BANKS; i++ ) { struct membank *ext_bank =3D &(ext_regions->bank[ext_regions->nr_b= anks]); =20 - ext_bank->start =3D ROUNDUP(bankbase[i] + kinfo->mem.bank[i].size,= SZ_2M); + ext_bank->start =3D ROUNDUP(bankbase[i] + kinfo_mem->bank[i].size,= SZ_2M); =20 bankend =3D ~0ULL >> (64 - p2m_ipa_bits); bankend =3D min(bankend, bankbase[i] + banksize[i] - 1); @@ -1120,7 +1125,7 @@ int __init make_hypervisor_node(struct domain *d, gic_interrupt_t intr; int res; void *fdt =3D kinfo->fdt; - struct meminfo *ext_regions =3D NULL; + struct membanks *ext_regions =3D NULL; unsigned int i, nr_ext_regions; =20 dt_dprintk("Create hypervisor node\n"); @@ -1156,10 +1161,12 @@ int __init make_hypervisor_node(struct domain *d, } else { - ext_regions =3D xzalloc(struct meminfo); + ext_regions =3D xzalloc_flex_struct(struct membanks, bank, NR_MEM_= BANKS); if ( !ext_regions ) return -ENOMEM; =20 + ext_regions->max_banks =3D NR_MEM_BANKS; + if ( is_domain_direct_mapped(d) ) { if ( !is_iommu_enabled(d) ) @@ -1728,6 +1735,7 @@ static int __init handle_node(struct domain *d, struc= t kernel_info *kinfo, =20 if ( node =3D=3D dt_host ) { + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(= ); int addrcells =3D dt_child_n_addr_cells(node); int sizecells =3D dt_child_n_size_cells(node); =20 @@ -1753,7 +1761,8 @@ static int __init handle_node(struct domain *d, struc= t kernel_info *kinfo, if ( res ) return res; =20 - res =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, &kin= fo->mem); + res =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, + kernel_info_get_mem(kinfo)); if ( res ) return res; =20 @@ -1761,10 +1770,10 @@ static int __init handle_node(struct domain *d, str= uct kernel_info *kinfo, * Create a second memory node to store the ranges covering * reserved-memory regions. */ - if ( bootinfo.reserved_mem.nr_banks > 0 ) + if ( reserved_mem->nr_banks > 0 ) { res =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, - &bootinfo.reserved_mem); + reserved_mem); if ( res ) return res; } @@ -2038,7 +2047,7 @@ int __init construct_domain(struct domain *d, struct = kernel_info *kinfo) =20 static int __init construct_dom0(struct domain *d) { - struct kernel_info kinfo =3D {}; + struct kernel_info kinfo =3D KERNEL_INFO_INIT; int rc; =20 /* Sanity! */ diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index 0cb29f90a066..199f5260229d 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -157,14 +157,14 @@ static void __init *lookup_fdt_config_table(EFI_SYSTE= M_TABLE *sys_table) return fdt; } =20 -static bool __init meminfo_add_bank(struct meminfo *mem, +static bool __init meminfo_add_bank(struct membanks *mem, EFI_MEMORY_DESCRIPTOR *desc) { struct membank *bank; paddr_t start =3D desc->PhysicalStart; paddr_t size =3D desc->NumberOfPages * EFI_PAGE_SIZE; =20 - if ( mem->nr_banks >=3D NR_MEM_BANKS ) + if ( mem->nr_banks >=3D mem->max_banks ) return false; #ifdef CONFIG_ACPI if ( check_reserved_regions_overlap(start, size) ) @@ -198,7 +198,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinf= o(EFI_MEMORY_DESCRIPTOR * (desc_ptr->Type =3D=3D EfiBootServicesCode || desc_ptr->Type =3D=3D EfiBootServicesData))) ) { - if ( !meminfo_add_bank(&bootinfo.mem, desc_ptr) ) + if ( !meminfo_add_bank(bootinfo_get_mem(), desc_ptr) ) { PrintStr(L"Warning: All " __stringify(NR_MEM_BANKS) " bootinfo mem banks exhausted.\r\n"); @@ -208,7 +208,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinf= o(EFI_MEMORY_DESCRIPTOR * #ifdef CONFIG_ACPI else if ( desc_ptr->Type =3D=3D EfiACPIReclaimMemory ) { - if ( !meminfo_add_bank(&bootinfo.acpi, desc_ptr) ) + if ( !meminfo_add_bank(bootinfo_get_acpi(), desc_ptr) ) { PrintStr(L"Error: All " __stringify(NR_MEM_BANKS) " acpi meminfo mem banks exhausted.\r\n"); diff --git a/xen/arch/arm/efi/efi-dom0.c b/xen/arch/arm/efi/efi-dom0.c index aae0f979112a..baee8ab716cb 100644 --- a/xen/arch/arm/efi/efi-dom0.c +++ b/xen/arch/arm/efi/efi-dom0.c @@ -44,7 +44,7 @@ size_t __init estimate_efi_size(unsigned int mem_nr_banks) unsigned int acpi_mem_nr_banks =3D 0; =20 if ( !acpi_disabled ) - acpi_mem_nr_banks =3D bootinfo.acpi.nr_banks; + acpi_mem_nr_banks =3D bootinfo_get_acpi()->nr_banks; =20 size =3D ROUNDUP(est_size + ect_size + fw_vendor_size, 8); /* plus 1 for new created tables */ @@ -107,9 +107,10 @@ static void __init fill_efi_memory_descriptor(EFI_MEMO= RY_DESCRIPTOR *desc, } =20 void __init acpi_create_efi_mmap_table(struct domain *d, - const struct meminfo *mem, + const struct membanks *mem, struct membank tbl_add[]) { + const struct membanks *acpi =3D bootinfo_get_acpi(); EFI_MEMORY_DESCRIPTOR *desc; unsigned int i; u8 *base_ptr; @@ -122,10 +123,10 @@ void __init acpi_create_efi_mmap_table(struct domain = *d, fill_efi_memory_descriptor(desc, EfiConventionalMemory, mem->bank[i].start, mem->bank[i].size); =20 - for ( i =3D 0; i < bootinfo.acpi.nr_banks; i++, desc++ ) + for ( i =3D 0; i < acpi->nr_banks; i++, desc++ ) fill_efi_memory_descriptor(desc, EfiACPIReclaimMemory, - bootinfo.acpi.bank[i].start, - bootinfo.acpi.bank[i].size); + acpi->bank[i].start, + acpi->bank[i].size); =20 fill_efi_memory_descriptor(desc, EfiACPIReclaimMemory, d->arch.efi_acpi_gpa, d->arch.efi_acpi_len); @@ -133,7 +134,7 @@ void __init acpi_create_efi_mmap_table(struct domain *d, tbl_add[TBL_MMAP].start =3D d->arch.efi_acpi_gpa + acpi_get_table_offset(tbl_add, TBL_MMAP); tbl_add[TBL_MMAP].size =3D sizeof(EFI_MEMORY_DESCRIPTOR) - * (mem->nr_banks + bootinfo.acpi.nr_banks + 1= ); + * (mem->nr_banks + acpi->nr_banks + 1); } =20 /* Create /hypervisor/uefi node for efi properties. */ diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include= /asm/domain_build.h index da9e6025f37c..a6f276cc4263 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -15,7 +15,7 @@ int make_cpus_node(const struct domain *d, void *fdt); int make_hypervisor_node(struct domain *d, const struct kernel_info *kinfo, int addrcells, int sizecells); int make_memory_node(const struct domain *d, void *fdt, int addrcells, - int sizecells, struct meminfo *mem); + int sizecells, const struct membanks *mem); int make_psci_node(void *fdt); int make_timer_node(const struct kernel_info *kinfo); void evtchn_allocate(struct domain *d); diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/k= ernel.h index 0a23e86c2d37..d46f29ee6ce5 100644 --- a/xen/arch/arm/include/asm/kernel.h +++ b/xen/arch/arm/include/asm/kernel.h @@ -78,6 +78,14 @@ struct kernel_info { }; }; =20 +#define kernel_info_get_mem(kinfo) (&(kinfo)->mem.common) + +#define KERNEL_INFO_INIT \ +{ \ + .mem.common.max_banks =3D NR_MEM_BANKS, \ + .shm_mem.common.max_banks =3D NR_MEM_BANKS, \ +} + /* * Probe the kernel to detemine its type and select a loader. * diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index d15a88d2e0d1..696f55db86b1 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -56,8 +56,14 @@ struct membank { #endif }; =20 -struct meminfo { +struct membanks { unsigned int nr_banks; + unsigned int max_banks; + struct membank bank[]; +}; + +struct meminfo { + struct membanks common; struct membank bank[NR_MEM_BANKS]; }; =20 @@ -107,6 +113,19 @@ struct bootinfo { bool static_heap; }; =20 +#ifdef CONFIG_ACPI +#define BOOTINFO_ACPI_INIT .acpi.common.max_banks =3D NR_MEM_BANKS, +#else +#define BOOTINFO_ACPI_INIT +#endif + +#define BOOTINFO_INIT \ +{ \ + .mem.common.max_banks =3D NR_MEM_BANKS, \ + .reserved_mem.common.max_banks =3D NR_MEM_BANKS, \ + BOOTINFO_ACPI_INIT \ +} + struct map_range_data { struct domain *d; @@ -122,6 +141,23 @@ extern struct bootinfo bootinfo; =20 extern domid_t max_init_domid; =20 +static inline struct membanks *bootinfo_get_mem(void) +{ + return &bootinfo.mem.common; +} + +static inline struct membanks *bootinfo_get_reserved_mem(void) +{ + return &bootinfo.reserved_mem.common; +} + +#ifdef CONFIG_ACPI +static inline struct membanks *bootinfo_get_acpi(void) +{ + return &bootinfo.acpi.common; +} +#endif + void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); =20 size_t estimate_efi_size(unsigned int mem_nr_banks); @@ -130,7 +166,7 @@ void acpi_create_efi_system_table(struct domain *d, struct membank tbl_add[]); =20 void acpi_create_efi_mmap_table(struct domain *d, - const struct meminfo *mem, + const struct membanks *mem, struct membank tbl_add[]); =20 int acpi_make_efi_nodes(void *fdt, struct membank tbl_add[]); diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index bc3e5bd6f940..674388fa11a2 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -45,13 +45,14 @@ static void __init place_modules(struct kernel_info *in= fo, { /* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignm= ent */ const struct bootmodule *mod =3D info->initrd_bootmodule; + const struct membanks *mem =3D kernel_info_get_mem(info); const paddr_t initrd_len =3D ROUNDUP(mod ? mod->size : 0, MB(2)); const paddr_t dtb_len =3D ROUNDUP(fdt_totalsize(info->fdt), MB(2)); const paddr_t modsize =3D initrd_len + dtb_len; =20 /* Convenient */ - const paddr_t rambase =3D info->mem.bank[0].start; - const paddr_t ramsize =3D info->mem.bank[0].size; + const paddr_t rambase =3D mem->bank[0].start; + const paddr_t ramsize =3D mem->bank[0].size; const paddr_t ramend =3D rambase + ramsize; const paddr_t kernsize =3D ROUNDUP(kernend, MB(2)) - kernbase; const paddr_t ram128mb =3D rambase + MB(128); @@ -96,11 +97,12 @@ static void __init place_modules(struct kernel_info *in= fo, =20 static paddr_t __init kernel_zimage_place(struct kernel_info *info) { + const struct membanks *mem =3D kernel_info_get_mem(info); paddr_t load_addr; =20 #ifdef CONFIG_ARM_64 if ( (info->type =3D=3D DOMAIN_64BIT) && (info->zimage.start =3D=3D 0)= ) - return info->mem.bank[0].start + info->zimage.text_offset; + return mem->bank[0].start + info->zimage.text_offset; #endif =20 /* @@ -113,8 +115,8 @@ static paddr_t __init kernel_zimage_place(struct kernel= _info *info) { paddr_t load_end; =20 - load_end =3D info->mem.bank[0].start + info->mem.bank[0].size; - load_end =3D MIN(info->mem.bank[0].start + MB(128), load_end); + load_end =3D mem->bank[0].start + mem->bank[0].size; + load_end =3D MIN(mem->bank[0].start + MB(128), load_end); =20 load_addr =3D load_end - info->zimage.len; /* Align to 2MB */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index b9a7f61f73ef..e00dbb135113 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -48,7 +48,7 @@ #include #include =20 -struct bootinfo __initdata bootinfo; +struct bootinfo __initdata bootinfo =3D BOOTINFO_INIT; =20 /* * Sanitized version of cpuinfo containing only features available on all @@ -207,6 +207,7 @@ static void __init dt_unreserved_regions(paddr_t s, pad= dr_t e, void (*cb)(paddr_t ps, paddr_t pe= ), unsigned int first) { + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); unsigned int i, nr; int rc; =20 @@ -240,14 +241,14 @@ static void __init dt_unreserved_regions(paddr_t s, p= addr_t e, * kinds. * * When retrieving the corresponding reserved-memory addresses - * below, we need to index the bootinfo.reserved_mem bank starting + * below, we need to index the reserved_mem->bank starting * from 0, and only counting the reserved-memory modules. Hence, * we need to use i - nr. */ - for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ ) + for ( ; i - nr < reserved_mem->nr_banks; i++ ) { - paddr_t r_s =3D bootinfo.reserved_mem.bank[i - nr].start; - paddr_t r_e =3D r_s + bootinfo.reserved_mem.bank[i - nr].size; + paddr_t r_s =3D reserved_mem->bank[i - nr].start; + paddr_t r_e =3D r_s + reserved_mem->bank[i - nr].size; =20 if ( s < r_e && r_s < e ) { @@ -264,18 +265,18 @@ static void __init dt_unreserved_regions(paddr_t s, p= addr_t e, * TODO: '*_end' could be 0 if the bank/region is at the end of the physic= al * address space. This is for now not handled as it requires more rework. */ -static bool __init meminfo_overlap_check(struct meminfo *meminfo, +static bool __init meminfo_overlap_check(const struct membanks *mem, paddr_t region_start, paddr_t region_size) { paddr_t bank_start =3D INVALID_PADDR, bank_end =3D 0; paddr_t region_end =3D region_start + region_size; - unsigned int i, bank_num =3D meminfo->nr_banks; + unsigned int i, bank_num =3D mem->nr_banks; =20 for ( i =3D 0; i < bank_num; i++ ) { - bank_start =3D meminfo->bank[i].start; - bank_end =3D bank_start + meminfo->bank[i].size; + bank_start =3D mem->bank[i].start; + bank_end =3D bank_start + mem->bank[i].size; =20 if ( region_end <=3D bank_start || region_start >=3D bank_end ) continue; @@ -339,8 +340,11 @@ void __init fw_unreserved_regions(paddr_t s, paddr_t e, bool __init check_reserved_regions_overlap(paddr_t region_start, paddr_t region_size) { - /* Check if input region is overlapping with bootinfo.reserved_mem ban= ks */ - if ( meminfo_overlap_check(&bootinfo.reserved_mem, + /* + * Check if input region is overlapping with bootinfo_get_reserved_mem= () + * banks + */ + if ( meminfo_overlap_check(bootinfo_get_reserved_mem(), region_start, region_size) ) return true; =20 @@ -351,7 +355,7 @@ bool __init check_reserved_regions_overlap(paddr_t regi= on_start, =20 #ifdef CONFIG_ACPI /* Check if input region is overlapping with ACPI EfiACPIReclaimMemory= */ - if ( meminfo_overlap_check(&bootinfo.acpi, region_start, region_size) ) + if ( meminfo_overlap_check(bootinfo_get_acpi(), region_start, region_s= ize) ) return true; #endif =20 @@ -580,6 +584,7 @@ static paddr_t __init next_module(paddr_t s, paddr_t *e= nd) =20 void __init init_pdx(void) { + const struct membanks *mem =3D bootinfo_get_mem(); paddr_t bank_start, bank_size, bank_end; =20 /* @@ -592,18 +597,18 @@ void __init init_pdx(void) uint64_t mask =3D pdx_init_mask(0x0); int bank; =20 - for ( bank =3D 0 ; bank < bootinfo.mem.nr_banks; bank++ ) + for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) { - bank_start =3D bootinfo.mem.bank[bank].start; - bank_size =3D bootinfo.mem.bank[bank].size; + bank_start =3D mem->bank[bank].start; + bank_size =3D mem->bank[bank].size; =20 mask |=3D bank_start | pdx_region_mask(bank_start, bank_size); } =20 - for ( bank =3D 0 ; bank < bootinfo.mem.nr_banks; bank++ ) + for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) { - bank_start =3D bootinfo.mem.bank[bank].start; - bank_size =3D bootinfo.mem.bank[bank].size; + bank_start =3D mem->bank[bank].start; + bank_size =3D mem->bank[bank].size; =20 if (~mask & pdx_region_mask(bank_start, bank_size)) mask =3D 0; @@ -611,10 +616,10 @@ void __init init_pdx(void) =20 pfn_pdx_hole_setup(mask >> PAGE_SHIFT); =20 - for ( bank =3D 0 ; bank < bootinfo.mem.nr_banks; bank++ ) + for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) { - bank_start =3D bootinfo.mem.bank[bank].start; - bank_size =3D bootinfo.mem.bank[bank].size; + bank_start =3D mem->bank[bank].start; + bank_size =3D mem->bank[bank].size; bank_end =3D bank_start + bank_size; =20 set_pdx_range(paddr_to_pfn(bank_start), @@ -636,18 +641,19 @@ void __init init_pdx(void) void __init populate_boot_allocator(void) { unsigned int i; - const struct meminfo *banks =3D &bootinfo.mem; + const struct membanks *banks =3D bootinfo_get_mem(); + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); paddr_t s, e; =20 if ( bootinfo.static_heap ) { - for ( i =3D 0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + for ( i =3D 0 ; i < reserved_mem->nr_banks; i++ ) { - if ( bootinfo.reserved_mem.bank[i].type !=3D MEMBANK_STATIC_HE= AP ) + if ( reserved_mem->bank[i].type !=3D MEMBANK_STATIC_HEAP ) continue; =20 - s =3D bootinfo.reserved_mem.bank[i].start; - e =3D s + bootinfo.reserved_mem.bank[i].size; + s =3D reserved_mem->bank[i].start; + e =3D s + reserved_mem->bank[i].size; #ifdef CONFIG_ARM_32 /* Avoid the xenheap, note that the xenheap cannot across a ba= nk */ if ( s <=3D mfn_to_maddr(directmap_mfn_start) && diff --git a/xen/arch/arm/static-memory.c b/xen/arch/arm/static-memory.c index cffbab7241b7..34bd12696a53 100644 --- a/xen/arch/arm/static-memory.c +++ b/xen/arch/arm/static-memory.c @@ -85,6 +85,7 @@ static int __init parse_static_mem_prop(const struct dt_d= evice_node *node, void __init allocate_static_memory(struct domain *d, struct kernel_info *k= info, const struct dt_device_node *node) { + struct membanks *mem =3D kernel_info_get_mem(kinfo); u32 addr_cells, size_cells, reg_cells; unsigned int nr_banks, gbank, bank =3D 0; const uint64_t rambase[] =3D GUEST_RAM_BANK_BASES; @@ -106,7 +107,7 @@ void __init allocate_static_memory(struct domain *d, st= ruct kernel_info *kinfo, */ gbank =3D 0; gsize =3D ramsize[gbank]; - kinfo->mem.bank[gbank].start =3D rambase[gbank]; + mem->bank[gbank].start =3D rambase[gbank]; nr_banks =3D length / (reg_cells * sizeof (u32)); =20 for ( ; bank < nr_banks; bank++ ) @@ -122,7 +123,7 @@ void __init allocate_static_memory(struct domain *d, st= ruct kernel_info *kinfo, while ( 1 ) { /* Map as much as possible the static range to the guest bank = */ - if ( !append_static_memory_to_bank(d, &kinfo->mem.bank[gbank],= smfn, + if ( !append_static_memory_to_bank(d, &mem->bank[gbank], smfn, min(psize, gsize)) ) goto fail; =20 @@ -153,14 +154,14 @@ void __init allocate_static_memory(struct domain *d, = struct kernel_info *kinfo, /* Update to the next guest bank. */ gbank++; gsize =3D ramsize[gbank]; - kinfo->mem.bank[gbank].start =3D rambase[gbank]; + mem->bank[gbank].start =3D rambase[gbank]; } } =20 tot_size +=3D psize; } =20 - kinfo->mem.nr_banks =3D ++gbank; + mem->nr_banks =3D ++gbank; =20 kinfo->unassigned_mem -=3D tot_size; /* @@ -190,6 +191,7 @@ void __init allocate_static_memory(struct domain *d, st= ruct kernel_info *kinfo, void __init assign_static_memory_11(struct domain *d, struct kernel_info *= kinfo, const struct dt_device_node *node) { + struct membanks *mem =3D kernel_info_get_mem(kinfo); u32 addr_cells, size_cells, reg_cells; unsigned int nr_banks, bank =3D 0; const __be32 *cell; @@ -206,7 +208,7 @@ void __init assign_static_memory_11(struct domain *d, s= truct kernel_info *kinfo, reg_cells =3D addr_cells + size_cells; nr_banks =3D length / (reg_cells * sizeof(u32)); =20 - if ( nr_banks > NR_MEM_BANKS ) + if ( nr_banks > mem->max_banks ) { printk(XENLOG_ERR "%pd: exceed max number of supported guest memory banks.\n"= , d); @@ -224,15 +226,15 @@ void __init assign_static_memory_11(struct domain *d,= struct kernel_info *kinfo, d, bank, pbase, pbase + psize); =20 /* One guest memory bank is matched with one physical memory bank.= */ - kinfo->mem.bank[bank].start =3D pbase; - if ( !append_static_memory_to_bank(d, &kinfo->mem.bank[bank], + mem->bank[bank].start =3D pbase; + if ( !append_static_memory_to_bank(d, &mem->bank[bank], smfn, psize) ) goto fail; =20 kinfo->unassigned_mem -=3D psize; } =20 - kinfo->mem.nr_banks =3D nr_banks; + mem->nr_banks =3D nr_banks; =20 /* * The property 'memory' should match the amount of memory given to @@ -257,14 +259,15 @@ void __init assign_static_memory_11(struct domain *d,= struct kernel_info *kinfo, /* Static memory initialization */ void __init init_staticmem_pages(void) { + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); unsigned int bank; =20 - for ( bank =3D 0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) + for ( bank =3D 0 ; bank < reserved_mem->nr_banks; bank++ ) { - if ( bootinfo.reserved_mem.bank[bank].type =3D=3D MEMBANK_STATIC_D= OMAIN ) + if ( reserved_mem->bank[bank].type =3D=3D MEMBANK_STATIC_DOMAIN ) { - 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_start =3D _mfn(PFN_UP(reserved_mem->bank[bank].star= t)); + unsigned long bank_pages =3D PFN_DOWN(reserved_mem->bank[bank]= .size); mfn_t bank_end =3D mfn_add(bank_start, bank_pages); =20 if ( mfn_x(bank_end) <=3D mfn_x(bank_start) ) diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 349b85667684..11f3c0da81a4 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -10,22 +10,23 @@ static int __init acquire_nr_borrower_domain(struct dom= ain *d, paddr_t pbase, paddr_t psize, unsigned long *nr_borrowers) { + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); unsigned int bank; =20 /* Iterate reserved memory to find requested shm bank. */ - for ( bank =3D 0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) + for ( bank =3D 0 ; bank < reserved_mem->nr_banks; bank++ ) { - paddr_t bank_start =3D bootinfo.reserved_mem.bank[bank].start; - paddr_t bank_size =3D bootinfo.reserved_mem.bank[bank].size; + paddr_t bank_start =3D reserved_mem->bank[bank].start; + paddr_t bank_size =3D reserved_mem->bank[bank].size; =20 if ( (pbase =3D=3D bank_start) && (psize =3D=3D bank_size) ) break; } =20 - if ( bank =3D=3D bootinfo.reserved_mem.nr_banks ) + if ( bank =3D=3D reserved_mem->nr_banks ) return -ENOENT; =20 - *nr_borrowers =3D bootinfo.reserved_mem.bank[bank].nr_shm_borrowers; + *nr_borrowers =3D reserved_mem->bank[bank].nr_shm_borrowers; =20 return 0; } @@ -157,17 +158,17 @@ static int __init assign_shared_memory(struct domain = *d, return ret; } =20 -static int __init append_shm_bank_to_domain(struct kernel_info *kinfo, +static int __init append_shm_bank_to_domain(struct membanks *shm_mem, paddr_t start, paddr_t size, const char *shm_id) { - if ( kinfo->shm_mem.nr_banks >=3D NR_MEM_BANKS ) + if ( shm_mem->nr_banks >=3D shm_mem->max_banks ) return -ENOMEM; =20 - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].start =3D start; - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].size =3D size; - safe_strcpy(kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].shm_id, shm_i= d); - kinfo->shm_mem.nr_banks++; + shm_mem->bank[shm_mem->nr_banks].start =3D start; + shm_mem->bank[shm_mem->nr_banks].size =3D size; + safe_strcpy(shm_mem->bank[shm_mem->nr_banks].shm_id, shm_id); + shm_mem->nr_banks++; =20 return 0; } @@ -269,7 +270,8 @@ int __init process_shm(struct domain *d, struct kernel_= info *kinfo, * Record static shared memory region info for later setting * up shm-node in guest device tree. */ - ret =3D append_shm_bank_to_domain(kinfo, gbase, psize, shm_id); + ret =3D append_shm_bank_to_domain(&kinfo->shm_mem.common, gbase, p= size, + shm_id); if ( ret ) return ret; } @@ -280,7 +282,7 @@ int __init process_shm(struct domain *d, struct kernel_= info *kinfo, static int __init make_shm_memory_node(const struct kernel_info *kinfo, int addrcells, int sizecells) { - const struct meminfo *mem =3D &kinfo->shm_mem; + const struct membanks *mem =3D &kinfo->shm_mem.common; void *fdt =3D kinfo->fdt; unsigned int i =3D 0; int res =3D 0; @@ -351,7 +353,7 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, const struct fdt_property *prop, *prop_id, *prop_role; const __be32 *cell; paddr_t paddr, gaddr, size, end; - struct meminfo *mem =3D &bootinfo.reserved_mem; + struct membanks *mem =3D bootinfo_get_reserved_mem(); unsigned int i; int len; bool owner =3D false; @@ -461,7 +463,7 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, =20 if ( i =3D=3D mem->nr_banks ) { - if ( i < NR_MEM_BANKS ) + if (i < mem->max_banks) { if ( check_reserved_regions_overlap(paddr, size) ) return -EINVAL; @@ -492,7 +494,7 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, int __init make_resv_memory_node(const struct kernel_info *kinfo, int addr= cells, int sizecells) { - const struct meminfo *mem =3D &kinfo->shm_mem; + const struct membanks *mem =3D &kinfo->shm_mem.common; void *fdt =3D kinfo->fdt; int res =3D 0; /* Placeholder for reserved-memory\0 */ --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425855534198.23292992838094; Thu, 18 Apr 2024 00:37:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708014.1106565 (Exim 4.92) (envelope-from ) id 1rxMKW-00059Q-6N; Thu, 18 Apr 2024 07:37:12 +0000 Received: by outflank-mailman (output) from mailman id 708014.1106565; Thu, 18 Apr 2024 07:37:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKW-00059B-1o; Thu, 18 Apr 2024 07:37:12 +0000 Received: by outflank-mailman (input) for mailman id 708014; Thu, 18 Apr 2024 07:37:10 +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 1rxMKU-00046V-Rx for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:10 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7600a980-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:08 +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 6FBCD339; Thu, 18 Apr 2024 00:37:36 -0700 (PDT) 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 C104C3F64C; Thu, 18 Apr 2024 00:37:07 -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: 7600a980-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 05/12] xen/arm: Conditional compilation of kernel_info.shm_mem member Date: Thu, 18 Apr 2024 08:36:45 +0100 Message-Id: <20240418073652.3622828-6-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425857868100001 Content-Type: text/plain; charset="utf-8" The user of shm_mem member of the 'struct kernel_info' is only the code managing the static shared memory feature, which can be compiled out using CONFIG_STATIC_SHM, so in case the feature is not requested, that member won't be used and will waste memory space. To address this issue, protect the member with the Kconfig parameter and modify the signature of the only function using it to remove any reference to the member from outside the static-shmem module. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v2: - add Michal R-by - Removed the signature modification of make_resv_memory_node from this patch v1: - new patch --- --- xen/arch/arm/include/asm/kernel.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/k= ernel.h index d46f29ee6ce5..eb3cb7809ccf 100644 --- a/xen/arch/arm/include/asm/kernel.h +++ b/xen/arch/arm/include/asm/kernel.h @@ -39,7 +39,9 @@ struct kernel_info { void *fdt; /* flat device tree */ paddr_t unassigned_mem; /* RAM not (yet) assigned to a bank */ struct meminfo mem; +#ifdef CONFIG_STATIC_SHM struct meminfo shm_mem; +#endif =20 /* kernel entry point */ paddr_t entry; @@ -80,10 +82,16 @@ struct kernel_info { =20 #define kernel_info_get_mem(kinfo) (&(kinfo)->mem.common) =20 +#ifdef CONFIG_STATIC_SHM +#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks =3D NR_MEM_BANK= S, +#else +#define KERNEL_INFO_SHM_MEM_INIT +#endif + #define KERNEL_INFO_INIT \ { \ .mem.common.max_banks =3D NR_MEM_BANKS, \ - .shm_mem.common.max_banks =3D NR_MEM_BANKS, \ + KERNEL_INFO_SHM_MEM_INIT \ } =20 /* --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425850922855.9507962690444; Thu, 18 Apr 2024 00:37:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708015.1106570 (Exim 4.92) (envelope-from ) id 1rxMKW-0005CA-Ep; Thu, 18 Apr 2024 07:37:12 +0000 Received: by outflank-mailman (output) from mailman id 708015.1106570; Thu, 18 Apr 2024 07:37:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKW-0005B7-98; Thu, 18 Apr 2024 07:37:12 +0000 Received: by outflank-mailman (input) for mailman id 708015; Thu, 18 Apr 2024 07:37:11 +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 1rxMKV-00057l-Gq for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:11 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7723327f-fd56-11ee-b909-491648fe20b8; Thu, 18 Apr 2024 09:37:10 +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 B6A791576; Thu, 18 Apr 2024 00:37:37 -0700 (PDT) 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 141503F64C; Thu, 18 Apr 2024 00:37:08 -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: 7723327f-fd56-11ee-b909-491648fe20b8 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 06/12] xen/arm: Avoid code duplication in find_unallocated_memory Date: Thu, 18 Apr 2024 08:36:46 +0100 Message-Id: <20240418073652.3622828-7-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425851733100001 Content-Type: text/plain; charset="utf-8" The function find_unallocated_memory is using the same code to loop through 2 structure of the same type, in order to avoid code duplication, rework the code to have only one loop that goes through all the structures, this will be used to avoid duplication when the static shared memory banks will be introduced as a separate structure from reserved memory. Take the occasion to add the error code to the error message in case 'rangeset_remove_range' fails. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3: - Fixed the wrong logic, now the function correctly adds the available ram to the rangeset and afterwards removes the Dom0 memory and reserved memory from it. - take the occasion to print the error code in the error message as explained in the commit msg. v2: - Add comment in the loop inside find_unallocated_memory to improve readability v1: - new patch --- --- xen/arch/arm/domain_build.c | 53 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 02e4dcafe78f..7c7038254473 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -868,12 +868,14 @@ static int __init add_ext_regions(unsigned long s_gfn= , unsigned long e_gfn, static int __init find_unallocated_memory(const struct kernel_info *kinfo, struct membanks *ext_regions) { - const struct membanks *kinfo_mem =3D kernel_info_get_mem(kinfo); const struct membanks *mem =3D bootinfo_get_mem(); - const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); + const struct membanks *mem_banks[] =3D { + kernel_info_get_mem(kinfo), + bootinfo_get_reserved_mem(), + }; struct rangeset *unalloc_mem; paddr_t start, end; - unsigned int i; + unsigned int i, j; int res; =20 dt_dprintk("Find unallocated memory for extended regions\n"); @@ -897,35 +899,26 @@ static int __init find_unallocated_memory(const struc= t kernel_info *kinfo, } } =20 - /* Remove RAM assigned to Dom0 */ - for ( i =3D 0; i < kinfo_mem->nr_banks; i++ ) - { - start =3D kinfo_mem->bank[i].start; - end =3D kinfo_mem->bank[i].start + kinfo_mem->bank[i].size; - res =3D rangeset_remove_range(unalloc_mem, PFN_DOWN(start), - PFN_DOWN(end - 1)); - if ( res ) - { - printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr= "\n", - start, end); - goto out; - } - } - - /* Remove reserved-memory regions */ - for ( i =3D 0; i < reserved_mem->nr_banks; i++ ) - { - start =3D reserved_mem->bank[i].start; - end =3D reserved_mem->bank[i].start + reserved_mem->bank[i].size; - res =3D rangeset_remove_range(unalloc_mem, PFN_DOWN(start), - PFN_DOWN(end - 1)); - if ( res ) + /* + * Exclude the following regions: + * 1) Remove RAM assigned to Dom0 + * 2) Remove reserved memory + */ + for ( i =3D 0; i < ARRAY_SIZE(mem_banks); i++ ) + for ( j =3D 0; j < mem_banks[i]->nr_banks; j++ ) { - printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr= "\n", - start, end); - goto out; + start =3D mem_banks[i]->bank[j].start; + end =3D mem_banks[i]->bank[j].start + mem_banks[i]->bank[j].si= ze; + res =3D rangeset_remove_range(unalloc_mem, PFN_DOWN(start), + PFN_DOWN(end - 1)); + if ( res ) + { + printk(XENLOG_ERR + "Failed to add: %#"PRIpaddr"->%#"PRIpaddr", error %= d\n", + start, end, res); + goto out; + } } - } =20 /* Remove grant table region */ if ( kinfo->gnttab_size ) --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425856086546.0029875910609; Thu, 18 Apr 2024 00:37:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708017.1106592 (Exim 4.92) (envelope-from ) id 1rxMKY-0005qh-Og; Thu, 18 Apr 2024 07:37:14 +0000 Received: by outflank-mailman (output) from mailman id 708017.1106592; Thu, 18 Apr 2024 07:37:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKY-0005pT-Ha; Thu, 18 Apr 2024 07:37:14 +0000 Received: by outflank-mailman (input) for mailman id 708017; Thu, 18 Apr 2024 07:37:13 +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 1rxMKX-00046V-9h for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:13 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 778a20b6-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:11 +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 099E81595; Thu, 18 Apr 2024 00:37:39 -0700 (PDT) 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 5B2463F64C; Thu, 18 Apr 2024 00:37:10 -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: 778a20b6-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 07/12] xen/arm: Avoid code duplication in check_reserved_regions_overlap Date: Thu, 18 Apr 2024 08:36:47 +0100 Message-Id: <20240418073652.3622828-8-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425857868100002 Content-Type: text/plain; charset="utf-8" The function check_reserved_regions_overlap is calling 'meminfo_overlap_check' on the same type of structure, this code can be written in a way to avoid code duplication, so rework the function to do that. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3: - add Michal R-by v2: - no changes v1: - new patch --- --- xen/arch/arm/setup.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index e00dbb135113..003b0446af27 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -340,25 +340,27 @@ void __init fw_unreserved_regions(paddr_t s, paddr_t = e, bool __init check_reserved_regions_overlap(paddr_t region_start, paddr_t region_size) { + const struct membanks *mem_banks[] =3D { + bootinfo_get_reserved_mem(), +#ifdef CONFIG_ACPI + bootinfo_get_acpi(), +#endif + }; + unsigned int i; + /* - * Check if input region is overlapping with bootinfo_get_reserved_mem= () - * banks + * Check if input region is overlapping with reserved memory banks or + * ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) */ - if ( meminfo_overlap_check(bootinfo_get_reserved_mem(), - region_start, region_size) ) - return true; + for ( i =3D 0; i < ARRAY_SIZE(mem_banks); i++ ) + if ( meminfo_overlap_check(mem_banks[i], region_start, region_size= ) ) + return true; =20 /* Check if input region is overlapping with bootmodules */ if ( bootmodules_overlap_check(&bootinfo.modules, region_start, region_size) ) return true; =20 -#ifdef CONFIG_ACPI - /* Check if input region is overlapping with ACPI EfiACPIReclaimMemory= */ - if ( meminfo_overlap_check(bootinfo_get_acpi(), region_start, region_s= ize) ) - return true; -#endif - return false; } =20 --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425861059485.6692243141538; Thu, 18 Apr 2024 00:37:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708018.1106604 (Exim 4.92) (envelope-from ) id 1rxMKa-0006BJ-3M; Thu, 18 Apr 2024 07:37:16 +0000 Received: by outflank-mailman (output) from mailman id 708018.1106604; Thu, 18 Apr 2024 07:37:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKZ-0006At-SA; Thu, 18 Apr 2024 07:37:15 +0000 Received: by outflank-mailman (input) for mailman id 708018; Thu, 18 Apr 2024 07:37:14 +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 1rxMKY-00046V-Li for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:14 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 78549005-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:12 +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 50D75DA7; Thu, 18 Apr 2024 00:37:40 -0700 (PDT) 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 A260A3F64C; Thu, 18 Apr 2024 00:37:11 -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: 78549005-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 08/12] xen/arm: Introduce helper for static memory pages Date: Thu, 18 Apr 2024 08:36:48 +0100 Message-Id: <20240418073652.3622828-9-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425861693100007 Content-Type: text/plain; charset="utf-8" Introduce a new helper function in the static-memory module that can be called to manage static memory banks, this is done to reuse the code when other modules would like to manage static memory banks that are not part of the reserved_mem structure, this is done because the static shared memory banks will be removed from reserved_mem. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v2: - Add Michal R-by - Changed commit msg v1: - new patch --- --- xen/arch/arm/include/asm/static-memory.h | 13 +++++++++++++ xen/arch/arm/static-memory.c | 12 +----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/include/asm/static-memory.h b/xen/arch/arm/includ= e/asm/static-memory.h index 3e3efd70c38d..804166e541ef 100644 --- a/xen/arch/arm/include/asm/static-memory.h +++ b/xen/arch/arm/include/asm/static-memory.h @@ -3,10 +3,23 @@ #ifndef __ASM_STATIC_MEMORY_H_ #define __ASM_STATIC_MEMORY_H_ =20 +#include #include =20 #ifdef CONFIG_STATIC_MEMORY =20 +static inline void init_staticmem_bank(const struct membank *bank) +{ + mfn_t bank_start =3D _mfn(PFN_UP(bank->start)); + unsigned long bank_pages =3D PFN_DOWN(bank->size); + mfn_t bank_end =3D mfn_add(bank_start, bank_pages); + + if ( mfn_x(bank_end) <=3D mfn_x(bank_start) ) + return; + + unprepare_staticmem_pages(mfn_to_page(bank_start), bank_pages, false); +} + void allocate_static_memory(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node); void assign_static_memory_11(struct domain *d, struct kernel_info *kinfo, diff --git a/xen/arch/arm/static-memory.c b/xen/arch/arm/static-memory.c index 34bd12696a53..d4585c5a0633 100644 --- a/xen/arch/arm/static-memory.c +++ b/xen/arch/arm/static-memory.c @@ -265,17 +265,7 @@ void __init init_staticmem_pages(void) for ( bank =3D 0 ; bank < reserved_mem->nr_banks; bank++ ) { if ( reserved_mem->bank[bank].type =3D=3D MEMBANK_STATIC_DOMAIN ) - { - mfn_t bank_start =3D _mfn(PFN_UP(reserved_mem->bank[bank].star= t)); - unsigned long bank_pages =3D PFN_DOWN(reserved_mem->bank[bank]= .size); - mfn_t bank_end =3D mfn_add(bank_start, bank_pages); - - if ( mfn_x(bank_end) <=3D mfn_x(bank_start) ) - return; - - unprepare_staticmem_pages(mfn_to_page(bank_start), - bank_pages, false); - } + init_staticmem_bank(&reserved_mem->bank[bank]); } } =20 --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425859603536.7201384265277; Thu, 18 Apr 2024 00:37:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708019.1106614 (Exim 4.92) (envelope-from ) id 1rxMKc-0006gU-H9; Thu, 18 Apr 2024 07:37:18 +0000 Received: by outflank-mailman (output) from mailman id 708019.1106614; Thu, 18 Apr 2024 07:37:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKc-0006gB-Bz; Thu, 18 Apr 2024 07:37:18 +0000 Received: by outflank-mailman (input) for mailman id 708019; Thu, 18 Apr 2024 07:37:17 +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 1rxMKb-00046V-Iq for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:17 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 79146624-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:13 +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 98ED2339; Thu, 18 Apr 2024 00:37:41 -0700 (PDT) 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 EA84C3F64C; Thu, 18 Apr 2024 00:37:12 -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: 79146624-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 09/12] xen/arm: Reduce struct membank size on static shared memory Date: Thu, 18 Apr 2024 08:36:49 +0100 Message-Id: <20240418073652.3622828-10-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425859750100005 Content-Type: text/plain; charset="utf-8" Currently the memory footprint of the static shared memory feature is impacting all the struct meminfo instances with memory space that is not going to be used. To solve this issue, rework the static shared memory extra information linked to the memory bank to another structure, struct shmem_membank_extra, and exploit the struct membank padding to host a pointer to that structure in a union with the enum membank_type, with this trick the 'struct membank' has the same size with or without the static shared memory, given that the 'type' and 'shmem_extra' are never used at the same time, hence the 'struct membank' won't grow in size. Afterwards, create a new structure 'struct shared_meminfo' which has the same interface of 'struct meminfo', but requires less banks, defined by the number in NR_SHMEM_BANKS, which is 32 at the moment and should be enough for the current use cases, the value might be increased in te future if needed. Finally, this structure hosts also the extra information for the static shared memory banks. The fields 'bank' and 'extra' of this structure are meant to be linked by the index (e.g. extra[idx] will have the information for the bank[idx], for i=3D0..NR_SHMEM_BANKS), the convinient pointer 'shmem_extra' of 'struct membank' is then linked to the related 'extra' bank to ease the fruition when a function has access only to the 'struct membanks common' of 'struct shared_meminfo'. The last part of this work is to move the allocation of the static shared memory banks from the 'reserved_mem' to a new 'shmem' member of the 'struct bootinfo'. Change also the 'shm_mem' member type to be 'struct shared_meminfo' in order to match the above changes and allow a memory space reduction also in 'struct kernel_info'. Now that the structure Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3: - rebase changes, improved comment in find_unallocated_memory - Add Michal R-by v2: - Made clear that the struct membank is not growing in size in the commit message. - Add static assert for the struct shared_meminfo bank field. v1: - new patch --- --- xen/arch/arm/arm32/mmu/mm.c | 24 ++++++++ xen/arch/arm/arm64/mmu/mm.c | 2 + xen/arch/arm/bootfdt.c | 1 + xen/arch/arm/domain_build.c | 5 ++ xen/arch/arm/include/asm/kernel.h | 4 +- xen/arch/arm/include/asm/setup.h | 41 ++++++++++++- xen/arch/arm/include/asm/static-shmem.h | 8 +++ xen/arch/arm/setup.c | 25 +++++++- xen/arch/arm/static-shmem.c | 79 +++++++++++++++++++------ 9 files changed, 165 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/arm32/mmu/mm.c b/xen/arch/arm/arm32/mmu/mm.c index 84c89da909bf..23150122f7c4 100644 --- a/xen/arch/arm/arm32/mmu/mm.c +++ b/xen/arch/arm/arm32/mmu/mm.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 static unsigned long opt_xenheap_megabytes __initdata; integer_param("xenheap_megabytes", opt_xenheap_megabytes); @@ -43,6 +44,9 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t= e, int first_mod) { const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); +#ifdef CONFIG_STATIC_SHM + const struct membanks *shmem =3D bootinfo_get_shmem(); +#endif const struct bootmodules *mi =3D &bootinfo.modules; int i; int nr; @@ -119,6 +123,25 @@ static paddr_t __init consider_modules(paddr_t s, padd= r_t e, return consider_modules(s, r_s, size, align, i + 1); } } + +#ifdef CONFIG_STATIC_SHM + nr +=3D reserved_mem->nr_banks; + for ( ; i - nr < shmem->nr_banks; i++ ) + { + paddr_t r_s =3D shmem->bank[i - nr].start; + paddr_t r_e =3D r_s + shmem->bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + r_e =3D consider_modules(r_e, e, size, align, i + 1); + if ( r_e ) + return r_e; + + return consider_modules(s, r_s, size, align, i + 1); + } + } +#endif + return e; } =20 @@ -295,6 +318,7 @@ void __init setup_mm(void) mfn_to_maddr(directmap_mfn_end)); =20 init_staticmem_pages(); + init_sharedmem_pages(); } =20 /* diff --git a/xen/arch/arm/arm64/mmu/mm.c b/xen/arch/arm/arm64/mmu/mm.c index f8aaf4ac18be..293acb67e09c 100644 --- a/xen/arch/arm/arm64/mmu/mm.c +++ b/xen/arch/arm/arm64/mmu/mm.c @@ -6,6 +6,7 @@ =20 #include #include +#include =20 /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn @@ -236,6 +237,7 @@ void __init setup_mm(void) max_page =3D PFN_DOWN(ram_end); =20 init_staticmem_pages(); + init_sharedmem_pages(); } =20 /* diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 4c80962f79d4..4d708442a19e 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -511,6 +511,7 @@ static void __init early_print_info(void) mem_resv->bank[j].start, mem_resv->bank[j].start + mem_resv->bank[j].size - 1); } + early_print_info_shmem(); printk("\n"); for ( i =3D 0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start, diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 7c7038254473..2fc7feeae3c3 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -863,6 +863,7 @@ static int __init add_ext_regions(unsigned long s_gfn, = unsigned long e_gfn, * regions we exclude every region assigned to Dom0 from the Host RAM: * - domain RAM * - reserved-memory + * - static shared memory * - grant table space */ static int __init find_unallocated_memory(const struct kernel_info *kinfo, @@ -872,6 +873,9 @@ static int __init find_unallocated_memory(const struct = kernel_info *kinfo, const struct membanks *mem_banks[] =3D { kernel_info_get_mem(kinfo), bootinfo_get_reserved_mem(), +#ifdef CONFIG_STATIC_SHM + bootinfo_get_shmem(), +#endif }; struct rangeset *unalloc_mem; paddr_t start, end; @@ -903,6 +907,7 @@ static int __init find_unallocated_memory(const struct = kernel_info *kinfo, * Exclude the following regions: * 1) Remove RAM assigned to Dom0 * 2) Remove reserved memory + * 3) Remove static shared memory (when the feature is enabled) */ for ( i =3D 0; i < ARRAY_SIZE(mem_banks); i++ ) for ( j =3D 0; j < mem_banks[i]->nr_banks; j++ ) diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/k= ernel.h index eb3cb7809ccf..16a2bfc01e27 100644 --- a/xen/arch/arm/include/asm/kernel.h +++ b/xen/arch/arm/include/asm/kernel.h @@ -40,7 +40,7 @@ struct kernel_info { paddr_t unassigned_mem; /* RAM not (yet) assigned to a bank */ struct meminfo mem; #ifdef CONFIG_STATIC_SHM - struct meminfo shm_mem; + struct shared_meminfo shm_mem; #endif =20 /* kernel entry point */ @@ -83,7 +83,7 @@ struct kernel_info { #define kernel_info_get_mem(kinfo) (&(kinfo)->mem.common) =20 #ifdef CONFIG_STATIC_SHM -#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks =3D NR_MEM_BANK= S, +#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks =3D NR_SHMEM_BA= NKS, #else #define KERNEL_INFO_SHM_MEM_INIT #endif diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 696f55db86b1..28fb659fe946 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -9,6 +9,7 @@ #define MAX_FDT_SIZE SZ_2M =20 #define NR_MEM_BANKS 256 +#define NR_SHMEM_BANKS 32 =20 #define MAX_MODULES 32 /* Current maximum useful modules */ =20 @@ -46,14 +47,20 @@ enum membank_type { /* Indicates the maximum number of characters(\0 included) for shm_id */ #define MAX_SHM_ID_LENGTH 16 =20 +struct shmem_membank_extra { + char shm_id[MAX_SHM_ID_LENGTH]; + unsigned int nr_shm_borrowers; +}; + struct membank { paddr_t start; paddr_t size; - enum membank_type type; + union { + enum membank_type type; #ifdef CONFIG_STATIC_SHM - char shm_id[MAX_SHM_ID_LENGTH]; - unsigned int nr_shm_borrowers; + struct shmem_membank_extra *shmem_extra; #endif + }; }; =20 struct membanks { @@ -67,6 +74,12 @@ struct meminfo { struct membank bank[NR_MEM_BANKS]; }; =20 +struct shared_meminfo { + struct membanks common; + struct membank bank[NR_SHMEM_BANKS]; + struct shmem_membank_extra extra[NR_SHMEM_BANKS]; +}; + /* * The domU flag is set for kernels and ramdisks of "xen,domain" nodes. * The purpose of the domU flag is to avoid getting confused in @@ -109,6 +122,9 @@ struct bootinfo { struct bootcmdlines cmdlines; #ifdef CONFIG_ACPI struct meminfo acpi; +#endif +#ifdef CONFIG_STATIC_SHM + struct shared_meminfo shmem; #endif bool static_heap; }; @@ -119,11 +135,18 @@ struct bootinfo { #define BOOTINFO_ACPI_INIT #endif =20 +#ifdef CONFIG_STATIC_SHM +#define BOOTINFO_SHMEM_INIT .shmem.common.max_banks =3D NR_SHMEM_BANKS, +#else +#define BOOTINFO_SHMEM_INIT +#endif + #define BOOTINFO_INIT \ { \ .mem.common.max_banks =3D NR_MEM_BANKS, \ .reserved_mem.common.max_banks =3D NR_MEM_BANKS, \ BOOTINFO_ACPI_INIT \ + BOOTINFO_SHMEM_INIT \ } =20 struct map_range_data @@ -158,6 +181,18 @@ static inline struct membanks *bootinfo_get_acpi(void) } #endif =20 +#ifdef CONFIG_STATIC_SHM +static inline struct membanks *bootinfo_get_shmem(void) +{ + return &bootinfo.shmem.common; +} + +static inline struct shmem_membank_extra *bootinfo_get_shmem_extra(void) +{ + return bootinfo.shmem.extra; +} +#endif + void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); =20 size_t estimate_efi_size(unsigned int mem_nr_banks); diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include= /asm/static-shmem.h index 680594b6843d..90aafc81e740 100644 --- a/xen/arch/arm/include/asm/static-shmem.h +++ b/xen/arch/arm/include/asm/static-shmem.h @@ -24,6 +24,10 @@ static inline int process_shm_chosen(struct domain *d, int process_shm_node(const void *fdt, int node, uint32_t address_cells, uint32_t size_cells); =20 +void early_print_info_shmem(void); + +void init_sharedmem_pages(void); + #else /* !CONFIG_STATIC_SHM */ =20 static inline int make_resv_memory_node(const struct kernel_info *kinfo, @@ -51,6 +55,10 @@ static inline int process_shm_node(const void *fdt, int = node, return -EINVAL; } =20 +static inline void early_print_info_shmem(void) {}; + +static inline void init_sharedmem_pages(void) {}; + #endif /* CONFIG_STATIC_SHM */ =20 #endif /* __ASM_STATIC_SHMEM_H_ */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 003b0446af27..d242674381d4 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -208,6 +208,9 @@ static void __init dt_unreserved_regions(paddr_t s, pad= dr_t e, unsigned int first) { const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); +#ifdef CONFIG_STATIC_SHM + const struct membanks *shmem =3D bootinfo_get_shmem(); +#endif unsigned int i, nr; int rc; =20 @@ -258,6 +261,22 @@ static void __init dt_unreserved_regions(paddr_t s, pa= ddr_t e, } } =20 +#ifdef CONFIG_STATIC_SHM + nr +=3D reserved_mem->nr_banks; + for ( ; i - nr < shmem->nr_banks; i++ ) + { + paddr_t r_s =3D shmem->bank[i - nr].start; + paddr_t r_e =3D r_s + shmem->bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + dt_unreserved_regions(r_e, e, cb, i + 1); + dt_unreserved_regions(s, r_s, cb, i + 1); + return; + } + } +#endif + cb(s, e); } =20 @@ -344,13 +363,17 @@ bool __init check_reserved_regions_overlap(paddr_t re= gion_start, bootinfo_get_reserved_mem(), #ifdef CONFIG_ACPI bootinfo_get_acpi(), +#endif +#ifdef CONFIG_STATIC_SHM + bootinfo_get_shmem(), #endif }; unsigned int i; =20 /* * Check if input region is overlapping with reserved memory banks or - * ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) + * ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) or static + * shared memory banks (when static shared memory feature is enabled) */ for ( i =3D 0; i < ARRAY_SIZE(mem_banks); i++ ) if ( meminfo_overlap_check(mem_banks[i], region_start, region_size= ) ) diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 11f3c0da81a4..fcf8227bf404 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -4,29 +4,40 @@ #include =20 #include +#include #include =20 +static void __init __maybe_unused build_assertions(void) +{ + /* + * Check that no padding is between struct membanks "bank" flexible ar= ray + * member and struct shared_meminfo "bank" member + */ + BUILD_BUG_ON((offsetof(struct membanks, bank) !=3D + offsetof(struct shared_meminfo, bank))); +} + static int __init acquire_nr_borrower_domain(struct domain *d, paddr_t pbase, paddr_t psize, unsigned long *nr_borrowers) { - const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); + const struct membanks *shmem =3D bootinfo_get_shmem(); unsigned int bank; =20 /* Iterate reserved memory to find requested shm bank. */ - for ( bank =3D 0 ; bank < reserved_mem->nr_banks; bank++ ) + for ( bank =3D 0 ; bank < shmem->nr_banks; bank++ ) { - paddr_t bank_start =3D reserved_mem->bank[bank].start; - paddr_t bank_size =3D reserved_mem->bank[bank].size; + paddr_t bank_start =3D shmem->bank[bank].start; + paddr_t bank_size =3D shmem->bank[bank].size; =20 if ( (pbase =3D=3D bank_start) && (psize =3D=3D bank_size) ) break; } =20 - if ( bank =3D=3D reserved_mem->nr_banks ) + if ( bank =3D=3D shmem->nr_banks ) return -ENOENT; =20 - *nr_borrowers =3D reserved_mem->bank[bank].nr_shm_borrowers; + *nr_borrowers =3D shmem->bank[bank].shmem_extra->nr_shm_borrowers; =20 return 0; } @@ -158,16 +169,22 @@ static int __init assign_shared_memory(struct domain = *d, return ret; } =20 -static int __init append_shm_bank_to_domain(struct membanks *shm_mem, - paddr_t start, paddr_t size, - const char *shm_id) +static int __init +append_shm_bank_to_domain(struct shared_meminfo *kinfo_shm_mem, paddr_t st= art, + paddr_t size, const char *shm_id) { + struct membanks *shm_mem =3D &kinfo_shm_mem->common; + struct shmem_membank_extra *shm_mem_extra; + if ( shm_mem->nr_banks >=3D shm_mem->max_banks ) return -ENOMEM; =20 + shm_mem_extra =3D &kinfo_shm_mem->extra[shm_mem->nr_banks]; + shm_mem->bank[shm_mem->nr_banks].start =3D start; shm_mem->bank[shm_mem->nr_banks].size =3D size; - safe_strcpy(shm_mem->bank[shm_mem->nr_banks].shm_id, shm_id); + safe_strcpy(shm_mem_extra->shm_id, shm_id); + shm_mem->bank[shm_mem->nr_banks].shmem_extra =3D shm_mem_extra; shm_mem->nr_banks++; =20 return 0; @@ -270,7 +287,7 @@ int __init process_shm(struct domain *d, struct kernel_= info *kinfo, * Record static shared memory region info for later setting * up shm-node in guest device tree. */ - ret =3D append_shm_bank_to_domain(&kinfo->shm_mem.common, gbase, p= size, + ret =3D append_shm_bank_to_domain(&kinfo->shm_mem, gbase, psize, shm_id); if ( ret ) return ret; @@ -325,7 +342,8 @@ static int __init make_shm_memory_node(const struct ker= nel_info *kinfo, dt_dprintk("Shared memory bank %u: %#"PRIx64"->%#"PRIx64"\n", i, start, start + size); =20 - res =3D fdt_property_string(fdt, "xen,id", mem->bank[i].shm_id); + res =3D fdt_property_string(fdt, "xen,id", + mem->bank[i].shmem_extra->shm_id); if ( res ) return res; =20 @@ -353,7 +371,8 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, const struct fdt_property *prop, *prop_id, *prop_role; const __be32 *cell; paddr_t paddr, gaddr, size, end; - struct membanks *mem =3D bootinfo_get_reserved_mem(); + struct membanks *mem =3D bootinfo_get_shmem(); + struct shmem_membank_extra *shmem_extra =3D bootinfo_get_shmem_extra(); unsigned int i; int len; bool owner =3D false; @@ -442,7 +461,8 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, */ if ( paddr =3D=3D mem->bank[i].start && size =3D=3D mem->bank[i].s= ize ) { - if ( strncmp(shm_id, mem->bank[i].shm_id, MAX_SHM_ID_LENGTH) = =3D=3D 0 ) + if ( strncmp(shm_id, shmem_extra[i].shm_id, + MAX_SHM_ID_LENGTH) =3D=3D 0 ) break; else { @@ -451,7 +471,8 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, return -EINVAL; } } - else if ( strncmp(shm_id, mem->bank[i].shm_id, MAX_SHM_ID_LENGTH) = !=3D 0 ) + else if ( strncmp(shm_id, shmem_extra[i].shm_id, + MAX_SHM_ID_LENGTH) !=3D 0 ) continue; else { @@ -469,10 +490,10 @@ int __init process_shm_node(const void *fdt, int node= , uint32_t address_cells, return -EINVAL; =20 /* Static shared memory shall be reserved from any other use. = */ - safe_strcpy(mem->bank[mem->nr_banks].shm_id, shm_id); + safe_strcpy(shmem_extra[mem->nr_banks].shm_id, shm_id); mem->bank[mem->nr_banks].start =3D paddr; mem->bank[mem->nr_banks].size =3D size; - mem->bank[mem->nr_banks].type =3D MEMBANK_STATIC_DOMAIN; + mem->bank[mem->nr_banks].shmem_extra =3D &shmem_extra[mem->nr_= banks]; mem->nr_banks++; } else @@ -486,7 +507,7 @@ int __init process_shm_node(const void *fdt, int node, = uint32_t address_cells, * to calculate the reference count. */ if ( !owner ) - mem->bank[i].nr_shm_borrowers++; + shmem_extra[i].nr_shm_borrowers++; =20 return 0; } @@ -531,6 +552,28 @@ int __init make_resv_memory_node(const struct kernel_i= nfo *kinfo, int addrcells, return res; } =20 +void __init early_print_info_shmem(void) +{ + const struct membanks *shmem =3D bootinfo_get_shmem(); + unsigned int bank; + + for ( bank =3D 0; bank < shmem->nr_banks; bank++ ) + { + printk(" SHMEM[%u]: %"PRIpaddr" - %"PRIpaddr"\n", bank, + shmem->bank[bank].start, + shmem->bank[bank].start + shmem->bank[bank].size - 1); + } +} + +void __init init_sharedmem_pages(void) +{ + const struct membanks *shmem =3D bootinfo_get_shmem(); + unsigned int bank; + + for ( bank =3D 0 ; bank < shmem->nr_banks; bank++ ) + init_staticmem_bank(&shmem->bank[bank]); +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713425863998572.1069053614092; Thu, 18 Apr 2024 00:37:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708020.1106624 (Exim 4.92) (envelope-from ) id 1rxMKe-00073G-3x; Thu, 18 Apr 2024 07:37:20 +0000 Received: by outflank-mailman (output) from mailman id 708020.1106624; Thu, 18 Apr 2024 07:37:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMKe-000728-0q; Thu, 18 Apr 2024 07:37:20 +0000 Received: by outflank-mailman (input) for mailman id 708020; Thu, 18 Apr 2024 07:37:18 +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 1rxMKc-00046V-Is for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:18 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7a0205ce-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:15 +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 2B1E6DA7; Thu, 18 Apr 2024 00:37:43 -0700 (PDT) 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 3E1713F64C; Thu, 18 Apr 2024 00:37:14 -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: 7a0205ce-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v3 10/12] xen/arm: remove shm holes from extended regions Date: Thu, 18 Apr 2024 08:36:50 +0100 Message-Id: <20240418073652.3622828-11-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713425865738100001 Content-Type: text/plain; charset="utf-8" From: Penny Zheng Static shared memory acts as reserved memory in guest, so it shall be excluded from extended regions. Extended regions are taken care of under three different scenarios: normal DomU, direct-map domain with iommu on, and direct-map domain with iommu off. For normal DomU, we create a new function "remove_shm_holes_for_domU", to firstly transfer original outputs into the format of "struct rangeset", then use "remove_shm_from_rangeset" to remove static shm from them. For direct-map domain with iommu on, after we get guest shm info from "kinf= o", we use "remove_shm_from_rangeset" to remove static shm. For direct-map domain with iommu off, as static shm has already been taken care of through find_unallocated_memory, we do nothing. Signed-off-by: Penny Zheng Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3: - Put size -1 inside PFN_DOWN so that error message has the 'end' unchange= d. - Add expanation comment inside remove_shm_holes_for_domU v2: - Fixed commit title, fixed comment, moved call of remove_shm_from_rangeset after populating rangeset in find_memory_holes, print error code when possible - used PFN_DOWN where needed v1: - Rework of https://patchwork.kernel.org/project/xen-devel/patch/202312060= 90623.1932275-8-Penny.Zheng@arm.com/ --- --- xen/arch/arm/domain_build.c | 16 ++++- xen/arch/arm/include/asm/domain_build.h | 2 + xen/arch/arm/include/asm/static-shmem.h | 18 +++++ xen/arch/arm/static-shmem.c | 94 +++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2fc7feeae3c3..0cc39b0bd7bb 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -816,8 +816,8 @@ int __init make_memory_node(const struct domain *d, return res; } =20 -static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, - void *data) +int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, + void *data) { struct membanks *ext_regions =3D data; paddr_t start, size; @@ -990,6 +990,8 @@ static int __init handle_pci_range(const struct dt_devi= ce_node *dev, * - MMIO * - Host RAM * - PCI aperture + * - Static shared memory regions, which are described by special property + * "xen,shared-mem" */ static int __init find_memory_holes(const struct kernel_info *kinfo, struct membanks *ext_regions) @@ -1017,6 +1019,11 @@ static int __init find_memory_holes(const struct ker= nel_info *kinfo, goto out; } =20 + /* Remove static shared memory regions */ + res =3D remove_shm_from_rangeset(kinfo, mem_holes); + if ( res ) + goto out; + /* * Remove regions described by "reg" and "ranges" properties where * the memory is addressable (MMIO, RAM, PCI BAR, etc). @@ -1109,7 +1116,10 @@ static int __init find_domU_holes(const struct kerne= l_info *kinfo, res =3D 0; } =20 - return res; + if ( res ) + return res; + + return remove_shm_holes_for_domU(kinfo, ext_regions); } =20 int __init make_hypervisor_node(struct domain *d, diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include= /asm/domain_build.h index a6f276cc4263..026d975da28e 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -51,6 +51,8 @@ static inline int prepare_acpi(struct domain *d, struct k= ernel_info *kinfo) int prepare_acpi(struct domain *d, struct kernel_info *kinfo); #endif =20 +int add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data); + #endif =20 /* diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include= /asm/static-shmem.h index 90aafc81e740..2e8b138eb989 100644 --- a/xen/arch/arm/include/asm/static-shmem.h +++ b/xen/arch/arm/include/asm/static-shmem.h @@ -28,6 +28,12 @@ void early_print_info_shmem(void); =20 void init_sharedmem_pages(void); =20 +int remove_shm_from_rangeset(const struct kernel_info *kinfo, + struct rangeset *rangeset); + +int remove_shm_holes_for_domU(const struct kernel_info *kinfo, + struct membanks *ext_regions); + #else /* !CONFIG_STATIC_SHM */ =20 static inline int make_resv_memory_node(const struct kernel_info *kinfo, @@ -59,6 +65,18 @@ static inline void early_print_info_shmem(void) {}; =20 static inline void init_sharedmem_pages(void) {}; =20 +static inline int remove_shm_from_rangeset(const struct kernel_info *kinfo, + struct rangeset *rangeset) +{ + return 0; +} + +static inline int remove_shm_holes_for_domU(const struct kernel_info *kinf= o, + struct membanks *ext_regions) +{ + return 0; +} + #endif /* CONFIG_STATIC_SHM */ =20 #endif /* __ASM_STATIC_SHMEM_H_ */ diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index fcf8227bf404..12e2df939915 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 #include +#include #include =20 #include @@ -574,6 +575,99 @@ void __init init_sharedmem_pages(void) init_staticmem_bank(&shmem->bank[bank]); } =20 +int __init remove_shm_from_rangeset(const struct kernel_info *kinfo, + struct rangeset *rangeset) +{ + const struct membanks *shm_mem =3D &kinfo->shm_mem.common; + unsigned int i; + + /* Remove static shared memory regions */ + for ( i =3D 0; i < shm_mem->nr_banks; i++ ) + { + paddr_t start, end; + int res; + + start =3D shm_mem->bank[i].start; + end =3D shm_mem->bank[i].start + shm_mem->bank[i].size; + res =3D rangeset_remove_range(rangeset, PFN_DOWN(start), + PFN_DOWN(end - 1)); + if ( res ) + { + printk(XENLOG_ERR + "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr", error: %= d\n", + start, end, res); + return -EINVAL; + } + } + + return 0; +} + +int __init remove_shm_holes_for_domU(const struct kernel_info *kinfo, + struct membanks *ext_regions) +{ + const struct membanks *shm_mem =3D &kinfo->shm_mem.common; + struct rangeset *guest_holes; + unsigned int i; + paddr_t start; + paddr_t end; + int res; + + /* No static shared memory region. */ + if ( shm_mem->nr_banks =3D=3D 0 ) + return 0; + + dt_dprintk("Remove static shared memory holes from extended regions of= DomU\n"); + + guest_holes =3D rangeset_new(NULL, NULL, 0); + if ( !guest_holes ) + return -ENOMEM; + + /* Copy extended regions sets into the rangeset */ + for ( i =3D 0; i < ext_regions->nr_banks; i++ ) + { + start =3D ext_regions->bank[i].start; + end =3D start + ext_regions->bank[i].size; + + res =3D rangeset_add_range(guest_holes, PFN_DOWN(start), + PFN_DOWN(end - 1)); + if ( res ) + { + printk(XENLOG_ERR + "Failed to add: %#"PRIpaddr"->%#"PRIpaddr", error: %d\n= ", + start, end, res); + goto out; + } + } + + /* Remove static shared memory regions */ + res =3D remove_shm_from_rangeset(kinfo, guest_holes); + if ( res ) + goto out; + + /* + * Take the interval of memory starting from the first extended region= bank + * start address and ending to the end of the last extended region ban= k. + */ + i =3D ext_regions->nr_banks - 1; + start =3D ext_regions->bank[0].start; + end =3D ext_regions->bank[i].start + ext_regions->bank[i].size - 1; + + /* Reset original extended regions to hold new value */ + ext_regions->nr_banks =3D 0; + res =3D rangeset_report_ranges(guest_holes, PFN_DOWN(start), PFN_DOWN(= end), + add_ext_regions, ext_regions); + if ( res ) + ext_regions->nr_banks =3D 0; + else if ( !ext_regions->nr_banks ) + res =3D -ENOENT; + + out: + rangeset_destroy(guest_holes); + + return res; +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713426391675313.53071434755486; Thu, 18 Apr 2024 00:46:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708080.1106676 (Exim 4.92) (envelope-from ) id 1rxMTK-00068w-7Y; Thu, 18 Apr 2024 07:46:18 +0000 Received: by outflank-mailman (output) from mailman id 708080.1106676; Thu, 18 Apr 2024 07:46:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxMTK-00068p-3V; Thu, 18 Apr 2024 07:46:18 +0000 Received: by outflank-mailman (input) for mailman id 708080; Thu, 18 Apr 2024 07:46:16 +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 1rxMKd-00046V-JA for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:19 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7b01e855-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:17 +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 B11731576; Thu, 18 Apr 2024 00:37:44 -0700 (PDT) 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 C42B53F64C; Thu, 18 Apr 2024 00:37:15 -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: 7b01e855-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng Subject: [PATCH v3 11/12] xen/arm: fix duplicate /reserved-memory node in Dom0 Date: Thu, 18 Apr 2024 08:36:51 +0100 Message-Id: <20240418073652.3622828-12-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713426393497100001 Content-Type: text/plain; charset="utf-8" From: Penny Zheng In case there is a /reserved-memory node already present in the host dtb, current Xen codes would create yet another /reserved-memory node when the static shared memory feature is enabled and static shared memory regions are present. This would result in an incorrect device tree generation and hwdom would not be able to detect the static shared memory region. Avoid this issue by checking the presence of the /reserved-memory node and appending the nodes instead of generating a duplicate /reserved-memory. Make make_shm_memory_node externally visible and rename it to make_shm_resv_memory_node to make clear it produces childs for /reserved-memory. Signed-off-by: Penny Zheng Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v2: - fix comment, remove function signature change, fixed commit msg - rename make_shm_memory_node to make_shm_resv_memory_node in order to make clear that it produces childs for /reserved-memory - Add Michal R-by v1: - Rework of https://patchwork.kernel.org/project/xen-devel/patch/202312060= 90623.1932275-11-Penny.Zheng@arm.com/ --- xen/arch/arm/domain_build.c | 23 ++++++++++++++++++++--- xen/arch/arm/include/asm/static-shmem.h | 9 +++++++++ xen/arch/arm/static-shmem.c | 8 ++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 0cc39b0bd7bb..68532ddc084c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1640,6 +1640,7 @@ static int __init handle_node(struct domain *d, struc= t kernel_info *kinfo, DT_MATCH_PATH("/hypervisor"), { /* sentinel */ }, }; + static __initdata bool res_mem_node_found =3D false; struct dt_device_node *child; int res, i, nirq, irq_id; const char *name; @@ -1734,6 +1735,19 @@ static int __init handle_node(struct domain *d, stru= ct kernel_info *kinfo, if ( res ) return res; =20 + if ( dt_node_path_is_equal(node, "/reserved-memory") ) + { + res_mem_node_found =3D true; + /* + * Avoid duplicate /reserved-memory nodes in Device Tree, so add t= he + * static shared memory nodes there. + */ + res =3D make_shm_resv_memory_node(kinfo, dt_n_addr_cells(node), + dt_n_size_cells(node)); + if ( res ) + return res; + } + for ( child =3D node->child; child !=3D NULL; child =3D child->sibling= ) { res =3D handle_node(d, kinfo, child, p2mt); @@ -1786,9 +1800,12 @@ static int __init handle_node(struct domain *d, stru= ct kernel_info *kinfo, return res; } =20 - res =3D make_resv_memory_node(kinfo, addrcells, sizecells); - if ( res ) - return res; + if ( !res_mem_node_found ) + { + res =3D make_resv_memory_node(kinfo, addrcells, sizecells); + if ( res ) + return res; + } } =20 res =3D fdt_end_node(kinfo->fdt); diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include= /asm/static-shmem.h index 2e8b138eb989..7495a91e7a31 100644 --- a/xen/arch/arm/include/asm/static-shmem.h +++ b/xen/arch/arm/include/asm/static-shmem.h @@ -34,6 +34,9 @@ int remove_shm_from_rangeset(const struct kernel_info *ki= nfo, int remove_shm_holes_for_domU(const struct kernel_info *kinfo, struct membanks *ext_regions); =20 +int make_shm_resv_memory_node(const struct kernel_info *kinfo, int addrcel= ls, + int sizecells); + #else /* !CONFIG_STATIC_SHM */ =20 static inline int make_resv_memory_node(const struct kernel_info *kinfo, @@ -77,6 +80,12 @@ static inline int remove_shm_holes_for_domU(const struct= kernel_info *kinfo, return 0; } =20 +static inline int make_shm_resv_memory_node(const struct kernel_info *kinf= o, + int addrcells, int sizecells) +{ + return 0; +} + #endif /* CONFIG_STATIC_SHM */ =20 #endif /* __ASM_STATIC_SHMEM_H_ */ diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 12e2df939915..c85f60dd1bf7 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -297,8 +297,8 @@ int __init process_shm(struct domain *d, struct kernel_= info *kinfo, return 0; } =20 -static int __init make_shm_memory_node(const struct kernel_info *kinfo, - int addrcells, int sizecells) +int __init make_shm_resv_memory_node(const struct kernel_info *kinfo, + int addrcells, int sizecells) { const struct membanks *mem =3D &kinfo->shm_mem.common; void *fdt =3D kinfo->fdt; @@ -306,7 +306,7 @@ static int __init make_shm_memory_node(const struct ker= nel_info *kinfo, int res =3D 0; =20 if ( mem->nr_banks =3D=3D 0 ) - return -ENOENT; + return 0; =20 /* * For each shared memory region, a range is exposed under @@ -544,7 +544,7 @@ int __init make_resv_memory_node(const struct kernel_in= fo *kinfo, int addrcells, if ( res ) return res; =20 - res =3D make_shm_memory_node(kinfo, addrcells, sizecells); + res =3D make_shm_resv_memory_node(kinfo, addrcells, sizecells); if ( res ) return res; =20 --=20 2.34.1 From nobody Fri May 17 04:59:56 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 1713426285086822.5665871579045; Thu, 18 Apr 2024 00:44:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.708063.1106661 (Exim 4.92) (envelope-from ) id 1rxMRa-0004Fp-ON; Thu, 18 Apr 2024 07:44:30 +0000 Received: by outflank-mailman (output) from mailman id 708063.1106661; Thu, 18 Apr 2024 07:44: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 1rxMRa-0004Ea-Ge; Thu, 18 Apr 2024 07:44:30 +0000 Received: by outflank-mailman (input) for mailman id 708063; Thu, 18 Apr 2024 07:44:29 +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 1rxMKe-00046V-OO for xen-devel@lists.xenproject.org; Thu, 18 Apr 2024 07:37:20 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7bb438ca-fd56-11ee-94a3-07e782e9044d; Thu, 18 Apr 2024 09:37:18 +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 044ED339; Thu, 18 Apr 2024 00:37:46 -0700 (PDT) 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 55B893F64C; Thu, 18 Apr 2024 00:37:17 -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: 7bb438ca-fd56-11ee-94a3-07e782e9044d From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 12/12] xen/arm: List static shared memory regions as /memory nodes Date: Thu, 18 Apr 2024 08:36:52 +0100 Message-Id: <20240418073652.3622828-13-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418073652.3622828-1-luca.fancellu@arm.com> References: <20240418073652.3622828-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713426285209100001 Content-Type: text/plain; charset="utf-8" Currently Xen is not exporting the static shared memory regions to the device tree as /memory node, this commit is fixing this issue. Given that now make_memory_node needs a parameter 'struct kernel_info' in order to call the new function shm_mem_node_fill_reg_range, take the occasion to remove the unused struct domain parameter. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3: - removed previous patch that was merging the intervals, rebase changes. v2: - try to use make_memory_node, don't add overlapping ranges of memory, commit message changed. v1: - new patch --- --- xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain_build.c | 34 +++++++++++++++++-------- xen/arch/arm/include/asm/domain_build.h | 2 +- xen/arch/arm/include/asm/static-shmem.h | 15 +++++++++++ xen/arch/arm/static-shmem.c | 23 +++++++++++++++++ 5 files changed, 63 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 51cf03221d56..74f053c242f4 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -642,7 +642,7 @@ static int __init prepare_dtb_domU(struct domain *d, st= ruct kernel_info *kinfo) if ( ret ) goto err; =20 - ret =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, + ret =3D make_memory_node(kinfo, addrcells, sizecells, kernel_info_get_mem(kinfo)); if ( ret ) goto err; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 68532ddc084c..15f888169c4e 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -756,15 +756,14 @@ int __init domain_fdt_begin_node(void *fdt, const cha= r *name, uint64_t unit) return fdt_begin_node(fdt, buf); } =20 -int __init make_memory_node(const struct domain *d, - void *fdt, - int addrcells, int sizecells, - const struct membanks *mem) +int __init make_memory_node(const struct kernel_info *kinfo, int addrcells, + int sizecells, const struct membanks *mem) { + void *fdt =3D kinfo->fdt; unsigned int i; int res, reg_size =3D addrcells + sizecells; int nr_cells =3D 0; - __be32 reg[NR_MEM_BANKS * 4 /* Worst case addrcells + sizecells */]; + __be32 reg[DT_MEM_NODE_REG_RANGE_SIZE]; __be32 *cells; =20 if ( mem->nr_banks =3D=3D 0 ) @@ -797,14 +796,28 @@ int __init make_memory_node(const struct domain *d, if ( mem->bank[i].type =3D=3D MEMBANK_STATIC_DOMAIN ) continue; =20 - dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n", - i, start, start + size); - nr_cells +=3D reg_size; BUG_ON(nr_cells >=3D ARRAY_SIZE(reg)); dt_child_set_range(&cells, addrcells, sizecells, start, size); } =20 + /* + * static shared memory banks need to be listed as /memory node, so wh= en + * this function is handling the normal memory, add the banks. + */ + if ( mem =3D=3D kernel_info_get_mem(kinfo) ) + shm_mem_node_fill_reg_range(kinfo, reg, &nr_cells, addrcells, + sizecells); + + for ( cells =3D reg, i =3D 0; cells < reg + nr_cells; i++, cells +=3D = reg_size ) + { + u64 start =3D dt_read_number(cells, addrcells); + u64 size =3D dt_read_number(cells + addrcells, sizecells); + + dt_dprintk(" Bank %d: %#"PRIx64"->%#"PRIx64"\n", + i, start, start + size); + } + dt_dprintk("(reg size %d, nr cells %d)\n", reg_size, nr_cells); =20 res =3D fdt_property(fdt, "reg", reg, nr_cells * sizeof(*reg)); @@ -1783,7 +1796,7 @@ static int __init handle_node(struct domain *d, struc= t kernel_info *kinfo, if ( res ) return res; =20 - res =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, + res =3D make_memory_node(kinfo, addrcells, sizecells, kernel_info_get_mem(kinfo)); if ( res ) return res; @@ -1794,8 +1807,7 @@ static int __init handle_node(struct domain *d, struc= t kernel_info *kinfo, */ if ( reserved_mem->nr_banks > 0 ) { - res =3D make_memory_node(d, kinfo->fdt, addrcells, sizecells, - reserved_mem); + res =3D make_memory_node(kinfo, addrcells, sizecells, reserved= _mem); if ( res ) return res; } diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include= /asm/domain_build.h index 026d975da28e..45936212ca21 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -14,7 +14,7 @@ int make_chosen_node(const struct kernel_info *kinfo); int make_cpus_node(const struct domain *d, void *fdt); int make_hypervisor_node(struct domain *d, const struct kernel_info *kinfo, int addrcells, int sizecells); -int make_memory_node(const struct domain *d, void *fdt, int addrcells, +int make_memory_node(const struct kernel_info *kinfo, int addrcells, int sizecells, const struct membanks *mem); int make_psci_node(void *fdt); int make_timer_node(const struct kernel_info *kinfo); diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include= /asm/static-shmem.h index 7495a91e7a31..3b6569e5703f 100644 --- a/xen/arch/arm/include/asm/static-shmem.h +++ b/xen/arch/arm/include/asm/static-shmem.h @@ -3,10 +3,15 @@ #ifndef __ASM_STATIC_SHMEM_H_ #define __ASM_STATIC_SHMEM_H_ =20 +#include #include +#include =20 #ifdef CONFIG_STATIC_SHM =20 +/* Worst case /memory node reg element: (addrcells + sizecells) */ +#define DT_MEM_NODE_REG_RANGE_SIZE ((NR_MEM_BANKS + NR_SHMEM_BANKS) * 4) + int make_resv_memory_node(const struct kernel_info *kinfo, int addrcells, int sizecells); =20 @@ -37,8 +42,14 @@ int remove_shm_holes_for_domU(const struct kernel_info *= kinfo, int make_shm_resv_memory_node(const struct kernel_info *kinfo, int addrcel= ls, int sizecells); =20 +void shm_mem_node_fill_reg_range(const struct kernel_info *kinfo, __be32 *= reg, + int *nr_cells, int addrcells, int sizecel= ls); + #else /* !CONFIG_STATIC_SHM */ =20 +/* Worst case /memory node reg element: (addrcells + sizecells) */ +#define DT_MEM_NODE_REG_RANGE_SIZE (NR_MEM_BANKS * 4) + static inline int make_resv_memory_node(const struct kernel_info *kinfo, int addrcells, int sizecells) { @@ -86,6 +97,10 @@ static inline int make_shm_resv_memory_node(const struct= kernel_info *kinfo, return 0; } =20 +static inline void shm_mem_node_fill_reg_range(const struct kernel_info *k= info, + __be32 *reg, int *nr_cells, + int addrcells, int sizecell= s) {}; + #endif /* CONFIG_STATIC_SHM */ =20 #endif /* __ASM_STATIC_SHMEM_H_ */ diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index c85f60dd1bf7..07c93a820508 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include #include @@ -668,6 +669,28 @@ int __init remove_shm_holes_for_domU(const struct kern= el_info *kinfo, return res; } =20 +void __init shm_mem_node_fill_reg_range(const struct kernel_info *kinfo, + __be32 *reg, int *nr_cells, + int addrcells, int sizecells) +{ + const struct membanks *mem =3D &kinfo->shm_mem.common; + unsigned int i; + __be32 *cells; + + BUG_ON(!nr_cells || !reg); + + cells =3D ®[*nr_cells]; + for ( i =3D 0; i < mem->nr_banks; i++ ) + { + u64 start =3D mem->bank[i].start; + u64 size =3D mem->bank[i].size; + + *nr_cells +=3D addrcells + sizecells; + BUG_ON(*nr_cells >=3D DT_MEM_NODE_REG_RANGE_SIZE); + dt_child_set_range(&cells, addrcells, sizecells, start, size); + } +} + /* * Local variables: * mode: C --=20 2.34.1