From patchwork Thu Aug 8 00:31:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 11083019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D755912 for ; Thu, 8 Aug 2019 00:34:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 400C328AB9 for ; Thu, 8 Aug 2019 00:34:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3304928AD4; Thu, 8 Aug 2019 00:34:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B5E128AB9 for ; Thu, 8 Aug 2019 00:34:19 +0000 (UTC) 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 X-Inumbo-ID: fc477a7e-b973-11e9-8e0f-6f3baea1f60d 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 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: 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) From: =?utf-8?q?Marek_Marczykowski-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_Marczykowski-G?= =?utf-8?q?=C3=B3recki?= , Tim Deegan , Julien Grall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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=mapbs 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= 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= parameter early in xen.efi too, both in xen.efi command line and cfg file. Signed-off-by: Marek Marczykowski-Górecki --- 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=no). This option should not normally be required except for debugging purposes. ### efi - = List of [ rs=, attr=no|uc ] + = List of [ rs=, attr=no|uc, mapbs= ] Controls for interacting with the system Extended Firmware Interface. @@ -899,6 +899,10 @@ Controls for interacting with the system Extended Firmware Interface. leave the memory regions unmapped, while `attr=uc` will map them as fully uncacheable. +* The `mapbs=` boolean controls whether EfiBootServices{Code,Data} should + remain mapped after Exit() BootServices call. By default those memory regions + will not be mapped after Exit() BootServices call. + ### ept > `= List of [ ad=, pml= ]` 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 .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 /* Skip Multiboot2 information fixed part. */ lea (MB2_fixed_sizeof+MULTIBOOT2_TAG_ALIGN-1)(%rbx),%ecx @@ -241,7 +242,7 @@ __efi64_mb2_start: /* Are EFI boot services available? */ cmpl $MULTIBOOT2_TAG_TYPE_EFI_BS,MB2_tag_type(%rcx) - jne .Lefi_mb2_st + jne .Lefi_mb2_cmdline /* 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 +.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 + /* 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: /* * 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 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 *image_name, name.s = "xen"; place_string(&mbi.cmdline, name.s); - if ( mbi.cmdline ) + if ( mbi.cmdline ) { mbi.flags |= 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) static void __init efi_arch_flush_dcache_area(const void *vaddr, UINTN size) { } -void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) +void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable, + const char *cmdline) { EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; UINTN cols, gop_mode = ~0, rows; @@ -685,6 +688,9 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable efi_init(ImageHandle, SystemTable); + if (cmdline) + efi_early_parse_cmdline(cmdline); + efi_console_set_mode(); 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-offsets.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(); 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, CHAR16 *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); 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) static bool __initdata efi_map_uc; +/* + * 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 = -EINVAL; } + else if ( (val = parse_boolean("mapbs", s, ss)) >= 0 ) + { + map_bs = val; + } else rc = -EINVAL; s = ss + 1; - } while ( *ss ); + /* + * End parsing on both '\0' and ' ', + * to make efi_early_parse_cmdline simpler. + */ + } while ( *ss && *ss != ' '); return rc; } custom_param("efi", parse_efi_param); +/* Extract efi= param early in the boot */ +static void __init efi_early_parse_cmdline(const char *cmdline) +{ + const char *efi_opt = strstr(cmdline, "efi="); + 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,