Re: [PATCH v2 4/8] x86, efi: Reserve UEFI 2.8 Specific Purpose Memory for dax
On Sat, Jun 8, 2019 at 12:20 AM Ard Biesheuvel wrote: > > On Fri, 7 Jun 2019 at 19:34, Dan Williams wrote: > > > > On Fri, Jun 7, 2019 at 8:23 AM Dan Williams > > wrote: > > > > > > On Fri, Jun 7, 2019 at 5:29 AM Ard Biesheuvel > > > wrote: > > [..] > > > > > #ifdef CONFIG_EFI_APPLICATION_RESERVED > > > > > static inline bool is_efi_application_reserved(efi_memory_desc_t *md) > > > > > { > > > > > return md->type == EFI_CONVENTIONAL_MEMORY > > > > > && (md->attribute & EFI_MEMORY_SP); > > > > > } > > > > > #else > > > > > static inline bool is_efi_application_reserved(efi_memory_desc_t *md) > > > > > { > > > > > return false; > > > > > } > > > > > #endif > > > > > > > > I think this policy decision should not live inside the EFI subsystem. > > > > EFI just gives you the memory map, and mangling that information > > > > depending on whether you think a certain memory attribute should be > > > > ignored is the job of the MM subsystem. > > > > > > The problem is that we don't have an mm subsystem at the time a > > > decision needs to be made. The reservation policy needs to be deployed > > > before even memblock has been initialized in order to keep kernel > > > allocations out of the reservation. I agree with the sentiment I just > > > don't see how to practically achieve an optional "System RAM" vs > > > "Application Reserved" routing decision without an early (before > > > e820__memblock_setup()) conditional branch. > > > > I can at least move it out of include/linux/efi.h and move it to > > arch/x86/include/asm/efi.h since it is an x86 specific policy decision > > / implementation for now. > > No, that doesn't make sense to me. If it must live in the EFI > subsystem, I'd prefer it to be in the core code, not in x86 specific > code, since there is nothing x86 specific about it. Ok, but it's still not clear to me where you would accept an early detection of EFI_CONVENTIONAL_MEMORY + EFI_MEMORY_SP and route it away from the "System RAM" default. Please just recommend a place to land a conditional branch that translates between the base EFI type + attribute and E820_RAM and E820_APPLICATION_RESERVED. > Perhaps a efi=xxx command line option would be in order to influence > the builtin default, but it can be a followup patch independent of > this series. Sure, but I expect the default polarity of the branch is a compile time option with an efi= override.
[PATCH AUTOSEL 5.1 25/70] efi/x86/Add missing error handling to old_memmap 1:1 mapping code
From: Gen Zhang [ Upstream commit 4e78921ba4dd0aca1cc89168f45039add4183f8e ] 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] Signed-off-by: Gen Zhang Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rob Bradford Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20190525112559.7917-2-ard.biesheu...@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/platform/efi/efi.c| 2 ++ arch/x86/platform/efi/efi_64.c | 9 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index e1cb01a22fa8..a7189a3b4d70 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -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); diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index cf0347f61b21..08ce8177c3af 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -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) -- 2.20.1
[PATCH AUTOSEL 4.19 17/49] efi/x86/Add missing error handling to old_memmap 1:1 mapping code
From: Gen Zhang [ Upstream commit 4e78921ba4dd0aca1cc89168f45039add4183f8e ] 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] Signed-off-by: Gen Zhang Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rob Bradford Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20190525112559.7917-2-ard.biesheu...@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/platform/efi/efi.c| 2 ++ arch/x86/platform/efi/efi_64.c | 9 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 9061babfbc83..353019d4e6c9 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -86,6 +86,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); diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index ee5d08f25ce4..dfc809b31c7c 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -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) -- 2.20.1
Re: [PATCH v2 4/8] x86, efi: Reserve UEFI 2.8 Specific Purpose Memory for dax
On Fri, 7 Jun 2019 at 19:34, Dan Williams wrote: > > On Fri, Jun 7, 2019 at 8:23 AM Dan Williams wrote: > > > > On Fri, Jun 7, 2019 at 5:29 AM Ard Biesheuvel > > wrote: > [..] > > > > #ifdef CONFIG_EFI_APPLICATION_RESERVED > > > > static inline bool is_efi_application_reserved(efi_memory_desc_t *md) > > > > { > > > > return md->type == EFI_CONVENTIONAL_MEMORY > > > > && (md->attribute & EFI_MEMORY_SP); > > > > } > > > > #else > > > > static inline bool is_efi_application_reserved(efi_memory_desc_t *md) > > > > { > > > > return false; > > > > } > > > > #endif > > > > > > I think this policy decision should not live inside the EFI subsystem. > > > EFI just gives you the memory map, and mangling that information > > > depending on whether you think a certain memory attribute should be > > > ignored is the job of the MM subsystem. > > > > The problem is that we don't have an mm subsystem at the time a > > decision needs to be made. The reservation policy needs to be deployed > > before even memblock has been initialized in order to keep kernel > > allocations out of the reservation. I agree with the sentiment I just > > don't see how to practically achieve an optional "System RAM" vs > > "Application Reserved" routing decision without an early (before > > e820__memblock_setup()) conditional branch. > > I can at least move it out of include/linux/efi.h and move it to > arch/x86/include/asm/efi.h since it is an x86 specific policy decision > / implementation for now. No, that doesn't make sense to me. If it must live in the EFI subsystem, I'd prefer it to be in the core code, not in x86 specific code, since there is nothing x86 specific about it. Perhaps a efi=xxx command line option would be in order to influence the builtin default, but it can be a followup patch independent of this series.