From nobody Sat May 18 09:48:40 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; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) ARC-Seal: i=2; a=rsa-sha256; t=1653951123; cv=pass; d=zohomail.com; s=zohoarc; b=DrZUZ5mYfEx5GqiOLzbApRJQle+tv7YU+C3IaHR7tEHeft5wajgIIWqnYl+dAO1CWqPU0DczAj/dBz3MHgTXmcX2MG4iPz1lxjCx1fT5IrZrw7vsP2LKYObY8GtGKXsqSsTmfMTgX2Xu9yWKMZUaMz7ZZuJ6HeS72H7Dt88dvEI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653951123; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2+etTsXf8iWllebDioWmtCtaWII0LrkP35ocYWHoB/I=; b=eXNIHGuN5UAr+kLbNHLLY1cRjTrJEZKWkSr3t7l6Dh6kAjx0LILeFn8oNTE1/4eSVrL0mrAZcD+iLt756tccfln1wxqXPM9blMNe3rhT/RsgjlHSS4Np+agq+VlOpc59KtqEgiAakREPRNq9Og/hMlajzsY+p1SI4tfnpdR+/+8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1653951123419434.0294886298459; Mon, 30 May 2022 15:52:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.338919.563765 (Exim 4.92) (envelope-from ) id 1nvoEj-0003G8-SO; Mon, 30 May 2022 22:51:45 +0000 Received: by outflank-mailman (output) from mailman id 338919.563765; Mon, 30 May 2022 22:51:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nvoEj-0003F9-Ig; Mon, 30 May 2022 22:51:45 +0000 Received: by outflank-mailman (input) for mailman id 338919; Mon, 30 May 2022 22:51:44 +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 1nvo5R-000799-AV for xen-devel@lists.xenproject.org; Mon, 30 May 2022 22:42:09 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bbc29904-e069-11ec-837f-e5687231ffcc; Tue, 31 May 2022 00:42:08 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1653950519242310.60530902135247; Mon, 30 May 2022 15:41:59 -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: bbc29904-e069-11ec-837f-e5687231ffcc ARC-Seal: i=1; a=rsa-sha256; t=1653950521; cv=none; d=zohomail.com; s=zohoarc; b=RxB74e1r1rnfOsVx9gK0CxQZgO3Hu8VtwZUSf6IgJAc5PflyNI0fbvpv6GEZ/XYjkBE6KpH5pn8JZiS22UvSHzHErKXuYSOVMb/dJzbw7T7NN1Hk4QJaOYk/q/YO+dZXGyKuLehkA6w5jSOn34FLnXVlCSTY2K0q7o2r4nm0FXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653950521; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=2+etTsXf8iWllebDioWmtCtaWII0LrkP35ocYWHoB/I=; b=hJFyPSqkOUVI3H9q3eLvGA8dISVN/rM4xp/FSaAavtGnhMFJlTSmXAsRSEam5Mx8sONqIc7l4HGKdaIV2NJ0PVFrKBbEscWNb4phcnBbguW1dUG5fcca+EU2iiXR2YC48Dk9gjYrUJCK0ycH7RSGogz123fS2/GPBMvrHOCgv98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1653950521; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=2+etTsXf8iWllebDioWmtCtaWII0LrkP35ocYWHoB/I=; b=SxokjebdsIBmtYMxINXGexQDmrmm+sA2AyKe9T8m8htkd01gX7wnCaIPF00Is+K8 2wVnU4N+Eu5KyDztbTzgknca93xGh1G9b/yUFFueDxjthJCuu87mAoIUk6gSxXDatPP c1K4ez9khzvVrRGSvjVietSCeHREaba6n2cFtGXk= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Volodymyr Babchuk , Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, sstabellini@kernel.org, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Bertrand Marquis , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [RFC PATCH 1/4] kconfig: allow configuration of maximum modules Date: Mon, 30 May 2022 22:41:23 -0400 Message-Id: <20220531024127.23669-2-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220531024127.23669-1-dpsmith@apertussolutions.com> References: <20220531024127.23669-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1653951124507100001 Content-Type: text/plain; charset="utf-8" For x86 the number of allowable multiboot modules varies between the differ= ent entry points, non-efi boot, pvh boot, and efi boot. In the case of both Arm= and x86 this value is fixed to values based on generalized assumptions. With hyperlaunch for x86 and dom0less on Arm, use of static sizes results in lar= ge allocations compiled into the hypervisor that will go unused by many use ca= ses. This commit introduces a Kconfig variable that is set with sane defaults ba= sed on configuration selection. This variable is in turned used as the array si= ze for the cases where a static allocated array of boot modules is declared. Signed-off-by: Daniel P. Smith Reviewed-by: Bertrand Marquis --- xen/arch/Kconfig | 12 ++++++++++++ xen/arch/arm/include/asm/setup.h | 5 +++-- xen/arch/x86/efi/efi-boot.h | 2 +- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/setup.c | 4 ++-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig index f16eb0df43..57b14e22c9 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -17,3 +17,15 @@ config NR_CPUS For CPU cores which support Simultaneous Multi-Threading or similar technologies, this the number of logical threads which Xen will support. + +config NR_BOOTMODS + int "Maximum number of boot modules that a loader can pass" + range 1 64 + default "8" if X86 + default "32" if ARM + help + Controls the build-time size of various arrays allocated for + parsing the boot modules passed by a loader when starting Xen. + + This is of particular interest when using Xen's hypervisor domain + capabilities such as dom0less. diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 2bb01ecfa8..312a3e4209 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -10,7 +10,8 @@ =20 #define NR_MEM_BANKS 256 =20 -#define MAX_MODULES 32 /* Current maximum useful modules */ +/* Current maximum useful modules */ +#define MAX_MODULES CONFIG_NR_BOOTMODS =20 typedef enum { BOOTMOD_XEN, @@ -38,7 +39,7 @@ struct meminfo { * 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 * kernel_probe, where we try to guess which is the dom0 kernel and - * initrd to be compatible with all versions of the multiboot spec.=20 + * initrd to be compatible with all versions of the multiboot spec. */ #define BOOTMOD_MAX_CMDLINE 1024 struct bootmodule { diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 6e65b569b0..4e1a799749 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -18,7 +18,7 @@ static multiboot_info_t __initdata mbi =3D { * The array size needs to be one larger than the number of modules we * support - see __start_xen(). */ -static module_t __initdata mb_modules[5]; +static module_t __initdata mb_modules[CONFIG_NR_BOOTMODS + 1]; =20 static void __init edd_put_string(u8 *dst, size_t n, const char *src) { diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh= -boot.c index 498625eae0..834b1ad16b 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -32,7 +32,7 @@ bool __initdata pvh_boot; uint32_t __initdata pvh_start_info_pa; =20 static multiboot_info_t __initdata pvh_mbi; -static module_t __initdata pvh_mbi_mods[8]; +static module_t __initdata pvh_mbi_mods[CONFIG_NR_BOOTMOD + 1]; static const char *__initdata pvh_loader =3D "PVH Directboot"; =20 static void __init convert_pvh_info(multiboot_info_t **mbi, diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index ed67b50c9d..3f5e602e00 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1017,9 +1017,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) panic("dom0 kernel not specified. Check bootloader configuration\n= "); =20 /* Check that we don't have a silly number of modules. */ - if ( mbi->mods_count > sizeof(module_map) * 8 ) + if ( mbi->mods_count > CONFIG_NR_BOOTMODS ) { - mbi->mods_count =3D sizeof(module_map) * 8; + mbi->mods_count =3D CONFIG_NR_BOOTMODS; printk("Excessive multiboot modules - using the first %u only\n", mbi->mods_count); } --=20 2.20.1 From nobody Sat May 18 09:48:40 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; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) ARC-Seal: i=2; a=rsa-sha256; t=1653951126; cv=pass; d=zohomail.com; s=zohoarc; b=L5/30/HeVPHt1TxpRDIijJPTo0VjrN5c/0lSck6K/oYuAbqBBZPa5XVR+AIBtfqTqMjnPRxZCCHnpYXE9KtuI2qhr5ecUdGnRzEoYo5lzUN5wqRFsLmMDH1w1wdf78TqJyAUg9RQlS1bp5cux+dVXGtI76BAKdTZWq0EvpMX7Vo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653951126; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iAGucPdV3glHdtZABJs2CPxR/bL8xV7VFYB5AxMoSfc=; b=iuEoNT+57m0YMtYDT7AsdFjV3LpcXgmUbF3lJns5eW3DTKC1GI3DJmlxwHCHhzeNInoZ1x8pXOPzQVikQiSQgfu6ASn5NwV1tucid8xy1MCdZUWaMWdmmy88lHYfQXIHhewAOZITa5RY7/2jBojYlAF21J5XmZbeR5dD+zadWrY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 165395112643499.61988354406617; Mon, 30 May 2022 15:52:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.338924.563782 (Exim 4.92) (envelope-from ) id 1nvoEm-0003nG-9l; Mon, 30 May 2022 22:51:48 +0000 Received: by outflank-mailman (output) from mailman id 338924.563782; Mon, 30 May 2022 22:51:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nvoEm-0003n3-56; Mon, 30 May 2022 22:51:48 +0000 Received: by outflank-mailman (input) for mailman id 338924; Mon, 30 May 2022 22:51:46 +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 1nvo5k-000799-VG for xen-devel@lists.xenproject.org; Mon, 30 May 2022 22:42:29 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c77b6256-e069-11ec-837f-e5687231ffcc; Tue, 31 May 2022 00:42:27 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1653950520786963.2599323551407; Mon, 30 May 2022 15:42:00 -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: c77b6256-e069-11ec-837f-e5687231ffcc ARC-Seal: i=1; a=rsa-sha256; t=1653950523; cv=none; d=zohomail.com; s=zohoarc; b=e9pf82uT1+AgRUwvRHljQ3G2Zsg2NnZDD3cxpbCheLfPmFO2qJnrbI/9Sl8sP0QKOzkkMpwoVCkAK9NDwTHQ6zMH/hJ/jRPEnN2Z1Lk1WGJSqXbNib0TY1qVU8OPdxtSizwo7hDQtF5YrpZ2e6KElOHiPqpaQZrOW5RDb/40Ew8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653950523; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=iAGucPdV3glHdtZABJs2CPxR/bL8xV7VFYB5AxMoSfc=; b=J32e/CeBeSMVOOAhRY8ND7fWlBjx9I1BwOdOT4zT+inqN+M11Zs0HmF/naaLdCtufv2WV+KgAvYM4lSinFA0JWHG9KSi1Oow6ACwmdue5phWMqkHz6MKHEwdkLtcK10fJ2YK/X3OA1MspuIQlfsa2d62Ho9M4pC9l0ezUkn2Ykw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1653950523; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Reply-To; bh=iAGucPdV3glHdtZABJs2CPxR/bL8xV7VFYB5AxMoSfc=; b=MKli1T29u3OeXeN0juTd4Hzsdz8wvXUTJUsgdL3YPmH0xIVY95lg5y1Q+9SLbiJK MuP/WcU8/xTvVPGKLAii86cvpn39DBYTtSKiVSJ5z3X8kmunxwoftWfTnu9IP0Y08wQ DT2uvis3q6cYMtPqU5yIXBGhKTgtfvCl4gW8Vc7U= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, sstabellini@kernel.org, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall Subject: [RFC PATCH 2/4] headers: introduce generalized boot info Date: Mon, 30 May 2022 22:41:24 -0400 Message-Id: <20220531024127.23669-3-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220531024127.23669-1-dpsmith@apertussolutions.com> References: <20220531024127.23669-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1653951128558100001 The x86 and Arm architectures represent in memory the general boot informat= ion and boot modules differently despite having commonality. The x86 representations are bound to the multiboot v1 structures while the Arm representations are a slightly generalized meta-data container for the boot material. The multiboot structure does not lend itself well to being expand= ed to accommodate additional metadata, both general and boot module specific. = The Arm structures are not bound to an external specification and thus are able= to be expanded for solutions such as dom0less. This commit introduces a set of structures patterned off the Arm structures= to represent the boot information in a manner that captures common data. The structures provide an arch field to allow arch specific expansions to the structures. The intended goal of these new common structures is to enable commonality between the different architectures. =C2=A0Specifically to enab= le dom0less and hyperlaunch to have a common representation of boot-time constructed domains. Signed-off-by: Daniel P. Smith --- xen/arch/x86/include/asm/bootinfo.h | 45 ++++++++++++++++++++++++ xen/include/xen/bootinfo.h | 54 +++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 xen/arch/x86/include/asm/bootinfo.h create mode 100644 xen/include/xen/bootinfo.h diff --git a/xen/arch/x86/include/asm/bootinfo.h b/xen/arch/x86/include/asm= /bootinfo.h new file mode 100644 index 0000000000..13e49f2b87 --- /dev/null +++ b/xen/arch/x86/include/asm/bootinfo.h @@ -0,0 +1,45 @@ +#ifndef __ARCH_X86_BOOTINFO_H__ +#define __ARCH_X86_BOOTINFO_H__ + +/* unused for x86 */ +struct arch_bootstring { }; + +struct __packed arch_bootmodule { +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 + uint32_t flags; + uint32_t headroom; +}; + +struct __packed arch_boot_info { + uint32_t flags; +#define BOOTINFO_FLAG_X86_MEMLIMITS 1U << 0 +#define BOOTINFO_FLAG_X86_BOOTDEV 1U << 1 +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 +#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_AOUT_SYMS 1U << 4 +#define BOOTINFO_FLAG_X86_ELF_SYMS 1U << 5 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_DRIVES 1U << 7 +#define BOOTINFO_FLAG_X86_BIOSCONFIG 1U << 8 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 +#define BOOTINFO_FLAG_X86_APM 1U << 10 + + char *boot_loader_name; + + uint32_t mem_lower; + uint32_t mem_upper; + + uint32_t mmap_length; + paddr_t mmap_addr; +}; + +struct __packed mb_memmap { + uint32_t size; + uint32_t base_addr_low; + uint32_t base_addr_high; + uint32_t length_low; + uint32_t length_high; + uint32_t type; +}; + +#endif diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h new file mode 100644 index 0000000000..42b53a3ca6 --- /dev/null +++ b/xen/include/xen/bootinfo.h @@ -0,0 +1,54 @@ +#ifndef __XEN_BOOTINFO_H__ +#define __XEN_BOOTINFO_H__ + +#include +#include + +#include + +typedef enum { + BOOTMOD_UNKNOWN, + BOOTMOD_XEN, + BOOTMOD_FDT, + BOOTMOD_KERNEL, + BOOTMOD_RAMDISK, + BOOTMOD_XSM, + BOOTMOD_UCODE, + BOOTMOD_GUEST_DTB, +} bootmodule_kind; + +typedef enum { + BOOTSTR_EMPTY, + BOOTSTR_STRING, + BOOTSTR_CMDLINE, +} bootstring_kind; + +#define BOOTMOD_MAX_STRING 1024 +struct __packed boot_string { + bootstring_kind kind; + struct arch_bootstring *arch; + + char bytes[BOOTMOD_MAX_STRING]; + size_t len; +}; + +struct __packed boot_module { + bootmodule_kind kind; + paddr_t start; + mfn_t mfn; + size_t size; + + struct arch_bootmodule *arch; + struct boot_string string; +}; + +struct __packed boot_info { + char *cmdline; + + uint32_t nr_mods; + struct boot_module *mods; + + struct arch_boot_info *arch; +}; + +#endif --=20 2.20.1 From nobody Sat May 18 09:48:40 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; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) ARC-Seal: i=2; a=rsa-sha256; t=1653951127; cv=pass; d=zohomail.com; s=zohoarc; b=RWCbX1h3jZG7M7jAOc32opAbsvfkjzMxHCeCgsc1WHTiuMKaMrHaJMcVhGipHbsG3LEJxrd7EH50QuS8TbnLcVOHa9P2zcNshCm167t63OTBwJktZKBN1FRn/H2DdR7j/baUM6YBLFT6GZX79+/qW/QkpWyuBlwd0hNPuuYdAGY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653951127; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uWZhwVvs+kMg/Fm6P9a8fRK9wIT+9jMYCWMw8CQL0M0=; b=ib/tewzy5PU7BdIzt1BxRzYHZjSeWLN06AtU2dFtqu1IKOxoRCleygtDzceVsJDas4Os3BF1vfCfePgWG9S5YrEtZcewfABOU8e54hygi/8DRf3xcohdbueke08jGaagHIP5i11oNdUzG3lyuivlYryMTU5Db+aPEtPKNXHfv4Y= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1653951127628334.4722252632138; Mon, 30 May 2022 15:52:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.338916.563760 (Exim 4.92) (envelope-from ) id 1nvoEj-0003Cp-Cg; Mon, 30 May 2022 22:51:45 +0000 Received: by outflank-mailman (output) from mailman id 338916.563760; Mon, 30 May 2022 22:51:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nvoEj-0003Ci-8a; Mon, 30 May 2022 22:51:45 +0000 Received: by outflank-mailman (input) for mailman id 338916; Mon, 30 May 2022 22:51:44 +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 1nvo5z-0006Rh-OJ for xen-devel@lists.xenproject.org; Mon, 30 May 2022 22:42:44 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cf2a065c-e069-11ec-bd2c-47488cf2e6aa; Tue, 31 May 2022 00:42:40 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1653950522594696.5498699912004; Mon, 30 May 2022 15:42:02 -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: cf2a065c-e069-11ec-bd2c-47488cf2e6aa ARC-Seal: i=1; a=rsa-sha256; t=1653950523; cv=none; d=zohomail.com; s=zohoarc; b=E/BunImJSl5fmbZFKPm/Ab/bh32c/HTZgu/DUPvDGyj8BuYI1UixOyD+xZU4QJG7pwaOlahwe8ygDuZ7YCAKx3SBmWDF/hGp7HlsXEijJLLqZB2pS6eYkYC/dRu+VtntrJ/T/uUGMkFuCsaXhhmdPr5co+GKzWRVDoqJmF019DQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653950523; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=uWZhwVvs+kMg/Fm6P9a8fRK9wIT+9jMYCWMw8CQL0M0=; b=WY0BN37i/RORGEsWjkDLf/NXj1bBVO3XMCXJQooB5fsW042MivY0NeCCQWQyLjqE+5xlAowwaYyUF3wHVsYkEcoMPtTJeZV12yCdL76v+pXUGP6Az0rhj1aOkuLKv5/yYpRjpqvzvhjMz+nuR9mJzUqTyJyjpkDluD3iSCZNMm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1653950523; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=uWZhwVvs+kMg/Fm6P9a8fRK9wIT+9jMYCWMw8CQL0M0=; b=ofEpTkpvhNVYeIsq+XbWq3MdAgEmCBDxWQKQ4LUJXeT77AlcohC3IUyHp101QkLG smIia3M07LZ2eE+eWTTTRGOfUNwH8s3bDCTu6oFE8cda0mylemWHMbE40DI1qO9ER8W tmybM0RDqtYn/gwjT9NoRGHdUquJorKZs9114v1w= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu , "Daniel P. Smith" Cc: scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Julien Grall , Stefano Stabellini , Daniel De Graaf Subject: [RFC PATCH 3/4] x86: adopt new boot info structures Date: Mon, 30 May 2022 22:41:25 -0400 Message-Id: <20220531024127.23669-4-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220531024127.23669-1-dpsmith@apertussolutions.com> References: <20220531024127.23669-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1653951128594100002 Content-Type: text/plain; charset="utf-8" This commit replaces the use of the multiboot v1 structures starting at __start_xen(). The majority of this commit is converting the fields being accessed for the startup calculations. While adapting the ucode boot module location logic, this code was refactored to reduce some of the unnecessary complexity. Signed-off-by: Daniel P. Smith --- xen/arch/x86/bzimage.c | 16 +- xen/arch/x86/cpu/microcode/core.c | 134 ++++++++------ xen/arch/x86/dom0_build.c | 13 +- xen/arch/x86/hvm/dom0_build.c | 42 ++--- xen/arch/x86/include/asm/bzimage.h | 5 +- xen/arch/x86/include/asm/dom0_build.h | 15 +- xen/arch/x86/include/asm/setup.h | 14 +- xen/arch/x86/pv/dom0_build.c | 34 ++-- xen/arch/x86/setup.c | 249 +++++++++++++++----------- xen/include/xen/bootinfo.h | 47 +++++ xen/include/xsm/xsm.h | 26 ++- xen/xsm/xsm_core.c | 22 ++- xen/xsm/xsm_policy.c | 44 ++--- 13 files changed, 391 insertions(+), 270 deletions(-) diff --git a/xen/arch/x86/bzimage.c b/xen/arch/x86/bzimage.c index ac4fd428be..c742a04687 100644 --- a/xen/arch/x86/bzimage.c +++ b/xen/arch/x86/bzimage.c @@ -69,10 +69,8 @@ static __init int bzimage_check(struct setup_header *hdr= , unsigned long len) return 1; } =20 -static unsigned long __initdata orig_image_len; - -unsigned long __init bzimage_headroom(void *image_start, - unsigned long image_length) +unsigned long __init bzimage_headroom( + void *image_start, unsigned long image_length) { struct setup_header *hdr =3D (struct setup_header *)image_start; int err; @@ -91,7 +89,6 @@ unsigned long __init bzimage_headroom(void *image_start, if ( elf_is_elfbinary(image_start, image_length) ) return 0; =20 - orig_image_len =3D image_length; headroom =3D output_length(image_start, image_length); if (gzip_check(image_start, image_length)) { @@ -104,12 +101,15 @@ unsigned long __init bzimage_headroom(void *image_sta= rt, return headroom; } =20 -int __init bzimage_parse(void *image_base, void **image_start, - unsigned long *image_len) +int __init bzimage_parse( + void *image_base, void **image_start, unsigned int headroom, + unsigned long *image_len) { struct setup_header *hdr =3D (struct setup_header *)(*image_start); int err =3D bzimage_check(hdr, *image_len); - unsigned long output_len; + unsigned long output_len, orig_image_len; + + orig_image_len =3D *image_len - headroom; =20 if ( err < 0 ) return err; diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 452a7ca773..f773eb89e8 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -22,6 +22,7 @@ */ =20 #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include =20 + #include #include #include @@ -54,7 +56,6 @@ */ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 =20 -static module_t __initdata ucode_mod; static signed int __initdata ucode_mod_idx; static bool_t __initdata ucode_mod_forced; static unsigned int nr_cores; @@ -147,74 +148,113 @@ static int __init cf_check parse_ucode(const char *s) } custom_param("ucode", parse_ucode); =20 -void __init microcode_scan_module( - unsigned long *module_map, - const multiboot_info_t *mbi) +#define MICROCODE_MODULE_MATCH 1 +#define MICROCODE_MODULE_NONMATCH 0 + +static int __init microcode_check_module(struct boot_module *mod) { - module_t *mod =3D (module_t *)__va(mbi->mods_addr); uint64_t *_blob_start; unsigned long _blob_size; - struct cpio_data cd; + struct cpio_data cd =3D { NULL, 0 }; long offset; const char *p =3D NULL; - int i; - - ucode_blob.size =3D 0; - if ( !ucode_scan ) - return; =20 if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD ) p =3D "kernel/x86/microcode/AuthenticAMD.bin"; else if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL ) p =3D "kernel/x86/microcode/GenuineIntel.bin"; else + return -EFAULT; + + _blob_start =3D bootstrap_map(mod); + _blob_size =3D mod->size; + if ( !_blob_start ) + { + printk("Could not map multiboot module (0x%lx) (size: %ld)\n", + mod->start, _blob_size); + /* Non-fatal error, so just say no match */ + return MICROCODE_MODULE_NONMATCH; + } + + cd =3D find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */= ); + + if ( cd.data ) + { + ucode_blob.size =3D cd.size; + ucode_blob.data =3D cd.data; + + mod->kind =3D BOOTMOD_UCODE; + return MICROCODE_MODULE_MATCH; + } + + bootstrap_map(NULL); + + return 0; +} + +void __init microcode_scan_module(struct boot_info *bi) +{ + int idx =3D 0; + + if ( !ucode_scan ) return; =20 /* - * Try all modules and see whichever could be the microcode blob. + * Try unidentified modules and see which could be the microcode blob. */ - for ( i =3D 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ ) + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, idx); + while ( idx < bi->nr_mods ) { - if ( !test_bit(i, module_map) ) - continue; + int ret; =20 - _blob_start =3D bootstrap_map(&mod[i]); - _blob_size =3D mod[i].mod_end; - if ( !_blob_start ) + ret =3D microcode_check_module(&bi->mods[idx]); + switch ( ret ) { - printk("Could not map multiboot module #%d (size: %ld)\n", - i, _blob_size); + case MICROCODE_MODULE_MATCH: + return; + case MICROCODE_MODULE_NONMATCH: + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, ++idx= ); continue; + default: + printk("%s: (err: %d) unable to check microcode\n", + __func__, ret); + return; } - cd.data =3D NULL; - cd.size =3D 0; - cd =3D find_cpio_data(p, _blob_start, _blob_size, &offset /* ignor= e */); - if ( cd.data ) - { - ucode_blob.size =3D cd.size; - ucode_blob.data =3D cd.data; - break; - } - bootstrap_map(NULL); } } -void __init microcode_grab_module( - unsigned long *module_map, - const multiboot_info_t *mbi) + +void __init microcode_grab_module(struct boot_info *bi) { - module_t *mod =3D (module_t *)__va(mbi->mods_addr); + ucode_blob.size =3D 0; =20 if ( ucode_mod_idx < 0 ) - ucode_mod_idx +=3D mbi->mods_count; - if ( ucode_mod_idx <=3D 0 || ucode_mod_idx >=3D mbi->mods_count || - !__test_and_clear_bit(ucode_mod_idx, module_map) ) - goto scan; - ucode_mod =3D mod[ucode_mod_idx]; -scan: + ucode_mod_idx +=3D bi->nr_mods; + if ( ucode_mod_idx >=3D 0 && ucode_mod_idx <=3D bi->nr_mods && + bi->mods[ucode_mod_idx].kind =3D=3D BOOTMOD_UNKNOWN ) + { + int ret =3D microcode_check_module(&bi->mods[ucode_mod_idx]); + + switch ( ret ) + { + case MICROCODE_MODULE_MATCH: + return; + case MICROCODE_MODULE_NONMATCH: + break; + default: + printk("%s: (err: %d) unable to check microcode\n", + __func__, ret); + return; + } + } + if ( ucode_scan ) - microcode_scan_module(module_map, mbi); + microcode_scan_module(bi); } =20 +/* Undefining as they are not needed anymore */ +#undef MICROCODE_MODULE_MATCH +#undef MICROCODE_MODULE_NONMATCH + static struct microcode_ops __ro_after_init ucode_ops; =20 static DEFINE_SPINLOCK(microcode_mutex); @@ -711,11 +751,6 @@ static int __init cf_check microcode_init(void) ucode_blob.size =3D 0; ucode_blob.data =3D NULL; } - else if ( ucode_mod.mod_end ) - { - bootstrap_map(NULL); - ucode_mod.mod_end =3D 0; - } =20 return 0; } @@ -745,11 +780,6 @@ static int __init early_microcode_update_cpu(void) len =3D ucode_blob.size; data =3D ucode_blob.data; } - else if ( ucode_mod.mod_end ) - { - len =3D ucode_mod.mod_end; - data =3D bootstrap_map(&ucode_mod); - } =20 if ( !data ) return -ENOMEM; @@ -799,7 +829,7 @@ int __init early_microcode_init(void) =20 alternative_vcall(ucode_ops.collect_cpu_info); =20 - if ( ucode_mod.mod_end || ucode_blob.size ) + if ( ucode_blob.size ) rc =3D early_microcode_update_cpu(); =20 return rc; diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index 79234f18ff..5a27e50e32 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -1,9 +1,10 @@ /*************************************************************************= ***** * dom0_build.c - *=20 + * * Copyright (c) 2002-2005, K A Fraser */ =20 +#include #include #include #include @@ -574,9 +575,9 @@ int __init dom0_setup_permissions(struct domain *d) return rc; } =20 -int __init construct_dom0(struct domain *d, const module_t *image, - unsigned long image_headroom, module_t *initrd, - char *cmdline) +int __init construct_dom0( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { int rc; =20 @@ -588,9 +589,9 @@ int __init construct_dom0(struct domain *d, const modul= e_t *image, process_pending_softirqs(); =20 if ( is_hvm_domain(d) ) - rc =3D dom0_construct_pvh(d, image, image_headroom, initrd, cmdlin= e); + rc =3D dom0_construct_pvh(d, image, initrd, cmdline); else if ( is_pv_domain(d) ) - rc =3D dom0_construct_pv(d, image, image_headroom, initrd, cmdline= ); + rc =3D dom0_construct_pv(d, image, initrd, cmdline); else panic("Cannot construct Dom0. No guest interface available\n"); =20 diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index 1864d048a1..4e903a848d 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -19,9 +19,9 @@ */ =20 #include +#include #include #include -#include #include #include =20 @@ -543,14 +543,13 @@ static paddr_t __init find_memory( return INVALID_PADDR; } =20 -static int __init pvh_load_kernel(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, void *image_base, - char *cmdline, paddr_t *entry, - paddr_t *start_info_addr) +static int __init pvh_load_kernel( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, void *image_base, char *cmdline, + paddr_t *entry, paddr_t *start_info_addr) { - void *image_start =3D image_base + image_headroom; - unsigned long image_len =3D image->mod_end; + void *image_start =3D image_base + image->arch->headroom; + unsigned long image_len =3D image->size; struct elf_binary elf; struct elf_dom_parms parms; paddr_t last_addr; @@ -559,7 +558,9 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, struct vcpu *v =3D d->vcpu[0]; int rc; =20 - if ( (rc =3D bzimage_parse(image_base, &image_start, &image_len)) !=3D= 0 ) + if ( (rc =3D + bzimage_parse(image_base, &image_start, image->arch->headroom, + &image_len)) !=3D 0 ) { printk("Error trying to detect bz compressed kernel\n"); return rc; @@ -606,7 +607,7 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, * simplify it. */ last_addr =3D find_memory(d, &elf, sizeof(start_info) + - (initrd ? ROUNDUP(initrd->mod_end, PAGE_SIZE) + + (initrd ? ROUNDUP(initrd->size, PAGE_SIZE) + sizeof(mod) : 0) + (cmdline ? ROUNDUP(strlen(cmdline) + 1, @@ -620,8 +621,8 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, =20 if ( initrd !=3D NULL ) { - rc =3D hvm_copy_to_guest_phys(last_addr, mfn_to_virt(initrd->mod_s= tart), - initrd->mod_end, v); + rc =3D hvm_copy_to_guest_phys(last_addr, maddr_to_virt(initrd->sta= rt), + initrd->size, v); if ( rc ) { printk("Unable to copy initrd to guest\n"); @@ -629,11 +630,11 @@ static int __init pvh_load_kernel(struct domain *d, c= onst module_t *image, } =20 mod.paddr =3D last_addr; - mod.size =3D initrd->mod_end; - last_addr +=3D ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4); - if ( initrd->string ) + mod.size =3D initrd->size; + last_addr +=3D ROUNDUP(initrd->size, elf_64bit(&elf) ? 8 : 4); + if ( initrd->string.kind =3D=3D BOOTSTR_CMDLINE ) { - char *str =3D __va(initrd->string); + char *str =3D initrd->string.bytes; size_t len =3D strlen(str) + 1; =20 rc =3D hvm_copy_to_guest_phys(last_addr, str, len, v); @@ -1216,10 +1217,9 @@ static void __hwdom_init pvh_setup_mmcfg(struct doma= in *d) } } =20 -int __init dom0_construct_pvh(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline) +int __init dom0_construct_pvh( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { paddr_t entry, start_info; int rc; @@ -1249,7 +1249,7 @@ int __init dom0_construct_pvh(struct domain *d, const= module_t *image, return rc; } =20 - rc =3D pvh_load_kernel(d, image, image_headroom, initrd, bootstrap_map= (image), + rc =3D pvh_load_kernel(d, image, initrd, bootstrap_map(image), cmdline, &entry, &start_info); if ( rc ) { diff --git a/xen/arch/x86/include/asm/bzimage.h b/xen/arch/x86/include/asm/= bzimage.h index 7ed69d3910..5a5a25b4d7 100644 --- a/xen/arch/x86/include/asm/bzimage.h +++ b/xen/arch/x86/include/asm/bzimage.h @@ -5,7 +5,8 @@ =20 unsigned long bzimage_headroom(void *image_start, unsigned long image_leng= th); =20 -int bzimage_parse(void *image_base, void **image_start, - unsigned long *image_len); +int bzimage_parse( + void *image_base, void **image_start, unsigned int headroom, + unsigned long *image_len); =20 #endif /* __X86_BZIMAGE_H__ */ diff --git a/xen/arch/x86/include/asm/dom0_build.h b/xen/arch/x86/include/a= sm/dom0_build.h index a5f8c9e67f..ad33413710 100644 --- a/xen/arch/x86/include/asm/dom0_build.h +++ b/xen/arch/x86/include/asm/dom0_build.h @@ -1,6 +1,7 @@ #ifndef _DOM0_BUILD_H_ #define _DOM0_BUILD_H_ =20 +#include #include #include =20 @@ -13,15 +14,13 @@ unsigned long dom0_compute_nr_pages(struct domain *d, unsigned long initrd_len); int dom0_setup_permissions(struct domain *d); =20 -int dom0_construct_pv(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline); +int __init dom0_construct_pv( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); =20 -int dom0_construct_pvh(struct domain *d, const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline); +int __init dom0_construct_pvh( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); =20 unsigned long dom0_paging_pages(const struct domain *d, unsigned long nr_pages); diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index 21037b7f31..11bdfc5723 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -1,7 +1,8 @@ #ifndef __X86_SETUP_H_ #define __X86_SETUP_H_ =20 -#include +#include + #include =20 extern const char __2M_text_start[], __2M_text_end[]; @@ -33,20 +34,17 @@ static inline void vesa_init(void) {}; #endif =20 int construct_dom0( - struct domain *d, - const module_t *kernel, unsigned long kernel_headroom, - module_t *initrd, - char *cmdline); + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline); void setup_io_bitmap(struct domain *d); =20 unsigned long initial_images_nrpages(nodeid_t node); void discard_initial_images(void); -void *bootstrap_map(const module_t *mod); +void *bootstrap_map(const struct boot_module *mod); =20 int xen_in_range(unsigned long mfn); =20 -void microcode_grab_module( - unsigned long *, const multiboot_info_t *); +void __init microcode_grab_module(struct boot_info *bi); =20 extern uint8_t kbd_shift_flags; =20 diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index e501979a86..f6131147ef 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2005, K A Fraser */ =20 +#include #include #include #include @@ -294,11 +295,9 @@ static struct page_info * __init alloc_chunk(struct do= main *d, return page; } =20 -int __init dom0_construct_pv(struct domain *d, - const module_t *image, - unsigned long image_headroom, - module_t *initrd, - char *cmdline) +int __init dom0_construct_pv( + struct domain *d, const struct boot_module *image, + struct boot_module *initrd, char *cmdline) { int i, rc, order, machine; bool compatible, compat; @@ -314,9 +313,9 @@ int __init dom0_construct_pv(struct domain *d, start_info_t *si; struct vcpu *v =3D d->vcpu[0]; void *image_base =3D bootstrap_map(image); - unsigned long image_len =3D image->mod_end; - void *image_start =3D image_base + image_headroom; - unsigned long initrd_len =3D initrd ? initrd->mod_end : 0; + unsigned long image_len =3D image->size; + void *image_start =3D image_base + image->arch->headroom; + unsigned long initrd_len =3D initrd ? initrd->size : 0; l4_pgentry_t *l4tab =3D NULL, *l4start =3D NULL; l3_pgentry_t *l3tab =3D NULL, *l3start =3D NULL; l2_pgentry_t *l2tab =3D NULL, *l2start =3D NULL; @@ -355,7 +354,9 @@ int __init dom0_construct_pv(struct domain *d, =20 d->max_pages =3D ~0U; =20 - if ( (rc =3D bzimage_parse(image_base, &image_start, &image_len)) !=3D= 0 ) + if ( (rc =3D + bzimage_parse(image_base, &image_start, image->arch->headroom, + &image_len)) !=3D 0 ) return rc; =20 if ( (rc =3D elf_init(&elf, image_start, image_len)) !=3D 0 ) @@ -544,7 +545,7 @@ int __init dom0_construct_pv(struct domain *d, initrd_pfn =3D vinitrd_start ? (vinitrd_start - v_start) >> PAGE_SHIFT : domain_tot_pages(d); - initrd_mfn =3D mfn =3D initrd->mod_start; + initrd_mfn =3D mfn =3D mfn_x(initrd->mfn); count =3D PFN_UP(initrd_len); if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)= ) ) @@ -559,12 +560,13 @@ int __init dom0_construct_pv(struct domain *d, free_domheap_pages(page, order); page +=3D 1UL << order; } - memcpy(page_to_virt(page), mfn_to_virt(initrd->mod_start), + memcpy(page_to_virt(page), maddr_to_virt(initrd->start), initrd_len); - mpt_alloc =3D (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc =3D initrd->start; init_domheap_pages(mpt_alloc, mpt_alloc + PAGE_ALIGN(initrd_len)); - initrd->mod_start =3D initrd_mfn =3D mfn_x(page_to_mfn(page)); + bootmodule_update_mfn(initrd, page_to_mfn(page)); + initrd_mfn =3D mfn_x(initrd->mfn); } else { @@ -572,7 +574,7 @@ int __init dom0_construct_pv(struct domain *d, if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); } - initrd->mod_end =3D 0; + initrd->size =3D 0; } =20 printk("PHYSICAL MEMORY ARRANGEMENT:\n" @@ -583,7 +585,7 @@ int __init dom0_construct_pv(struct domain *d, nr_pages - domain_tot_pages(d)); if ( initrd ) { - mpt_alloc =3D (paddr_t)initrd->mod_start << PAGE_SHIFT; + mpt_alloc =3D initrd->start; printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, mpt_alloc, mpt_alloc + initrd_len); } @@ -804,7 +806,7 @@ int __init dom0_construct_pv(struct domain *d, if ( pfn >=3D initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn =3D initrd->mod_start + (pfn - initrd_pfn); + mfn =3D mfn_x(initrd->mfn) + (pfn - initrd_pfn); else mfn -=3D PFN_UP(initrd_len); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 3f5e602e00..a7bf698d52 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -271,8 +272,48 @@ static int __init cf_check parse_acpi_param(const char= *s) } custom_param("acpi", parse_acpi_param); =20 -static const module_t *__initdata initial_images; -static unsigned int __initdata nr_initial_images; +struct boot_info __initdata *boot_info; + +static struct boot_info __initdata x86_bi; +static struct arch_boot_info __initdata x86_bi_arch; +static struct boot_module __initdata x86_mods[CONFIG_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata x86_arch_mods[CONFIG_NR_BOOTMODS = + 1]; + +static void __init mb_to_bootinfo(multiboot_info_t *mbi, module_t *mods) +{ + int i; + + x86_bi.arch =3D &x86_bi_arch; + x86_bi.mods =3D x86_mods; + + x86_bi.cmdline =3D __va(mbi->cmdline); + + /* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */ + x86_bi_arch.flags =3D mbi->flags; + x86_bi_arch.mem_upper =3D mbi->mem_upper; + x86_bi_arch.mem_lower =3D mbi->mem_lower; + x86_bi_arch.mmap_length =3D mbi->mmap_length; + x86_bi_arch.mmap_addr =3D mbi->mmap_addr; + x86_bi_arch.boot_loader_name =3D __va(mbi->boot_loader_name); + + x86_bi.nr_mods =3D mbi->mods_count; + for ( i =3D 0; i <=3D CONFIG_NR_BOOTMODS; i++) + { + x86_mods[i].arch =3D &x86_arch_mods[i]; + + if ( i < x86_bi.nr_mods ) + { + bootmodule_update_start(&x86_mods[i], mods[i].mod_start); + x86_mods[i].size =3D mods[i].mod_end - mods[i].mod_start; + + x86_mods[i].string.len =3D strlcpy(x86_mods[i].string.bytes, + __va(mods[i].string), + BOOTMOD_MAX_STRING); + } + } + + boot_info =3D &x86_bi; +} =20 unsigned long __init initial_images_nrpages(nodeid_t node) { @@ -281,10 +322,10 @@ unsigned long __init initial_images_nrpages(nodeid_t = node) unsigned long nr; unsigned int i; =20 - for ( nr =3D i =3D 0; i < nr_initial_images; ++i ) + for ( nr =3D i =3D 0; i < boot_info->nr_mods; ++i ) { - unsigned long start =3D initial_images[i].mod_start; - unsigned long end =3D start + PFN_UP(initial_images[i].mod_end); + unsigned long start =3D mfn_x(boot_info->mods[i].mfn); + unsigned long end =3D start + PFN_UP(boot_info->mods[i].size); =20 if ( end > node_start && node_end > start ) nr +=3D min(node_end, end) - max(node_start, start); @@ -297,16 +338,15 @@ void __init discard_initial_images(void) { unsigned int i; =20 - for ( i =3D 0; i < nr_initial_images; ++i ) + for ( i =3D 0; i < boot_info->nr_mods; ++i ) { - uint64_t start =3D (uint64_t)initial_images[i].mod_start << PAGE_S= HIFT; + uint64_t start =3D (uint64_t)boot_info->mods[i].start; =20 init_domheap_pages(start, - start + PAGE_ALIGN(initial_images[i].mod_end)); + start + PAGE_ALIGN(boot_info->mods[i].size)); } =20 - nr_initial_images =3D 0; - initial_images =3D NULL; + boot_info->nr_mods =3D 0; } =20 extern char __init_begin[], __init_end[], __bss_start[], __bss_end[]; @@ -393,14 +433,14 @@ static void __init normalise_cpu_order(void) * Ensure a given physical memory range is present in the bootstrap mappin= gs. * Use superpage mappings to ensure that pagetable memory needn't be alloc= ated. */ -void *__init bootstrap_map(const module_t *mod) +void *__init bootstrap_map(const struct boot_module *mod) { static unsigned long __initdata map_cur =3D BOOTSTRAP_MAP_BASE; uint64_t start, end, mask =3D (1L << L2_PAGETABLE_SHIFT) - 1; void *ret; =20 if ( system_state !=3D SYS_STATE_early_boot ) - return mod ? mfn_to_virt(mod->mod_start) : NULL; + return mod ? maddr_to_virt(mod->start) : NULL; =20 if ( !mod ) { @@ -409,8 +449,8 @@ void *__init bootstrap_map(const module_t *mod) return NULL; } =20 - start =3D (uint64_t)mod->mod_start << PAGE_SHIFT; - end =3D start + mod->mod_end; + start =3D (uint64_t)mod->start; + end =3D start + mod->size; if ( start >=3D end ) return NULL; =20 @@ -437,25 +477,25 @@ static void *__init move_memory( =20 while ( size ) { - module_t mod; + struct boot_module mod; unsigned int soffs =3D src & mask; unsigned int doffs =3D dst & mask; unsigned int sz; void *d, *s; =20 - mod.mod_start =3D (src - soffs) >> PAGE_SHIFT; - mod.mod_end =3D soffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - sz =3D mod.mod_end - soffs; + mod.start =3D src - soffs; + mod.size =3D soffs + size; + if ( mod.size > blksz ) + mod.size =3D blksz; + sz =3D mod.size - soffs; s =3D bootstrap_map(&mod); =20 - mod.mod_start =3D (dst - doffs) >> PAGE_SHIFT; - mod.mod_end =3D doffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - if ( sz > mod.mod_end - doffs ) - sz =3D mod.mod_end - doffs; + mod.start =3D dst - doffs; + mod.size =3D doffs + size; + if ( mod.size > blksz ) + mod.size =3D blksz; + if ( sz > mod.size - doffs ) + sz =3D mod.size - doffs; d =3D bootstrap_map(&mod); =20 memmove(d + doffs, s + soffs, sz); @@ -476,7 +516,7 @@ static void *__init move_memory( #undef BOOTSTRAP_MAP_LIMIT =20 static uint64_t __init consider_modules( - uint64_t s, uint64_t e, uint32_t size, const module_t *mod, + uint64_t s, uint64_t e, uint32_t size, const struct boot_module *mod, unsigned int nr_mods, unsigned int this_mod) { unsigned int i; @@ -486,8 +526,8 @@ static uint64_t __init consider_modules( =20 for ( i =3D 0; i < nr_mods ; ++i ) { - uint64_t start =3D (uint64_t)mod[i].mod_start << PAGE_SHIFT; - uint64_t end =3D start + PAGE_ALIGN(mod[i].mod_end); + uint64_t start =3D (uint64_t)mod[i].start; + uint64_t end =3D start + PAGE_ALIGN(mod[i].size); =20 if ( i =3D=3D this_mod ) continue; @@ -753,10 +793,8 @@ static unsigned int __init copy_bios_e820(struct e820e= ntry *map, unsigned int li return n; } =20 -static struct domain *__init create_dom0(const module_t *image, - unsigned long headroom, - module_t *initrd, const char *kex= tra, - const char *loader) +static struct domain *__init create_dom0( + const struct boot_info *bi, const char *kextra, const char *loader) { struct xen_domctl_createdomain dom0_cfg =3D { .flags =3D IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity = : 0, @@ -769,9 +807,14 @@ static struct domain *__init create_dom0(const module_= t *image, .misc_flags =3D opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0, }, }; + struct boot_module *image =3D bootmodule_next_by_kind(bi, BOOTMOD_KERN= EL, 0); + struct boot_module *initrd =3D bootmodule_next_by_kind(bi, BOOTMOD_RAM= DISK, 0); struct domain *d; char *cmdline; - domid_t domid; + domid_t domid =3D 0; + + if ( image =3D=3D NULL ) + panic("Error creating d%uv0\n", domid); =20 if ( opt_dom0_pvh ) { @@ -798,7 +841,8 @@ static struct domain *__init create_dom0(const module_t= *image, panic("Error creating d%uv0\n", domid); =20 /* Grab the DOM0 command line. */ - cmdline =3D image->string ? __va(image->string) : NULL; + cmdline =3D (image->string.kind =3D=3D BOOTSTR_CMDLINE) ? + image->string.bytes : NULL; if ( cmdline || kextra ) { static char __initdata dom0_cmdline[MAX_GUEST_CMDLINE]; @@ -838,7 +882,7 @@ static struct domain *__init create_dom0(const module_t= *image, write_cr4(read_cr4() & ~X86_CR4_SMAP); } =20 - if ( construct_dom0(d, image, headroom, initrd, cmdline) !=3D 0 ) + if ( construct_dom0(d, image, initrd, cmdline) !=3D 0 ) panic("Could not construct domain 0\n"); =20 if ( cpu_has_smap ) @@ -862,7 +906,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) unsigned int initrdidx, num_parked =3D 0; multiboot_info_t *mbi; module_t *mod; - unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1]; + unsigned long nr_pages, raw_max_page; int i, j, e820_warn =3D 0, bytes =3D 0; unsigned long eb_start, eb_end; bool acpi_boot_table_init_done =3D false, relocated =3D false; @@ -907,12 +951,14 @@ void __init noreturn __start_xen(unsigned long mbi_p) mod =3D __va(mbi->mods_addr); } =20 - loader =3D (mbi->flags & MBI_LOADERNAME) - ? (char *)__va(mbi->boot_loader_name) : "unknown"; + mb_to_bootinfo(mbi, mod); + + loader =3D (boot_info->arch->flags & BOOTINFO_FLAG_X86_LOADERNAME) + ? boot_info->arch->boot_loader_name : "unknown"; =20 /* Parse the command-line options. */ - cmdline =3D cmdline_cook((mbi->flags & MBI_CMDLINE) ? - __va(mbi->cmdline) : NULL, + cmdline =3D cmdline_cook((boot_info->arch->flags & BOOTINFO_FLAG_X86_C= MDLINE) ? + boot_info->cmdline : NULL, loader); if ( (kextra =3D strstr(cmdline, " -- ")) !=3D NULL ) { @@ -1013,19 +1059,22 @@ void __init noreturn __start_xen(unsigned long mbi_= p) bootsym(boot_edd_info_nr)); =20 /* Check that we have at least one Multiboot module. */ - if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count =3D=3D 0) ) + if ( !(boot_info->arch->flags & BOOTINFO_FLAG_X86_MODULES) || + (boot_info->nr_mods =3D=3D 0) ) panic("dom0 kernel not specified. Check bootloader configuration\n= "); =20 /* Check that we don't have a silly number of modules. */ - if ( mbi->mods_count > CONFIG_NR_BOOTMODS ) + if ( boot_info->nr_mods > CONFIG_NR_BOOTMODS ) { - mbi->mods_count =3D CONFIG_NR_BOOTMODS; + boot_info->nr_mods =3D CONFIG_NR_BOOTMODS ; printk("Excessive multiboot modules - using the first %u only\n", - mbi->mods_count); + boot_info->nr_mods); } =20 - bitmap_fill(module_map, mbi->mods_count); - __clear_bit(0, module_map); /* Dom0 kernel is always first */ + /* Dom0 kernel is the first boot module */ + boot_info->mods[0].kind =3D BOOTMOD_KERNEL; + if ( boot_info->mods[0].string.len ) + boot_info->mods[0].string.kind =3D BOOTSTR_CMDLINE; =20 if ( pvh_boot ) { @@ -1049,19 +1098,19 @@ void __init noreturn __start_xen(unsigned long mbi_= p) } else if ( efi_enabled(EFI_BOOT) ) memmap_type =3D "EFI"; - else if ( (e820_raw.nr_map =3D=20 + else if ( (e820_raw.nr_map =3D copy_bios_e820(e820_raw.map, ARRAY_SIZE(e820_raw.map))) !=3D 0 ) { memmap_type =3D "Xen-e820"; } - else if ( mbi->flags & MBI_MEMMAP ) + else if ( boot_info->arch->flags & BOOTINFO_FLAG_X86_MEMMAP ) { memmap_type =3D "Multiboot-e820"; - while ( bytes < mbi->mmap_length && + while ( bytes < boot_info->arch->mmap_length && e820_raw.nr_map < ARRAY_SIZE(e820_raw.map) ) { - memory_map_t *map =3D __va(mbi->mmap_addr + bytes); + struct mb_memmap *map =3D __va(boot_info->arch->mmap_addr + by= tes); =20 /* * This is a gross workaround for a BIOS bug. Some bootloaders= do @@ -1162,17 +1211,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT); kexec_reserve_area(&boot_e820); =20 - initial_images =3D mod; - nr_initial_images =3D mbi->mods_count; - - for ( i =3D 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ ) - { - if ( mod[i].mod_start & (PAGE_SIZE - 1) ) + for ( i =3D 0; !efi_enabled(EFI_LOADER) && i < boot_info->nr_mods; i++= ) + if ( boot_info->mods[i].start & (PAGE_SIZE - 1) ) panic("Bootloader didn't honor module alignment request\n"); - mod[i].mod_end -=3D mod[i].mod_start; - mod[i].mod_start >>=3D PAGE_SHIFT; - mod[i].reserved =3D 0; - } =20 if ( xen_phys_start ) { @@ -1183,11 +1224,14 @@ void __init noreturn __start_xen(unsigned long mbi_= p) * respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ - mod[mbi->mods_count].mod_start =3D virt_to_mfn(_stext); - mod[mbi->mods_count].mod_end =3D __2M_rwdata_end - _stext; + bootmodule_update_start(&boot_info->mods[boot_info->nr_mods], + virt_to_maddr(_stext)); + boot_info->mods[boot_info->nr_mods].size =3D __2M_rwdata_end - _st= ext; } =20 - modules_headroom =3D bzimage_headroom(bootstrap_map(mod), mod->mod_end= ); + boot_info->mods[0].arch->headroom =3D bzimage_headroom( + bootstrap_map(&boot_info->mods[0]), + boot_info->mods[0].size); bootstrap_map(NULL); =20 #ifndef highmem_start @@ -1244,7 +1288,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { /* Don't overlap with modules. */ end =3D consider_modules(s, e, reloc_size + mask, - mod, mbi->mods_count, -1); + boot_info->mods, boot_info->nr_mods, -1= ); end &=3D ~mask; } else @@ -1348,31 +1392,32 @@ void __init noreturn __start_xen(unsigned long mbi_= p) } =20 /* Is the region suitable for relocating the multiboot modules? */ - for ( j =3D mbi->mods_count - 1; j >=3D 0; j-- ) + for ( j =3D boot_info->nr_mods - 1; j >=3D 0; j-- ) { - unsigned long headroom =3D j ? 0 : modules_headroom; - unsigned long size =3D PAGE_ALIGN(headroom + mod[j].mod_end); + struct boot_module *mod =3D boot_info->mods; + unsigned long headroom =3D mod[j].arch->headroom; + unsigned long size =3D PAGE_ALIGN(headroom + mod[j].size); =20 - if ( mod[j].reserved ) + if ( mod[j].arch->flags & BOOTMOD_FLAG_X86_RELOCATED ) continue; =20 /* Don't overlap with other modules (or Xen itself). */ end =3D consider_modules(s, e, size, mod, - mbi->mods_count + relocated, j); + boot_info->nr_mods + relocated, j); =20 if ( highmem_start && end > highmem_start ) continue; =20 if ( s < end && (headroom || - ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) ) + ((end - size) >> PAGE_SHIFT) > mfn_x(mod[j].mfn)) ) { move_memory(end - size + headroom, - (uint64_t)mod[j].mod_start << PAGE_SHIFT, - mod[j].mod_end, 0); - mod[j].mod_start =3D (end - size) >> PAGE_SHIFT; - mod[j].mod_end +=3D headroom; - mod[j].reserved =3D 1; + (uint64_t)mod[j].start, + mod[j].size, 0); + bootmodule_update_start(&mod[j], end - size); + mod[j].size +=3D headroom; + mod[j].arch->flags |=3D BOOTMOD_FLAG_X86_RELOCATED; } } =20 @@ -1384,8 +1429,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) while ( !kexec_crash_area.start ) { /* Don't overlap with modules (or Xen itself). */ - e =3D consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size)= , mod, - mbi->mods_count + relocated, -1); + e =3D consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size), + boot_info->mods, + boot_info->nr_mods + relocated, -1); if ( s >=3D e ) break; if ( e > kexec_crash_area_limit ) @@ -1398,13 +1444,14 @@ void __init noreturn __start_xen(unsigned long mbi_= p) #endif } =20 - if ( modules_headroom && !mod->reserved ) + if ( boot_info->mods[0].arch->headroom && + !(boot_info->mods[0].arch->flags & BOOTMOD_FLAG_X86_RELOCATED) ) panic("Not enough memory to relocate the dom0 kernel image\n"); - for ( i =3D 0; i < mbi->mods_count; ++i ) + for ( i =3D 0; i < boot_info->nr_mods; ++i ) { - uint64_t s =3D (uint64_t)mod[i].mod_start << PAGE_SHIFT; + uint64_t s =3D (uint64_t)boot_info->mods[i].start; =20 - reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end)); + reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(boot_info->mods[i].= size)); } =20 if ( !xen_phys_start ) @@ -1469,10 +1516,10 @@ void __init noreturn __start_xen(unsigned long mbi_= p) ASSERT(j); } map_e =3D boot_e820.map[j].addr + boot_e820.map[j].size; - for ( j =3D 0; j < mbi->mods_count; ++j ) + for ( j =3D 0; j < boot_info->nr_mods; ++j ) { - uint64_t end =3D pfn_to_paddr(mod[j].mod_start) + - mod[j].mod_end; + uint64_t end =3D mfn_to_maddr(boot_info->mods[j].mfn) + + boot_info->mods[j].size; =20 if ( map_e < end ) map_e =3D end; @@ -1545,13 +1592,14 @@ void __init noreturn __start_xen(unsigned long mbi_= p) } } =20 - for ( i =3D 0; i < mbi->mods_count; ++i ) + for ( i =3D 0; i < boot_info->nr_mods; ++i ) { - set_pdx_range(mod[i].mod_start, - mod[i].mod_start + PFN_UP(mod[i].mod_end)); - map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start), - _mfn(mod[i].mod_start), - PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR); + set_pdx_range(mfn_x(boot_info->mods[i].mfn), + mfn_x(boot_info->mods[i].mfn) + + PFN_UP(boot_info->mods[i].size)); + map_pages_to_xen((unsigned long)maddr_to_virt(boot_info->mods[i].s= tart), + boot_info->mods[i].mfn, + PFN_UP(boot_info->mods[i].size), PAGE_HYPERVISOR); } =20 #ifdef CONFIG_KEXEC @@ -1561,7 +1609,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) unsigned long e =3D min(s + PFN_UP(kexec_crash_area.size), PFN_UP(__pa(HYPERVISOR_VIRT_END - 1))); =20 - if ( e > s )=20 + if ( e > s ) map_pages_to_xen((unsigned long)__va(kexec_crash_area.start), _mfn(s), e - s, PAGE_HYPERVISOR); } @@ -1701,7 +1749,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) mmio_ro_ranges =3D rangeset_new(NULL, "r/o mmio ranges", RANGESETF_prettyprint_hex); =20 - if ( xsm_multiboot_init(module_map, mbi) ) + if ( xsm_bootmodule_init(boot_info) ) warning_add("WARNING: XSM failed to initialize.\n" "This has implications on the security of the system,\= n" "as uncontrolled communications between trusted and\n" @@ -1774,7 +1822,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) =20 init_IRQ(); =20 - microcode_grab_module(module_map, mbi); + microcode_grab_module(boot_info); =20 timer_init(); =20 @@ -1906,7 +1954,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) =20 do_initcalls(); =20 - if ( opt_watchdog )=20 + if ( opt_watchdog ) watchdog_setup(); =20 if ( !tboot_protect_mem_regions() ) @@ -1922,8 +1970,11 @@ void __init noreturn __start_xen(unsigned long mbi_p) cpu_has_nx ? XENLOG_INFO : XENLOG_WARNING "Warning: ", cpu_has_nx ? "" : "not "); =20 - initrdidx =3D find_first_bit(module_map, mbi->mods_count); - if ( bitmap_weight(module_map, mbi->mods_count) > 1 ) + initrdidx =3D bootmodule_next_idx_by_kind(boot_info, BOOTMOD_UNKNOWN, = 0); + if ( initrdidx < boot_info->nr_mods ) + boot_info->mods[initrdidx].kind =3D BOOTMOD_RAMDISK; + + if ( bootmodule_count_by_kind(boot_info, BOOTMOD_UNKNOWN) > 1 ) printk(XENLOG_WARNING "Multiple initrd candidates, picking module #%u\n", initrdidx); @@ -1932,9 +1983,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * We're going to setup domain0 using the module(s) that we stashed sa= fely * above our heap. The second module, if present, is an initrd ramdisk. */ - dom0 =3D create_dom0(mod, modules_headroom, - initrdidx < mbi->mods_count ? mod + initrdidx : NUL= L, - kextra, loader); + dom0 =3D create_dom0(boot_info, kextra, loader); if ( !dom0 ) panic("Could not set up DOM0 guest OS\n"); =20 diff --git a/xen/include/xen/bootinfo.h b/xen/include/xen/bootinfo.h index 42b53a3ca6..dde8202f62 100644 --- a/xen/include/xen/bootinfo.h +++ b/xen/include/xen/bootinfo.h @@ -51,4 +51,51 @@ struct __packed boot_info { struct arch_boot_info *arch; }; =20 +extern struct boot_info *boot_info; + +static inline unsigned long bootmodule_next_idx_by_kind( + const struct boot_info *bi, bootmodule_kind kind, unsigned long start) +{ + for ( ; start < bi->nr_mods; start++ ) + if ( bi->mods[start].kind =3D=3D kind ) + return start; + + return bi->nr_mods + 1; +} + +static inline unsigned long bootmodule_count_by_kind( + const struct boot_info *bi, bootmodule_kind kind) +{ + unsigned long count =3D 0; + int i; + + for ( i=3D0; i < bi->nr_mods; i++ ) + if ( bi->mods[i].kind =3D=3D kind ) + count++; + + return count; +} + +static inline struct boot_module *bootmodule_next_by_kind( + const struct boot_info *bi, bootmodule_kind kind, unsigned long start) +{ + for ( ; start < bi->nr_mods; start++ ) + if ( bi->mods[start].kind =3D=3D kind ) + return &bi->mods[start]; + + return NULL; +} + +static inline void bootmodule_update_start(struct boot_module *b, paddr_t = new_start) +{ + b->start =3D new_start; + b->mfn =3D maddr_to_mfn(new_start); +} + +static inline void bootmodule_update_mfn(struct boot_module *b, mfn_t new_= mfn) +{ + b->mfn =3D new_mfn; + b->start =3D mfn_to_maddr(new_mfn); +} + #endif diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 1676c261c9..bd72c2220e 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -16,8 +16,8 @@ #define __XSM_H__ =20 #include +#include #include -#include =20 /* policy magic number (defined by XSM_MAGIC) */ typedef uint32_t xsm_magic_t; @@ -770,15 +770,14 @@ static inline int xsm_argo_send(const struct domain *= d, const struct domain *t) =20 #endif /* XSM_NO_WRAPPERS */ =20 -#ifdef CONFIG_MULTIBOOT -int xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi); -int xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, - const unsigned char *policy_buffer[], size_t *policy_size); -#endif +#ifndef CONFIG_HAS_DEVICE_TREE +int xsm_bootmodule_init(const struct boot_info *bi); +int xsm_bootmodule_policy_init( + const struct boot_info *bi, const unsigned char *policy_buffer[], + size_t *policy_size); + +#else =20 -#ifdef CONFIG_HAS_DEVICE_TREE /* * Initialize XSM * @@ -820,15 +819,14 @@ static const inline struct xsm_ops *silo_init(void) =20 #include =20 -#ifdef CONFIG_MULTIBOOT -static inline int xsm_multiboot_init ( - unsigned long *module_map, const multiboot_info_t *mbi) +#ifndef CONFIG_HAS_DEVICE_TREE +static inline int xsm_bootmodule_init(const struct boot_info *bi) { return 0; } -#endif =20 -#ifdef CONFIG_HAS_DEVICE_TREE +#else + static inline int xsm_dt_init(void) { return 0; diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index 6377895e1e..f9066738b5 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -10,6 +10,7 @@ * as published by the Free Software Foundation. */ =20 +#include #include #include #include @@ -136,9 +137,13 @@ static int __init xsm_core_init(const void *policy_buf= fer, size_t policy_size) return 0; } =20 -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_init( - unsigned long *module_map, const multiboot_info_t *mbi) +/* + * ifdef'ing this against multiboot is no longer valid as the boot module + * is agnostic and it will be possible to dropped the ifndef should Arm + * adopt boot info + */ +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_init(const struct boot_info *bi) { int ret =3D 0; const unsigned char *policy_buffer; @@ -148,8 +153,7 @@ int __init xsm_multiboot_init( =20 if ( policy_file_required && XSM_MAGIC ) { - ret =3D xsm_multiboot_policy_init(module_map, mbi, &policy_buffer, - &policy_size); + ret =3D xsm_bootmodule_policy_init(bi, &policy_buffer, &policy_siz= e); if ( ret ) { bootstrap_map(NULL); @@ -162,9 +166,9 @@ int __init xsm_multiboot_init( =20 return 0; } -#endif =20 -#ifdef CONFIG_HAS_DEVICE_TREE +#else + int __init xsm_dt_init(void) { int ret =3D 0; @@ -215,9 +219,9 @@ bool __init has_xsm_magic(paddr_t start) =20 return false; } -#endif +#endif /* CONFIG_HAS_DEVICE_TREE */ =20 -#endif +#endif /* CONFIG_XSM */ =20 long cf_check do_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op) { diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index 6a4f769aec..45ce013ead 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -18,24 +18,22 @@ * */ =20 -#include -#ifdef CONFIG_MULTIBOOT -#include -#include -#endif #include +#include +#include + #ifdef CONFIG_HAS_DEVICE_TREE -# include # include #endif =20 -#ifdef CONFIG_MULTIBOOT -int __init xsm_multiboot_policy_init( - unsigned long *module_map, const multiboot_info_t *mbi, - const unsigned char *policy_buffer[], size_t *policy_size) +# include + +#ifndef CONFIG_HAS_DEVICE_TREE +int __init xsm_bootmodule_policy_init( + const struct boot_info *bi, const unsigned char *policy_buffer[], + size_t *policy_size) { - int i; - module_t *mod =3D (module_t *)__va(mbi->mods_addr); + unsigned long idx =3D 0; int rc =3D -ENOENT; u32 *_policy_start; unsigned long _policy_len; @@ -47,17 +45,11 @@ int __init xsm_multiboot_policy_init( rc =3D 0; #endif =20 - /* - * Try all modules and see whichever could be the binary policy. - * Adjust module_map for the module that is the binary policy. - */ - for ( i =3D mbi->mods_count-1; i >=3D 1; i-- ) + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, idx); + while ( idx < bi->nr_mods ) { - if ( !test_bit(i, module_map) ) - continue; - - _policy_start =3D bootstrap_map(mod + i); - _policy_len =3D mod[i].mod_end; + _policy_start =3D bootstrap_map(&bi->mods[idx]); + _policy_len =3D bi->mods[idx].size; =20 if ( (xsm_magic_t)(*_policy_start) =3D=3D XSM_MAGIC ) { @@ -67,13 +59,13 @@ int __init xsm_multiboot_policy_init( printk("Policy len %#lx, start at %p.\n", _policy_len,_policy_start); =20 - __clear_bit(i, module_map); + bi->mods[idx].kind =3D BOOTMOD_XSM; rc =3D 0; break; - } =20 bootstrap_map(NULL); + idx =3D bootmodule_next_idx_by_kind(bi, BOOTMOD_UNKNOWN, ++idx); } =20 if ( rc =3D=3D -ENOENT ) @@ -81,9 +73,9 @@ int __init xsm_multiboot_policy_init( =20 return rc; } -#endif =20 -#ifdef CONFIG_HAS_DEVICE_TREE +#else + int __init xsm_dt_policy_init(void **policy_buffer, size_t *policy_size) { struct bootmodule *mod =3D boot_module_find_by_kind(BOOTMOD_XSM); --=20 2.20.1 From nobody Sat May 18 09:48:40 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; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) ARC-Seal: i=2; a=rsa-sha256; t=1653951119; cv=pass; d=zohomail.com; s=zohoarc; b=QCLDpWjXkoW3XuDsWnAKllW3ISPX8D2R7XqTp4A5G053rbKGMx4BJuL4ufS+LkGC2xlOk5iS4NOsuYDHZTKd8WdTfwACtuETAFrTDh3CXUOEgo9uBD6PIneBT6YqDfxN2cpoDCPQExBhYojgwvoup2At3jpkgkJrYeXQ6MPdoHs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653951119; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QsrPUqkDtUvJ+NOAy+kFxwJxYrCsp40uZ3+rvq7odxY=; b=kLn+V/xXBMMoNJb4C9YPZqFruKpD5/BMIlP0s2PRbRaHdrQtTbDo4lpjUavLMZc546PQiVoKxbX8CEa3Jv2A900/JeucAlOXJQj6ZBjvJT2YRIFabCoIYsnbLWdoPNt/RCT7JXBDKMVSJJbm/8iH2wDU6LLaFMqslTpQkCEnE8g= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dpsmith@apertussolutions.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; arc=pass (i=1 dmarc=pass fromdomain=apertussolutions.com) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1653951119033459.53508598169753; Mon, 30 May 2022 15:51:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.338906.563738 (Exim 4.92) (envelope-from ) id 1nvoEY-0002WS-Nb; Mon, 30 May 2022 22:51:34 +0000 Received: by outflank-mailman (output) from mailman id 338906.563738; Mon, 30 May 2022 22:51: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 1nvoEY-0002WL-Iz; Mon, 30 May 2022 22:51:34 +0000 Received: by outflank-mailman (input) for mailman id 338906; Mon, 30 May 2022 22:51:33 +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 1nvo6I-0006Rh-Mt for xen-devel@lists.xenproject.org; Mon, 30 May 2022 22:43:03 +0000 Received: from sender4-of-o51.zoho.com (sender4-of-o51.zoho.com [136.143.188.51]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dafb0382-e069-11ec-bd2c-47488cf2e6aa; Tue, 31 May 2022 00:43:00 +0200 (CEST) Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 165395052385312.548724071218999; Mon, 30 May 2022 15:42: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: dafb0382-e069-11ec-bd2c-47488cf2e6aa ARC-Seal: i=1; a=rsa-sha256; t=1653950525; cv=none; d=zohomail.com; s=zohoarc; b=LyctmwvFWMx31av57yID37Qi68+X4ucdKeqV6YkmP8mzN0KfeBvmJUQFbgZ+49CyC8tnGxazc80+bwKBgNUnZYFsPxJB3Pq5w43AdI+0w+4CmtzRVVKbSZZ6qhzSUYQaRe5+VcK6x9pdc8F4TkH/Z4pCTYuRbOCu9R+/BWGkEgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653950525; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=QsrPUqkDtUvJ+NOAy+kFxwJxYrCsp40uZ3+rvq7odxY=; b=Gouo+NXbdg4kORk1NrCvGCd8GnKwhs6uvCIlbn7kPMsjLBpDDMric1xOHQd7b4dNR2pJrls+5PHVfcN9/JVTP7T4jmGKMmJfIsV5wSlU2mwXvFDo+o20jqiV+TQYffocvSlIXam0s+0u1mvEkzzdiyCTcOceQcZ1ZBIDCN6DzF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1653950525; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Reply-To; bh=QsrPUqkDtUvJ+NOAy+kFxwJxYrCsp40uZ3+rvq7odxY=; b=XV2fMoPrhoslbADyC77oBQFaEqy7NYBxgk8mCNcUFhdAcoioG/AWlSqQxH2DY7PO +EaV/mVhQQ+WpzxNUdj04ALCmK4d2tgBmHLwshHq8k+3nKRSYbg/kVCS3DmYmN9DjvN PCRT7OOA2cuBUEOPJ6uyjJB2C9sxhLTo7k+iP3X8= From: "Daniel P. Smith" To: xen-devel@lists.xenproject.org, Wei Liu Cc: "Daniel P. Smith" , scott.davis@starlab.io, christopher.clark@starlab.io, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [RFC PATCH 4/4] x86: refactor entrypoints to new boot info Date: Mon, 30 May 2022 22:41:26 -0400 Message-Id: <20220531024127.23669-5-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220531024127.23669-1-dpsmith@apertussolutions.com> References: <20220531024127.23669-1-dpsmith@apertussolutions.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-ZohoMail-DKIM: pass (identity dpsmith@apertussolutions.com) X-ZM-MESSAGEID: 1653951120796100003 This previous commit added a transition point from multiboot v1 structures = to the new boot info structures at the earliest common point for all the x86 entrypoints. The result is that each of the entrypoints would construct a multiboot v1 structure from the structures used by each entrypoint. =C2=A0T= his meant that multiboot2, EFI, and PVH all converted their structures over to mutlib= oot v1 to only be converted again upon entering __start_xen(). This commit drops the translation function and moves the population of the = new boot info structures down into the various entrypoints. Signed-off-by: Daniel P. Smith --- xen/arch/x86/boot/boot_info32.h | 81 ++++++++++ xen/arch/x86/boot/defs.h | 17 +- xen/arch/x86/boot/reloc.c | 187 +++++++++++++++------- xen/arch/x86/efi/efi-boot.h | 96 ++++++----- xen/arch/x86/guest/xen/pvh-boot.c | 58 ++++--- xen/arch/x86/include/asm/guest/pvh-boot.h | 6 +- xen/arch/x86/setup.c | 71 +++----- xen/common/efi/boot.c | 4 +- 8 files changed, 342 insertions(+), 178 deletions(-) create mode 100644 xen/arch/x86/boot/boot_info32.h diff --git a/xen/arch/x86/boot/boot_info32.h b/xen/arch/x86/boot/boot_info3= 2.h new file mode 100644 index 0000000000..76c78e2cae --- /dev/null +++ b/xen/arch/x86/boot/boot_info32.h @@ -0,0 +1,81 @@ +#ifndef __BOOT_INFO32_H__ +#define __BOOT_INFO32_H__ + +#include "defs.h" + +typedef enum { + BOOTMOD_UNKNOWN, + BOOTMOD_XEN, + BOOTMOD_FDT, + BOOTMOD_KERNEL, + BOOTMOD_RAMDISK, + BOOTMOD_XSM, + BOOTMOD_UCODE, + BOOTMOD_GUEST_DTB, +} bootmodule_kind; + +typedef enum { + BOOTSTR_EMPTY, + BOOTSTR_STRING, + BOOTSTR_CMDLINE, +} bootstring_kind; + +#define BOOTMOD_MAX_STRING 1024 +struct boot_string { + u32 kind; + u64 arch; + + char bytes[BOOTMOD_MAX_STRING]; + u64 len; +}; + +struct arch_bootmodule { + bool relocated; + u32 flags; +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 + u32 headroom; +}; + +struct boot_module { + u32 kind; + u64 start; + u64 mfn; + u64 size; + + u64 arch; + struct boot_string string; +}; + +struct arch_boot_info { + u32 flags; +#define BOOTINFO_FLAG_X86_MEMLIMITS 1U << 0 +#define BOOTINFO_FLAG_X86_BOOTDEV 1U << 1 +#define BOOTINFO_FLAG_X86_CMDLINE 1U << 2 +#define BOOTINFO_FLAG_X86_MODULES 1U << 3 +#define BOOTINFO_FLAG_X86_AOUT_SYMS 1U << 4 +#define BOOTINFO_FLAG_X86_ELF_SYMS 1U << 5 +#define BOOTINFO_FLAG_X86_MEMMAP 1U << 6 +#define BOOTINFO_FLAG_X86_DRIVES 1U << 7 +#define BOOTINFO_FLAG_X86_BIOSCONFIG 1U << 8 +#define BOOTINFO_FLAG_X86_LOADERNAME 1U << 9 +#define BOOTINFO_FLAG_X86_APM 1U << 10 + + u64 boot_loader_name; + + u32 mem_lower; + u32 mem_upper; + + u32 mmap_length; + u64 mmap_addr; +}; + +struct boot_info { + u64 cmdline; + + u32 nr_mods; + u64 mods; + + u64 arch; +}; + +#endif diff --git a/xen/arch/x86/boot/defs.h b/xen/arch/x86/boot/defs.h index f9840044ec..d742a2b52a 100644 --- a/xen/arch/x86/boot/defs.h +++ b/xen/arch/x86/boot/defs.h @@ -22,11 +22,11 @@ =20 #include "../../../include/xen/stdbool.h" =20 -#define __maybe_unused __attribute__((__unused__)) -#define __packed __attribute__((__packed__)) -#define __stdcall __attribute__((__stdcall__)) +#define __maybe_unused __attribute__((__unused__)) +#define __packed __attribute__((__packed__)) +#define __stdcall __attribute__((__stdcall__)) =20 -#define NULL ((void *)0) +#define NULL ((void *)0) =20 #define ALIGN_UP(arg, align) \ (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1)) @@ -43,9 +43,10 @@ (void) (&_x =3D=3D &_y); \ _x > _y ? _x : _y; }) =20 -#define _p(val) ((void *)(unsigned long)(val)) +#define _p(val) ((void *)(unsigned long)(val)) +#define _addr(val) ((unsigned long)(void *)(val)) =20 -#define tolower(c) ((c) | 0x20) +#define tolower(c) ((c) | 0x20) =20 typedef unsigned char u8; typedef unsigned short u16; @@ -57,7 +58,7 @@ typedef u16 uint16_t; typedef u32 uint32_t; typedef u64 uint64_t; =20 -#define U16_MAX ((u16)(~0U)) -#define UINT_MAX (~0U) +#define U16_MAX ((u16)(~0U)) +#define UINT_MAX (~0U) =20 #endif /* __BOOT_DEFS_H__ */ diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c index e22bb974bf..4c40cadff6 100644 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -27,6 +27,7 @@ asm ( ); =20 #include "defs.h" +#include "boot_info32.h" #include "../../../include/xen/multiboot.h" #include "../../../include/xen/multiboot2.h" =20 @@ -138,65 +139,116 @@ static struct hvm_start_info *pvh_info_reloc(u32 in) return out; } =20 -static multiboot_info_t *mbi_reloc(u32 mbi_in) +static struct boot_info *mbi_reloc(u32 mbi_in) { + const multiboot_info_t *mbi =3D _p(mbi_in); + struct boot_info *binfo; + struct arch_boot_info *arch_binfo; int i; - multiboot_info_t *mbi_out; + uint32_t ptr; =20 - mbi_out =3D _p(copy_mem(mbi_in, sizeof(*mbi_out))); + ptr =3D alloc_mem(sizeof(*binfo)); + zero_mem(ptr, sizeof(*binfo)); + binfo =3D _p(ptr); =20 - if ( mbi_out->flags & MBI_CMDLINE ) - mbi_out->cmdline =3D copy_string(mbi_out->cmdline); + ptr =3D alloc_mem(sizeof(*arch_binfo)); + zero_mem(ptr, sizeof(*arch_binfo)); + binfo->arch =3D ptr; + arch_binfo =3D _p(ptr); =20 - if ( mbi_out->flags & MBI_MODULES ) + if ( mbi->flags & MBI_CMDLINE ) + { + ptr =3D copy_string(mbi->cmdline); + binfo->cmdline =3D ptr; + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_CMDLINE; + } + + if ( mbi->flags & MBI_MODULES ) { module_t *mods; + struct boot_module *bi_mods; + struct arch_bootmodule *arch_bi_mods; + + /* + * We have to allocate one more module slot here. At some point + * __start_xen() may put Xen image placement into it. + */ + ptr =3D alloc_mem((mbi->mods_count + 1) * sizeof(*bi_mods)); + binfo->nr_mods =3D mbi->mods_count; + binfo->mods =3D ptr; + bi_mods =3D _p(ptr); =20 - mbi_out->mods_addr =3D copy_mem(mbi_out->mods_addr, - mbi_out->mods_count * sizeof(module_= t)); + ptr =3D alloc_mem((mbi->mods_count + 1) * sizeof(*arch_bi_mods)); + arch_bi_mods =3D _p(ptr); =20 - mods =3D _p(mbi_out->mods_addr); + /* map the +1 allocated for Xen image */ + bi_mods[mbi->mods_count].arch =3D _addr(&arch_bi_mods[mbi->mods_co= unt]); =20 - for ( i =3D 0; i < mbi_out->mods_count; i++ ) + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MODULES; + + mods =3D _p(mbi->mods_addr); + + for ( i =3D 0; i < mbi->mods_count; i++ ) { + bi_mods[i].start =3D mods[i].mod_start; + bi_mods[i].size =3D mods[i].mod_end - mods[i].mod_start; + if ( mods[i].string ) - mods[i].string =3D copy_string(mods[i].string); + { + int j; + char *c =3D _p(mods[i].string); + + for ( j =3D 0; *c !=3D '\0'; j++, c++ ) + bi_mods[i].string.bytes[j] =3D *c; + + bi_mods[i].string.len =3D j + 1; + } + + bi_mods[i].arch =3D _addr(&arch_bi_mods[i]); } } =20 - if ( mbi_out->flags & MBI_MEMMAP ) - mbi_out->mmap_addr =3D copy_mem(mbi_out->mmap_addr, mbi_out->mmap_= length); - - if ( mbi_out->flags & MBI_LOADERNAME ) - mbi_out->boot_loader_name =3D copy_string(mbi_out->boot_loader_nam= e); + if ( mbi->flags & MBI_MEMMAP ) + { + arch_binfo->mmap_addr =3D copy_mem(mbi->mmap_addr, mbi->mmap_lengt= h); + arch_binfo->mmap_length =3D mbi->mmap_length; + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MEMMAP; + } =20 - /* Mask features we don't understand or don't relocate. */ - mbi_out->flags &=3D (MBI_MEMLIMITS | - MBI_CMDLINE | - MBI_MODULES | - MBI_MEMMAP | - MBI_LOADERNAME); + if ( mbi->flags & MBI_LOADERNAME ) + { + ptr =3D copy_string(mbi->boot_loader_name); + arch_binfo->boot_loader_name =3D ptr; + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_LOADERNAME; + } =20 - return mbi_out; + return binfo; } =20 -static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) +static struct boot_info *mbi2_reloc(uint32_t mbi_in, uint32_t video_out) { const multiboot2_fixed_t *mbi_fix =3D _p(mbi_in); const multiboot2_memory_map_t *mmap_src; const multiboot2_tag_t *tag; - module_t *mbi_out_mods =3D NULL; memory_map_t *mmap_dst; - multiboot_info_t *mbi_out; + struct boot_info *binfo; + struct arch_boot_info *arch_binfo; + struct boot_module *bi_mods; + struct arch_bootmodule *arch_bi_mods; #ifdef CONFIG_VIDEO struct boot_video_info *video =3D NULL; #endif u32 ptr; unsigned int i, mod_idx =3D 0; =20 - ptr =3D alloc_mem(sizeof(*mbi_out)); - mbi_out =3D _p(ptr); - zero_mem(ptr, sizeof(*mbi_out)); + ptr =3D alloc_mem(sizeof(*binfo)); + zero_mem(ptr, sizeof(*binfo)); + binfo =3D _p(ptr); + + ptr =3D alloc_mem(sizeof(*arch_binfo)); + zero_mem(ptr, sizeof(*arch_binfo)); + binfo->arch =3D ptr; + arch_binfo =3D _p(ptr); =20 /* Skip Multiboot2 information fixed part. */ ptr =3D ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN); @@ -206,21 +258,28 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) tag =3D _p(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN))= ) { if ( tag->type =3D=3D MULTIBOOT2_TAG_TYPE_MODULE ) - ++mbi_out->mods_count; + ++binfo->nr_mods; else if ( tag->type =3D=3D MULTIBOOT2_TAG_TYPE_END ) break; } =20 - if ( mbi_out->mods_count ) + if ( binfo->nr_mods ) { - mbi_out->flags |=3D MBI_MODULES; /* * We have to allocate one more module slot here. At some point * __start_xen() may put Xen image placement into it. */ - mbi_out->mods_addr =3D alloc_mem((mbi_out->mods_count + 1) * - sizeof(*mbi_out_mods)); - mbi_out_mods =3D _p(mbi_out->mods_addr); + ptr =3D alloc_mem((binfo->nr_mods + 1) * sizeof(*bi_mods)); + binfo->mods =3D ptr; + bi_mods =3D _p(ptr); + + ptr =3D alloc_mem((binfo->nr_mods + 1) * sizeof(*arch_bi_mods)); + arch_bi_mods =3D _p(ptr); + + /* map the +1 allocated for Xen image */ + bi_mods[binfo->nr_mods].arch =3D _addr(&arch_bi_mods[binfo->nr_mod= s]); + + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MODULES; } =20 /* Skip Multiboot2 information fixed part. */ @@ -232,39 +291,38 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) switch ( tag->type ) { case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME: - mbi_out->flags |=3D MBI_LOADERNAME; ptr =3D get_mb2_string(tag, string, string); - mbi_out->boot_loader_name =3D copy_string(ptr); + arch_binfo->boot_loader_name =3D copy_string(ptr); + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_LOADERNAME; break; =20 case MULTIBOOT2_TAG_TYPE_CMDLINE: - mbi_out->flags |=3D MBI_CMDLINE; ptr =3D get_mb2_string(tag, string, string); - mbi_out->cmdline =3D copy_string(ptr); + binfo->cmdline =3D copy_string(ptr); + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_CMDLINE; break; =20 case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO: - mbi_out->flags |=3D MBI_MEMLIMITS; - mbi_out->mem_lower =3D get_mb2_data(tag, basic_meminfo, mem_lo= wer); - mbi_out->mem_upper =3D get_mb2_data(tag, basic_meminfo, mem_up= per); + arch_binfo->mem_lower =3D get_mb2_data(tag, basic_meminfo, mem= _lower); + arch_binfo->mem_upper =3D get_mb2_data(tag, basic_meminfo, mem= _upper); break; =20 case MULTIBOOT2_TAG_TYPE_MMAP: if ( get_mb2_data(tag, mmap, entry_size) < sizeof(*mmap_src) ) break; =20 - mbi_out->flags |=3D MBI_MEMMAP; - mbi_out->mmap_length =3D get_mb2_data(tag, mmap, size); - mbi_out->mmap_length -=3D sizeof(multiboot2_tag_mmap_t); - mbi_out->mmap_length /=3D get_mb2_data(tag, mmap, entry_size); - mbi_out->mmap_length *=3D sizeof(*mmap_dst); + arch_binfo->mmap_length =3D get_mb2_data(tag, mmap, size); + arch_binfo->mmap_length -=3D sizeof(multiboot2_tag_mmap_t); + arch_binfo->mmap_length /=3D get_mb2_data(tag, mmap, entry_siz= e); + arch_binfo->mmap_length *=3D sizeof(*mmap_dst); =20 - mbi_out->mmap_addr =3D alloc_mem(mbi_out->mmap_length); + arch_binfo->mmap_addr =3D alloc_mem(arch_binfo->mmap_length); + arch_binfo->flags |=3D BOOTINFO_FLAG_X86_MEMMAP; =20 mmap_src =3D get_mb2_data(tag, mmap, entries); - mmap_dst =3D _p(mbi_out->mmap_addr); + mmap_dst =3D _p(arch_binfo->mmap_addr); =20 - for ( i =3D 0; i < mbi_out->mmap_length / sizeof(*mmap_dst); i= ++ ) + for ( i =3D 0; i < arch_binfo->mmap_length / sizeof(*mmap_dst)= ; i++ ) { /* Init size member properly. */ mmap_dst[i].size =3D sizeof(*mmap_dst); @@ -280,14 +338,27 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) break; =20 case MULTIBOOT2_TAG_TYPE_MODULE: - if ( mod_idx >=3D mbi_out->mods_count ) + if ( mod_idx >=3D binfo->nr_mods ) break; =20 - mbi_out_mods[mod_idx].mod_start =3D get_mb2_data(tag, module, = mod_start); - mbi_out_mods[mod_idx].mod_end =3D get_mb2_data(tag, module, mo= d_end); + bi_mods[mod_idx].start =3D get_mb2_data(tag, module, mod_start= ); + bi_mods[mod_idx].size =3D get_mb2_data(tag, module, mod_end) + - bi_mods[mod_idx].start; + ptr =3D get_mb2_string(tag, module, cmdline); - mbi_out_mods[mod_idx].string =3D copy_string(ptr); - mbi_out_mods[mod_idx].reserved =3D 0; + if ( ptr ) + { + int i; + char *c =3D _p(ptr); + + for ( i =3D 0; *c !=3D '\0'; i++, c++ ) + bi_mods[mod_idx].string.bytes[i] =3D *c; + + bi_mods[mod_idx].string.len =3D i + 1; + } + + bi_mods[mod_idx].arch =3D _addr(&arch_bi_mods[mod_idx]); + ++mod_idx; break; =20 @@ -344,11 +415,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, = uint32_t video_out) video->orig_video_isVGA =3D 0x23; #endif =20 - return mbi_out; + return binfo; } =20 -void *__stdcall reloc(uint32_t magic, uint32_t in, uint32_t trampoline, - uint32_t video_info) +void *__stdcall reloc( + uint32_t magic, uint32_t in, uint32_t trampoline, uint32_t video_info) { alloc =3D trampoline; =20 diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 4e1a799749..933eb30a28 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -11,14 +11,17 @@ #include =20 static struct file __initdata ucode; -static multiboot_info_t __initdata mbi =3D { - .flags =3D MBI_MODULES | MBI_LOADERNAME -}; + +static struct boot_info __initdata efi_bi; +static struct arch_boot_info __initdata efi_bi_arch; /* * The array size needs to be one larger than the number of modules we * support - see __start_xen(). */ -static module_t __initdata mb_modules[CONFIG_NR_BOOTMODS + 1]; +static struct boot_module __initdata efi_mods[CONFIG_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata efi_arch_mods[CONFIG_NR_BOOTMODS = + 1]; + +static const char *__initdata efi_loader =3D "PVH Directboot"; =20 static void __init edd_put_string(u8 *dst, size_t n, const char *src) { @@ -269,20 +272,37 @@ static void __init noreturn efi_arch_post_exit_boot(v= oid) : [cr3] "r" (idle_pg_table), [cs] "i" (__HYPERVISOR_CS), [ds] "r" (__HYPERVISOR_DS), - "D" (&mbi) + "D" (&efi_bi) : "memory" ); unreachable(); } =20 -static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image, - EFI_FILE_HANDLE dir_handle, - const char *section) +static struct boot_info __init *efi_arch_bootinfo_init(void) { + int i; + + efi_bi.arch =3D &efi_bi_arch; + efi_bi.mods =3D efi_mods; + + for ( i=3D0; i <=3D CONFIG_NR_BOOTMODS; i++ ) + efi_bi.mods[i].arch =3D &efi_arch_mods[i]; + + efi_bi_arch.boot_loader_name =3D _p(efi_loader); + + efi_bi_arch.flags =3D BOOTINFO_FLAG_X86_MODULES | + BOOTINFO_FLAG_X86_LOADERNAME; + return &efi_bi; } =20 -static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image, - EFI_FILE_HANDLE dir_handle, - const char *section) +static void __init efi_arch_cfg_file_early( + const EFI_LOADED_IMAGE *image, EFI_FILE_HANDLE dir_handle, + const char *section) +{ +} + +static void __init efi_arch_cfg_file_late( + const EFI_LOADED_IMAGE *image, EFI_FILE_HANDLE dir_handle, + const char *section) { union string name; =20 @@ -294,16 +314,15 @@ static void __init efi_arch_cfg_file_late(const EFI_L= OADED_IMAGE *image, name.s =3D get_value(&cfg, "global", "ucode"); if ( name.s ) { - microcode_set_module(mbi.mods_count); + microcode_set_module(efi_bi.nr_mods); split_string(name.s); read_file(dir_handle, s2w(&name), &ucode, NULL); efi_bs->FreePool(name.w); } } =20 -static void __init efi_arch_handle_cmdline(CHAR16 *image_name, - CHAR16 *cmdline_options, - const char *cfgfile_options) +static void __init efi_arch_handle_cmdline( + CHAR16 *image_name, CHAR16 *cmdline_options, const char *cfgfile_optio= ns) { union string name; =20 @@ -311,10 +330,10 @@ static void __init efi_arch_handle_cmdline(CHAR16 *im= age_name, { name.w =3D cmdline_options; w2s(&name); - place_string(&mbi.cmdline, name.s); + place_string((uint32_t *)efi_bi.cmdline, name.s); } if ( cfgfile_options ) - place_string(&mbi.cmdline, cfgfile_options); + place_string((uint32_t *)efi_bi.cmdline, cfgfile_options); /* Insert image name last, as it gets prefixed to the other options. */ if ( image_name ) { @@ -323,16 +342,10 @@ static void __init efi_arch_handle_cmdline(CHAR16 *im= age_name, } else name.s =3D "xen"; - place_string(&mbi.cmdline, name.s); + place_string((uint32_t *)efi_bi.cmdline, name.s); =20 - if ( mbi.cmdline ) - mbi.flags |=3D MBI_CMDLINE; - /* - * These must not be initialized statically, since the value must - * not get relocated when processing base relocations later. - */ - mbi.boot_loader_name =3D (long)"EFI"; - mbi.mods_addr =3D (long)mb_modules; + if ( efi_bi.cmdline ) + efi_bi_arch.flags |=3D BOOTINFO_FLAG_X86_CMDLINE; } =20 static void __init efi_arch_edd(void) @@ -695,9 +708,8 @@ static void __init efi_arch_memory_setup(void) #undef l2_4G_offset } =20 -static void __init efi_arch_handle_module(const struct file *file, - const CHAR16 *name, - const char *options) +static void __init efi_arch_handle_module( + const struct file *file, const CHAR16 *name, const char *options) { union string local_name; void *ptr; @@ -715,17 +727,25 @@ static void __init efi_arch_handle_module(const struc= t file *file, w2s(&local_name); =20 /* - * If options are provided, put them in - * mb_modules[mbi.mods_count].string after the filename, with a space - * separating them. place_string() prepends strings and adds separati= ng - * spaces, so the call order is reversed. + * Set module string to filename and if options are provided, put them= in + * after the filename, with a space separating them. */ + strlcpy(efi_bi.mods[efi_bi.nr_mods].string.bytes, local_name.s, + BOOTMOD_MAX_STRING); if ( options ) - place_string(&mb_modules[mbi.mods_count].string, options); - place_string(&mb_modules[mbi.mods_count].string, local_name.s); - mb_modules[mbi.mods_count].mod_start =3D file->addr >> PAGE_SHIFT; - mb_modules[mbi.mods_count].mod_end =3D file->size; - ++mbi.mods_count; + { + strlcat(efi_bi.mods[efi_bi.nr_mods].string.bytes, " ", + BOOTMOD_MAX_STRING); + strlcat(efi_bi.mods[efi_bi.nr_mods].string.bytes, options, + BOOTMOD_MAX_STRING); + } + efi_bi.mods[efi_bi.nr_mods].string.kind =3D BOOTSTR_CMDLINE; + + efi_bi.mods[efi_bi.nr_mods].start =3D file->addr; + efi_bi.mods[efi_bi.nr_mods].mfn =3D maddr_to_mfn(file->addr); + efi_bi.mods[efi_bi.nr_mods].size =3D file->size; + + ++efi_bi.nr_mods; efi_bs->FreePool(ptr); } =20 diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh= -boot.c index 834b1ad16b..c7081e70d0 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -18,6 +18,7 @@ * * Copyright (c) 2017 Citrix Systems Ltd. */ +#include #include #include #include @@ -31,12 +32,26 @@ bool __initdata pvh_boot; uint32_t __initdata pvh_start_info_pa; =20 -static multiboot_info_t __initdata pvh_mbi; -static module_t __initdata pvh_mbi_mods[CONFIG_NR_BOOTMOD + 1]; +static struct boot_info __initdata pvh_bi; +static struct arch_boot_info __initdata pvh_bi_arch; +static struct boot_module __initdata pvh_mods[CONFIG_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata pvh_arch_mods[CONFIG_NR_BOOTMODS = + 1]; static const char *__initdata pvh_loader =3D "PVH Directboot"; =20 -static void __init convert_pvh_info(multiboot_info_t **mbi, - module_t **mod) +static void __init init_pvh_info(void) +{ + int i; + + pvh_bi.arch =3D &pvh_bi_arch; + pvh_bi.mods =3D pvh_mods; + + for ( i=3D0; i <=3D CONFIG_NR_BOOTMODS; i++ ) + pvh_bi.mods[i].arch =3D &pvh_arch_mods[i]; + + pvh_bi.arch->boot_loader_name =3D _p(pvh_loader); +} + +static void __init convert_pvh_info(struct boot_info *bi) { const struct hvm_start_info *pvh_info =3D __va(pvh_start_info_pa); const struct hvm_modlist_entry *entry; @@ -50,23 +65,22 @@ static void __init convert_pvh_info(multiboot_info_t **= mbi, * required. The extra element is used to aid relocation. See * arch/x86/setup.c:__start_xen(). */ - if ( ARRAY_SIZE(pvh_mbi_mods) <=3D pvh_info->nr_modules ) + if ( ARRAY_SIZE(bi->mods) <=3D pvh_info->nr_modules ) panic("The module array is too small, size %zu, requested %u\n", - ARRAY_SIZE(pvh_mbi_mods), pvh_info->nr_modules); + ARRAY_SIZE(pvh_mods), pvh_info->nr_modules); =20 /* * Turn hvm_start_info into mbi. Luckily all modules are placed under = 4GB * boundary on x86. */ - pvh_mbi.flags =3D MBI_CMDLINE | MBI_MODULES | MBI_LOADERNAME; + bi->arch->flags =3D BOOTINFO_FLAG_X86_CMDLINE | BOOTINFO_FLAG_X86_MODU= LES + | BOOTINFO_FLAG_X86_LOADERNAME; =20 BUG_ON(pvh_info->cmdline_paddr >> 32); - pvh_mbi.cmdline =3D pvh_info->cmdline_paddr; - pvh_mbi.boot_loader_name =3D __pa(pvh_loader); + bi->cmdline =3D _p(__va(pvh_info->cmdline_paddr)); =20 - BUG_ON(pvh_info->nr_modules >=3D ARRAY_SIZE(pvh_mbi_mods)); - pvh_mbi.mods_count =3D pvh_info->nr_modules; - pvh_mbi.mods_addr =3D __pa(pvh_mbi_mods); + BUG_ON(pvh_info->nr_modules >=3D ARRAY_SIZE(pvh_mods)); + bi->nr_mods =3D pvh_info->nr_modules; =20 entry =3D __va(pvh_info->modlist_paddr); for ( i =3D 0; i < pvh_info->nr_modules; i++ ) @@ -74,15 +88,20 @@ static void __init convert_pvh_info(multiboot_info_t **= mbi, BUG_ON(entry[i].paddr >> 32); BUG_ON(entry[i].cmdline_paddr >> 32); =20 - pvh_mbi_mods[i].mod_start =3D entry[i].paddr; - pvh_mbi_mods[i].mod_end =3D entry[i].paddr + entry[i].size; - pvh_mbi_mods[i].string =3D entry[i].cmdline_paddr; + bi->mods[i].start =3D entry[i].paddr; + bi->mods[i].size =3D entry[i].size; + if ( entry[i].cmdline_paddr) + { + char *c =3D _p(__va(entry[i].cmdline_paddr)); + + safe_strcpy(bi->mods[i].string.bytes, c); + bi->mods[i].string.kind =3D BOOTSTR_CMDLINE; + } } =20 rsdp_hint =3D pvh_info->rsdp_paddr; =20 - *mbi =3D &pvh_mbi; - *mod =3D pvh_mbi_mods; + *bi =3D &pvh_bi; } =20 static void __init get_memory_map(void) @@ -99,9 +118,10 @@ static void __init get_memory_map(void) sanitize_e820_map(e820_raw.map, &e820_raw.nr_map); } =20 -void __init pvh_init(multiboot_info_t **mbi, module_t **mod) +void __init pvh_init(struct boot_info **bi) { - convert_pvh_info(mbi, mod); + *bi =3D init_pvh_info(); + convert_pvh_info(*bi); =20 hypervisor_probe(); ASSERT(xen_guest); diff --git a/xen/arch/x86/include/asm/guest/pvh-boot.h b/xen/arch/x86/inclu= de/asm/guest/pvh-boot.h index 48ffd1a0b1..120baf4ebb 100644 --- a/xen/arch/x86/include/asm/guest/pvh-boot.h +++ b/xen/arch/x86/include/asm/guest/pvh-boot.h @@ -19,13 +19,13 @@ #ifndef __X86_PVH_BOOT_H__ #define __X86_PVH_BOOT_H__ =20 -#include +#include =20 #ifdef CONFIG_PVH_GUEST =20 extern bool pvh_boot; =20 -void pvh_init(multiboot_info_t **mbi, module_t **mod); +void __init pvh_init(struct boot_info **bi); void pvh_print_info(void); =20 #else @@ -34,7 +34,7 @@ void pvh_print_info(void); =20 #define pvh_boot 0 =20 -static inline void pvh_init(multiboot_info_t **mbi, module_t **mod) +static inline void __init pvh_init(struct boot_info **bi) { ASSERT_UNREACHABLE(); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index a7bf698d52..e3922f3a30 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -274,47 +273,6 @@ custom_param("acpi", parse_acpi_param); =20 struct boot_info __initdata *boot_info; =20 -static struct boot_info __initdata x86_bi; -static struct arch_boot_info __initdata x86_bi_arch; -static struct boot_module __initdata x86_mods[CONFIG_NR_BOOTMODS + 1]; -static struct arch_bootmodule __initdata x86_arch_mods[CONFIG_NR_BOOTMODS = + 1]; - -static void __init mb_to_bootinfo(multiboot_info_t *mbi, module_t *mods) -{ - int i; - - x86_bi.arch =3D &x86_bi_arch; - x86_bi.mods =3D x86_mods; - - x86_bi.cmdline =3D __va(mbi->cmdline); - - /* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */ - x86_bi_arch.flags =3D mbi->flags; - x86_bi_arch.mem_upper =3D mbi->mem_upper; - x86_bi_arch.mem_lower =3D mbi->mem_lower; - x86_bi_arch.mmap_length =3D mbi->mmap_length; - x86_bi_arch.mmap_addr =3D mbi->mmap_addr; - x86_bi_arch.boot_loader_name =3D __va(mbi->boot_loader_name); - - x86_bi.nr_mods =3D mbi->mods_count; - for ( i =3D 0; i <=3D CONFIG_NR_BOOTMODS; i++) - { - x86_mods[i].arch =3D &x86_arch_mods[i]; - - if ( i < x86_bi.nr_mods ) - { - bootmodule_update_start(&x86_mods[i], mods[i].mod_start); - x86_mods[i].size =3D mods[i].mod_end - mods[i].mod_start; - - x86_mods[i].string.len =3D strlcpy(x86_mods[i].string.bytes, - __va(mods[i].string), - BOOTMOD_MAX_STRING); - } - } - - boot_info =3D &x86_bi; -} - unsigned long __init initial_images_nrpages(nodeid_t node) { unsigned long node_start =3D node_start_pfn(node); @@ -897,15 +855,13 @@ static struct domain *__init create_dom0( /* How much of the directmap is prebuilt at compile time. */ #define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) =20 -void __init noreturn __start_xen(unsigned long mbi_p) +void __init noreturn __start_xen(unsigned long bi_p) { char *memmap_type =3D NULL; char *cmdline, *kextra, *loader; void *bsp_stack; struct cpu_info *info =3D get_cpu_info(), *bsp_info; unsigned int initrdidx, num_parked =3D 0; - multiboot_info_t *mbi; - module_t *mod; unsigned long nr_pages, raw_max_page; int i, j, e820_warn =3D 0, bytes =3D 0; unsigned long eb_start, eb_end; @@ -942,16 +898,29 @@ void __init noreturn __start_xen(unsigned long mbi_p) =20 if ( pvh_boot ) { - ASSERT(mbi_p =3D=3D 0); - pvh_init(&mbi, &mod); + ASSERT(bi_p =3D=3D 0); + pvh_init(&boot_info); } else { - mbi =3D __va(mbi_p); - mod =3D __va(mbi->mods_addr); - } + /* + * Since addresses were setup before virtual addressing was enable= d, + * fixup pointers to virtual addresses for proper dereferencing. + */ + boot_info =3D __va(bi_p); + boot_info->cmdline =3D __va(boot_info->cmdline); + boot_info->mods =3D __va(boot_info->mods); + boot_info->arch =3D __va(boot_info->arch); + + boot_info->arch->boot_loader_name =3D + __va(boot_info->arch->boot_loader_name); =20 - mb_to_bootinfo(mbi, mod); + for ( i =3D 0; i <=3D boot_info->nr_mods; i++ ) + { + boot_info->mods[i].mfn =3D maddr_to_mfn(boot_info->mods[i].sta= rt); + boot_info->mods[i].arch =3D __va(boot_info->mods[i].arch); + } + } =20 loader =3D (boot_info->arch->flags & BOOTINFO_FLAG_X86_LOADERNAME) ? boot_info->arch->boot_loader_name : "unknown"; diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index a25e1d29f1..287e48b49a 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -11,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -1222,6 +1222,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *S= ystemTable) =20 efi_arch_relocate_image(0); =20 + efi_arch_bootinfo_init(); + if ( use_cfg_file ) { EFI_FILE_HANDLE dir_handle; --=20 2.20.1