History

efi/x86: Drop 'systab' member from struct efi

The systab member in struct efi has outlived its usefulness, now that we have better ways to access the only piece of information we are interested in after init, which is the EFI runtime services table address. So instead of instantiating a doctored copy at early boot with lots of mangled values, and switching the pointer when switching into virtual mode, let's grab the values we need directly, and get rid of the systab pointer entirely.

Ard Biesheuvel committed 6 years ago

Commit fd268301 parent 8819ba32 files · +41 −98Browse files

Unified · Split

2 files
  1. arch/x86/platform/efi/efi.c +14 −73
  2. include/linux/efi.h +27 −25
arch/x86/platform/efi/efi.c+14−73
@@ -54,8 +54,6 @@ · 53 unmodified lines
54#include <asm/x86_init.h>54#include <asm/x86_init.h>
55#include <asm/uv/uv.h>55#include <asm/uv/uv.h>
56 56
57static efi_system_table_t efi_systab __initdata;
58
59static unsigned long efi_systab_phys __initdata;57static unsigned long efi_systab_phys __initdata;
60static unsigned long prop_phys = EFI_INVALID_TABLE_ADDR;58static unsigned long prop_phys = EFI_INVALID_TABLE_ADDR;
61static unsigned long uga_phys = EFI_INVALID_TABLE_ADDR;59static unsigned long uga_phys = EFI_INVALID_TABLE_ADDR;
@@ -359,28 +357,8 @@ static int __init efi_systab_init(unsigned long phys) · 297 unmodified lines
359 if (efi_enabled(EFI_64BIT)) {357 if (efi_enabled(EFI_64BIT)) {
360 const efi_system_table_64_t *systab64 = p;358 const efi_system_table_64_t *systab64 = p;
361 359
362 efi_systab.hdr = systab64->hdr;360 efi_runtime = systab64->runtime;
363 efi_systab.fw_vendor = systab64->fw_vendor;361 over4g = systab64->runtime > U32_MAX;
364 efi_systab.fw_revision = systab64->fw_revision;
365 efi_systab.con_in_handle = systab64->con_in_handle;
366 efi_systab.con_in = systab64->con_in;
367 efi_systab.con_out_handle = systab64->con_out_handle;
368 efi_systab.con_out = (void *)(unsigned long)systab64->con_out;
369 efi_systab.stderr_handle = systab64->stderr_handle;
370 efi_systab.stderr = systab64->stderr;
371 efi_systab.runtime = (void *)(unsigned long)systab64->runtime;
372 efi_systab.boottime = (void *)(unsigned long)systab64->boottime;
373 efi_systab.nr_tables = systab64->nr_tables;
374 efi_systab.tables = systab64->tables;
375
376 over4g = systab64->con_in_handle > U32_MAX ||
377 systab64->con_in > U32_MAX ||
378 systab64->con_out_handle > U32_MAX ||
379 systab64->con_out > U32_MAX ||
380 systab64->stderr_handle > U32_MAX ||
381 systab64->stderr > U32_MAX ||
382 systab64->runtime > U32_MAX ||
383 systab64->boottime > U32_MAX;
384 362
385 if (efi_setup) {363 if (efi_setup) {
386 struct efi_setup_data *data;364 struct efi_setup_data *data;
@@ -391,38 +369,33 @@ static int __init efi_systab_init(unsigned long phys) · 4 unmodified lines
391 return -ENOMEM;369 return -ENOMEM;
392 }370 }
393 371
394 efi_systab.fw_vendor = (unsigned long)data->fw_vendor;372 efi_fw_vendor = (unsigned long)data->fw_vendor;
395 efi_systab.tables = (unsigned long)data->tables;373 efi_config_table = (unsigned long)data->tables;
396 374
397 over4g |= data->fw_vendor > U32_MAX ||375 over4g |= data->fw_vendor > U32_MAX ||
398 data->tables > U32_MAX;376 data->tables > U32_MAX;
399 377
400 early_memunmap(data, sizeof(*data));378 early_memunmap(data, sizeof(*data));
401 } else {379 } else {
380 efi_fw_vendor = systab64->fw_vendor;
381 efi_config_table = systab64->tables;
382
402 over4g |= systab64->fw_vendor > U32_MAX ||383 over4g |= systab64->fw_vendor > U32_MAX ||
403 systab64->tables > U32_MAX;384 systab64->tables > U32_MAX;
404 }385 }
386 efi_nr_tables = systab64->nr_tables;
405 } else {387 } else {
406 const efi_system_table_32_t *systab32 = p;388 const efi_system_table_32_t *systab32 = p;
407 389
408 efi_systab.hdr = systab32->hdr;390 efi_fw_vendor = systab32->fw_vendor;
409 efi_systab.fw_vendor = systab32->fw_vendor;391 efi_runtime = systab32->runtime;
410 efi_systab.fw_revision = systab32->fw_revision;392 efi_config_table = systab32->tables;
411 efi_systab.con_in_handle = systab32->con_in_handle;393 efi_nr_tables = systab32->nr_tables;
412 efi_systab.con_in = systab32->con_in;
413 efi_systab.con_out_handle = systab32->con_out_handle;
414 efi_systab.con_out = (void *)(unsigned long)systab32->con_out;
415 efi_systab.stderr_handle = systab32->stderr_handle;
416 efi_systab.stderr = systab32->stderr;
417 efi_systab.runtime = (void *)(unsigned long)systab32->runtime;
418 efi_systab.boottime = (void *)(unsigned long)systab32->boottime;
419 efi_systab.nr_tables = systab32->nr_tables;
420 efi_systab.tables = systab32->tables;
421 }394 }
422 395
423 efi.runtime_version = hdr->revision;396 efi.runtime_version = hdr->revision;
424 397
425 efi_systab_report_header(hdr, efi_systab.fw_vendor);398 efi_systab_report_header(hdr, efi_fw_vendor);
426 early_memunmap(p, size);399 early_memunmap(p, size);
427 400
428 if (IS_ENABLED(CONFIG_X86_32) && over4g) {401 if (IS_ENABLED(CONFIG_X86_32) && over4g) {
@@ -430,7 +403,6 @@ static int __init efi_systab_init(unsigned long phys) · 1 unmodified line
430 return -EINVAL;403 return -EINVAL;
431 }404 }
432 405
433 efi.systab = &efi_systab;
434 return 0;406 return 0;
435}407}
436 408
@@ -478,11 +450,6 @@ void __init efi_init(void) · 41 unmodified lines
478 if (efi_systab_init(efi_systab_phys))450 if (efi_systab_init(efi_systab_phys))
479 return;451 return;
480 452
481 efi_config_table = (unsigned long)efi.systab->tables;
482 efi_nr_tables = efi.systab->nr_tables;
483 efi_fw_vendor = (unsigned long)efi.systab->fw_vendor;
484 efi_runtime = (unsigned long)efi.systab->runtime;
485
486 if (efi_reuse_config(efi_config_table, efi_nr_tables))453 if (efi_reuse_config(efi_config_table, efi_nr_tables))
487 return;454 return;
488 455
@@ -624,20 +591,6 @@ static void __init efi_merge_regions(void) · 135 unmodified lines
624 }591 }
625}592}
626 593
627static void __init get_systab_virt_addr(efi_memory_desc_t *md)
628{
629 unsigned long size;
630 u64 end, systab;
631
632 size = md->num_pages << EFI_PAGE_SHIFT;
633 end = md->phys_addr + size;
634 systab = efi_systab_phys;
635 if (md->phys_addr <= systab && systab < end) {
636 systab += md->virt_addr - md->phys_addr;
637 efi.systab = (efi_system_table_t *)(unsigned long)systab;
638 }
639}
640
641static void *realloc_pages(void *old_memmap, int old_shift)594static void *realloc_pages(void *old_memmap, int old_shift)
642{595{
643 void *ret;596 void *ret;
@@ -793,7 +746,6 @@ static void * __init efi_map_regions(int *count, int *pg_shift) · 149 unmodified lines
793 continue;746 continue;
794 747
795 efi_map_region(md);748 efi_map_region(md);
796 get_systab_virt_addr(md);
797 749
798 if (left < desc_size) {750 if (left < desc_size) {
799 new_memmap = realloc_pages(new_memmap, *pg_shift);751 new_memmap = realloc_pages(new_memmap, *pg_shift);
@@ -819,8 +771,6 @@ static void __init kexec_enter_virtual_mode(void) · 19 unmodified lines
819 efi_memory_desc_t *md;771 efi_memory_desc_t *md;
820 unsigned int num_pages;772 unsigned int num_pages;
821 773
822 efi.systab = NULL;
823
824 /*774 /*
825 * We don't do virtual mode, since we don't do runtime services, on775 * We don't do virtual mode, since we don't do runtime services, on
826 * non-native EFI. With the UV1 memmap, we don't do runtime services in776 * non-native EFI. With the UV1 memmap, we don't do runtime services in
@@ -843,10 +793,8 @@ static void __init kexec_enter_virtual_mode(void) · 16 unmodified lines
843 * Map efi regions which were passed via setup_data. The virt_addr is a793 * Map efi regions which were passed via setup_data. The virt_addr is a
844 * fixed addr which was used in first kernel of a kexec boot.794 * fixed addr which was used in first kernel of a kexec boot.
845 */795 */
846 for_each_efi_memory_desc(md) {796 for_each_efi_memory_desc(md)
847 efi_map_region_fixed(md); /* FIXME: add error handling */797 efi_map_region_fixed(md); /* FIXME: add error handling */
848 get_systab_virt_addr(md);
849 }
850 798
851 /*799 /*
852 * Unregister the early EFI memmap from efi_init() and install800 * Unregister the early EFI memmap from efi_init() and install
@@ -861,8 +809,6 @@ static void __init kexec_enter_virtual_mode(void) · 8 unmodified lines
861 return;809 return;
862 }810 }
863 811
864 BUG_ON(!efi.systab);
865
866 num_pages = ALIGN(efi.memmap.nr_map * efi.memmap.desc_size, PAGE_SIZE);812 num_pages = ALIGN(efi.memmap.nr_map * efi.memmap.desc_size, PAGE_SIZE);
867 num_pages >>= PAGE_SHIFT;813 num_pages >>= PAGE_SHIFT;
868 814
@@ -905,8 +851,6 @@ static void __init __efi_enter_virtual_mode(void) · 36 unmodified lines
905 efi_status_t status;851 efi_status_t status;
906 unsigned long pa;852 unsigned long pa;
907 853
908 efi.systab = NULL;
909
910 if (efi_alloc_page_tables()) {854 if (efi_alloc_page_tables()) {
911 pr_err("Failed to allocate EFI page tables\n");855 pr_err("Failed to allocate EFI page tables\n");
912 goto err;856 goto err;
@@ -938,9 +882,6 @@ static void __init __efi_enter_virtual_mode(void) · 25 unmodified lines
938 efi_print_memmap();882 efi_print_memmap();
939 }883 }
940 884
941 if (WARN_ON(!efi.systab))
942 goto err;
943
944 if (efi_setup_page_tables(pa, 1 << pg_shift))885 if (efi_setup_page_tables(pa, 1 << pg_shift))
945 goto err;886 goto err;
946 887
include/linux/efi.h+27−25
@@ -530,31 +530,33 @@ typedef struct { · 529 unmodified lines
530 */530 */
531extern struct efi {531extern struct efi {
532 const efi_runtime_services_t *runtime; /* EFI runtime services table */532 const efi_runtime_services_t *runtime; /* EFI runtime services table */
533 efi_system_table_t *systab; /* EFI system table */533 unsigned int runtime_version; /* Runtime services version */
534 unsigned int runtime_version; /* Runtime services version */534
535 unsigned long acpi; /* ACPI table (IA64 ext 0.71) */535 unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
536 unsigned long acpi20; /* ACPI table (ACPI 2.0) */536 unsigned long acpi20; /* ACPI table (ACPI 2.0) */
537 unsigned long smbios; /* SMBIOS table (32 bit entry point) */537 unsigned long smbios; /* SMBIOS table (32 bit entry point) */
538 unsigned long smbios3; /* SMBIOS table (64 bit entry point) */538 unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
539 unsigned long esrt; /* ESRT table */539 unsigned long esrt; /* ESRT table */
540 unsigned long tpm_log; /* TPM2 Event Log table */540 unsigned long tpm_log; /* TPM2 Event Log table */
541 unsigned long tpm_final_log; /* TPM2 Final Events Log table */541 unsigned long tpm_final_log; /* TPM2 Final Events Log table */
542 efi_get_time_t *get_time;542
543 efi_set_time_t *set_time;543 efi_get_time_t *get_time;
544 efi_get_wakeup_time_t *get_wakeup_time;544 efi_set_time_t *set_time;
545 efi_set_wakeup_time_t *set_wakeup_time;545 efi_get_wakeup_time_t *get_wakeup_time;
546 efi_get_variable_t *get_variable;546 efi_set_wakeup_time_t *set_wakeup_time;
547 efi_get_next_variable_t *get_next_variable;547 efi_get_variable_t *get_variable;
548 efi_set_variable_t *set_variable;548 efi_get_next_variable_t *get_next_variable;
549 efi_set_variable_t *set_variable_nonblocking;549 efi_set_variable_t *set_variable;
550 efi_query_variable_info_t *query_variable_info;550 efi_set_variable_t *set_variable_nonblocking;
551 efi_query_variable_info_t *query_variable_info_nonblocking;551 efi_query_variable_info_t *query_variable_info;
552 efi_update_capsule_t *update_capsule;552 efi_query_variable_info_t *query_variable_info_nonblocking;
553 efi_query_capsule_caps_t *query_capsule_caps;553 efi_update_capsule_t *update_capsule;
554 efi_get_next_high_mono_count_t *get_next_high_mono_count;554 efi_query_capsule_caps_t *query_capsule_caps;
555 efi_reset_system_t *reset_system;555 efi_get_next_high_mono_count_t *get_next_high_mono_count;
556 struct efi_memory_map memmap;556 efi_reset_system_t *reset_system;
557 unsigned long flags;557
558 struct efi_memory_map memmap;
559 unsigned long flags;
558} efi;560} efi;
559 561
560extern struct mm_struct efi_mm;562extern struct mm_struct efi_mm;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t