From nobody Mon Feb 9 07:55:33 2026 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=1657141608; cv=pass; d=zohomail.com; s=zohoarc; b=RCBY4VW6tNMj5067ip9/GwGY58U/yPN8mZwpeMOVeFTEBpdRR/hTqYErO3R/Uyn4uT4FOOYONECMHT6j3FBwdE/ZNm4mzscpDzpfdr20gfFu49ShPVfH9duXIxAd9+ywS22KUbmPSvFHJ8RN79Gxd8K/bnlOnkgql9tuI4VvV7M= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141608; 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=E/AB0m5ePJCFrkWnhxRrqf9yCakYmeSAVavi9TF9QYs=; b=m5NIwLBx3ljpVw10OJ0i493VwmNHUXUuHA7r7MeqO54O3taceQIZuTSdTR1vxVXdjahD7KcnD2DPot5snND29OqUREiiqZwRfuRO1Z8kYH0l9oTj/0sVjGooV9J9gMe7/JNiiLSFLMmhaS/7aD7qJaQGWOX3155UoN4kHAUE2hE= 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 165714160879399.59184106262819; Wed, 6 Jul 2022 14:06:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.362535.592597 (Exim 4.92) (envelope-from ) id 1o9CE7-0005Ta-QC; Wed, 06 Jul 2022 21:06:27 +0000 Received: by outflank-mailman (output) from mailman id 362535.592597; Wed, 06 Jul 2022 21:06:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o9CE7-0005TR-N7; Wed, 06 Jul 2022 21:06:27 +0000 Received: by outflank-mailman (input) for mailman id 362535; Wed, 06 Jul 2022 21:06:26 +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 1o9CE6-0003HV-37 for xen-devel@lists.xenproject.org; Wed, 06 Jul 2022 21:06:26 +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 7d4658e6-fd6f-11ec-924f-1f966e50362f; Wed, 06 Jul 2022 23:06:24 +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 1657141508934176.79563610292462; Wed, 6 Jul 2022 14:05:08 -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: 7d4658e6-fd6f-11ec-924f-1f966e50362f ARC-Seal: i=1; a=rsa-sha256; t=1657141510; cv=none; d=zohomail.com; s=zohoarc; b=R27CxvffThjlCN85YFvIcEeKXShctWJstvrmFXX9vLPYr2jkMH2DqDxvPcqRau4QcFdJlHcWDQNrhyKm/sD/MbnSNTfmNfe5IPpCDHUObz6CMcTXBJG7aZFtOiZX+h3kF8IQQXb5Hx7xZvbnP1VLmEODEjiD8IsSWhAp35QYFH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657141510; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=E/AB0m5ePJCFrkWnhxRrqf9yCakYmeSAVavi9TF9QYs=; b=L4yilOPz5AgLb7ClL5LK+pDGpZ90TeKwTaYW9OMItBJnzfRMVmiLqD3gxS1kO2vpiEyHFd6RxazobxCQe0Vjz69KkDGeIfsIu17lqitrB7N//kyOvFpbjqadSIQQzK1NNqrWwmalXULTZzZsvz+yrcIlc8/ryJRV6X7lbh5e8uc= 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=1657141510; 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=E/AB0m5ePJCFrkWnhxRrqf9yCakYmeSAVavi9TF9QYs=; b=ecg9RE4yp5kpuFIsVxGnBl9VZ2goLVel8IwuGsyJxtmowPE3FTFUldySQ4y3UXz0 t3UmfzzsH8bNQkEag+uJjDxRy8sq1byW1Op/hYNlRMuGR98vFHT/uIbhQZ9+GR7nm5H 6oQDY6ekC3qJmhRQxQE1P03SR4gmzXyo9KQaRbuE= 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: [PATCH v1 04/18] x86: refactor entrypoints to new boot info Date: Wed, 6 Jul 2022 17:04:39 -0400 Message-Id: <20220706210454.30096-5-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220706210454.30096-1-dpsmith@apertussolutions.com> References: <20220706210454.30096-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: 1657141609705100001 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 Reviewed-by: Christopher Clark --- xen/arch/x86/boot/boot_info32.h | 94 +++++++++++ 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 | 64 +++++--- 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, 359 insertions(+), 180 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..01af950efc --- /dev/null +++ b/xen/arch/x86/boot/boot_info32.h @@ -0,0 +1,94 @@ +#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 __packed boot_string { + u32 kind; + u64 arch; + + char bytes[BOOTMOD_MAX_STRING]; + u64 len; +}; + +struct __packed arch_bootmodule { + bool relocated; + u32 flags; +#define BOOTMOD_FLAG_X86_RELOCATED 1U << 0 + u32 headroom; +}; + +struct __packed boot_module { + u32 kind; + u64 start; + u64 mfn; + u64 size; + + u64 arch; + struct boot_string string; +}; + +struct __packed arch_boot_info { + /* uint32_t */ + 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 + + /* bool */ + u8 xen_guest; + + /* char* */ + u64 boot_loader_name; + u64 kextra; + + /* uint32_t */ + u32 mem_lower; + u32 mem_upper; + + /* uint32_t */ + u32 mmap_length; + /* paddr_t */ + u64 mmap_addr; +}; + +struct __packed boot_info { + /* char* */ + u64 cmdline; + + /* uint32_t */ + u32 nr_mods; + /* struct boot_module* */ + u64 mods; + + /* struct arch_boot_info* */ + 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..28cf5df0a3 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,28 @@ 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 const char *__initdata pvh_loader =3D "PVH Directboot"; +static struct boot_info __initdata pvh_bi; +static struct arch_boot_info __initdata arch_pvh_bi; +static struct boot_module __initdata pvh_mods[CONFIG_NR_BOOTMODS + 1]; +static struct arch_bootmodule __initdata arch_pvh_mods[CONFIG_NR_BOOTMODS = + 1]; +static char __initdata *pvh_loader =3D "PVH Directboot"; =20 -static void __init convert_pvh_info(multiboot_info_t **mbi, - module_t **mod) +static struct boot_info __init *init_pvh_info(void) +{ + int i; + + pvh_bi.arch =3D &arch_pvh_bi; + pvh_bi.mods =3D pvh_mods; + + for ( i=3D0; i <=3D CONFIG_NR_BOOTMODS; i++ ) + pvh_bi.mods[i].arch =3D &arch_pvh_mods[i]; + + pvh_bi.arch->boot_loader_name =3D pvh_loader; + + return &pvh_bi; +} + +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 +67,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(pvh_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 +90,18 @@ 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; - - *mbi =3D &pvh_mbi; - *mod =3D pvh_mbi_mods; } =20 static void __init get_memory_map(void) @@ -99,13 +118,16 @@ 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); =20 + (*bi)->arch->xen_guest =3D xen_guest; + get_memory_map(); } =20 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 2700f4eb3e..ad37f4a658 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -273,47 +272,6 @@ custom_param("acpi", parse_acpi_param); =20 struct boot_info __initdata *boot_info; =20 -static void __init mb_to_bootinfo(multiboot_info_t *mbi, module_t *mods) -{ - static struct boot_info __initdata x86_binfo; - static struct arch_boot_info __initdata arch_x86_binfo; - static struct boot_module __initdata x86_mods[CONFIG_NR_BOOTMODS += 1]; - static struct arch_bootmodule __initdata - arch_x86_mods[CONFIG_NR_BOOTMODS += 1]; - int i; - - x86_binfo.arch =3D &arch_x86_binfo; - x86_binfo.mods =3D x86_mods; - - x86_binfo.cmdline =3D __va(mbi->cmdline); - - /* The BOOTINFO_FLAG_X86_* flags are a 1-1 map to MBI_* */ - arch_x86_binfo.flags =3D mbi->flags; - arch_x86_binfo.mem_upper =3D mbi->mem_upper; - arch_x86_binfo.mem_lower =3D mbi->mem_lower; - arch_x86_binfo.mmap_length =3D mbi->mmap_length; - arch_x86_binfo.mmap_addr =3D mbi->mmap_addr; - arch_x86_binfo.boot_loader_name =3D __va(mbi->boot_loader_name); - - x86_binfo.nr_mods =3D mbi->mods_count; - for ( i =3D 0; i <=3D CONFIG_NR_BOOTMODS; i++) - { - x86_mods[i].arch =3D &arch_x86_mods[i]; - - if ( i < x86_binfo.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_binfo; -} - unsigned long __init initial_images_nrpages(nodeid_t node) { unsigned long node_start =3D node_start_pfn(node); @@ -900,15 +858,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; @@ -945,16 +901,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