From patchwork Tue Apr 19 15:49:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 12818727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D799C433EF for ; Tue, 19 Apr 2022 15:49:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.308318.524013 (Exim 4.92) (envelope-from ) id 1ngq6j-0006eY-5L; Tue, 19 Apr 2022 15:49:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 308318.524013; Tue, 19 Apr 2022 15:49:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ngq6j-0006eO-28; Tue, 19 Apr 2022 15:49:37 +0000 Received: by outflank-mailman (input) for mailman id 308318; Tue, 19 Apr 2022 15:49:35 +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 1ngq6h-0006bg-OZ for xen-devel@lists.xenproject.org; Tue, 19 Apr 2022 15:49:35 +0000 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4f1a3660-bff8-11ec-a405-831a346695d4; Tue, 19 Apr 2022 17:49:34 +0200 (CEST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id C8CA75C01B9; Tue, 19 Apr 2022 11:49:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 19 Apr 2022 11:49:33 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 19 Apr 2022 11:49:33 -0400 (EDT) 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: 4f1a3660-bff8-11ec-a405-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1650383373; x=1650469773; bh=/ sHDqu5TR+my1VccR9iUf0aiaYoUSa126jvmh3CA+Xk=; b=c8FvKmdLc6lFlXIaX 1GbBfeZgu60Wek4Z5Pvxw3wIflxj6k+jsBGqWu4tUnv4XtOTOMB/i7uPwpj/e/oO Pcexr7nx6G7BNREGg4AZ9oINFVaqsja657tvmusXByrTRI6ypXmG0kYBS4FJ1H3I hJc7Q372MpgdvM4YSEXSHTdTp7gytWmIh86Q1E84OMrBkYrB51GyN5P5yy/aL1Y7 biFLVaWf4b2AvMgSwDPnfDgYmqU5Gd7oyjay/tuwKOdjLMuf3AgWuHIGIfeihjCq BExjc3bqlhbAD0bXrwTXPYRLp5Of8Ps2cvj10OMr73zEPIVovaFL0IuqrIC927GI 0lGxA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrvddtfedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggujgesghdtreertddtvdenucfhrhhomhepffgvmhhiucfo rghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhnghhslh grsgdrtghomheqnecuggftrfgrthhtvghrnhepveefleduheekhfdtfffffedukeevtedu leekfffgudfhtdduhfevueefueegtefhnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhslhgr sgdrtghomh X-ME-Proxy: Date: Tue, 19 Apr 2022 11:49:29 -0400 From: Demi Marie Obenour To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v3 3/4] Add a new hypercall to get the ESRT Message-ID: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: This hypercall can be used to get the ESRT from the hypervisor. It returning successfully also indicates that Xen has reserved the ESRT and it can safely be parsed by dom0. --- xen/common/efi/boot.c | 15 ++++++++++----- xen/common/efi/efi.h | 2 ++ xen/common/efi/runtime.c | 14 ++++++++++++++ xen/include/public/platform.h | 7 +++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 31664818c1..01b2409c5e 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -567,8 +567,6 @@ static int __init efi_check_dt_boot(const EFI_LOADED_IMAGE *loaded_image) } #endif -static UINTN __initdata esrt = EFI_INVALID_TABLE_ADDR; - static bool __init is_esrt_valid( const EFI_MEMORY_DESCRIPTOR *const desc) { @@ -594,9 +592,13 @@ static bool __init is_esrt_valid( esrt_ptr = (const ESRT *)esrt; if ( esrt_ptr->Version != 1 || !esrt_ptr->Count ) return false; - return esrt_ptr->Count <= - (available_len - sizeof(*esrt_ptr)) / - sizeof(esrt_ptr->Entries[0]); + if ( esrt_ptr->Count > + (available_len - sizeof(*esrt_ptr)) / + sizeof(esrt_ptr->Entries[0]) ) + return false; + esrt_size = sizeof(*esrt_ptr) + + esrt_ptr->Count * sizeof(esrt_ptr->Entries[0]); + return true; } /* @@ -1121,6 +1123,9 @@ static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *Syste } } + if ( esrt_desc == (const EFI_MEMORY_DESCRIPTOR *)EFI_INVALID_TABLE_ADDR ) + esrt = EFI_INVALID_TABLE_ADDR; + efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size, efi_mdesc_size, mdesc_ver); diff --git a/xen/common/efi/efi.h b/xen/common/efi/efi.h index 02f499071a..0736662ebc 100644 --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -46,6 +46,8 @@ extern const EFI_RUNTIME_SERVICES *efi_rs; extern UINTN efi_memmap_size, efi_mdesc_size; extern void *efi_memmap; extern const EFI_MEMORY_DESCRIPTOR *esrt_desc; +extern UINTN esrt; +extern UINTN esrt_size; #ifdef CONFIG_X86 extern mfn_t efi_l4_mfn; diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index 0d09647952..4466d5379c 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -227,6 +227,12 @@ const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n) #endif /* COMPAT */ #ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */ + +#ifndef COMPAT +UINTN esrt = EFI_INVALID_TABLE_ADDR; +UINTN esrt_size = 0; +#endif + int efi_get_info(uint32_t idx, union xenpf_efi_info *info) { unsigned int i, n; @@ -311,6 +317,14 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info) info->apple_properties.size = efi_apple_properties_len; break; + case XEN_FW_EFI_ESRT: + if ( esrt_desc == (const EFI_MEMORY_DESCRIPTOR *)EFI_INVALID_TABLE_ADDR ) + return -ENODATA; + if ( info->esrt.size < esrt_size ) + return -ERANGE; + if ( copy_to_guest(info->esrt.table, (const ESRT *)esrt, esrt_size) ) + return -EFAULT; + break; default: return -EINVAL; } diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h index 8100133509..a848df2066 100644 --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -243,6 +243,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_efi_runtime_call_t); #define XEN_FW_EFI_RT_VERSION 4 #define XEN_FW_EFI_PCI_ROM 5 #define XEN_FW_EFI_APPLE_PROPERTIES 6 +#define XEN_FW_EFI_ESRT 7 #define XEN_FW_KBD_SHIFT_FLAGS 5 struct xenpf_firmware_info { /* IN variables. */ @@ -307,6 +308,12 @@ struct xenpf_firmware_info { uint64_t address; xen_ulong_t size; } apple_properties; + struct { + /* IN variables */ + uint64_t size; + /* OUT variables */ + XEN_GUEST_HANDLE(void) table; + } esrt; } efi_info; /* XEN_FW_EFI_INFO */ /* Int16, Fn02: Get keyboard shift flags. */