Skip to content

Commit 33b8544

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/x86: Drop two near identical versions of efi_runtime_init()
The routines efi_runtime_init32() and efi_runtime_init64() are almost indistinguishable, and the only relevant difference is the offset in the runtime struct from where to obtain the physical address of the SetVirtualAddressMap() routine. However, this address is only used once, when installing the virtual address map that the OS will use to invoke EFI runtime services, and at the time of the call, we will necessarily be running with a 1:1 mapping, and so there is no need to do the map/unmap dance here to retrieve the address. In fact, in the preceding changes to these users, we stopped using the address recorded here entirely. So let's just get rid of all this code since it no longer serves a purpose. While at it, tweak the logic so that we handle unsupported and disable EFI runtime services in the same way, and unmap the EFI memory map in both cases. Signed-off-by: Ard Biesheuvel <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arvind Sankar <[email protected]> Cc: Matthew Garrett <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent ea5e191 commit 33b8544

File tree

2 files changed

+5
-109
lines changed

2 files changed

+5
-109
lines changed

arch/x86/platform/efi/efi.c

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -429,87 +429,6 @@ static int __init efi_systab_init(void *phys)
429429
return 0;
430430
}
431431

432-
static int __init efi_runtime_init32(void)
433-
{
434-
efi_runtime_services_32_t *runtime;
435-
436-
runtime = early_memremap((unsigned long)efi.systab->runtime,
437-
sizeof(efi_runtime_services_32_t));
438-
if (!runtime) {
439-
pr_err("Could not map the runtime service table!\n");
440-
return -ENOMEM;
441-
}
442-
443-
/*
444-
* We will only need *early* access to the SetVirtualAddressMap
445-
* EFI runtime service. All other runtime services will be called
446-
* via the virtual mapping.
447-
*/
448-
efi_phys.set_virtual_address_map =
449-
(efi_set_virtual_address_map_t *)
450-
(unsigned long)runtime->set_virtual_address_map;
451-
early_memunmap(runtime, sizeof(efi_runtime_services_32_t));
452-
453-
return 0;
454-
}
455-
456-
static int __init efi_runtime_init64(void)
457-
{
458-
efi_runtime_services_64_t *runtime;
459-
460-
runtime = early_memremap((unsigned long)efi.systab->runtime,
461-
sizeof(efi_runtime_services_64_t));
462-
if (!runtime) {
463-
pr_err("Could not map the runtime service table!\n");
464-
return -ENOMEM;
465-
}
466-
467-
/*
468-
* We will only need *early* access to the SetVirtualAddressMap
469-
* EFI runtime service. All other runtime services will be called
470-
* via the virtual mapping.
471-
*/
472-
efi_phys.set_virtual_address_map =
473-
(efi_set_virtual_address_map_t *)
474-
(unsigned long)runtime->set_virtual_address_map;
475-
early_memunmap(runtime, sizeof(efi_runtime_services_64_t));
476-
477-
return 0;
478-
}
479-
480-
static int __init efi_runtime_init(void)
481-
{
482-
int rv;
483-
484-
/*
485-
* Check out the runtime services table. We need to map
486-
* the runtime services table so that we can grab the physical
487-
* address of several of the EFI runtime functions, needed to
488-
* set the firmware into virtual mode.
489-
*
490-
* When EFI_PARAVIRT is in force then we could not map runtime
491-
* service memory region because we do not have direct access to it.
492-
* However, runtime services are available through proxy functions
493-
* (e.g. in case of Xen dom0 EFI implementation they call special
494-
* hypercall which executes relevant EFI functions) and that is why
495-
* they are always enabled.
496-
*/
497-
498-
if (!efi_enabled(EFI_PARAVIRT)) {
499-
if (efi_enabled(EFI_64BIT))
500-
rv = efi_runtime_init64();
501-
else
502-
rv = efi_runtime_init32();
503-
504-
if (rv)
505-
return rv;
506-
}
507-
508-
set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
509-
510-
return 0;
511-
}
512-
513432
void __init efi_init(void)
514433
{
515434
efi_char16_t *c16;
@@ -567,13 +486,13 @@ void __init efi_init(void)
567486

568487
if (!efi_runtime_supported())
569488
pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n");
570-
else {
571-
if (efi_runtime_disabled() || efi_runtime_init()) {
572-
efi_memmap_unmap();
573-
return;
574-
}
489+
490+
if (!efi_runtime_supported() || efi_runtime_disabled()) {
491+
efi_memmap_unmap();
492+
return;
575493
}
576494

495+
set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
577496
efi_clean_memmap();
578497

579498
if (efi_enabled(EFI_DBG))
@@ -934,8 +853,6 @@ static void __init kexec_enter_virtual_mode(void)
934853

935854
efi_native_runtime_setup();
936855

937-
efi.set_virtual_address_map = NULL;
938-
939856
if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX))
940857
runtime_code_page_mkexec();
941858
#endif
@@ -1040,8 +957,6 @@ static void __init __efi_enter_virtual_mode(void)
1040957
else
1041958
efi_thunk_runtime_setup();
1042959

1043-
efi.set_virtual_address_map = NULL;
1044-
1045960
/*
1046961
* Apply more restrictive page table mapping attributes now that
1047962
* SVAM() has been called and the firmware has performed all

include/linux/efi.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -539,24 +539,6 @@ typedef struct {
539539
u32 query_variable_info;
540540
} efi_runtime_services_32_t;
541541

542-
typedef struct {
543-
efi_table_hdr_t hdr;
544-
u64 get_time;
545-
u64 set_time;
546-
u64 get_wakeup_time;
547-
u64 set_wakeup_time;
548-
u64 set_virtual_address_map;
549-
u64 convert_pointer;
550-
u64 get_variable;
551-
u64 get_next_variable;
552-
u64 set_variable;
553-
u64 get_next_high_mono_count;
554-
u64 reset_system;
555-
u64 update_capsule;
556-
u64 query_capsule_caps;
557-
u64 query_variable_info;
558-
} efi_runtime_services_64_t;
559-
560542
typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
561543
typedef efi_status_t efi_set_time_t (efi_time_t *tm);
562544
typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
@@ -946,7 +928,6 @@ extern struct efi {
946928
efi_query_capsule_caps_t *query_capsule_caps;
947929
efi_get_next_high_mono_count_t *get_next_high_mono_count;
948930
efi_reset_system_t *reset_system;
949-
efi_set_virtual_address_map_t *set_virtual_address_map;
950931
struct efi_memory_map memmap;
951932
unsigned long flags;
952933
} efi;

0 commit comments

Comments
 (0)