From nobody Fri Apr 26 23:12:13 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565224448; cv=none; d=zoho.com; s=zohoarc; b=G7WLxQoqwyjZ9XmhNlGFWULk1FnhSwNFcQm8j0gxhTmp1fwCxgGtF4qiqRA3oLofGU1OpTpn3TxqHHZvi33kV2mbJotIDfrE+ZWe0kSTJHXO9YZlFJr9HtJ2BMFFMeM5BSSLaVyIZYR5cDVqIYVENsHyLwgbta2Og32TI2tXGTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565224448; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=4E+LQTI9Wvy80YDoCNY5qdbuMGh031lZPV+OsSNce4U=; b=KJyJ9eAAesNISMj6nfpfX97qNt9Re2TAC9iXkvR6krts391uBtNSmyKafsoBXLNNCb6eySgD3j4kfyeJP1q849ChKhWTYP+gB5AE1+Desl/CD870N7XtdzSG5RQwrEgQosDCcIbGu5IE/HC6+lGtoz8CLjE+GWB3zU6OWwR5Fzs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 156522444811598.75977012178703; Wed, 7 Aug 2019 17:34:08 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvWLz-0007gV-Fe; Thu, 08 Aug 2019 00:32:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvWLx-0007gQ-UK for xen-devel@lists.xenproject.org; Thu, 08 Aug 2019 00:32:26 +0000 Received: from new3-smtp.messagingengine.com (unknown [66.111.4.229]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id fc477a7e-b973-11e9-8e0f-6f3baea1f60d; Thu, 08 Aug 2019 00:32:21 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id 820E71ADA; Wed, 7 Aug 2019 20:32:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 07 Aug 2019 20:32:21 -0400 Received: from localhost.localdomain (ip5b412221.dynamic.kabel-deutschland.de [91.65.34.33]) by mail.messagingengine.com (Postfix) with ESMTPA id 586AA380074; Wed, 7 Aug 2019 20:32:18 -0400 (EDT) X-Inumbo-ID: fc477a7e-b973-11e9-8e0f-6f3baea1f60d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=7CAn2w zROOlQxCp/x5wA/QaANP3flaRsiZ28v3cUbck=; b=D9Bhv0rhP4vhgRoGaImTQp 1Tp04Y6McQPFJOLGwSIDhIOwSSfBgZt22Ibbhgh26eonNTVKyFuXnSIZ5DD3ibLE JdLTAtKIg2rtqUBe+hQeoWn+c3mYZKecDlikTQCOLKB/lwqx0AZNtDxhRhoO9KE3 e3HDuvzpblX8BvDLaUjZJxE7zkdQOvDW8p9PTws46KOOI0heKF/Wb4TdlZIH5u0m s/dBsi1J2vh59xDEVxJcfYh5JVqat4p2bxi3DR7UlA3f45TKt8SDnBIjLJeJrVZa pB6Y5sOUr5nQ2WvWaRYnw/O1YB4BJioMlSLhSzhs3P0VcOhoSckjD4DbNou54z1w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddruddugedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffogggtohfgsehtkeertdertdejnecuhfhrohhmpeforghrvghk ucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesihhnvh hishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucffohhmrghinhephhgvrggurdhs sgenucfkphepledurdeihedrfeegrdeffeenucfrrghrrghmpehmrghilhhfrhhomhepmh grrhhmrghrvghksehinhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomhenucevlhhu shhtvghrufhiiigvpedt X-ME-Proxy: From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Date: Thu, 8 Aug 2019 02:31:57 +0200 Message-Id: <20190808003158.5256-1-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Organization: Invisible Things Lab Subject: [Xen-devel] [PATCH] EFI: add efi=mapbs option and parse efi= early X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Tim Deegan , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When booting Xen via xen.efi, there is /mapbs option to workaround certain platform issues (added in f36886bdf4 "EFI/early: add /mapbs to map EfiBootServices{Code,Data}"). Add support for efi=3Dmapbs on Xen cmdline for the same effect and parse it very early in the multiboot2+EFI boot path. Normally cmdline is parsed after relocating MB2 structure, which happens too late. To have efi=3D parsed early enough, save cmdline pointer in head.S and pass it as yet another argument to efi_multiboot2(). This way we avoid introducing yet another MB2 structure parser. To keep consistency, handle efi=3D parameter early in xen.efi too, both in xen.efi command line and cfg file. Signed-off-by: Marek Marczykowski-G=C3=B3recki --- docs/misc/xen-command-line.pandoc | 6 +++++- xen/arch/x86/boot/head.S | 21 ++++++++++++++++++--- xen/arch/x86/efi/efi-boot.h | 10 ++++++++-- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/common/efi/boot.c | 23 ++++++++++++++++++++++- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 7c72e31032..b2dfd64b48 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -886,7 +886,7 @@ disable it (edid=3Dno). This option should not normally= be required except for debugging purposes. =20 ### efi - =3D List of [ rs=3D, attr=3Dno|uc ] + =3D List of [ rs=3D, attr=3Dno|uc, mapbs=3D ] =20 Controls for interacting with the system Extended Firmware Interface. =20 @@ -899,6 +899,10 @@ Controls for interacting with the system Extended Firm= ware Interface. leave the memory regions unmapped, while `attr=3Duc` will map them as = fully uncacheable. =20 +* The `mapbs=3D` boolean controls whether EfiBootServices{Code,Data} sho= uld + remain mapped after Exit() BootServices call. By default those memory = regions + will not be mapped after Exit() BootServices call. + ### ept > `=3D List of [ ad=3D, pml=3D ]` =20 diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index d78bed394a..b13f46c70e 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -224,9 +224,10 @@ __efi64_mb2_start: jmp x86_32_switch =20 .Lefi_multiboot2_proto: - /* Zero EFI SystemTable and EFI ImageHandle addresses. */ + /* Zero EFI SystemTable, EFI ImageHandle and cmdline addresses. */ xor %esi,%esi xor %edi,%edi + xor %rdx,%rdx =20 /* Skip Multiboot2 information fixed part. */ lea (MB2_fixed_sizeof+MULTIBOOT2_TAG_ALIGN-1)(%rbx),%ecx @@ -241,7 +242,7 @@ __efi64_mb2_start: =20 /* Are EFI boot services available? */ cmpl $MULTIBOOT2_TAG_TYPE_EFI_BS,MB2_tag_type(%rcx) - jne .Lefi_mb2_st + jne .Lefi_mb2_cmdline =20 /* We are on EFI platform and EFI boot services are available. */ incb efi_platform(%rip) @@ -253,6 +254,14 @@ __efi64_mb2_start: incb skip_realmode(%rip) jmp .Lefi_mb2_next_tag =20 +.Lefi_mb2_cmdline: + /* Get cmdline address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_CMDLINE,MB2_tag_type(%rcx) + jne .Lefi_mb2_st + + lea MB2_string(%rcx),%rdx + jmp .Lefi_mb2_next_tag + .Lefi_mb2_st: /* Get EFI SystemTable address from Multiboot2 information. */ cmpl $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx) @@ -264,6 +273,11 @@ __efi64_mb2_start: cmove MB2_efi64_ih(%rcx),%rdi je .Lefi_mb2_next_tag =20 + /* Get cmdline address from Multiboot2 information. */ + cmpl $MULTIBOOT2_TAG_TYPE_CMDLINE,MB2_tag_type(%rcx) + cmove MB2_efi64_ih(%rcx),%rdi + je .Lefi_mb2_next_tag + /* Is it the end of Multiboot2 information? */ cmpl $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx) je .Lrun_bs @@ -327,7 +341,8 @@ __efi64_mb2_start: =20 /* * efi_multiboot2() is called according to System V AMD64 ABI: - * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable. + * - IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable, + * %rdx - MB2 cmdline. */ call efi_multiboot2 =20 diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 7a13a30bc0..df5e98e6bc 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -315,8 +315,10 @@ static void __init efi_arch_handle_cmdline(CHAR16 *ima= ge_name, name.s =3D "xen"; place_string(&mbi.cmdline, name.s); =20 - if ( mbi.cmdline ) + if ( mbi.cmdline ) { mbi.flags |=3D MBI_CMDLINE; + efi_early_parse_cmdline(mbi.cmdline); + } /* * These must not be initialized statically, since the value must * not get relocated when processing base relocations later. @@ -675,7 +677,8 @@ static bool __init efi_arch_use_config_file(EFI_SYSTEM_= TABLE *SystemTable) =20 static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN siz= e) { } =20 -void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *Syste= mTable) +void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *Syste= mTable, + const char *cmdline) { EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; UINTN cols, gop_mode =3D ~0, rows; @@ -685,6 +688,9 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_= SYSTEM_TABLE *SystemTable =20 efi_init(ImageHandle, SystemTable); =20 + if (cmdline) + efi_early_parse_cmdline(cmdline); + efi_console_set_mode(); =20 if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, diff --git a/xen/arch/x86/x86_64/asm-offsets.c b/xen/arch/x86/x86_64/asm-of= fsets.c index 33930ce97c..b5be6ca30f 100644 --- a/xen/arch/x86/x86_64/asm-offsets.c +++ b/xen/arch/x86/x86_64/asm-offsets.c @@ -163,6 +163,7 @@ void __dummy__(void) OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower); OFFSET(MB2_efi64_st, multiboot2_tag_efi64_t, pointer); OFFSET(MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer); + OFFSET(MB2_string, multiboot2_tag_string_t, string); BLANK(); =20 DEFINE(l2_identmap_sizeof, sizeof(l2_identmap)); diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 79193784ff..a8514bbb5f 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -126,6 +126,7 @@ static bool read_file(EFI_FILE_HANDLE dir_handle, CHAR1= 6 *name, static size_t wstrlen(const CHAR16 * s); static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz); static bool match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2); +static void efi_early_parse_cmdline(const char *cmdline); =20 static void efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable= ); static void efi_console_set_mode(void); @@ -1386,6 +1387,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *= SystemTable) =20 static bool __initdata efi_map_uc; =20 +/* + * Warning: this function must be idempotent as it may be called multiple + * times. + */ static int __init parse_efi_param(const char *s) { const char *ss; @@ -1412,16 +1417,32 @@ static int __init parse_efi_param(const char *s) else rc =3D -EINVAL; } + else if ( (val =3D parse_boolean("mapbs", s, ss)) >=3D 0 ) + { + map_bs =3D val; + } else rc =3D -EINVAL; =20 s =3D ss + 1; - } while ( *ss ); + /* + * End parsing on both '\0' and ' ', + * to make efi_early_parse_cmdline simpler. + */ + } while ( *ss && *ss !=3D ' '); =20 return rc; } custom_param("efi", parse_efi_param); =20 +/* Extract efi=3D param early in the boot */ +static void __init efi_early_parse_cmdline(const char *cmdline) +{ + const char *efi_opt =3D strstr(cmdline, "efi=3D"); + if ( efi_opt ) + parse_efi_param(efi_opt + 4); +} + #ifndef USE_SET_VIRTUAL_ADDRESS_MAP static __init void copy_mapping(unsigned long mfn, unsigned long end, bool (*is_valid)(unsigned long smfn, --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel