From nobody Fri Apr 26 05:59:14 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 1631716005459556.5480508517302; Wed, 15 Sep 2021 07:26:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.187704.336663 (Exim 4.92) (envelope-from ) id 1mQVrg-0002ri-A8; Wed, 15 Sep 2021 14:26:20 +0000 Received: by outflank-mailman (output) from mailman id 187704.336663; Wed, 15 Sep 2021 14:26: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 1mQVrg-0002r8-6w; Wed, 15 Sep 2021 14:26:20 +0000 Received: by outflank-mailman (input) for mailman id 187704; Wed, 15 Sep 2021 14:26:18 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mQVre-0002oh-5f for xen-devel@lists.xenproject.org; Wed, 15 Sep 2021 14:26:18 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e3319440-1630-11ec-b535-12813bfff9fa; Wed, 15 Sep 2021 14:26:16 +0000 (UTC) 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 839F71042; Wed, 15 Sep 2021 07:26:16 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.cambridge.arm.com [10.1.197.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9D5A43F719; Wed, 15 Sep 2021 07:26: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: e3319440-1630-11ec-b535-12813bfff9fa From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, wei.chen@arm.com, Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH 1/2] xen/efi: Restrict check for DT boot modules on EFI boot Date: Wed, 15 Sep 2021 15:26:01 +0100 Message-Id: <20210915142602.42862-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210915142602.42862-1-luca.fancellu@arm.com> References: <20210915142602.42862-1-luca.fancellu@arm.com> X-ZM-MESSAGEID: 1631716007752100003 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When Xen is started as EFI application, it is checking the presence of multiboot,module in the DT, if any is found, the configuration file is skipped. Restrict this check to just any multiboot,module that is a direct child of the /chosen node. Signed-off-by: Luca Fancellu --- xen/arch/arm/efi/efi-boot.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index cf9c37153f..5ff626c6a0 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -581,6 +581,8 @@ static void __init efi_arch_load_addr_check(EFI_LOADED_= IMAGE *loaded_image) =20 static bool __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable) { + int node; + bool dom0_module_found =3D false; /* * For arm, we may get a device tree from GRUB (or other bootloader) * that contains modules that have already been loaded into memory. In @@ -592,11 +594,35 @@ static bool __init efi_arch_use_config_file(EFI_SYSTE= M_TABLE *SystemTable) fdt =3D lookup_fdt_config_table(SystemTable); dtbfile.ptr =3D fdt; dtbfile.need_to_free =3D false; /* Config table memory can't be freed.= */ - if ( !fdt || fdt_node_offset_by_compatible(fdt, 0, "multiboot,module")= < 0 ) + + /* Locate chosen node */ + node =3D fdt_subnode_offset(fdt, 0, "chosen"); + + /* Cycle through every node inside chosen having multiboot,module */ + do { + int depth =3D 0; + node =3D fdt_node_offset_by_compatible(fdt, node, "multiboot,modul= e"); + /* + * If the multiboot,module just found is placed at depth less than= 3, + * it means that it is here: /chosen/ so it is a module to + * start dom0. (root is counted as 0) + */ + if ( node > 0 ) + { + depth =3D fdt_node_depth(fdt, node); + if ( (depth >=3D 0) && (depth < 3) ) + { + dom0_module_found =3D true; + break; + } + } + } while(node > 0); + + if ( !fdt || !dom0_module_found ) { /* * We either have no FDT, or one without modules, so we must have a - * Xen EFI configuration file to specify modules. (dom0 required) + * Xen EFI configuration file to specify modules. */ return true; } --=20 2.17.1 From nobody Fri Apr 26 05:59:14 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 163171600580753.11406044010653; Wed, 15 Sep 2021 07:26:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.187705.336681 (Exim 4.92) (envelope-from ) id 1mQVrk-0003MR-Jl; Wed, 15 Sep 2021 14:26:24 +0000 Received: by outflank-mailman (output) from mailman id 187705.336681; Wed, 15 Sep 2021 14:26:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mQVrk-0003MK-GV; Wed, 15 Sep 2021 14:26:24 +0000 Received: by outflank-mailman (input) for mailman id 187705; Wed, 15 Sep 2021 14:26:23 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mQVrj-0002oh-1A for xen-devel@lists.xenproject.org; Wed, 15 Sep 2021 14:26:23 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e433f3d8-1630-11ec-b535-12813bfff9fa; Wed, 15 Sep 2021 14:26:18 +0000 (UTC) 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 479AE6D; Wed, 15 Sep 2021 07:26:18 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.cambridge.arm.com [10.1.197.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B6D083F719; Wed, 15 Sep 2021 07:26:16 -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: e433f3d8-1630-11ec-b535-12813bfff9fa From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, wei.chen@arm.com, Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Volodymyr Babchuk Subject: [PATCH 2/2] arm/efi: Use dom0less configuration when using EFI boot Date: Wed, 15 Sep 2021 15:26:02 +0100 Message-Id: <20210915142602.42862-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210915142602.42862-1-luca.fancellu@arm.com> References: <20210915142602.42862-1-luca.fancellu@arm.com> X-ZM-MESSAGEID: 1631716007831100004 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch introduces the support for dom0less configuration when using UEFI boot on ARM, it permits the EFI boot to continue if no dom0 kernel is specified but at least one domU is found. Introduce the new property "uefi,binary" for device tree boot module nodes that are subnode of "xen,domain" compatible nodes. The property holds a string containing the file name of the binary that shall be loaded by the uefi loader from the filesystem. Update efi documentation about how to start a dom0less setup using UEFI Signed-off-by: Luca Fancellu --- docs/misc/efi.pandoc | 37 ++++++ xen/arch/arm/efi/efi-boot.h | 244 +++++++++++++++++++++++++++++++++++- xen/common/efi/boot.c | 20 ++- 3 files changed, 294 insertions(+), 7 deletions(-) diff --git a/docs/misc/efi.pandoc b/docs/misc/efi.pandoc index ac3cd58cae..db9b3273f8 100644 --- a/docs/misc/efi.pandoc +++ b/docs/misc/efi.pandoc @@ -165,3 +165,40 @@ sbsign \ --output xen.signed.efi \ xen.unified.efi ``` + +## UEFI boot and dom0less on ARM + +Dom0less feature is supported by ARM and it is possible to use it when Xen= is +started as an EFI application. +The way to specify the domU domains is by Device Tree as specified in the +[dom0less](dom0less.html) documentation page under the "Device Tree +configuration" section, but instead of declaring the reg property in the b= oot +module, the user must specify the "uefi,binary" property containing the na= me +of the binary file that has to be loaded in memory. +The UEFI stub will load the binary in memory and it will add the reg prope= rty +accordingly. + +An example here: + + domU1 { + #address-cells =3D <1>; + #size-cells =3D <1>; + compatible =3D "xen,domain"; + memory =3D <0 0x20000>; + cpus =3D <1>; + vpl011; + + module@1 { + compatible =3D "multiboot,kernel", "multiboot,module"; + uefi,binary =3D "vmlinuz-3.0.31-0.4-xen"; + bootargs =3D "console=3DttyAMA0"; + }; + module@2 { + compatible =3D "multiboot,ramdisk", "multiboot,module"; + uefi,binary =3D "initrd-3.0.31-0.4-xen"; + }; + module@3 { + compatible =3D "multiboot,ramdisk", "multiboot,module"; + uefi,binary =3D "passthrough.dtb"; + }; + }; diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index 5ff626c6a0..8d7ced70f2 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -8,9 +8,39 @@ #include #include =20 +typedef struct { + char* name; + int name_len; +} dom0less_module_name; + +/* + * Binaries will be translated into bootmodules, the maximum number for th= em is + * MAX_MODULES where we should remove a unit for Xen and one for Xen DTB + */ +#define MAX_DOM0LESS_MODULES (MAX_MODULES - 2) +static struct file __initdata dom0less_files[MAX_DOM0LESS_MODULES]; +static dom0less_module_name __initdata dom0less_bin_names[MAX_DOM0LESS_MOD= ULES]; +static uint32_t __initdata dom0less_modules_available =3D MAX_DOM0LESS_MOD= ULES; +static uint32_t __initdata dom0less_modules_idx =3D 0; + +#define ERROR_DOM0LESS_FILE_NOT_FOUND -1 + void noreturn efi_xen_start(void *fdt_ptr, uint32_t fdt_size); void __flush_dcache_area(const void *vaddr, unsigned long size); =20 +static int __init get_dom0less_file_index(const char* name, int name_len); +static uint32_t __init allocate_dom0less_file(EFI_FILE_HANDLE dir_handle, + const char* name, int name_l= en); +static void __init handle_dom0less_module_node(EFI_FILE_HANDLE dir_handle, + int module_node_offset, + int reg_addr_cells, + int reg_size_cells); +static void __init handle_dom0less_domain_node(EFI_FILE_HANDLE dir_handle, + int domain_node, + int addr_cells, + int size_cells); +static bool __init check_dom0less_efi_boot(EFI_FILE_HANDLE dir_handle); + #define DEVICE_TREE_GUID \ {0xb1b621d5, 0xf19c, 0x41a5, {0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0x= e0}} =20 @@ -552,8 +582,209 @@ static void __init efi_arch_handle_module(const struc= t file *file, kernel.size) < 0 ) blexit(L"Unable to set reg property."); } - else + else if ( !((file >=3D &dom0less_files[0]) && + (file <=3D &dom0less_files[MAX_DOM0LESS_MODULES-1])) ) + /* + * If file is not a dom0 module file and it's not any domU modules, + * stop here. + */ blexit(L"Unknown module type"); + + /* + * dom0less_modules_available is decremented here because for each dom0 + * file added, there will be an additional bootmodule, so the number + * of dom0less module files will be decremented because there is + * a maximum amount of bootmodules that can be loaded. + */ + dom0less_modules_available--; +} + +/* + * This function checks for a binary previously loaded with a give name, it + * returns the index of the file in the dom0less_files array or a negative + * number if no file with that name is found. + */ +static int __init get_dom0less_file_index(const char* name, int name_len) +{ + int ret =3D ERROR_DOM0LESS_FILE_NOT_FOUND; + + for (uint32_t i =3D 0; i < dom0less_modules_idx; i++) + { + dom0less_module_name* mod =3D &dom0less_bin_names[i]; + if ( (mod->name_len =3D=3D name_len) && + (strncmp(mod->name, name, name_len) =3D=3D 0) ) + { + ret =3D i; + break; + } + } + return ret; +} + +/* + * This function allocates a binary and keeps track of its name, it + * returns the index of the file in the dom0less_files array. + */ +static uint32_t __init allocate_dom0less_file(EFI_FILE_HANDLE dir_handle, + const char* name, int name_l= en) +{ + dom0less_module_name* file_name; + union string module_name; + struct file* file; + uint32_t ret_idx; + + /* + * Check if there is any space left for a domU module, the variable + * dom0less_modules_available is updated each time we use read_file(..= .) + * successfully. + */ + if ( !dom0less_modules_available ) + blexit(L"No space left for domU modules"); + + module_name.s =3D (char*) name; + ret_idx =3D dom0less_modules_idx; + file =3D &dom0less_files[ret_idx]; + + /* Save at this index the name of this binary */ + file_name =3D &dom0less_bin_names[ret_idx]; + + if ( efi_bs->AllocatePool(EfiLoaderData, (name_len + 1) * sizeof(char), + (void**)&file_name->name) !=3D EFI_SUCCESS ) + blexit(L"Error allocating memory for dom0less binary name"); + + /* Save name and length of the binary in the data structure */ + strlcpy(file_name->name, name, name_len); + file_name->name_len =3D name_len; + + /* Load the binary in memory */ + read_file(dir_handle, s2w(&module_name), file, NULL); + + /* s2w(...) allocates some memory, free it */ + efi_bs->FreePool(module_name.w); + + dom0less_modules_idx++; + + return ret_idx; +} + +/* + * This function checks for the presence of the uefi,binary property in the + * module, if found it loads the binary as dom0less module and sets the ri= ght + * address for the reg property into the module DT node. + */ +static void __init handle_dom0less_module_node(EFI_FILE_HANDLE dir_handle, + int module_node_offset, + int reg_addr_cells, + int reg_size_cells) +{ + const void* uefi_name_prop; + char mod_string[24]; /* Placeholder for module@ + a 64-bit number + \0= */ + int uefi_name_len, file_idx; + struct file* file; + + /* Read uefi,binary property to get the file name. */ + uefi_name_prop =3D fdt_getprop(fdt, module_node_offset, "uefi,binary", + &uefi_name_len); + + if ( NULL =3D=3D uefi_name_prop ) + /* Property not found */ + return; + + file_idx =3D get_dom0less_file_index(uefi_name_prop, uefi_name_len); + if (file_idx < 0) + file_idx =3D allocate_dom0less_file(dir_handle, uefi_name_prop, + uefi_name_len); + + file =3D &dom0less_files[file_idx]; + + snprintf(mod_string, sizeof(mod_string), "module@%"PRIx64, file->addr); + + /* Rename the module to be module@{address} */ + if ( fdt_set_name(fdt, module_node_offset, mod_string) < 0 ) + blexit(L"Unable to add domU ramdisk FDT node."); + + if ( fdt_set_reg(fdt, module_node_offset, reg_addr_cells, reg_size_cel= ls, + file->addr, file->size) < 0 ) + blexit(L"Unable to set reg property."); +} + +/* + * This function checks for boot modules under the domU guest domain node + * in the DT. + */ +static void __init handle_dom0less_domain_node(EFI_FILE_HANDLE dir_handle, + int domain_node, + int addr_cells, + int size_cells) +{ + /* + * Check for nodes compatible with multiboot,{kernel,ramdisk,device-tr= ee} + * inside this node + */ + for ( int module_node =3D fdt_first_subnode(fdt, domain_node); + module_node > 0; + module_node =3D fdt_next_subnode(fdt, module_node) ) + { + if ( (fdt_node_check_compatible(fdt, module_node, + "multiboot,kernel") =3D=3D 0) || + (fdt_node_check_compatible(fdt, module_node, + "multiboot,ramdisk") =3D=3D 0) || + (fdt_node_check_compatible(fdt, module_node, + "multiboot,device-tree") =3D=3D 0)= ) + { + /* The compatible is one of the strings above, check the modul= e */ + handle_dom0less_module_node(dir_handle, module_node, addr_cell= s, + size_cells); + } + } +} + +/* + * This function checks for xen domain nodes under the /chosen node for po= ssible + * domU guests to be loaded. + */ +static bool __init check_dom0less_efi_boot(EFI_FILE_HANDLE dir_handle) +{ + int chosen; + int addr_len, size_len; + + /* Check for the chosen node in the current DTB */ + chosen =3D setup_chosen_node(fdt, &addr_len, &size_len); + if ( chosen < 0 ) + blexit(L"Unable to setup chosen node"); + + /* Check for nodes compatible with xen,domain under the chosen node */ + for ( int node =3D fdt_first_subnode(fdt, chosen); + node > 0; + node =3D fdt_next_subnode(fdt, node) ) + { + int addr_cells, size_cells, len; + const struct fdt_property *prop; + + if ( fdt_node_check_compatible(fdt, node, "xen,domain") !=3D 0 ) + continue; + + /* Get or set #address-cells and #size-cells */ + prop =3D fdt_get_property(fdt, node, "#address-cells", &len); + if ( !prop ) + blexit(L"#address-cells not found in domain node."); + + addr_cells =3D fdt32_to_cpu(*((uint32_t *)prop->data)); + + prop =3D fdt_get_property(fdt, node, "#size-cells", &len); + if ( !prop ) + blexit(L"#size-cells not found in domain node."); + + size_cells =3D fdt32_to_cpu(*((uint32_t *)prop->data)); + + /* Found a node with compatible xen,domain; handle this node. */ + handle_dom0less_domain_node(dir_handle, node, addr_cells, size_cel= ls); + } + + if ( dom0less_modules_idx > 0 ) + return true; + + return false; } =20 static void __init efi_arch_cpu(void) @@ -562,8 +793,19 @@ static void __init efi_arch_cpu(void) =20 static void __init efi_arch_blexit(void) { + uint32_t i =3D 0; if ( dtbfile.need_to_free ) efi_bs->FreePages(dtbfile.addr, PFN_UP(dtbfile.size)); + /* Free dom0less files if any */ + for ( ; i < dom0less_modules_idx; i++ ) + { + /* Free dom0less binary names */ + efi_bs->FreePool(dom0less_bin_names[i].name); + /* Free dom0less binaries */ + if ( dom0less_files[i].need_to_free ) + efi_bs->FreePages(dom0less_files[i].addr, + PFN_UP(dom0less_files[i].size)); + } if ( memmap ) efi_bs->FreePool(memmap); } diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 758f9d74d2..65493c4b46 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1134,8 +1134,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *S= ystemTable) EFI_GRAPHICS_OUTPUT_PROTOCOL *gop =3D NULL; union string section =3D { NULL }, name; bool base_video =3D false; - const char *option_str; + const char *option_str =3D NULL; bool use_cfg_file; + bool dom0less_found =3D false; =20 __set_bit(EFI_BOOT, &efi_flags); __set_bit(EFI_LOADER, &efi_flags); @@ -1285,14 +1286,21 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE = *SystemTable) efi_bs->FreePool(name.w); } =20 - if ( !name.s ) - blexit(L"No Dom0 kernel image specified."); - efi_arch_cfg_file_early(loaded_image, dir_handle, section.s); =20 - option_str =3D split_string(name.s); +#ifdef CONFIG_ARM + /* dom0less feature is supported only on ARM */ + dom0less_found =3D check_dom0less_efi_boot(dir_handle); +#endif + + if ( !name.s && !dom0less_found ) + blexit(L"No Dom0 kernel image specified."); + + if ( name.s !=3D NULL ) + option_str =3D split_string(name.s); =20 - if ( !read_section(loaded_image, L"kernel", &kernel, option_str) ) + if ( (!read_section(loaded_image, L"kernel", &kernel, option_str))= && + (name.s !=3D NULL) ) { read_file(dir_handle, s2w(&name), &kernel, option_str); efi_bs->FreePool(name.w); --=20 2.17.1