efi/libstub: Get rid of 'sys_table_arg' macro parameter
authorArd Biesheuvel <ardb@kernel.org>
Tue, 24 Dec 2019 15:10:15 +0000 (16:10 +0100)
committerIngo Molnar <mingo@kernel.org>
Wed, 25 Dec 2019 09:49:21 +0000 (10:49 +0100)
The efi_call macros on ARM have a dependency on a variable 'sys_table_arg'
existing in the scope of the macro instantiation. Since this variable
always points to the same data structure, let's create a global getter
for it and use that instead.

Note that the use of a global variable with external linkage is avoided,
given the problems we had in the past with early processing of the GOT
tables.

While at it, drop the redundant casts in the efi_table_attr and
efi_call_proto macros.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-16-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/arm/include/asm/efi.h
arch/arm64/include/asm/efi.h
arch/x86/boot/compressed/eboot.c
drivers/firmware/efi/libstub/arm-stub.c
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/gop.c

index 9b0c64c28bffff9c62c0c435d0f560aef717732a..555364b7bd2acd1b79e478a5314e28284eebd337 100644 (file)
@@ -50,15 +50,15 @@ void efi_virtmap_unload(void);
 
 /* arch specific definitions used by the stub code */
 
-#define efi_call_early(f, ...)         sys_table_arg->boottime->f(__VA_ARGS__)
-#define efi_call_runtime(f, ...)       sys_table_arg->runtime->f(__VA_ARGS__)
+#define efi_call_early(f, ...)         efi_system_table()->boottime->f(__VA_ARGS__)
+#define efi_call_runtime(f, ...)       efi_system_table()->runtime->f(__VA_ARGS__)
 #define efi_is_native()                        (true)
 
 #define efi_table_attr(table, attr, instance)                          \
-       ((table##_t *)instance)->attr
+       instance->attr
 
 #define efi_call_proto(protocol, f, instance, ...)                     \
-       ((protocol##_t *)instance)->f(instance, ##__VA_ARGS__)
+       instance->f(instance, ##__VA_ARGS__)
 
 struct screen_info *alloc_screen_info(efi_system_table_t *sys_table_arg);
 void free_screen_info(efi_system_table_t *sys_table, struct screen_info *si);
index 189082c44c28cd7a1b9e727849c55c2826bf8ed1..9aa518d6758822fe52234144ec840f632cf9f96c 100644 (file)
@@ -93,15 +93,15 @@ static inline unsigned long efi_get_max_initrd_addr(unsigned long dram_base,
        return (image_addr & ~(SZ_1G - 1UL)) + (1UL << (VA_BITS_MIN - 1));
 }
 
-#define efi_call_early(f, ...)         sys_table_arg->boottime->f(__VA_ARGS__)
-#define efi_call_runtime(f, ...)       sys_table_arg->runtime->f(__VA_ARGS__)
+#define efi_call_early(f, ...)         efi_system_table()->boottime->f(__VA_ARGS__)
+#define efi_call_runtime(f, ...)       efi_system_table()->runtime->f(__VA_ARGS__)
 #define efi_is_native()                        (true)
 
 #define efi_table_attr(table, attr, instance)                          \
-       ((table##_t *)instance)->attr
+       instance->attr
 
 #define efi_call_proto(protocol, f, instance, ...)                     \
-       ((protocol##_t *)instance)->f(instance, ##__VA_ARGS__)
+       instance->f(instance, ##__VA_ARGS__)
 
 #define alloc_screen_info(x...)                &screen_info
 
index 36a26d6e2af0a896ee0c6e6653850f173cba7e19..3a7c900b9c66804437ffd3408297b664112f8c1f 100644 (file)
@@ -27,6 +27,11 @@ __pure const struct efi_config *__efi_early(void)
        return efi_early;
 }
 
+__pure efi_system_table_t *efi_system_table(void)
+{
+       return sys_table;
+}
+
 #define BOOT_SERVICES(bits)                                            \
 static void setup_boot_services##bits(struct efi_config *c)            \
 {                                                                      \
index 60a301e1c072c8b997d867d267a89bfa38cb2370..47f072ac3f30eae6b24a734cc8150873f45e11ec 100644 (file)
 
 static u64 virtmap_base = EFI_RT_VIRTUAL_BASE;
 
+static efi_system_table_t *__section(.data) sys_table;
+
+__pure efi_system_table_t *efi_system_table(void)
+{
+       return sys_table;
+}
+
 void efi_char16_printk(efi_system_table_t *sys_table_arg,
                              efi_char16_t *str)
 {
@@ -110,7 +117,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
  * for both archictectures, with the arch-specific code provided in the
  * handle_kernel_image() function.
  */
-unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
+unsigned long efi_entry(void *handle, efi_system_table_t *sys_table_arg,
                               unsigned long *image_addr)
 {
        efi_loaded_image_t *image;
@@ -131,6 +138,8 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
        enum efi_secureboot_mode secure_boot;
        struct screen_info *si;
 
+       sys_table = sys_table_arg;
+
        /* Check if we were booted by the EFI firmware */
        if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
                goto fail;
index 05739ae013c8283e6c7ef5f3134fe77b9df249b7..e6775c16a97dbb8d052011a3ab97c77fb7639952 100644 (file)
@@ -29,6 +29,8 @@ extern int __pure nokaslr(void);
 extern int __pure is_quiet(void);
 extern int __pure novamap(void);
 
+extern __pure efi_system_table_t  *efi_system_table(void);
+
 #define pr_efi(sys_table, msg)         do {                            \
        if (!is_quiet()) efi_printk(sys_table, "EFI stub: "msg);        \
 } while (0)
index 5f4fbc2ac687ab905f9575b0cb3d9a165a452a52..6c49d0a9aa3ff1fcb10a14138c80ae7013fdda46 100644 (file)
@@ -10,6 +10,8 @@
 #include <asm/efi.h>
 #include <asm/setup.h>
 
+#include "efistub.h"
+
 static void find_bits(unsigned long mask, u8 *pos, u8 *size)
 {
        u8 first, len;