All of lore.kernel.org
 help / color / mirror / Atom feed
From: Demi Marie Obenour <demi@invisiblethingslab.com>
To: xen-devel@lists.xenproject.org
Cc: Jan Beulich <jbeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: [PATCH v3 3/4] Add a new hypercall to get the ESRT
Date: Tue, 19 Apr 2022 11:49:29 -0400	[thread overview]
Message-ID: <Yl7aC2a+TtOaFtqZ@itl-email> (raw)
In-Reply-To: <Yl7WHv6+M+eJwQep@itl-email>

[-- Attachment #1: Type: text/plain, Size: 4362 bytes --]

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. */
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)
Invisible Things Lab

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2022-04-19 15:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 15:32 [PATCH v3 0/4] EFI System Resource Table support Demi Marie Obenour
2022-04-19 15:40 ` [PATCH v3 1/4] Grab the EFI System Resource Table and check it Demi Marie Obenour
2022-04-27  8:23   ` Jan Beulich
2022-04-27  8:42   ` Jan Beulich
2022-05-30  8:47     ` Henry Wang
2022-05-30 18:22       ` Demi Marie Obenour
2022-04-27  9:00   ` Jan Beulich
2022-04-19 15:40 ` [PATCH v3 2/4] Add a dedicated memory region for the ESRT Demi Marie Obenour
2022-04-27  8:40   ` Jan Beulich
2022-04-19 15:49 ` Demi Marie Obenour [this message]
2022-04-27  8:56   ` [PATCH v3 3/4] Add a new hypercall to get " Jan Beulich
2022-04-27 19:08     ` Demi Marie Obenour
2022-04-28  6:47       ` Jan Beulich
2022-04-28 22:54         ` Demi Marie Obenour
2022-04-29  8:40           ` Jan Beulich
2022-04-29 17:06             ` Demi Marie Obenour
2022-05-02  6:24               ` Jan Beulich
2022-05-02  7:11                 ` Demi Marie Obenour
2022-05-02  7:37                   ` Jan Beulich
2022-05-02  7:42                     ` Demi Marie Obenour
2022-04-19 15:51 ` [PATCH v3 4/4] Add emacs file-local variables Demi Marie Obenour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yl7aC2a+TtOaFtqZ@itl-email \
    --to=demi@invisiblethingslab.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.