EFI fixes for v5.2
The following changes since commit a188339ca5a396acc588e5851ed7e19f66b0ebd9:
Linux 5.2-rc1 (2019-05-19 15:47:09 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git tags/efi-urgent
for you to fetch changes up to a7decd94d514721f8bf5da02e3ae66758b80603a:
efi: Allow the number of EFI configuration tables entries to be zero (2019-05-25 13:10:50 +0200)
----------------------------------------------------------------
A pair of low priority EFI fixes for v5.2:
- deal with systems where EFI does not expose a single configuration table
- add missing handling for memory allocation failures to x86 old_map code
----------------------------------------------------------------
Gen Zhang (1):
efi/x86: Add missing error handling to old_memmap 1:1 mapping code
Rob Bradford (1):
efi: Allow the number of EFI configuration tables entries to be zero
arch/x86/platform/efi/efi.c | 2 ++ arch/x86/platform/efi/efi_64.c | 9 ++++++--- arch/x86/platform/efi/quirks.c | 3 +++ drivers/firmware/efi/efi.c | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-)
PATCH 1/2 efi/x86: Add missing error handling to old_memmap 1:1 mapping code
From: Gen Zhang <[email protected]>
The old_memmap flow in efi_call_phys_prolog() performs numerous memory allocations, and either does not check for failure at all, or it does but fails to propagate it back to the caller, which may end up calling into the firmware with an incomplete 1:1 mapping.
So let's fix this by returning NULL from efi_call_phys_prolog() on memory allocation failures only, and by handling this condition in the caller. Also, clean up any half baked sets of page tables that we may have created before returning with a NULL return value.
Note that any failure at this level will trigger a panic() two levels up, so none of this makes a huge difference, but it is a nice cleanup nonetheless.
--- arch/x86/platform/efi/efi.c | 2 ++ arch/x86/platform/efi/efi_64.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/platform/efi/efi.c +2 -0
@@ -85,6 +85,8 @@ static efi_status_t __init phys_efi_set_virtual_address_map(pgd_t *save_pgd; save_pgd =efi_call_phys_prolog (); +if (!save_pgd) +return EFI_ABORTED ;/* Disable interrupts around EFI calls: */ local_irq_save (flags);
arch/x86/platform/efi/efi_64.c +6 -3
@@ -84,13 +84,15 @@ pgd_t * __init efi_call_phys_prolog(void)if (!efi_enabled (EFI_OLD_MEMMAP )) {efi_switch_mm (&efi_mm); -return NULL ; +return efi_mm.pgd; }early_code_mapping_set_exec (1 ); n_pgds =DIV_ROUND_UP ((max_pfn <<PAGE_SHIFT ),PGDIR_SIZE ); save_pgd =kmalloc_array (n_pgds,sizeof (*save_pgd),GFP_KERNEL ); +if (!save_pgd) +return NULL ;/* * Build 1:1 identity mapping for efi=old_map usage. Note that
@@ -138,10 +140,11 @@ pgd_t * __init efi_call_phys_prolog(void)pgd_offset_k (pgd *PGDIR_SIZE )->pgd &= ~_PAGE_NX; } -out:__flush_tlb_all (); -return save_pgd; +out: +efi_call_phys_epilog (save_pgd); +return NULL ; }void __init efi_call_phys_epilog (pgd_t *save_pgd)
Signature · 1 line
2.20.1
tip-bot for Gen Zhang
merge bot[tip:efi/urgent] efi/x86/Add missing error handling to old_memmap 1:1 mapping code
efi/x86/Add missing error handling to old_memmap 1:1 mapping code
Commit-ID: 4e78921ba4dd0aca1cc89168f45039add4183f8e Gitweb: https://git.kernel.org/tip/4e78921ba4dd0aca1cc89168f45039add4183f8e Author: Gen Zhang <[email protected]> AuthorDate: Sat, 25 May 2019 13:25:58 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 25 May 2019 13:48:17 +0200
efi/x86/Add missing error handling to old_memmap 1:1 mapping code
The old_memmap flow in efi_call_phys_prolog() performs numerous memory allocations, and either does not check for failure at all, or it does but fails to propagate it back to the caller, which may end up calling into the firmware with an incomplete 1:1 mapping.
So let's fix this by returning NULL from efi_call_phys_prolog() on memory allocation failures only, and by handling this condition in the caller. Also, clean up any half baked sets of page tables that we may have created before returning with a NULL return value.
Note that any failure at this level will trigger a panic() two levels up, so none of this makes a huge difference, but it is a nice cleanup nonetheless.
[ardb: update commit log, add efi_call_phys_epilog() call on error path]
--- arch/x86/platform/efi/efi.c | 2 ++ arch/x86/platform/efi/efi_64.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/platform/efi/efi.c +2 -0
@@ -85,6 +85,8 @@ static efi_status_t __init phys_efi_set_virtual_address_map(pgd_t *save_pgd; save_pgd =efi_call_phys_prolog (); +if (!save_pgd) +return EFI_ABORTED ;/* Disable interrupts around EFI calls: */ local_irq_save (flags);
arch/x86/platform/efi/efi_64.c +6 -3
@@ -84,13 +84,15 @@ pgd_t * __init efi_call_phys_prolog(void)if (!efi_enabled (EFI_OLD_MEMMAP )) {efi_switch_mm (&efi_mm); -return NULL ; +return efi_mm.pgd; }early_code_mapping_set_exec (1 ); n_pgds =DIV_ROUND_UP ((max_pfn <<PAGE_SHIFT ),PGDIR_SIZE ); save_pgd =kmalloc_array (n_pgds,sizeof (*save_pgd),GFP_KERNEL ); +if (!save_pgd) +return NULL ;/* * Build 1:1 identity mapping for efi=old_map usage. Note that
@@ -138,10 +140,11 @@ pgd_t * __init efi_call_phys_prolog(void)pgd_offset_k (pgd *PGDIR_SIZE )->pgd &= ~_PAGE_NX; } -out:__flush_tlb_all (); -return save_pgd; +out: +efi_call_phys_epilog (save_pgd); +return NULL ; }void __init efi_call_phys_epilog (pgd_t *save_pgd)
PATCH 2/2 efi: Allow the number of EFI configuration tables entries to be zero
In reply to Ard BiesheuvelFrom: Rob Bradford <[email protected]>
Only try and access the EFI configuration tables if there there are any reported. This allows EFI to be continued to used on systems where there are no configuration table entries.
--- arch/x86/platform/efi/quirks.c | 3 +++ drivers/firmware/efi/efi.c | 3 +++ 2 files changed, 6 insertions(+)
arch/x86/platform/efi/quirks.c +3 -0
@@ -512,6 +512,9 @@ int __init efi_reuse_config(u64 tables, int nr_tables)void *p, *tablep;struct efi_setup_data *data; +if (nr_tables ==0 ) +return 0 ; +if (!efi_setup)return 0 ;
drivers/firmware/efi/efi.c +3 -0
@@ -636,6 +636,9 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)void *config_tables;int sz, ret; +if (efi.systab->nr_tables ==0 ) +return 0 ; +if (efi_enabled (EFI_64BIT )) sz =sizeof (efi_config_table_64_t);else
Signature · 1 line
2.20.1
tip-bot for Rob Bradford
merge bot[tip:efi/urgent] efi: Allow the number of EFI configuration tables entries to be zero
efi: Allow the number of EFI configuration tables entries to be zero
Commit-ID: 88447c5b93d98be847f428c39ba589779a59eb83 Gitweb: https://git.kernel.org/tip/88447c5b93d98be847f428c39ba589779a59eb83 Author: Rob Bradford <[email protected]> AuthorDate: Sat, 25 May 2019 13:25:59 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 25 May 2019 13:48:17 +0200
efi: Allow the number of EFI configuration tables entries to be zero
Only try and access the EFI configuration tables if there there are any reported. This allows EFI to be continued to used on systems where there are no configuration table entries.
--- arch/x86/platform/efi/quirks.c | 3 +++ drivers/firmware/efi/efi.c | 3 +++ 2 files changed, 6 insertions(+)
arch/x86/platform/efi/quirks.c +3 -0
@@ -513,6 +513,9 @@ int __init efi_reuse_config(u64 tables, int nr_tables)void *p, *tablep;struct efi_setup_data *data; +if (nr_tables ==0 ) +return 0 ; +if (!efi_setup)return 0 ;
drivers/firmware/efi/efi.c +3 -0
@@ -636,6 +636,9 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)void *config_tables;int sz, ret; +if (efi.systab->nr_tables ==0 ) +return 0 ; +if (efi_enabled (EFI_64BIT )) sz =sizeof (efi_config_table_64_t);else