Skip to content

Commit e2d68a9

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/x86: Don't panic or BUG() on non-critical error conditions
The logic in __efi_enter_virtual_mode() does a number of steps in sequence, all of which may fail in one way or the other. In most cases, we simply print an error and disable EFI runtime services support, but in some cases, we BUG() or panic() and bring down the system when encountering conditions that we could easily handle in the same way. While at it, replace a pointless page-to-virt-phys conversion with one that goes straight from struct page to physical. 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 5b279a2 commit e2d68a9

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

arch/x86/platform/efi/efi.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,14 @@ static void __init __efi_enter_virtual_mode(void)
889889

890890
if (efi_alloc_page_tables()) {
891891
pr_err("Failed to allocate EFI page tables\n");
892-
clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
893-
return;
892+
goto err;
894893
}
895894

896895
efi_merge_regions();
897896
new_memmap = efi_map_regions(&count, &pg_shift);
898897
if (!new_memmap) {
899898
pr_err("Error reallocating memory, EFI runtime non-functional!\n");
900-
clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
901-
return;
899+
goto err;
902900
}
903901

904902
pa = __pa(new_memmap);
@@ -912,21 +910,19 @@ static void __init __efi_enter_virtual_mode(void)
912910

913911
if (efi_memmap_init_late(pa, efi.memmap.desc_size * count)) {
914912
pr_err("Failed to remap late EFI memory map\n");
915-
clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
916-
return;
913+
goto err;
917914
}
918915

919916
if (efi_enabled(EFI_DBG)) {
920917
pr_info("EFI runtime memory map:\n");
921918
efi_print_memmap();
922919
}
923920

924-
BUG_ON(!efi.systab);
921+
if (WARN_ON(!efi.systab))
922+
goto err;
925923

926-
if (efi_setup_page_tables(pa, 1 << pg_shift)) {
927-
clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
928-
return;
929-
}
924+
if (efi_setup_page_tables(pa, 1 << pg_shift))
925+
goto err;
930926

931927
efi_sync_low_kernel_mappings();
932928

@@ -935,9 +931,9 @@ static void __init __efi_enter_virtual_mode(void)
935931
efi.memmap.desc_version,
936932
(efi_memory_desc_t *)pa);
937933
if (status != EFI_SUCCESS) {
938-
pr_alert("Unable to switch EFI into virtual mode (status=%lx)!\n",
939-
status);
940-
panic("EFI call to SetVirtualAddressMap() failed!");
934+
pr_err("Unable to switch EFI into virtual mode (status=%lx)!\n",
935+
status);
936+
goto err;
941937
}
942938

943939
efi_free_boot_services();
@@ -964,6 +960,10 @@ static void __init __efi_enter_virtual_mode(void)
964960

965961
/* clean DUMMY object */
966962
efi_delete_dummy_variable();
963+
return;
964+
965+
err:
966+
clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
967967
}
968968

969969
void __init efi_enter_virtual_mode(void)

arch/x86/platform/efi/efi_64.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,12 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
384384
return 0;
385385

386386
page = alloc_page(GFP_KERNEL|__GFP_DMA32);
387-
if (!page)
388-
panic("Unable to allocate EFI runtime stack < 4GB\n");
387+
if (!page) {
388+
pr_err("Unable to allocate EFI runtime stack < 4GB\n");
389+
return 1;
390+
}
389391

390-
efi_scratch.phys_stack = virt_to_phys(page_address(page));
391-
efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */
392+
efi_scratch.phys_stack = page_to_phys(page + 1); /* stack grows down */
392393

393394
npages = (_etext - _text) >> PAGE_SHIFT;
394395
text = __pa(_text);

0 commit comments

Comments
 (0)