From nobody Thu Nov 28 11:02:20 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 1670209122331964.7238883705479; Sun, 4 Dec 2022 18:58:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.453111.710770 (Exim 4.92) (envelope-from ) id 1p21gL-0000Cp-AA; Mon, 05 Dec 2022 02:58:13 +0000 Received: by outflank-mailman (output) from mailman id 453111.710770; Mon, 05 Dec 2022 02:58: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 1p21gL-0000Ci-7V; Mon, 05 Dec 2022 02:58:13 +0000 Received: by outflank-mailman (input) for mailman id 453111; Mon, 05 Dec 2022 02:58:12 +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 1p21gK-0000CU-Bq for xen-devel@lists.xenproject.org; Mon, 05 Dec 2022 02:58:12 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id a5f7033c-7448-11ed-91b6-6bf2151ebd3b; Mon, 05 Dec 2022 03:58:11 +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 48CFFD6E; Sun, 4 Dec 2022 18:58:15 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 806B53F73D; Sun, 4 Dec 2022 18:58:06 -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: a5f7033c-7448-11ed-91b6-6bf2151ebd3b From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 1/3] xen/arm: Add memory overlap check for bootinfo.reserved_mem Date: Mon, 5 Dec 2022 10:57:51 +0800 Message-Id: <20221205025753.2178965-2-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221205025753.2178965-1-Henry.Wang@arm.com> References: <20221205025753.2178965-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1670209124277100004 Content-Type: text/plain; charset="utf-8" As we are having more and more types of static region, and all of these static regions are defined in bootinfo.reserved_mem, it is necessary to add the overlap check of reserved memory regions in Xen, because such check will help user to identify the misconfiguration in the device tree at the early stage of boot time. Currently we have 3 types of static region, namely (1) static memory, (2) static heap, (3) static shared memory. (1) and (2) are parsed by the function `device_tree_get_meminfo()` and (3) is parsed using its own logic. Therefore, to unify the checking logic for all of these types of static region, this commit firstly introduces a helper `check_reserved_regions_overlap()` to check if an input physical address range is overlapping with the existing reserved memory regions defined in bootinfo. After that, use this helper in `device_tree_get_meminfo()` to do the overlap check of (1) and (2) and replace the original overlap check of (3) with this new helper. Signed-off-by: Henry Wang --- xen/arch/arm/bootfdt.c | 13 ++++---- xen/arch/arm/include/asm/setup.h | 2 ++ xen/arch/arm/setup.c | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 6014c0f852..b31379b9ac 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -91,6 +91,9 @@ static int __init device_tree_get_meminfo(const void *fdt= , int node, for ( i =3D 0; i < banks && mem->nr_banks < NR_MEM_BANKS; i++ ) { device_tree_get_reg(&cell, address_cells, size_cells, &start, &siz= e); + if ( mem =3D=3D &bootinfo.reserved_mem && + check_reserved_regions_overlap(start, size) ) + return -EINVAL; /* Some DT may describe empty bank, ignore them */ if ( !size ) continue; @@ -485,7 +488,9 @@ static int __init process_shm_node(const void *fdt, int= node, return -EINVAL; } =20 - if ( (end <=3D mem->bank[i].start) || (paddr >=3D bank_end) ) + if ( check_reserved_regions_overlap(paddr, size) ) + return -EINVAL; + else { if ( strcmp(shm_id, mem->bank[i].shm_id) !=3D 0 ) continue; @@ -496,12 +501,6 @@ static int __init process_shm_node(const void *fdt, in= t node, return -EINVAL; } } - else - { - printk("fdt: shared memory region overlap with an existing= entry %#"PRIpaddr" - %#"PRIpaddr"\n", - mem->bank[i].start, bank_end); - return -EINVAL; - } } } =20 diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index fdbf68aadc..6a9f88ecbb 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -143,6 +143,8 @@ void fw_unreserved_regions(paddr_t s, paddr_t e, size_t boot_fdt_info(const void *fdt, paddr_t paddr); const char *boot_fdt_cmdline(const void *fdt); =20 +int check_reserved_regions_overlap(paddr_t region_start, paddr_t region_si= ze); + struct bootmodule *add_boot_module(bootmodule_kind kind, paddr_t start, paddr_t size, bool domU); struct bootmodule *boot_module_find_by_kind(bootmodule_kind kind); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 4395640019..94d232605e 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -270,6 +270,42 @@ static void __init dt_unreserved_regions(paddr_t s, pa= ddr_t e, cb(s, e); } =20 +static int __init overlap_check(void *bootinfo_type, + paddr_t region_start, paddr_t region_end) +{ + unsigned int i, num =3D 0; + paddr_t bank_start =3D INVALID_PADDR, bank_end =3D 0; + char *type_str =3D "NONAME"; + + if ( bootinfo_type =3D=3D &bootinfo.reserved_mem ) + { + num =3D bootinfo.reserved_mem.nr_banks; + type_str =3D "reserved_mem"; + } + else + panic("Invalid bootinfo type passed to overlap check\n"); + + for ( i =3D 0; i < num; i++ ) + { + if ( bootinfo_type =3D=3D &bootinfo.reserved_mem ) + { + bank_start =3D bootinfo.reserved_mem.bank[i].start; + bank_end =3D bank_start + bootinfo.reserved_mem.bank[i].size; + } + + if ( region_end <=3D bank_start || region_start >=3D bank_end ) + continue; + else + { + printk("%s: Region %#"PRIpaddr" - %#"PRIpaddr" overlapping wit= h bank[%u] %#"PRIpaddr" - %#"PRIpaddr"\n", + type_str, region_start, region_end, i, bank_start, bank= _end); + return -EINVAL; + } + } + + return 0; +} + void __init fw_unreserved_regions(paddr_t s, paddr_t e, void (*cb)(paddr_t, paddr_t), unsigned int first) @@ -280,7 +316,23 @@ void __init fw_unreserved_regions(paddr_t s, paddr_t e, cb(s, e); } =20 +/* + * Given an input physical address range, check if this range is overlappi= ng + * with the existing reserved memory regions defined in bootinfo. + * Return 0 if the input physical address range is not overlapping with any + * existing reserved memory regions, otherwise -EINVAL. + */ +int __init check_reserved_regions_overlap(paddr_t region_start, + paddr_t region_size) +{ + paddr_t region_end =3D region_start + region_size; =20 + /* Check if input region is overlapping with bootinfo.reserved_mem ban= ks */ + if ( overlap_check(&bootinfo.reserved_mem, region_start, region_end) ) + return -EINVAL; + + return 0; +} =20 struct bootmodule __init *add_boot_module(bootmodule_kind kind, paddr_t start, paddr_t size, --=20 2.25.1 From nobody Thu Nov 28 11:02:20 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 1670209123499680.9738307205411; Sun, 4 Dec 2022 18:58:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.453112.710782 (Exim 4.92) (envelope-from ) id 1p21gM-0000TP-M0; Mon, 05 Dec 2022 02:58:14 +0000 Received: by outflank-mailman (output) from mailman id 453112.710782; Mon, 05 Dec 2022 02:58: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 1p21gM-0000TI-J4; Mon, 05 Dec 2022 02:58:14 +0000 Received: by outflank-mailman (input) for mailman id 453112; Mon, 05 Dec 2022 02:58:13 +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 1p21gL-0000CU-Qv for xen-devel@lists.xenproject.org; Mon, 05 Dec 2022 02:58:13 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id a83dd8c3-7448-11ed-91b6-6bf2151ebd3b; Mon, 05 Dec 2022 03:58:13 +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 EEF5414BF; Sun, 4 Dec 2022 18:58:18 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 32DEE3F73D; Sun, 4 Dec 2022 18:58:09 -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: a83dd8c3-7448-11ed-91b6-6bf2151ebd3b From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 2/3] xen/arm: Extend the memory overlap check to include bootmodules Date: Mon, 5 Dec 2022 10:57:52 +0800 Message-Id: <20221205025753.2178965-3-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221205025753.2178965-1-Henry.Wang@arm.com> References: <20221205025753.2178965-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1670209124263100003 Content-Type: text/plain; charset="utf-8" Similarly as the static regions defined in bootinfo.reserved_mem, the bootmodule regions defined in bootinfo.modules should also not be overlapping with memory regions in either bootinfo.reserved_mem or bootinfo.modules. Therefore, this commit extends the check in function `check_reserved_regions_overlap()` to include memory regions in bootinfo.modules, and use `check_reserved_regions_overlap()` in `add_boot_module()` to return early if any error occurs. Signed-off-by: Henry Wang --- xen/arch/arm/setup.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 94d232605e..b43c8e118a 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -282,6 +282,11 @@ static int __init overlap_check(void *bootinfo_type, num =3D bootinfo.reserved_mem.nr_banks; type_str =3D "reserved_mem"; } + else if ( bootinfo_type =3D=3D &bootinfo.modules ) + { + num =3D bootinfo.modules.nr_mods; + type_str =3D "bootmodules"; + } else panic("Invalid bootinfo type passed to overlap check\n"); =20 @@ -292,6 +297,11 @@ static int __init overlap_check(void *bootinfo_type, bank_start =3D bootinfo.reserved_mem.bank[i].start; bank_end =3D bank_start + bootinfo.reserved_mem.bank[i].size; } + else if ( bootinfo_type =3D=3D &bootinfo.modules ) + { + bank_start =3D bootinfo.modules.module[i].start; + bank_end =3D bank_start + bootinfo.modules.module[i].size; + } =20 if ( region_end <=3D bank_start || region_start >=3D bank_end ) continue; @@ -331,6 +341,10 @@ int __init check_reserved_regions_overlap(paddr_t regi= on_start, if ( overlap_check(&bootinfo.reserved_mem, region_start, region_end) ) return -EINVAL; =20 + /* Check if input region is overlapping with bootmodules */ + if ( overlap_check(&bootinfo.modules, region_start, region_end) ) + return -EINVAL; + return 0; } =20 @@ -348,6 +362,10 @@ struct bootmodule __init *add_boot_module(bootmodule_k= ind kind, boot_module_kind_as_string(kind), start, start + size); return NULL; } + + if ( check_reserved_regions_overlap(start, size) ) + return NULL; + for ( i =3D 0 ; i < mods->nr_mods ; i++ ) { mod =3D &mods->module[i]; --=20 2.25.1 From nobody Thu Nov 28 11:02:20 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 1670209124039953.9922965701982; Sun, 4 Dec 2022 18:58:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.453113.710792 (Exim 4.92) (envelope-from ) id 1p21gQ-0000mI-V6; Mon, 05 Dec 2022 02:58:18 +0000 Received: by outflank-mailman (output) from mailman id 453113.710792; Mon, 05 Dec 2022 02:58: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 1p21gQ-0000m9-S7; Mon, 05 Dec 2022 02:58:18 +0000 Received: by outflank-mailman (input) for mailman id 453113; Mon, 05 Dec 2022 02:58: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 1p21gP-0008OK-34 for xen-devel@lists.xenproject.org; Mon, 05 Dec 2022 02:58:17 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a9ece343-7448-11ed-8fd2-01056ac49cbb; Mon, 05 Dec 2022 03:58:15 +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 11F8C23A; Sun, 4 Dec 2022 18:58:22 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 49FD33F73D; Sun, 4 Dec 2022 18:58:13 -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: a9ece343-7448-11ed-8fd2-01056ac49cbb From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Henry Wang , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 3/3] xen/arm: Extend the memory overlap check to include EfiACPIReclaimMemory Date: Mon, 5 Dec 2022 10:57:53 +0800 Message-Id: <20221205025753.2178965-4-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221205025753.2178965-1-Henry.Wang@arm.com> References: <20221205025753.2178965-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1670209126047100007 Content-Type: text/plain; charset="utf-8" Similarly as the static regions and boot modules, memory regions with EfiACPIReclaimMemory type (defined in bootinfo.acpi if CONFIG_ACPI is enabled) should also not be overlapping with memory regions in bootinfo.reserved_mem and bootinfo.modules. Therefore, this commit further extends the check in function `check_reserved_regions_overlap()` to include memory regions in bootinfo.acpi, and use the extended `check_reserved_regions_overlap()` in `meminfo_add_bank()` defined in `efi-boot.h` to return early if any error occurs. Signed-off-by: Henry Wang --- xen/arch/arm/efi/efi-boot.h | 10 ++++++++-- xen/arch/arm/setup.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index 43a836c3a7..6121ba1f2f 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -161,13 +161,19 @@ static bool __init meminfo_add_bank(struct meminfo *m= em, 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 ) return false; +#ifdef CONFIG_ACPI + if ( check_reserved_regions_overlap(start, size) ) + return false; +#endif =20 bank =3D &mem->bank[mem->nr_banks]; - bank->start =3D desc->PhysicalStart; - bank->size =3D desc->NumberOfPages * EFI_PAGE_SIZE; + bank->start =3D start; + bank->size =3D size; =20 mem->nr_banks++; =20 diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index b43c8e118a..f2c2a3b6df 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -287,6 +287,13 @@ static int __init overlap_check(void *bootinfo_type, num =3D bootinfo.modules.nr_mods; type_str =3D "bootmodules"; } +#ifdef CONFIG_ACPI + else if ( bootinfo_type =3D=3D &bootinfo.acpi ) + { + num =3D bootinfo.acpi.nr_banks; + type_str =3D "EfiACPIReclaimMemory"; + } +#endif else panic("Invalid bootinfo type passed to overlap check\n"); =20 @@ -302,6 +309,13 @@ static int __init overlap_check(void *bootinfo_type, bank_start =3D bootinfo.modules.module[i].start; bank_end =3D bank_start + bootinfo.modules.module[i].size; } +#ifdef CONFIG_ACPI + else if ( bootinfo_type =3D=3D &bootinfo.acpi ) + { + bank_start =3D bootinfo.acpi.bank[i].start; + bank_end =3D bank_start + bootinfo.acpi.bank[i].size; + } +#endif =20 if ( region_end <=3D bank_start || region_start >=3D bank_end ) continue; @@ -345,6 +359,12 @@ int __init check_reserved_regions_overlap(paddr_t regi= on_start, if ( overlap_check(&bootinfo.modules, region_start, region_end) ) return -EINVAL; =20 +#ifdef CONFIG_ACPI + /* Check if input region is overlapping with ACPI EfiACPIReclaimMemory= */ + if ( overlap_check(&bootinfo.acpi, region_start, region_end) ) + return -EINVAL; +#endif + return 0; } =20 --=20 2.25.1