From nobody Sat May 18 14:10:11 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 1714050710917923.7424961045144; Thu, 25 Apr 2024 06:11:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.712060.1112456 (Exim 4.92) (envelope-from ) id 1rzysw-0000AN-N9; Thu, 25 Apr 2024 13:11:34 +0000 Received: by outflank-mailman (output) from mailman id 712060.1112456; Thu, 25 Apr 2024 13:11:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzysw-0000A8-Im; Thu, 25 Apr 2024 13:11:34 +0000 Received: by outflank-mailman (input) for mailman id 712060; Thu, 25 Apr 2024 13:11:32 +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 1rzysu-0008LR-Iy for xen-devel@lists.xenproject.org; Thu, 25 Apr 2024 13:11:32 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 54417f5a-0305-11ef-b4bb-af5377834399; Thu, 25 Apr 2024 15:11:30 +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 5496E1063; Thu, 25 Apr 2024 06:11:57 -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 481A73F7BD; Thu, 25 Apr 2024 06:11:28 -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: 54417f5a-0305-11ef-b4bb-af5377834399 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [RFC PATCH 1/2] xen/arm: Add DT reserve map regions to bootinfo.reserved_mem Date: Thu, 25 Apr 2024 14:11:18 +0100 Message-Id: <20240425131119.2299629-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240425131119.2299629-1-luca.fancellu@arm.com> References: <20240425131119.2299629-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1714050711207100002 Content-Type: text/plain; charset="utf-8" Currently the code is listing device tree reserve map regions as reserved memory for Xen, but they are not added into bootinfo.reserved_mem and they are fetched in multiple places using the same code sequence, causing duplication. Fix this by adding them to the bootinfo.reserved_mem at early stage. Signed-off-by: Luca Fancellu Acked-by: Julien Grall --- xen/arch/arm/arm32/mmu/mm.c | 29 +---------------- xen/arch/arm/bootfdt.c | 51 ++++++++++++++++++------------ xen/arch/arm/domain_build.c | 3 +- xen/arch/arm/include/asm/setup.h | 5 +++ xen/arch/arm/setup.c | 53 +++++++++----------------------- 5 files changed, 53 insertions(+), 88 deletions(-) diff --git a/xen/arch/arm/arm32/mmu/mm.c b/xen/arch/arm/arm32/mmu/mm.c index 23150122f7c4..be480c31ea05 100644 --- a/xen/arch/arm/arm32/mmu/mm.c +++ b/xen/arch/arm/arm32/mmu/mm.c @@ -73,33 +73,6 @@ static paddr_t __init consider_modules(paddr_t s, paddr_= t e, } } =20 - /* Now check any fdt reserved areas. */ - - nr =3D fdt_num_mem_rsv(device_tree_flattened); - - for ( ; i < mi->nr_mods + nr; i++ ) - { - paddr_t mod_s, mod_e; - - if ( fdt_get_mem_rsv_paddr(device_tree_flattened, - i - mi->nr_mods, - &mod_s, &mod_e ) < 0 ) - /* If we can't read it, pretend it doesn't exist... */ - continue; - - /* fdt_get_mem_rsv_paddr returns length */ - mod_e +=3D mod_s; - - if ( s < mod_e && mod_s < e ) - { - mod_e =3D consider_modules(mod_e, e, size, align, i+1); - if ( mod_e ) - return mod_e; - - return consider_modules(s, mod_s, size, align, i+1); - } - } - /* * i is the current bootmodule we are evaluating, across all * possible kinds of bootmodules. @@ -108,7 +81,7 @@ static paddr_t __init consider_modules(paddr_t s, paddr_= t e, * 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; + nr =3D mi->nr_mods; for ( ; i - nr < reserved_mem->nr_banks; i++ ) { paddr_t r_s =3D reserved_mem->bank[i - nr].start; diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 4d708442a19e..6e060111d95b 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -475,8 +475,7 @@ static void __init early_print_info(void) 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; - int nr_rsvd; + unsigned int i; =20 for ( i =3D 0; i < mi->nr_banks; i++ ) printk("RAM: %"PRIpaddr" - %"PRIpaddr"\n", @@ -490,26 +489,11 @@ static void __init early_print_info(void) mods->module[i].start + mods->module[i].size, boot_module_kind_as_string(mods->module[i].kind)); =20 - nr_rsvd =3D fdt_num_mem_rsv(device_tree_flattened); - if ( nr_rsvd < 0 ) - panic("Parsing FDT memory reserve map failed (%d)\n", nr_rsvd); - - for ( i =3D 0; i < nr_rsvd; i++ ) - { - paddr_t s, e; - - if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &s, &e) < 0 ) - continue; - - /* fdt_get_mem_rsv_paddr returns length */ - e +=3D s; - printk(" RESVD[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i, s, e); - } - for ( j =3D 0; j < mem_resv->nr_banks; j++, i++ ) + for ( i =3D 0; i < mem_resv->nr_banks; i++ ) { printk(" RESVD[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i, - mem_resv->bank[j].start, - mem_resv->bank[j].start + mem_resv->bank[j].size - 1); + mem_resv->bank[i].start, + mem_resv->bank[i].start + mem_resv->bank[i].size - 1); } early_print_info_shmem(); printk("\n"); @@ -550,7 +534,10 @@ 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 *reserved_mem =3D bootinfo_get_reserved_mem(); struct membanks *mem =3D bootinfo_get_mem(); + unsigned int i; + int nr_rsvd; int ret; =20 ret =3D fdt_check_header(fdt); @@ -559,6 +546,30 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t p= addr) =20 add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false); =20 + nr_rsvd =3D fdt_num_mem_rsv(fdt); + if ( nr_rsvd < 0 ) + panic("Parsing FDT memory reserve map failed (%d)\n", nr_rsvd); + + for ( i =3D 0; i < nr_rsvd; i++ ) + { + struct membank *bank; + paddr_t s, sz; + + if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &s, &sz) < 0 ) + continue; + + if ( reserved_mem->nr_banks < reserved_mem->max_banks ) + { + bank =3D &reserved_mem->bank[reserved_mem->nr_banks]; + bank->start =3D s; + bank->size =3D sz; + bank->type =3D MEMBANK_FDT_RESVMEM; + reserved_mem->nr_banks++; + } + else + panic("Cannot allocate reserved memory bank\n"); + } + ret =3D device_tree_for_each_node(fdt, 0, early_scan_node, NULL); if ( ret ) panic("Early FDT parsing failed (%d)\n", ret); diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 0784e4c5e315..6fc88a8234e4 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -793,7 +793,8 @@ int __init make_memory_node(const struct kernel_info *k= info, int addrcells, u64 start =3D mem->bank[i].start; u64 size =3D mem->bank[i].size; =20 - if ( mem->bank[i].type =3D=3D MEMBANK_STATIC_DOMAIN ) + if ( (mem->bank[i].type =3D=3D MEMBANK_STATIC_DOMAIN) || + (mem->bank[i].type =3D=3D MEMBANK_FDT_RESVMEM) ) continue; =20 nr_cells +=3D reg_size; diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 28fb659fe946..fc6967f9a435 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -42,6 +42,11 @@ enum membank_type { * in reserved_mem. */ MEMBANK_STATIC_HEAP, + /* + * The MEMBANK_FDT_RESVMEM type is used to indicate whether the memory + * bank is from the FDT reserve map. + */ + MEMBANK_FDT_RESVMEM, }; =20 /* Indicates the maximum number of characters(\0 included) for shm_id */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index d242674381d4..c4e5c19b11d6 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -210,48 +210,18 @@ static void __init dt_unreserved_regions(paddr_t s, p= addr_t e, const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); #ifdef CONFIG_STATIC_SHM const struct membanks *shmem =3D bootinfo_get_shmem(); + unsigned int offset; #endif - unsigned int i, nr; - int rc; - - rc =3D fdt_num_mem_rsv(device_tree_flattened); - if ( rc < 0 ) - panic("Unable to retrieve the number of reserved regions (rc=3D%d)= \n", - rc); - - nr =3D rc; - - for ( i =3D first; i < nr ; i++ ) - { - paddr_t r_s, r_e; - - if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &r_s, &r_e ) = < 0 ) - /* If we can't read it, pretend it doesn't exist... */ - continue; - - r_e +=3D r_s; /* fdt_get_mem_rsv_paddr returns length */ - - 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; - } - } + unsigned int i; =20 /* * i is the current bootmodule we are evaluating across all possible * kinds. - * - * When retrieving the corresponding reserved-memory addresses - * 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 < reserved_mem->nr_banks; i++ ) + for ( i =3D first; i < reserved_mem->nr_banks; i++ ) { - paddr_t r_s =3D reserved_mem->bank[i - nr].start; - paddr_t r_e =3D r_s + reserved_mem->bank[i - nr].size; + paddr_t r_s =3D reserved_mem->bank[i].start; + paddr_t r_e =3D r_s + reserved_mem->bank[i].size; =20 if ( s < r_e && r_s < e ) { @@ -262,11 +232,16 @@ static void __init dt_unreserved_regions(paddr_t s, p= addr_t e, } =20 #ifdef CONFIG_STATIC_SHM - nr +=3D reserved_mem->nr_banks; - for ( ; i - nr < shmem->nr_banks; i++ ) + /* + * When retrieving the corresponding shared memory addresses + * below, we need to index the shmem->bank starting from 0, hence + * we need to use i - reserved_mem->nr_banks. + */ + offset =3D reserved_mem->nr_banks; + for ( ; i - offset < 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; + paddr_t r_s =3D shmem->bank[i - offset].start; + paddr_t r_e =3D r_s + shmem->bank[i - offset].size; =20 if ( s < r_e && r_s < e ) { --=20 2.34.1 From nobody Sat May 18 14:10:11 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 1714050709817146.01446723906963; Thu, 25 Apr 2024 06:11:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.712059.1112447 (Exim 4.92) (envelope-from ) id 1rzysv-0008MC-Fy; Thu, 25 Apr 2024 13:11:33 +0000 Received: by outflank-mailman (output) from mailman id 712059.1112447; Thu, 25 Apr 2024 13:11:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rzysv-0008M5-BG; Thu, 25 Apr 2024 13:11:33 +0000 Received: by outflank-mailman (input) for mailman id 712059; Thu, 25 Apr 2024 13:11:31 +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 1rzyst-00086c-Q3 for xen-devel@lists.xenproject.org; Thu, 25 Apr 2024 13:11:31 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 54e89254-0305-11ef-909a-e314d9c70b13; Thu, 25 Apr 2024 15:11:30 +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 6B9821576; Thu, 25 Apr 2024 06:11:58 -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 5F8563F7BD; Thu, 25 Apr 2024 06:11:29 -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: 54e89254-0305-11ef-909a-e314d9c70b13 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [RFC PATCH 2/2] xen/arm: Rework dt_unreserved_regions to avoid recursion Date: Thu, 25 Apr 2024 14:11:19 +0100 Message-Id: <20240425131119.2299629-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240425131119.2299629-1-luca.fancellu@arm.com> References: <20240425131119.2299629-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1714050711218100004 Content-Type: text/plain; charset="utf-8" The function dt_unreserved_regions is currently using recursion to compute the non overlapping ranges of a passed region against the reserved memory banks, in the spirit of removing the recursion to improve safety and also improve the scalability of the function, rework its code to use an iterative algorithm with the same result. The function was taking an additional parameter 'first', but given the rework and given that the function was always initially called with this parameter as zero, remove the parameter and update the codebase to reflect the change. Signed-off-by: Luca Fancellu --- xen/arch/arm/include/asm/setup.h | 8 +- xen/arch/arm/include/asm/static-shmem.h | 7 +- xen/arch/arm/kernel.c | 2 +- xen/arch/arm/setup.c | 133 ++++++++++++++++-------- 4 files changed, 96 insertions(+), 54 deletions(-) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index fc6967f9a435..24519b9ed969 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -9,7 +9,12 @@ #define MAX_FDT_SIZE SZ_2M =20 #define NR_MEM_BANKS 256 + +#ifdef CONFIG_STATIC_SHM #define NR_SHMEM_BANKS 32 +#else +#define NR_SHMEM_BANKS 0 +#endif =20 #define MAX_MODULES 32 /* Current maximum useful modules */ =20 @@ -215,8 +220,7 @@ void create_dom0(void); =20 void discard_initial_modules(void); void fw_unreserved_regions(paddr_t s, paddr_t e, - void (*cb)(paddr_t ps, paddr_t pe), - unsigned int first); + void (*cb)(paddr_t ps, paddr_t pe)); =20 size_t boot_fdt_info(const void *fdt, paddr_t paddr); const char *boot_fdt_cmdline(const void *fdt); diff --git a/xen/arch/arm/include/asm/static-shmem.h b/xen/arch/arm/include= /asm/static-shmem.h index 3b6569e5703f..1b7c7ea0e17d 100644 --- a/xen/arch/arm/include/asm/static-shmem.h +++ b/xen/arch/arm/include/asm/static-shmem.h @@ -7,11 +7,11 @@ #include #include =20 -#ifdef CONFIG_STATIC_SHM - /* Worst case /memory node reg element: (addrcells + sizecells) */ #define DT_MEM_NODE_REG_RANGE_SIZE ((NR_MEM_BANKS + NR_SHMEM_BANKS) * 4) =20 +#ifdef CONFIG_STATIC_SHM + int make_resv_memory_node(const struct kernel_info *kinfo, int addrcells, int sizecells); =20 @@ -47,9 +47,6 @@ void shm_mem_node_fill_reg_range(const struct kernel_info= *kinfo, __be32 *reg, =20 #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) { diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 674388fa11a2..ecbeec518754 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -247,7 +247,7 @@ static __init int kernel_decompress(struct bootmodule *= mod, uint32_t offset) * Free the original kernel, update the pointers to the * decompressed kernel */ - fw_unreserved_regions(addr, addr + size, init_domheap_pages, 0); + fw_unreserved_regions(addr, addr + size, init_domheap_pages); =20 return 0; } diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index c4e5c19b11d6..d737fe56e539 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -204,55 +204,97 @@ static void __init processor_id(void) } =20 static void __init dt_unreserved_regions(paddr_t s, paddr_t e, - void (*cb)(paddr_t ps, paddr_t pe= ), - unsigned int first) + void (*cb)(paddr_t ps, paddr_t pe= )) { - const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); -#ifdef CONFIG_STATIC_SHM - const struct membanks *shmem =3D bootinfo_get_shmem(); - unsigned int offset; -#endif - unsigned int i; - /* - * i is the current bootmodule we are evaluating across all possible - * kinds. + * The worst case scenario is to have N reserved region ovelapping the + * passed one, so having N+1 regions in the stack */ - for ( i =3D first; i < reserved_mem->nr_banks; i++ ) - { - paddr_t r_s =3D reserved_mem->bank[i].start; - paddr_t r_e =3D r_s + reserved_mem->bank[i].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; - } - } - + struct { + paddr_t s; + paddr_t e; + unsigned int dict; + unsigned int bank; + } stack[NR_MEM_BANKS + NR_SHMEM_BANKS + 1]; + const struct membanks *mem_banks[] =3D { + bootinfo_get_reserved_mem(), #ifdef CONFIG_STATIC_SHM - /* - * When retrieving the corresponding shared memory addresses - * below, we need to index the shmem->bank starting from 0, hence - * we need to use i - reserved_mem->nr_banks. - */ - offset =3D reserved_mem->nr_banks; - for ( ; i - offset < shmem->nr_banks; i++ ) + bootinfo_get_shmem(), +#endif + }; + unsigned int count =3D 0; + unsigned int i, j; + + /* Push the initial region into the stack */ + stack[count].s =3D s; + stack[count].e =3D e; + stack[count].dict =3D 0; + stack[count].bank =3D 0; + count++; + while ( count > 0 ) { - paddr_t r_s =3D shmem->bank[i - offset].start; - paddr_t r_e =3D r_s + shmem->bank[i - offset].size; - - if ( s < r_e && r_s < e ) + paddr_t b_s, b_e; + /* Take out last element of the stack */ + count--; + i =3D stack[count].dict; + j =3D stack[count].bank; + b_s =3D stack[count].s; + b_e =3D stack[count].e; + /* Start checking for overlapping banks */ + for ( ; i < ARRAY_SIZE(mem_banks); i++ ) { - dt_unreserved_regions(r_e, e, cb, i + 1); - dt_unreserved_regions(s, r_s, cb, i + 1); - return; + for ( ; j < mem_banks[i]->nr_banks; j++ ) + { + paddr_t r_s =3D mem_banks[i]->bank[j].start; + paddr_t r_e =3D r_s + mem_banks[i]->bank[j].size; + + if ( b_s < r_e && r_s < b_e ) + { + /* + * Region is overlapping, push the two non overlap rang= es in + * the stack + */ + if ( (count + 2) < ARRAY_SIZE(stack) ) + { + /* + * Push initial non overlapping part of the region= into + * the stack + */ + stack[count].s =3D b_s; + stack[count].e =3D r_s; + stack[count].dict =3D i; + stack[count].bank =3D j + 1; + count++; + /* + * Push last non overlapping part of the region in= to + * the stack + */ + stack[count].s =3D r_e; + stack[count].e =3D b_e; + stack[count].dict =3D i; + stack[count].bank =3D j + 1; + count++; + } + else + panic("dt_unreserved_regions: stack space exausted= "); + + /* + * Retrieve the last region pushed to check against ot= her + * banks, so break the loop through the banks and pop + * a new region from the stack + */ + goto regions_pushed; + } + } + j =3D 0; } + /* + * This point is reached when the region doesn't overlap with any = other + * region, so call the callback on it. + */ + cb(b_s, b_e); + regions_pushed: } -#endif - - cb(s, e); } =20 /* @@ -316,11 +358,10 @@ static bool __init bootmodules_overlap_check(struct b= ootmodules *bootmodules, } =20 void __init fw_unreserved_regions(paddr_t s, paddr_t e, - void (*cb)(paddr_t ps, paddr_t pe), - unsigned int first) + void (*cb)(paddr_t ps, paddr_t pe)) { if ( acpi_disabled ) - dt_unreserved_regions(s, e, cb, first); + dt_unreserved_regions(s, e, cb); else cb(s, e); } @@ -527,7 +568,7 @@ void __init discard_initial_modules(void) !mfn_valid(maddr_to_mfn(e)) ) continue; =20 - fw_unreserved_regions(s, e, init_domheap_pages, 0); + fw_unreserved_regions(s, e, init_domheap_pages); } =20 mi->nr_mods =3D 0; @@ -702,7 +743,7 @@ void __init populate_boot_allocator(void) } #endif =20 - fw_unreserved_regions(s, e, init_boot_pages, 0); + fw_unreserved_regions(s, e, init_boot_pages); s =3D n; } } --=20 2.34.1