From patchwork Tue Apr 4 16:02:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96739 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp263267qgd; Tue, 4 Apr 2017 09:03:34 -0700 (PDT) X-Received: by 10.98.76.140 with SMTP id e12mr23504103pfj.82.1491321814703; Tue, 04 Apr 2017 09:03:34 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si7404096pge.59.2017.04.04.09.03.34; Tue, 04 Apr 2017 09:03:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754868AbdDDQDR (ORCPT + 25 others); Tue, 4 Apr 2017 12:03:17 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:37217 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754800AbdDDQDN (ORCPT ); Tue, 4 Apr 2017 12:03:13 -0400 Received: by mail-wm0-f54.google.com with SMTP id x124so32343197wmf.0 for ; Tue, 04 Apr 2017 09:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U+WcXNNxOdeqTQzwVPkjnWf2u5+ZA2LVDyTUb4kg0H0=; b=BdyYFI2uYpmc5atnR3ADJ6vsL3kpqNCrlX81P/f0IA4QvZQSqomvaYrPpuXogCC+kh dk9q3fuhfrm1Pskpd0rGL36kiZQ0UTX1oIZspos2o/WkvCzI9OD85voNSZQ7i5P4NM+G +f/fErblg+MVwCjddJpNuWW6JwbVTRKCZ1eU8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=U+WcXNNxOdeqTQzwVPkjnWf2u5+ZA2LVDyTUb4kg0H0=; b=KBj0nEDdV9z2HUf2CL7ElD87wn7J3+TfqdnM8lyO0ndQW1Jkw4uRxysUCAt79MtPUl l70biaQvliV8SCiwgB+v7ygI1VeatqUl43gijzcZGP1QU1GLPCFLl++A8HnO49Gc9qUl ldsmFw/RrAW3YwU5jLRRKOmdUxNGeMmetnrY+7n4/f4qr9nnI3rB9SRzReoXPfirfL6d HYderdxWFj8XreaybGVxYNgEQIBah0BcjTJKUKy0/+QfRd2/1wB6sdMGSM7yuE0br6Qh pJ1FdfP0wxK4LlHdt138Zt+zdCVI2VBUR5VawjK/FUX8izVVam1p7wsX20QaJP5+wzU7 h2nQ== X-Gm-Message-State: AFeK/H3kg+tfvrJx8XkRWqJNYk1sATvWbIxq8zVUAZ0JolPenmKl98bu2kf9ZmisgZn12qv7 X-Received: by 10.28.157.150 with SMTP id g144mr15612454wme.89.1491321791652; Tue, 04 Apr 2017 09:03:11 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id z88sm19686465wrb.1.2017.04.04.09.03.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:03:10 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Andy Lutomirski , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 01/12] x86/efi: Clean up efi CR3 save/restore Date: Tue, 4 Apr 2017 17:02:36 +0100 Message-Id: <20170404160245.27812-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404160245.27812-1-ard.biesheuvel@linaro.org> References: <20170404160245.27812-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski efi_call_phys_prolog() used to return a "pgd_t *" that meant one of three different things depending on kernel and system configuration. Clean it up so it uses a union and is more explicit about what's going on. Signed-off-by: Andy Lutomirski Cc: Ard Biesheuvel Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Ingo Molnar Signed-off-by: Matt Fleming Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 17 +++++++++++++++-- arch/x86/platform/efi/efi.c | 6 +++--- arch/x86/platform/efi/efi_32.c | 12 ++++++------ arch/x86/platform/efi/efi_64.c | 22 ++++++++++++---------- 4 files changed, 36 insertions(+), 21 deletions(-) -- 2.9.3 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 2f77bcefe6b4..6d74cc3802e6 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -111,11 +111,24 @@ extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size, #endif /* CONFIG_X86_32 */ +union efi_saved_pgd { + /* + * If !EFI_OLD_MEMMAP or we're 32-bit, this is a verbatim saved CR3 + * value. + */ + unsigned long cr3; + +#ifdef CONFIG_X86_64 + /* If EFI_OLD_MEMMAP, this is a kmalloced copy of the pgd. */ + pgd_t *pgd; +#endif +}; + extern struct efi_scratch efi_scratch; extern void __init efi_set_executable(efi_memory_desc_t *md, bool executable); extern int __init efi_memblock_x86_reserve_range(void); -extern pgd_t * __init efi_call_phys_prolog(void); -extern void __init efi_call_phys_epilog(pgd_t *save_pgd); +extern union efi_saved_pgd __init efi_call_phys_prolog(void); +extern void __init efi_call_phys_epilog(union efi_saved_pgd saved_pgd); extern void __init efi_print_memmap(void); extern void __init efi_memory_uc(u64 addr, unsigned long size); extern void __init efi_map_region(efi_memory_desc_t *md); diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 565dff3c9a12..217dc166c649 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -81,9 +81,9 @@ static efi_status_t __init phys_efi_set_virtual_address_map( { efi_status_t status; unsigned long flags; - pgd_t *save_pgd; + union efi_saved_pgd saved_pgd; - save_pgd = efi_call_phys_prolog(); + saved_pgd = efi_call_phys_prolog(); /* Disable interrupts around EFI calls: */ local_irq_save(flags); @@ -92,7 +92,7 @@ static efi_status_t __init phys_efi_set_virtual_address_map( descriptor_version, virtual_map); local_irq_restore(flags); - efi_call_phys_epilog(save_pgd); + efi_call_phys_epilog(saved_pgd); return status; } diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c index cef39b097649..9b1abcf6e7bb 100644 --- a/arch/x86/platform/efi/efi_32.c +++ b/arch/x86/platform/efi/efi_32.c @@ -58,13 +58,13 @@ void __init efi_map_region(efi_memory_desc_t *md) void __init efi_map_region_fixed(efi_memory_desc_t *md) {} void __init parse_efi_setup(u64 phys_addr, u32 data_len) {} -pgd_t * __init efi_call_phys_prolog(void) +union efi_saved_pgd __init efi_call_phys_prolog(void) { struct desc_ptr gdt_descr; - pgd_t *save_pgd; + union efi_saved_pgd saved_pgd; /* Current pgd is swapper_pg_dir, we'll restore it later: */ - save_pgd = swapper_pg_dir; + saved_pgd.cr3 = __pa(swapper_pg_dir); load_cr3(initial_page_table); __flush_tlb_all(); @@ -72,10 +72,10 @@ pgd_t * __init efi_call_phys_prolog(void) gdt_descr.size = GDT_SIZE - 1; load_gdt(&gdt_descr); - return save_pgd; + return saved_pgd; } -void __init efi_call_phys_epilog(pgd_t *save_pgd) +void __init efi_call_phys_epilog(union efi_saved_pgd saved_pgd) { struct desc_ptr gdt_descr; @@ -83,7 +83,7 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd) gdt_descr.size = GDT_SIZE - 1; load_gdt(&gdt_descr); - load_cr3(save_pgd); + write_cr3(saved_pgd.cr3); __flush_tlb_all(); } diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index a4695da42d77..d56dd864fb1c 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -69,16 +69,16 @@ static void __init early_code_mapping_set_exec(int executable) } } -pgd_t * __init efi_call_phys_prolog(void) +union efi_saved_pgd __init efi_call_phys_prolog(void) { unsigned long vaddress; - pgd_t *save_pgd; + union efi_saved_pgd saved_pgd; int pgd; int n_pgds; if (!efi_enabled(EFI_OLD_MEMMAP)) { - save_pgd = (pgd_t *)read_cr3(); + saved_pgd.cr3 = read_cr3(); write_cr3((unsigned long)efi_scratch.efi_pgt); goto out; } @@ -86,20 +86,21 @@ pgd_t * __init efi_call_phys_prolog(void) 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); + saved_pgd.pgd = kmalloc_array(n_pgds, sizeof(*saved_pgd.pgd), + GFP_KERNEL); for (pgd = 0; pgd < n_pgds; pgd++) { - save_pgd[pgd] = *pgd_offset_k(pgd * PGDIR_SIZE); + saved_pgd.pgd[pgd] = *pgd_offset_k(pgd * PGDIR_SIZE); vaddress = (unsigned long)__va(pgd * PGDIR_SIZE); set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress)); } out: __flush_tlb_all(); - return save_pgd; + return saved_pgd; } -void __init efi_call_phys_epilog(pgd_t *save_pgd) +void __init efi_call_phys_epilog(union efi_saved_pgd saved_pgd) { /* * After the lock is released, the original page table is restored. @@ -108,7 +109,7 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd) int nr_pgds; if (!efi_enabled(EFI_OLD_MEMMAP)) { - write_cr3((unsigned long)save_pgd); + write_cr3(saved_pgd.cr3); __flush_tlb_all(); return; } @@ -116,9 +117,10 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd) nr_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE); for (pgd_idx = 0; pgd_idx < nr_pgds; pgd_idx++) - set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), save_pgd[pgd_idx]); + set_pgd(pgd_offset_k(pgd_idx * PGDIR_SIZE), + saved_pgd.pgd[pgd_idx]); - kfree(save_pgd); + kfree(saved_pgd.pgd); __flush_tlb_all(); early_code_mapping_set_exec(0); From patchwork Tue Apr 4 16:02:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96741 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp263287qgd; Tue, 4 Apr 2017 09:03:36 -0700 (PDT) X-Received: by 10.99.147.16 with SMTP id b16mr24981804pge.126.1491321816479; Tue, 04 Apr 2017 09:03:36 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si7404096pge.59.2017.04.04.09.03.36; Tue, 04 Apr 2017 09:03:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932140AbdDDQD3 (ORCPT + 25 others); Tue, 4 Apr 2017 12:03:29 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36097 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932092AbdDDQDZ (ORCPT ); Tue, 4 Apr 2017 12:03:25 -0400 Received: by mail-wm0-f41.google.com with SMTP id o81so29493173wmb.1 for ; Tue, 04 Apr 2017 09:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HdQqJl8Qda/2hBvEmVzQTsn5K/1JnqrEU3fXfndOhIo=; b=cXPoROjW+4jEPDOw6deIk+2eHYbHUo/Id3ckUe6a1yKYjv/LdUOInaK/tdG//y+V5b dFOq+2ZE0gDW8EUCjPM/beKhcA2ukow3e62u3c8o43L6D9SOF7VYKSpRVidftPTD2ZC2 CfFZeMepCN3MWRPhn3lQCxv7R0m9J17gqVi8M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HdQqJl8Qda/2hBvEmVzQTsn5K/1JnqrEU3fXfndOhIo=; b=I9mX05ht8Fxro7tt6YTDNEki3pbduNeR8T2IJSVTFkUtltf7ejd/5fo0rDYKkvVw6h KuKlDdESkc+fRFzc45afKg1ftpWZoe3FS0I8MKIYdVe8nQeaRSFsGbMlSuuM98mz0C4s CHFlz1LfVa7/DCdxg7Eu+d+abJj6MJur6BQspP/VVM76y4XxlGa+9dVv91MZ52T2K+Wp 6WeeUZJf3Qgn80pcsUsBVxnGyQaY8MuAOYkmwZfF+qb2F3uCWQn9kWV9g1ufxuOd6SDA 5NYkrBTkXAjaJ68rKVAS6MKSsI9XnuAFflexlkFdU/99VNNEMrmKef4c1Q5lquv93tUl 6qVQ== X-Gm-Message-State: AFeK/H2jYmijiE82m34EtHbmKteHwpKp6eeT5LnaAIi7tJi1HpTDeuHv +UpL4MVV5GjSyxFW X-Received: by 10.28.87.138 with SMTP id l132mr15310112wmb.95.1491321798432; Tue, 04 Apr 2017 09:03:18 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id z88sm19686465wrb.1.2017.04.04.09.03.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:03:17 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 03/12] efi: arm-stub: Round up FDT allocation to mapping size Date: Tue, 4 Apr 2017 17:02:39 +0100 Message-Id: <20170404160245.27812-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404160245.27812-1-ard.biesheuvel@linaro.org> References: <20170404160245.27812-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The FDT is mapped via a fixmap entry that is at least 2 MB in size and 2 MB aligned on 4 KB page size kernels. On UEFI systems, the FDT allocation may share this 2 MB mapping with a reserved region (or another memory region that we should never map), unless we account for this in the size of the allocation (the alignment is already 2 MB) So instead of taking guesses at the needed space, simply allocate 2 MB immediately. The allocation will be recorded as EFI_LOADER_DATA, and the kernel only memblock_reserve()'s the actual size of the FDT, so the unused space will be released back to the kernel. Cc: Matt Fleming Tested-by: Richard Ruigrok Reviewed-By: Jeffrey Hugo Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/efi.h | 1 + drivers/firmware/efi/libstub/fdt.c | 57 ++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 33 deletions(-) -- 2.9.3 diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index 083a52d3b59f..8f3043aba873 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -1,6 +1,7 @@ #ifndef _ASM_EFI_H #define _ASM_EFI_H +#include #include #include #include diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index 260c4b4b492e..41f457be64e8 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -206,6 +206,10 @@ static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg, return update_fdt_memmap(p->new_fdt_addr, map); } +#ifndef MAX_FDT_SIZE +#define MAX_FDT_SIZE SZ_2M +#endif + /* * Allocate memory for a new FDT, then add EFI, commandline, and * initrd related fields to the FDT. This routine increases the @@ -233,7 +237,6 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, u32 desc_ver; unsigned long mmap_key; efi_memory_desc_t *memory_map, *runtime_map; - unsigned long new_fdt_size; efi_status_t status; int runtime_entry_count = 0; struct efi_boot_memmap map; @@ -262,41 +265,29 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, "Exiting boot services and installing virtual address map...\n"); map.map = &memory_map; + status = efi_high_alloc(sys_table, MAX_FDT_SIZE, EFI_FDT_ALIGN, + new_fdt_addr, max_addr); + if (status != EFI_SUCCESS) { + pr_efi_err(sys_table, + "Unable to allocate memory for new device tree.\n"); + goto fail; + } + /* - * Estimate size of new FDT, and allocate memory for it. We - * will allocate a bigger buffer if this ends up being too - * small, so a rough guess is OK here. + * Now that we have done our final memory allocation (and free) + * we can get the memory map key needed for exit_boot_services(). */ - new_fdt_size = fdt_size + EFI_PAGE_SIZE; - while (1) { - status = efi_high_alloc(sys_table, new_fdt_size, EFI_FDT_ALIGN, - new_fdt_addr, max_addr); - if (status != EFI_SUCCESS) { - pr_efi_err(sys_table, "Unable to allocate memory for new device tree.\n"); - goto fail; - } - - status = update_fdt(sys_table, - (void *)fdt_addr, fdt_size, - (void *)*new_fdt_addr, new_fdt_size, - cmdline_ptr, initrd_addr, initrd_size); + status = efi_get_memory_map(sys_table, &map); + if (status != EFI_SUCCESS) + goto fail_free_new_fdt; - /* Succeeding the first time is the expected case. */ - if (status == EFI_SUCCESS) - break; + status = update_fdt(sys_table, (void *)fdt_addr, fdt_size, + (void *)*new_fdt_addr, MAX_FDT_SIZE, cmdline_ptr, + initrd_addr, initrd_size); - if (status == EFI_BUFFER_TOO_SMALL) { - /* - * We need to allocate more space for the new - * device tree, so free existing buffer that is - * too small. - */ - efi_free(sys_table, new_fdt_size, *new_fdt_addr); - new_fdt_size += EFI_PAGE_SIZE; - } else { - pr_efi_err(sys_table, "Unable to construct new device tree.\n"); - goto fail_free_new_fdt; - } + if (status != EFI_SUCCESS) { + pr_efi_err(sys_table, "Unable to construct new device tree.\n"); + goto fail_free_new_fdt; } priv.runtime_map = runtime_map; @@ -340,7 +331,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, pr_efi_err(sys_table, "Exit boot services failed.\n"); fail_free_new_fdt: - efi_free(sys_table, new_fdt_size, *new_fdt_addr); + efi_free(sys_table, MAX_FDT_SIZE, *new_fdt_addr); fail: sys_table->boottime->free_pool(runtime_map); From patchwork Tue Apr 4 16:02:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96742 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp263293qgd; Tue, 4 Apr 2017 09:03:36 -0700 (PDT) X-Received: by 10.84.232.67 with SMTP id f3mr30038854pln.42.1491321816839; Tue, 04 Apr 2017 09:03:36 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si7404096pge.59.2017.04.04.09.03.36; Tue, 04 Apr 2017 09:03:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932159AbdDDQDb (ORCPT + 25 others); Tue, 4 Apr 2017 12:03:31 -0400 Received: from mail-wr0-f177.google.com ([209.85.128.177]:36065 "EHLO mail-wr0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932122AbdDDQD3 (ORCPT ); Tue, 4 Apr 2017 12:03:29 -0400 Received: by mail-wr0-f177.google.com with SMTP id w11so216821249wrc.3 for ; Tue, 04 Apr 2017 09:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZEt6FzLlWs2T3BrbRahC/eZKd7vTwWpa0y4f2PD9y+4=; b=V0mmzeZCxIqnSu2gezC42gLm9vrGc5kIzrmj+me8cECIVUjqRKKq/zOf9C0w05si4w zXqSVoYdubMP9Y+Dv7JByG8Kjz+svrYaiJMuFlOrGzdk21/+1uW1ZANbEFYwnsLNa1/U Y4IKWM/XXfwHcC7KSBmLT3yAJuKLZab59/sTw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZEt6FzLlWs2T3BrbRahC/eZKd7vTwWpa0y4f2PD9y+4=; b=CiuqM92gsGxpur91cqi8CIy3grAM8YIbyUAUtODRof3+6RXsegQcU6eXMTKYF2iwXl 6+adAKwhamgnZNxOHaHmhMs+B41c7q+AvfopspoH/uUl3yZJ0J1EKt166lQLXRhN26do AoZb8FhvPrfhZdxO/6XoDVTNpR1bNzjadafxvfbA0Uq5AH6dKC09moC/Jhx+4lT+Wj6c n4lUTd1un7att+wwHTX06yPk9cP6iCIiYwo0lZDkaHPvZ1vp5ajqGdKK62TE+N/NPkDh uVAA8fYC10vGKkGha37ngzcjp4kPKHtY8dsktey0dIgJo9xldqPhw/3zGPwQVQuuEppq USXw== X-Gm-Message-State: AFeK/H0RT5o0q3f8HKyG+A8z9RBpCUfzctD267vaCrktel2NmUsxzp40rtyrdqUlfOjau3VR X-Received: by 10.223.154.2 with SMTP id z2mr21685454wrb.136.1491321802531; Tue, 04 Apr 2017 09:03:22 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id z88sm19686465wrb.1.2017.04.04.09.03.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:03:21 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Bhupesh Sharma , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 05/12] efi: bgrt: Enable ACPI BGRT handling on arm64 Date: Tue, 4 Apr 2017 17:02:41 +0100 Message-Id: <20170404160245.27812-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404160245.27812-1-ard.biesheuvel@linaro.org> References: <20170404160245.27812-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bhupesh Sharma Now that the ACPI BGRT handling code has been made generic, we can enable it for arm64. Cc: Matt Fleming Signed-off-by: Bhupesh Sharma [ardb: - update commit log to reflect that BGRT is only enabled for arm64 - add missing 'return' statement to dummy acpi_parse_bgrt()] Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/acpi.c | 3 +++ arch/x86/kernel/acpi/boot.c | 6 ------ drivers/acpi/Kconfig | 2 +- drivers/acpi/bgrt.c | 6 ++++++ include/linux/efi-bgrt.h | 5 +++++ 5 files changed, 15 insertions(+), 7 deletions(-) -- 2.9.3 diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index 64d9cbd61678..e25c11e727fe 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -233,6 +234,8 @@ void __init acpi_boot_table_init(void) early_init_dt_scan_chosen_stdout(); } else { parse_spcr(earlycon_init_is_deferred); + if (IS_ENABLED(CONFIG_ACPI_BGRT)) + acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt); } } diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index ae32838cac5f..a9d4fbcd1fd6 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -1559,12 +1559,6 @@ int __init early_acpi_boot_init(void) return 0; } -static int __init acpi_parse_bgrt(struct acpi_table_header *table) -{ - efi_bgrt_init(table); - return 0; -} - int __init acpi_boot_init(void) { /* those are executed after early-quirks are executed */ diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 83e5f7e1a20d..dad02c0f21b9 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -440,7 +440,7 @@ config ACPI_CUSTOM_METHOD config ACPI_BGRT bool "Boottime Graphics Resource Table support" - depends on EFI && X86 + depends on EFI && (X86 || ARM64) help This driver adds support for exposing the ACPI Boottime Graphics Resource Table, which allows the operating system to obtain diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c index ca28aa572aa9..df1c629205e7 100644 --- a/drivers/acpi/bgrt.c +++ b/drivers/acpi/bgrt.c @@ -81,6 +81,12 @@ static struct attribute_group bgrt_attribute_group = { .bin_attrs = bgrt_bin_attributes, }; +int __init acpi_parse_bgrt(struct acpi_table_header *table) +{ + efi_bgrt_init(table); + return 0; +} + static int __init bgrt_init(void) { int ret; diff --git a/include/linux/efi-bgrt.h b/include/linux/efi-bgrt.h index 2fd3993c370b..e6f624b53c3d 100644 --- a/include/linux/efi-bgrt.h +++ b/include/linux/efi-bgrt.h @@ -6,6 +6,7 @@ #ifdef CONFIG_ACPI_BGRT void efi_bgrt_init(struct acpi_table_header *table); +int __init acpi_parse_bgrt(struct acpi_table_header *table); /* The BGRT data itself; only valid if bgrt_image != NULL. */ extern size_t bgrt_image_size; @@ -14,6 +15,10 @@ extern struct acpi_table_bgrt bgrt_tab; #else /* !CONFIG_ACPI_BGRT */ static inline void efi_bgrt_init(struct acpi_table_header *table) {} +static inline int __init acpi_parse_bgrt(struct acpi_table_header *table) +{ + return 0; +} #endif /* !CONFIG_ACPI_BGRT */ From patchwork Tue Apr 4 16:02:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96746 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp264018qgd; Tue, 4 Apr 2017 09:04:58 -0700 (PDT) X-Received: by 10.84.174.129 with SMTP id r1mr29938003plb.173.1491321898450; Tue, 04 Apr 2017 09:04:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17si17845387pgh.300.2017.04.04.09.04.58; Tue, 04 Apr 2017 09:04:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932242AbdDDQEy (ORCPT + 25 others); Tue, 4 Apr 2017 12:04:54 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:36154 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932095AbdDDQD0 (ORCPT ); Tue, 4 Apr 2017 12:03:26 -0400 Received: by mail-wm0-f46.google.com with SMTP id o81so29495685wmb.1 for ; Tue, 04 Apr 2017 09:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RsGdcf/l9Pz6L6KlhRyDpWk7ys5icg29+hWgOhwAziM=; b=IvmWgqDVNWpgewudHP0JJJtkj/MU05m/BB4C0vcikjPmENe8ag1dFZjJtiIbX/4fQr 6fv1Q072zWUg0H6iysXZLVhNjBhj0AxPtsul3hmQh8PMWBl5Oa4yUHSqhUTfWv3EhHg4 u8DTNEfNgTrp8TZ1Xm56VM2/0fdQqqK+sfXRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RsGdcf/l9Pz6L6KlhRyDpWk7ys5icg29+hWgOhwAziM=; b=grOZklWb9NGzgJ/udJBr+9zkDeCxfRrcWztQSBH9I2xWdlfvipr8UCsT7UWaqldN2U gVNTM6SxQf3an3r1qtPLyBU7BtxNbLcc2NyO1aQNh3iIuOb/y5/2LSziYK8SrpJlED9k ZkofM9mNPvna4iepMg+x1Ia+Ak8V2qWd85S1zNqXo17MNnOKkAV1Dy89KadpfM0a5GoZ zxmCutCuu4R+EOwQKnXMbLs7nJsssHGtM59yx5NrYtQhfppP4wAADiwK9NU9eh0+7kEb Eii8WaJ3Gfm7f0JWT0GIrxcxFVJOjKRC7ahMj52r2Q0qJZw2JS3GCtbYZ3NeXD4JbpqY qTLQ== X-Gm-Message-State: AFeK/H2JRQ7FZO/ybeILCxI3AQO6GQBtHC6SWeaT1XyKHITeQOQ1hxZ+In0JqXnxwiJgSq/v X-Received: by 10.28.220.212 with SMTP id t203mr15684195wmg.62.1491321804843; Tue, 04 Apr 2017 09:03:24 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id z88sm19686465wrb.1.2017.04.04.09.03.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:03:24 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Evgeny Kalugin , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 06/12] pstore: return error code (if any) from efi_pstore_write Date: Tue, 4 Apr 2017 17:02:42 +0100 Message-Id: <20170404160245.27812-9-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404160245.27812-1-ard.biesheuvel@linaro.org> References: <20170404160245.27812-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Evgeny Kalugin For some reason return value from actual variable setting was ignored. With this change error code get transferred upwards through call stack. Signed-off-by: Evgeny Kalugin Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi-pstore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.9.3 diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index f402ba2eed46..6b5acefce6b3 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -274,9 +274,9 @@ static int efi_pstore_write(enum pstore_type_id type, for (i = 0; i < DUMP_NAME_LEN; i++) efi_name[i] = name[i]; - efivar_entry_set_safe(efi_name, vendor, PSTORE_EFI_ATTRIBUTES, - !pstore_cannot_block_path(reason), - size, psi->buf); + ret = efivar_entry_set_safe(efi_name, vendor, PSTORE_EFI_ATTRIBUTES, + !pstore_cannot_block_path(reason), + size, psi->buf); if (reason == KMSG_DUMP_OOPS) efivar_run_worker(); From patchwork Tue Apr 4 16:02:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96744 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp263470qgd; Tue, 4 Apr 2017 09:03:56 -0700 (PDT) X-Received: by 10.99.189.2 with SMTP id a2mr1196797pgf.85.1491321836491; Tue, 04 Apr 2017 09:03:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m185si17949495pfm.3.2017.04.04.09.03.56; Tue, 04 Apr 2017 09:03:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932186AbdDDQDj (ORCPT + 25 others); Tue, 4 Apr 2017 12:03:39 -0400 Received: from mail-wr0-f171.google.com ([209.85.128.171]:33259 "EHLO mail-wr0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932160AbdDDQDd (ORCPT ); Tue, 4 Apr 2017 12:03:33 -0400 Received: by mail-wr0-f171.google.com with SMTP id w43so217984082wrb.0 for ; Tue, 04 Apr 2017 09:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0EgdleSvvqkqB5lbe4pGFCfnf5I9SvBQ/3UlgPoCS8U=; b=Ja0qBBWIQyQdoCcQtfMrPn9EdxXg2JMpqtoQao2grNBce7RlCixwH9j6+L9qQjlznp 3HYBvjtE7dBi889vSRcRo2Z0bZa0sbj9mzIOpf6yqitJdjuBy9FHqy31VG3kgafYl2PM xWDhgDx3u2pRKCMUQrboGWjAjqKxb5xUgdKYw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0EgdleSvvqkqB5lbe4pGFCfnf5I9SvBQ/3UlgPoCS8U=; b=tXuXVezL1NYu7Mf4cEEcH8kmI8I45XDGn5ABP7d08RHk8k0R6DvOp/Y7FvdnqcOkmj LEG5cDme9jV2i2YbxJWYbCuwf513Ld7a6Xoa/VzASedM+hPv9ljv8MruW35tvaggrEzq y+wDT052duqIaPjN9FOFJaRPiJc0d1s9m8/NbcEjW9gmA0Q5vVjBE+Gnfk2jK9WLGRnN 9IzRWMot+goO44LbgC9cs8HWFHIc5zkOPtdu4NrBMzzRcwv32Qfl9s+Ltb2CxdRu49J3 c0RdrSsIm6G/+XEOomALAqnSSiB17vsKZZrVVDd1YDVfs9oNNmWufYHKZPqmD7NM+jK/ 0ugQ== X-Gm-Message-State: AFeK/H1Dcih6BIJsexesPXHef/mAxYenr/TsQy7W5RV6d3BCoBJ96/65a+R0B5jp6tMQvPsr X-Received: by 10.223.151.193 with SMTP id t1mr22274457wrb.149.1491321807386; Tue, 04 Apr 2017 09:03:27 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id z88sm19686465wrb.1.2017.04.04.09.03.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:03:26 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Baoquan He , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 07/12] x86/efi: Clean up a minor mistake in code comment Date: Tue, 4 Apr 2017 17:02:43 +0100 Message-Id: <20170404160245.27812-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404160245.27812-1-ard.biesheuvel@linaro.org> References: <20170404160245.27812-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baoquan He EFI allocate runtime services regions from EFI_VA_START, -4G, down to -68G, EFI_VA_END, 64G altogether. The mechanism was introduced in commit d2f7cbe7b26a7 ("x86/efi: Runtime services virtual mapping"). Clean it up to avoid confusion. Signed-off-by: Baoquan He Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.9.3 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index d56dd864fb1c..4e043a8c8556 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -47,7 +47,7 @@ #include /* - * We allocate runtime services regions bottom-up, starting from -4G, i.e. + * We allocate runtime services regions top-down, starting from -4G, i.e. * 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G. */ static u64 efi_va = EFI_VA_START; From patchwork Tue Apr 4 16:09:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96751 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp266235qgd; Tue, 4 Apr 2017 09:09:32 -0700 (PDT) X-Received: by 10.99.61.194 with SMTP id k185mr24969669pga.154.1491322172564; Tue, 04 Apr 2017 09:09:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92si17938993plc.124.2017.04.04.09.09.32; Tue, 04 Apr 2017 09:09:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932116AbdDDQJ3 (ORCPT + 25 others); Tue, 4 Apr 2017 12:09:29 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:36242 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754932AbdDDQJ0 (ORCPT ); Tue, 4 Apr 2017 12:09:26 -0400 Received: by mail-wm0-f47.google.com with SMTP id o81so29641304wmb.1 for ; Tue, 04 Apr 2017 09:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+7zBJxJc55cRuMaIdQONucqPp8KOx+kSvcIo4Suff7U=; b=P3ZL1539KjHE2F1u392xE+6TFblOkDM+7qM33lvQ5KBtkUoc7SbdvR5YjbRGaj7VIk 75XxHmd6FxTaO/B+WABYWMFoW2OfE6krQtsPr0rjedOhue00xHa4Qb6bm2xymx134SVh rFJoNRmyFKJNIJ1E5fkZRrJJkSuvicfZ4+7ow= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+7zBJxJc55cRuMaIdQONucqPp8KOx+kSvcIo4Suff7U=; b=qLqauJoRBtUENHNtiLeE/4qrsa6XpM1BLyGNu7iR6L7WMXPEHXHftaI5LFdPSWchO+ fN9/LNoBetmMGOTtCf6KaGuWjFTlxtzxNu9bdlEeoyafoFX9zvehKan6fv3QQKPVCnCI 17BASmwpithbdb8kUl+guzFWKGjM+/CdMbbh3FumvQVJTEyq8Ufnxf+0rPPTQOpuIR96 0TIo0APwC0dpOclAYDEMhW+oa9zfw6DXPrA7n87UnvX+/QhaU1mudBuw8VX1b4a+V5Uc 80cvD9/Ozd3vW4NeUAlS1T2VyxIj2JY1XepSmRXs6/wFLjD3NSjFoI8Y3eHGvsmayfwf eqcg== X-Gm-Message-State: AFeK/H2d8fNpkO9NleepasoRxz+h+Dh8VpTD3REhm7WTWqRgSYlvzpuP 2oY6UD6EWhoF30nt X-Received: by 10.28.232.202 with SMTP id f71mr1749231wmi.24.1491322164519; Tue, 04 Apr 2017 09:09:24 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id u66sm19003333wmd.24.2017.04.04.09.09.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:09:23 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: matt@codeblueprint.co.uk, mark.rutland@arm.com, roy.franz@cavium.com, rruigrok@codeaurora.org, leif.lindholm@linaro.org, jhugo@codeaurora.org, evgeny.kalugin@intel.com, eugene@hp.com, bp@alien8.de, bhsharma@redhat.com, bhe@redhat.com, Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 11/12] efi/libstub: arm/arm64: Disable debug prints on 'quiet' cmdline arg Date: Tue, 4 Apr 2017 17:09:09 +0100 Message-Id: <20170404160910.28115-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404160910.28115-1-ard.biesheuvel@linaro.org> References: <20170404160245.27812-1-ard.biesheuvel@linaro.org> <20170404160910.28115-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The EFI stub currently prints a number of diagnostic messages that do not carry a lot of information. Since these prints are not controlled by 'loglevel' or other command line parameters, and since they appear on the EFI framebuffer as well (if enabled), it would be nice if we could turn them off. So let's add support for the 'quiet' command line parameter in the stub, and disable the non-error prints if it is passed. Cc: Matt Fleming Acked-by: Mark Rutland Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm-stub.c | 20 ++++++++++---------- drivers/firmware/efi/libstub/arm32-stub.c | 2 ++ drivers/firmware/efi/libstub/efi-stub-helper.c | 9 +++++++++ drivers/firmware/efi/libstub/efistub.h | 7 +++++++ drivers/firmware/efi/libstub/secureboot.c | 2 ++ include/linux/efi.h | 3 --- 6 files changed, 30 insertions(+), 13 deletions(-) -- 2.9.3 diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index ac3222f6f805..657bb72c9e0b 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -116,8 +116,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) goto fail; - pr_efi(sys_table, "Booting Linux Kernel...\n"); - status = check_platform_features(sys_table); if (status != EFI_SUCCESS) goto fail; @@ -151,6 +149,16 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, goto fail; } + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || + IS_ENABLED(CONFIG_CMDLINE_FORCE) || + cmdline_size == 0) + efi_parse_options(CONFIG_CMDLINE); + + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) + efi_parse_options(cmdline_ptr); + + pr_efi(sys_table, "Booting Linux Kernel...\n"); + si = setup_graphics(sys_table); status = handle_kernel_image(sys_table, image_addr, &image_size, @@ -162,14 +170,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, goto fail_free_cmdline; } - if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || - IS_ENABLED(CONFIG_CMDLINE_FORCE) || - cmdline_size == 0) - efi_parse_options(CONFIG_CMDLINE); - - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) - efi_parse_options(cmdline_ptr); - secure_boot = efi_get_secureboot(sys_table); /* diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c index 18a8b5eb55e7..becbda445913 100644 --- a/drivers/firmware/efi/libstub/arm32-stub.c +++ b/drivers/firmware/efi/libstub/arm32-stub.c @@ -9,6 +9,8 @@ #include #include +#include "efistub.h" + efi_status_t check_platform_features(efi_system_table_t *sys_table_arg) { int block; diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index 2e17d2b8787c..b0184360efc6 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -33,11 +33,16 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE; static int __section(.data) __nokaslr; +static int __section(.data) __quiet; int __pure nokaslr(void) { return __nokaslr; } +int __pure is_quiet(void) +{ + return __quiet; +} #define EFI_MMAP_NR_SLACK_SLOTS 8 @@ -424,6 +429,10 @@ efi_status_t efi_parse_options(char const *cmdline) if (str == cmdline || (str && str > cmdline && *(str - 1) == ' ')) __nokaslr = 1; + str = strstr(cmdline, "quiet"); + if (str == cmdline || (str && str > cmdline && *(str - 1) == ' ')) + __quiet = 1; + /* * If no EFI parameters were specified on the cmdline we've got * nothing to do. diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index a7a2a2c3f199..83f268c05007 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -25,6 +25,13 @@ #endif extern int __pure nokaslr(void); +extern int __pure is_quiet(void); + +#define pr_efi(sys_table, msg) do { \ + if (!is_quiet()) efi_printk(sys_table, "EFI stub: "msg); \ +} while (0) + +#define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg) void efi_char16_printk(efi_system_table_t *, efi_char16_t *); diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c index 5da36e56b36a..8c34d50a4d80 100644 --- a/drivers/firmware/efi/libstub/secureboot.c +++ b/drivers/firmware/efi/libstub/secureboot.c @@ -12,6 +12,8 @@ #include #include +#include "efistub.h" + /* BIOS variables */ static const efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID; static const efi_char16_t const efi_SecureBoot_name[] = { diff --git a/include/linux/efi.h b/include/linux/efi.h index e485e87615d1..ec36f42a2add 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1435,9 +1435,6 @@ static inline int efi_runtime_map_copy(void *buf, size_t bufsz) /* prototypes shared between arch specific and generic stub code */ -#define pr_efi(sys_table, msg) efi_printk(sys_table, "EFI stub: "msg) -#define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg) - void efi_printk(efi_system_table_t *sys_table_arg, char *str); void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, From patchwork Tue Apr 4 16:09:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96752 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp266262qgd; Tue, 4 Apr 2017 09:09:35 -0700 (PDT) X-Received: by 10.84.247.23 with SMTP id n23mr29870519pll.39.1491322175352; Tue, 04 Apr 2017 09:09:35 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92si17938993plc.124.2017.04.04.09.09.35; Tue, 04 Apr 2017 09:09:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932146AbdDDQJc (ORCPT + 25 others); Tue, 4 Apr 2017 12:09:32 -0400 Received: from mail-wr0-f176.google.com ([209.85.128.176]:32845 "EHLO mail-wr0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932111AbdDDQJa (ORCPT ); Tue, 4 Apr 2017 12:09:30 -0400 Received: by mail-wr0-f176.google.com with SMTP id w43so218105467wrb.0 for ; Tue, 04 Apr 2017 09:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PZdrJC3hc+ZZkSqJi3ylGxsX1QnpS4xBhPA2gAGn/IU=; b=EY6Z9mldfUxUXy/IUHuNSfkMm5OXsiYyGGN+a6oYTPAJnjZtjg37hH80lG8QRwzvJf Q2kMoIbcEFDeJE2TsAO2X+HL7PJ3AEPGSYdXLtKEm3Th8G2H02t6k5zj/yBEjkYk4EtM P5v6hvlpBGjD3MAz6bcItAO4xbYajJcYS/UwM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PZdrJC3hc+ZZkSqJi3ylGxsX1QnpS4xBhPA2gAGn/IU=; b=WIaiVtDFtEJihDQR7HB+61gbsUKQoC5RB51rjt+9dLDr2xnNkASTvJozFwqzj6X2b4 JHL421ItMKXWJtBz5Hqmb9JmttxoVjcQY8FKsdr+lSo/Xi0hMZUhB0Dyqx11qzIRo3By aulQ3vRaqvZyLjBx+2ZYVhcFbwCElhk1QbqAUvVtlz2AB0UO+pjsoTqgMUjo1ywtDxYe tVPacFuZ+VVwa1lJmvJL108DfYYZH28QNrgrhjB2Aso7Kvub5Ks6CJ3dl4R5krv2JvSw 25CSHNzlFBlaZV1jOgTXZGxYX3v2O90WwzhJGSDnzPeuJNo4Ucm6DTXQbfFW7J0Bkq/b NYDg== X-Gm-Message-State: AFeK/H0MdzLU09378SX5+sJAweq25Z0acXZ4WB3ydZeg6Ui/3O6xrY1HhXCayN8YOC83km41 X-Received: by 10.223.170.66 with SMTP id q2mr20464762wrd.179.1491322168631; Tue, 04 Apr 2017 09:09:28 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id u66sm19003333wmd.24.2017.04.04.09.09.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:09:27 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: matt@codeblueprint.co.uk, mark.rutland@arm.com, roy.franz@cavium.com, rruigrok@codeaurora.org, leif.lindholm@linaro.org, jhugo@codeaurora.org, evgeny.kalugin@intel.com, eugene@hp.com, bp@alien8.de, bhsharma@redhat.com, bhe@redhat.com, Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 12/12] ef/libstub: arm/arm64: Randomize the base of the UEFI rt services region Date: Tue, 4 Apr 2017 17:09:10 +0100 Message-Id: <20170404160910.28115-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404160910.28115-1-ard.biesheuvel@linaro.org> References: <20170404160245.27812-1-ard.biesheuvel@linaro.org> <20170404160910.28115-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update the allocation logic for the virtual mapping of the UEFI runtime services to start from a randomized base address if KASLR is in effect, and if the UEFI firmware exposes an implementation of EFI_RNG_PROTOCOL. This makes it more difficult to predict the location of exploitable data structures in the runtime UEFI firmware, which increases robustness against attacks. Note that these regions are only mapped during the time a runtime service call is in progress, and only on a single CPU at a time, bit give the lack of a downside, let's enable it nonetheless. Cc: Ingo Molnar Cc: Borislav Petkov Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm-stub.c | 49 ++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 13 deletions(-) -- 2.9.3 diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 657bb72c9e0b..1e45ec51b094 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -18,6 +18,22 @@ #include "efistub.h" +/* + * This is the base address at which to start allocating virtual memory ranges + * for UEFI Runtime Services. This is in the low TTBR0 range so that we can use + * any allocation we choose, and eliminate the risk of a conflict after kexec. + * The value chosen is the largest non-zero power of 2 suitable for this purpose + * both on 32-bit and 64-bit ARM CPUs, to maximize the likelihood that it can + * be mapped efficiently. + * Since 32-bit ARM could potentially execute with a 1G/3G user/kernel split, + * map everything below 1 GB. (512 MB is a reasonable upper bound for the + * entire footprint of the UEFI runtime services memory regions) + */ +#define EFI_RT_VIRTUAL_BASE SZ_512M +#define EFI_RT_VIRTUAL_SIZE SZ_512M + +static u64 virtmap_base = EFI_RT_VIRTUAL_BASE; + efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image, void **__fh) { @@ -213,6 +229,25 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, efi_random_get_seed(sys_table); + if (!nokaslr()) { + /* + * Randomize the base of the UEFI runtime services region. + * Preserve the 2 MB alignment of the region by taking a + * shift of 21 bit positions into account when scaling + * the headroom value using a 32-bit random value. + */ + u64 headroom = TASK_SIZE - EFI_RT_VIRTUAL_BASE - + EFI_RT_VIRTUAL_SIZE; + u32 rnd; + + status = efi_get_random_bytes(sys_table, sizeof(rnd), + (u8 *)&rnd); + if (status == EFI_SUCCESS) { + virtmap_base = EFI_RT_VIRTUAL_BASE + + (((headroom >> 21) * rnd) >> (32 - 21)); + } + } + new_fdt_addr = fdt_addr; status = allocate_new_fdt_and_exit_boot(sys_table, handle, &new_fdt_addr, efi_get_max_fdt_addr(dram_base), @@ -242,18 +277,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, return EFI_ERROR; } -/* - * This is the base address at which to start allocating virtual memory ranges - * for UEFI Runtime Services. This is in the low TTBR0 range so that we can use - * any allocation we choose, and eliminate the risk of a conflict after kexec. - * The value chosen is the largest non-zero power of 2 suitable for this purpose - * both on 32-bit and 64-bit ARM CPUs, to maximize the likelihood that it can - * be mapped efficiently. - * Since 32-bit ARM could potentially execute with a 1G/3G user/kernel split, - * map everything below 1 GB. - */ -#define EFI_RT_VIRTUAL_BASE SZ_512M - static int cmp_mem_desc(const void *l, const void *r) { const efi_memory_desc_t *left = l, *right = r; @@ -303,7 +326,7 @@ void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size, unsigned long desc_size, efi_memory_desc_t *runtime_map, int *count) { - u64 efi_virt_base = EFI_RT_VIRTUAL_BASE; + u64 efi_virt_base = virtmap_base; efi_memory_desc_t *in, *prev = NULL, *out = runtime_map; int l;