From nobody Wed Feb 5 12:50:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1736427766317819.5957810435928; Thu, 9 Jan 2025 05:02:46 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.868347.1279867 (Exim 4.92) (envelope-from ) id 1tVsB2-0000gP-IN; Thu, 09 Jan 2025 13:02:20 +0000 Received: by outflank-mailman (output) from mailman id 868347.1279867; Thu, 09 Jan 2025 13:02: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 1tVsB2-0000gI-Fl; Thu, 09 Jan 2025 13:02:20 +0000 Received: by outflank-mailman (input) for mailman id 868347; Thu, 09 Jan 2025 13:02:19 +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 1tVsB1-0000g9-6Z for xen-devel@lists.xenproject.org; Thu, 09 Jan 2025 13:02:19 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id f33aa208-ce89-11ef-99a4-01e77a169b0f; Thu, 09 Jan 2025 14:02:16 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2311D13D5; Thu, 9 Jan 2025 05:02:44 -0800 (PST) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E27793F673; Thu, 9 Jan 2025 05:02:14 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f33aa208-ce89-11ef-99a4-01e77a169b0f From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Oleksii Kurochko Subject: [for-4.20 PATCH v3] xen/arm: Fully initialise struct membanks_hdr fields Date: Thu, 9 Jan 2025 13:02:04 +0000 Message-Id: <20250109130204.42545-1-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1736427769648116600 Content-Type: text/plain; charset="utf-8" Commit a14593e3995a ("xen/device-tree: Allow region overlapping with /memreserve/ ranges") introduced a type in the 'struct membanks_hdr' but forgot to update the 'struct kernel_info' initialiser, while it doesn't lead to failures because the field is not currently used while managing kernel_info structures, it's good to have it for completeness. There are other instance of structures using 'struct membanks_hdr' that are dynamically allocated and don't fully initialise these fields, provide a static inline helper for that. Fixes: a14593e3995a ("xen/device-tree: Allow region overlapping with /memre= serve/ ranges") Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- Changes from v2: - Banks created by Xen should be MEMORY type. (Michal) - Add R-by Michal Changes from v1: - Changed commit title and body msg - initialised max_banks and type for all structures using 'struct membanks= _hdr' --- --- xen/arch/arm/domain_build.c | 13 ++++--------- xen/arch/arm/include/asm/kernel.h | 5 ++++- xen/arch/arm/static-shmem.c | 3 ++- xen/include/xen/bootfdt.h | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index b072a16249fe..7b47abade196 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1039,7 +1039,7 @@ void __init allocate_memory(struct domain *d, struct = kernel_info *kinfo) */ if ( is_hardware_domain(d) ) { - struct membanks *gnttab =3D xzalloc_flex_struct(struct membanks, b= ank, 1); + struct membanks *gnttab =3D membanks_xzalloc(1, MEMORY); /* * Exclude the following regions: * 1) Remove reserved memory @@ -1057,13 +1057,10 @@ void __init allocate_memory(struct domain *d, struc= t kernel_info *kinfo) gnttab->bank[0].start =3D kinfo->gnttab_start; gnttab->bank[0].size =3D kinfo->gnttab_size; =20 - hwdom_free_mem =3D xzalloc_flex_struct(struct membanks, bank, - NR_MEM_BANKS); + hwdom_free_mem =3D membanks_xzalloc(NR_MEM_BANKS, MEMORY); if ( !hwdom_free_mem ) goto fail; =20 - hwdom_free_mem->max_banks =3D NR_MEM_BANKS; - if ( find_unallocated_memory(kinfo, mem_banks, ARRAY_SIZE(mem_bank= s), hwdom_free_mem, add_hwdom_free_region= s) ) goto fail; @@ -1293,7 +1290,7 @@ static int __init find_host_extended_regions(const st= ruct kernel_info *kinfo, struct membanks *ext_regions) { int res; - struct membanks *gnttab =3D xzalloc_flex_struct(struct membanks, bank,= 1); + struct membanks *gnttab =3D membanks_xzalloc(1, MEMORY); =20 /* * Exclude the following regions: @@ -1374,12 +1371,10 @@ int __init make_hypervisor_node(struct domain *d, } else { - ext_regions =3D xzalloc_flex_struct(struct membanks, bank, NR_MEM_= BANKS); + ext_regions =3D membanks_xzalloc(NR_MEM_BANKS, MEMORY); if ( !ext_regions ) return -ENOMEM; =20 - ext_regions->max_banks =3D NR_MEM_BANKS; - if ( domain_use_host_layout(d) ) { if ( !is_iommu_enabled(d) ) diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/k= ernel.h index 7e6e3c82a477..de3f945ae54c 100644 --- a/xen/arch/arm/include/asm/kernel.h +++ b/xen/arch/arm/include/asm/kernel.h @@ -92,7 +92,9 @@ kernel_info_get_mem_const(const struct kernel_info *kinfo) } =20 #ifdef CONFIG_STATIC_SHM -#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks =3D NR_SHMEM_BA= NKS, +#define KERNEL_INFO_SHM_MEM_INIT \ + .shm_mem.common.max_banks =3D NR_SHMEM_BANKS, \ + .shm_mem.common.type =3D STATIC_SHARED_MEMORY, #else #define KERNEL_INFO_SHM_MEM_INIT #endif @@ -100,6 +102,7 @@ kernel_info_get_mem_const(const struct kernel_info *kin= fo) #define KERNEL_INFO_INIT \ { \ .mem.common.max_banks =3D NR_MEM_BANKS, \ + .mem.common.type =3D MEMORY, \ KERNEL_INFO_SHM_MEM_INIT \ } =20 diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c index 66088a426785..8f87154c3587 100644 --- a/xen/arch/arm/static-shmem.c +++ b/xen/arch/arm/static-shmem.c @@ -20,7 +20,8 @@ static struct { struct membanks_hdr common; struct membank bank[NR_SHMEM_BANKS]; } shm_heap_banks __initdata =3D { - .common.max_banks =3D NR_SHMEM_BANKS + .common.max_banks =3D NR_SHMEM_BANKS, + .common.type =3D STATIC_SHARED_MEMORY }; =20 static inline struct membanks *get_shmem_heap_banks(void) diff --git a/xen/include/xen/bootfdt.h b/xen/include/xen/bootfdt.h index c8bbfd8979b2..80a90e53c001 100644 --- a/xen/include/xen/bootfdt.h +++ b/xen/include/xen/bootfdt.h @@ -4,6 +4,7 @@ #include #include #include +#include =20 #define MIN_FDT_ALIGN 8 =20 @@ -219,4 +220,19 @@ static inline struct shmem_membank_extra *bootinfo_get= _shmem_extra(void) } #endif =20 +static inline struct membanks *membanks_xzalloc(unsigned int nr, + enum region_type type) +{ + struct membanks *banks =3D xzalloc_flex_struct(struct membanks, bank, = nr); + + if ( !banks ) + goto out; + + banks->max_banks =3D nr; + banks->type =3D type; + + out: + return banks; +} + #endif /* XEN_BOOTFDT_H */ --=20 2.34.1