From patchwork Fri Jun 2 13:51:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 101251 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp204800obc; Fri, 2 Jun 2017 06:54:48 -0700 (PDT) X-Received: by 10.99.109.129 with SMTP id i123mr7270782pgc.103.1496411688285; Fri, 02 Jun 2017 06:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496411688; cv=none; d=google.com; s=arc-20160816; b=KLwrOR8EwtFI3mAgK7SaQLpaDoFgjzlur9tfSXhxYqJXMGrGep3dCXVC3QpvLgOlSS TVhBNBfPuj610L0/YLVwZpgUY25yNll7xZv3RUaDUUG5h6SeheTJd6VcgVesQo1tziUE 9EZXJL0Ur4k6M3W8ET67ToCTrK/hfixnMkcic/EQNeZc+RYk3tLGTcF/xKX0r1aTZQgc VSqfJZYP9DAOvI+5xevZhscZUM3j38WbGjqJOY3IDsKgIRcCugkXjpeardyzu3AHbY2W 9bpjB3C5fdj3XA+dV6U38dsWrhdLF5u0baP9TmapCkWkukHyTzFmgflWSQ9Lve6IY7cy iZEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=baG0akEVxT7GSMq4qIZKElqQqgM3hP1fxGluFdFhTlM=; b=hW3r0uPcJNU3836pZk5TzWZZD0l8kSERkYiLW8fa+/Vv3uD3qRysxJqHQ8NklKmUZd r4IyuevGyFag12nbenZUnwXxSmvH6A4Dv+3hrYnwjAPgjsaU65d0i8vqE/IAQdSf2AF3 gtQW5MpTZgxljKWzLUO+qBGvxya+KAfQP3zUJQlOSLVL6UsD1DiDQR/IZZ32J+kCmPJ9 dYUsF68N3/xLPvsO8TGixCX64wq+chcw/tAcCEiTmyPJlbej9Uqqo3YThQGDF/g55Ntm q3raOwN3Em8PcZB2tsj3LPA89giL1SCUbqyz4QCetc8Qn2OoRIon3JcZgHgDwoJL9//y CBBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s80si23734996pfi.388.2017.06.02.06.54.48; Fri, 02 Jun 2017 06:54:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751425AbdFBNyr (ORCPT + 2 others); Fri, 2 Jun 2017 09:54:47 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:36947 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751263AbdFBNyp (ORCPT ); Fri, 2 Jun 2017 09:54:45 -0400 Received: by mail-wm0-f54.google.com with SMTP id d127so27560081wmf.0 for ; Fri, 02 Jun 2017 06:54:44 -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=7OLj7Up4KJ5hHvntdum+L4A4rVuiVL1LxI7wkpXr2PU=; b=MoAYfnGbautzlZEy4CYgX0aRICYUxllZXweBTdOLWF+BClxzJkdZ38popxXOtyafFT 0cxJTpXpZIP9+DcbYR/e3cilsoH+awlaWBJp6wqvnmW5ihyAwNrPupi7rV5PDFd6Froo kl+bbV7rVK+8i+vce4M75ubDK79l+f8k8ENHo= 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=7OLj7Up4KJ5hHvntdum+L4A4rVuiVL1LxI7wkpXr2PU=; b=SHAtstYvrpOALM+dWW4dNP+P8/BEv8MmHIpfH57y9bY7DmPsULbxn4/f5Wv8LIy7tg hoNVrPVI3vmK6tM1cfzysDGOL9GF7ZrSHsV5BERdA361ocazYN0eFrbgJ7ZdX5oJ1H3k vwiHWBjLwuakNos6Drk44pqrwh54fbu/Uwi+JyJDhuUn+GVZKGZjspruwxYVqtPM1q1H 16w+StllVmi7cvtBf+2a+PhUa4bNPpu5uA0r03Tlz8dtI5o+7kQPnK8GuTlZWsmEboA/ wHIIjN7sBmddjcT/rvguAd9hDxVeFhQUl7aKo4BiE3z9+eSdZ4VFUtAL3olJxZFyZGbQ jRcw== X-Gm-Message-State: AODbwcApu5PH0mJdCDjpIClAi8h4LWmX7A8NF1GFxOtddn+C/NAf8yNg c8j1m4oCxW/zXIirK4hccQ== X-Received: by 10.80.149.209 with SMTP id x17mr6047493eda.175.1496411683361; Fri, 02 Jun 2017 06:54:43 -0700 (PDT) Received: from localhost.localdomain ([105.151.155.95]) by smtp.gmail.com with ESMTPSA id g48sm9756076edc.8.2017.06.02.06.54.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:54:42 -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, Borislav Petkov , Andy Lutomirski , Matt Fleming Subject: [PATCH 01/13] x86/efi: Clean up efi CR3 save/restore Date: Fri, 2 Jun 2017 13:51:55 +0000 Message-Id: <20170602135207.21708-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170602135207.21708-1-ard.biesheuvel@linaro.org> References: <20170602135207.21708-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@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 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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 7e76a4d8304b..dc2da5e2c7e4 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -82,9 +82,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); @@ -93,7 +93,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 3481268da3d0..403a987d06c7 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 c488625c9712..6fbf6c47e603 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 Fri Jun 2 13:51:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 101252 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp204830obc; Fri, 2 Jun 2017 06:54:52 -0700 (PDT) X-Received: by 10.101.90.78 with SMTP id z14mr7377165pgs.44.1496411692321; Fri, 02 Jun 2017 06:54:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496411692; cv=none; d=google.com; s=arc-20160816; b=EqBym+l91A+0tzrMAArmCCsg36kjMth7Ji2ANA1dvx7RXCl6O9TtlpKkLKAynqvu8E Nm6ae2NucHxplkHf6n9tR/+RwHGMMXaeRUfzxsiUXWPujlFfJb3QnWmN2aH33y88Pvs2 8ddxkuzJey2LfhQhET2XK9mI1unZDpvRCVCWE+CeN7QEOZV58TGWCY4t/AuZSwp0YG2y I8tSsFjy5/ghZjvJmxIYAXGA15WEg+vDSfx5+hLiJMp7VVcuRuj5va6rXt79cn0rFdyS ZPHKDCI3ZTU41mGCo9E4daku4/0MXXiowTnplUjiaEUAncbx0iFKoE5h1B4+OjssgHyc 2unA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=AcpeyAbkCIzbBTjd6Yajy98umXnFMVF5ZR/jjIsbPxA=; b=fV1sV8hy9P3suW9lkOLyzH6nsinKFatqSFX3svxd3Ce1chEpR1sLuLfRAQCv1JPqfy BTQVCTGGEJLPx12UUa8mJKdKRzrwOs4Nw5TwxY6Xx8XjsTJY+90b7wTIPcYDq9ZKDwdm vxDlsO+AvUQtOc0OLsXo6amoHicTHJtBWjju9Ejj0/Vs7vEFMFETmIDRstWZpT2xCMGl HykILogbQGqHozxMtRlMRHsuWF2URHB5rsFRm2guk2vaibCPYcDBwTcosO9TN5hD/h1g 24x+pjIb60nZM9+ggSTdBYYNDzYHphZ1XAugBCAARLuDIyAhJlXM3WM7TcJ21S9Z8QBL PYXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s80si23734996pfi.388.2017.06.02.06.54.52; Fri, 02 Jun 2017 06:54:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbdFBNyu (ORCPT + 2 others); Fri, 2 Jun 2017 09:54:50 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:36987 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751468AbdFBNyt (ORCPT ); Fri, 2 Jun 2017 09:54:49 -0400 Received: by mail-wm0-f45.google.com with SMTP id d127so27561673wmf.0 for ; Fri, 02 Jun 2017 06:54:49 -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=gQxKtWUKPg1ezXArF4TB0cLzuI7CK0EQGCTavdYwkew=; b=eb4oR1NG0H7JRRe+m5AwbTp4dK4oaT1NWDH9OiBTEhKSvnHIyvw8zF3uYLVLBBYVNr zGlcyZjTkc5XcTqAk6o+uSIsesqGTYprazNlGV0IbhW3XBX41XO20pX7aqB0B6pmRI1v OFb43ni7eTKiy6eqreVdJxosJYVmwpmuW0HdQ= 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=gQxKtWUKPg1ezXArF4TB0cLzuI7CK0EQGCTavdYwkew=; b=qlpMz/tWc6BL6UIXducyYh4Gn+u05kq71uPGXVGyLzkj/zTZouATng2xmiTLe63mOD /Oxh/I4sPSBVNzf2a6/GjbLzzoeJrxzxZ6vbZCH5RG00+L9bePa+r4pYmfZv0AV0pmYk y7GjqkEhmmXebbiljAS2nUSXUDptxK6YWV3RzvjzCY8m9CEFIbfZ4sCNm75AOpcJ2p9C JDez6645rLVtZkJ50rAI8cAiDWzJjBi9aSLekdgQsZdKUaU/hgYJPXy9OuWiGVf5/PUV Ua/Hn5DZBVqvlLBBbCvXH0snYpNq95HFcwZThEB+cTgk823KJGMKYA3JAb11yITr+TY6 4ETg== X-Gm-Message-State: AODbwcCR1OR/5y2nEyeNm1mTbNMUdd/NRvzIditqa9ns1PT6jwIsgeZO wQtwV8RKzqAcLujgUYisyw== X-Received: by 10.80.184.129 with SMTP id l1mr6064000ede.88.1496411687944; Fri, 02 Jun 2017 06:54:47 -0700 (PDT) Received: from localhost.localdomain ([105.151.155.95]) by smtp.gmail.com with ESMTPSA id g48sm9756076edc.8.2017.06.02.06.54.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:54:47 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Jan Kiszka , Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 03/13] efi/capsule: Remove pr_debug on ENOMEM or EFAULT Date: Fri, 2 Jun 2017 13:51:57 +0000 Message-Id: <20170602135207.21708-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170602135207.21708-1-ard.biesheuvel@linaro.org> References: <20170602135207.21708-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Jan Kiszka Both cases are not worth a debug log message - the error code is telling enough. Signed-off-by: Jan Kiszka Reviewed-by: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 91e91f7a8807..7b57dda2417d 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -88,10 +88,8 @@ static ssize_t efi_capsule_setup_info(struct capsule_info *cap_info, temp_page = krealloc(cap_info->pages, pages_needed * sizeof(void *), GFP_KERNEL | __GFP_ZERO); - if (!temp_page) { - pr_debug("%s: krealloc() failed\n", __func__); + if (!temp_page) return -ENOMEM; - } cap_info->pages = temp_page; cap_info->header_obtained = true; @@ -111,10 +109,8 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info) cap_hdr_temp = vmap(cap_info->pages, cap_info->index, VM_MAP, PAGE_KERNEL); - if (!cap_hdr_temp) { - pr_debug("%s: vmap() failed\n", __func__); + if (!cap_hdr_temp) return -ENOMEM; - } ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); vunmap(cap_hdr_temp); @@ -171,7 +167,6 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, if (!cap_info->page_bytes_remain) { page = alloc_page(GFP_KERNEL); if (!page) { - pr_debug("%s: alloc_page() failed\n", __func__); ret = -ENOMEM; goto failed; } @@ -184,7 +179,6 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, kbuff = kmap(page); if (!kbuff) { - pr_debug("%s: kmap() failed\n", __func__); ret = -ENOMEM; goto failed; } @@ -193,7 +187,6 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, /* Copy capsule binary data from user space to kernel space buffer */ write_byte = min_t(size_t, count, cap_info->page_bytes_remain); if (copy_from_user(kbuff, buff, write_byte)) { - pr_debug("%s: copy_from_user() failed\n", __func__); ret = -EFAULT; goto fail_unmap; } From patchwork Fri Jun 2 13:52:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 101260 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp205137obc; Fri, 2 Jun 2017 06:55:41 -0700 (PDT) X-Received: by 10.84.208.236 with SMTP id c41mr32021plj.95.1496411741815; Fri, 02 Jun 2017 06:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496411741; cv=none; d=google.com; s=arc-20160816; b=aTZSflTAFbM8Y0MG3YN1/hkPiElvWeuCMCqB+0FpmpWn0jp7tAMzSFHqRliAYLfDZn NMkdxIYP0cbB5tjwi4Gtd73mFDpHqVrybUqrIhHi8aapG/fwyS4CPVqQ5eDKVOrDrLA/ 7xTKFkEi6N9gk8Yf92XG4A69h23W498IgqO48I+IVBVX+Xlig963wGTt/gHWqsxY7yRJ ugsEkh4hTdrJE2R9f29pH+svdSp+BWFOgEI/pWrobG0hKTL4sLNnl1Y2v4DLyxHrAduw 2YqtVt18/Oi6N1CsUpnGo0bjdyfHBapdJtp1rEkI3zUV65JfjkN1MRuDoHqUqLMSpW8K PhCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=REUIvN9OMPV4fUP3gDNzmU+RlKc1AfnjypgmiHJnst4=; b=WJfzcT2+fYx8qaH6Jf2+EckpBDGVjuANonc5HGAWaLzzgxLKXzAneQGtyeh7qlMjic NNooUkoFfGKqyAuuhf2LxkPzzd/SqPRGO9kkJU5pDusDBDvyqXgBuML6iJ9sOLnbWkuv Dxd6mSyvXsfc+pit5gakn1K1CQvI6jmnzrcJT7bZNlvVWKPdJrCF0dGjreFkfffl6Ebh B2BbXHdyXjaGU4npj49V07awmhPxXm9Cu5yRsqe4GsiLX6N1BmdCGc2FlCUTZ85NoAcl VMKCG/8pBOxg+vmtfNkpR4GOomC1J/ZF/T/bgBg0J7XEP3PY9UYJK7bW8APFWCbjQFo+ hG1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si3183385pgj.43.2017.06.02.06.55.41; Fri, 02 Jun 2017 06:55:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751611AbdFBNzV (ORCPT + 2 others); Fri, 2 Jun 2017 09:55:21 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:36674 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751597AbdFBNzT (ORCPT ); Fri, 2 Jun 2017 09:55:19 -0400 Received: by mail-wm0-f49.google.com with SMTP id 7so26355828wmo.1 for ; Fri, 02 Jun 2017 06:55:08 -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=esFDaoQnflXguuSmAmJsAcYBe+fXr0flrf1fGkfahXY=; b=gIdCQUJjRfRkvFcdK08bomGle2qrK8A5nqe6rgY80M2HuL6p/BMPOdALnW9NAlz8iq Jltup8UkGYWp/a8LlMkS9/VZ+2+mzl94FsCBzDZnE5BqQ2FYFwlkTF24jUJmLnBob8xz mWRmuclAD3DB1mZ5nxedrsO/aAeHR9p+TPNkA= 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=esFDaoQnflXguuSmAmJsAcYBe+fXr0flrf1fGkfahXY=; b=nOGb4Y//1yk/Fcp3DvryBJCuYelphSb42GpLu2J9SBjmYC+d/Ryr+LNAiHqzb0JbL/ fn1OmB8JcVIvVana6mQE2yG2jqmQ59rddEsjPEmkIxiTuLtNiaM5T6AjBjcSgNwo2A9f 4LDHI32EP1B/m4Om6ETUFpuIFSOeAGrNu4TYN4FNVk6y1uA8a4Htt7sWMr1Qm3kVdYAm IPdxDwXoFPiTi2ZaT188BDnRmELz6oC+JE6XFMv3+TRCF6S5VYNCE/E0hrjS9xQhEsld 1UYHeJoqFX/U4nDw/FC6w9Gda9aHnvPWlnVzAwwYiEKq27nhlJXqfhWXQm3Xkn45yYqq r/cA== X-Gm-Message-State: AODbwcDRlHdSDxaQE3CVEY3py9Ne/pUxlkWvwRMiKJr78J+CGa/PmLK+ GJ3NL+LOwn8MA8MAFxMaeQ== X-Received: by 10.80.179.209 with SMTP id t17mr6208230edd.62.1496411702379; Fri, 02 Jun 2017 06:55:02 -0700 (PDT) Received: from localhost.localdomain ([105.151.155.95]) by smtp.gmail.com with ESMTPSA id g48sm9756076edc.8.2017.06.02.06.55.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:55:01 -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, Matt Fleming Subject: [PATCH 09/13] efi/capsule-loader: Use page addresses rather than struct page pointers Date: Fri, 2 Jun 2017 13:52:03 +0000 Message-Id: <20170602135207.21708-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170602135207.21708-1-ard.biesheuvel@linaro.org> References: <20170602135207.21708-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org To give some leeway to code that handles non-standard capsule headers, let's keep an array of page addresses rather than struct page pointers. This gives special implementations of efi_capsule_setup_info() the opportunity to mangle the payload a bit before it is presented to the firmware, without putting any knowledge of the nature of such quirks into the generic code. Cc: Matt Fleming Tested-by: "Bryan O'Donoghue" Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 12 ++++++++---- drivers/firmware/efi/capsule.c | 7 ++++--- include/linux/efi.h | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index cbc3526953d5..ec8ac5c4dd84 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -20,6 +20,10 @@ #define NO_FURTHER_WRITE_ACTION -1 +#ifndef phys_to_page +#define phys_to_page(x) pfn_to_page((x) >> PAGE_SHIFT) +#endif + /** * efi_free_all_buff_pages - free all previous allocated buffer pages * @cap_info: pointer to current instance of capsule_info structure @@ -31,7 +35,7 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) { while (cap_info->index > 0) - __free_page(cap_info->pages[--cap_info->index]); + __free_page(phys_to_page(cap_info->pages[--cap_info->index])); cap_info->index = NO_FURTHER_WRITE_ACTION; } @@ -161,12 +165,12 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, goto failed; } - cap_info->pages[cap_info->index++] = page; + cap_info->pages[cap_info->index++] = page_to_phys(page); cap_info->page_bytes_remain = PAGE_SIZE; + } else { + page = phys_to_page(cap_info->pages[cap_info->index - 1]); } - page = cap_info->pages[cap_info->index - 1]; - kbuff = kmap(page); kbuff += PAGE_SIZE - cap_info->page_bytes_remain; diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c index e603ccf39d80..901b9306bf94 100644 --- a/drivers/firmware/efi/capsule.c +++ b/drivers/firmware/efi/capsule.c @@ -214,7 +214,7 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule, * * Return 0 on success, a converted EFI status code on failure. */ -int efi_capsule_update(efi_capsule_header_t *capsule, struct page **pages) +int efi_capsule_update(efi_capsule_header_t *capsule, phys_addr_t *pages) { u32 imagesize = capsule->imagesize; efi_guid_t guid = capsule->guid; @@ -249,10 +249,11 @@ int efi_capsule_update(efi_capsule_header_t *capsule, struct page **pages) sglist = kmap(sg_pages[i]); for (j = 0; j < SGLIST_PER_PAGE && count > 0; j++) { - u64 sz = min_t(u64, imagesize, PAGE_SIZE); + u64 sz = min_t(u64, imagesize, + PAGE_SIZE - (u64)*pages % PAGE_SIZE); sglist[j].length = sz; - sglist[j].data = page_to_phys(*pages++); + sglist[j].data = *pages++; imagesize -= sz; count--; diff --git a/include/linux/efi.h b/include/linux/efi.h index a7379a2b5680..8269bcb8ccf7 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -143,7 +143,7 @@ struct capsule_info { long index; size_t count; size_t total_size; - struct page **pages; + phys_addr_t *pages; size_t page_bytes_remain; }; @@ -1415,7 +1415,7 @@ extern int efi_capsule_supported(efi_guid_t guid, u32 flags, size_t size, int *reset); extern int efi_capsule_update(efi_capsule_header_t *capsule, - struct page **pages); + phys_addr_t *pages); #ifdef CONFIG_EFI_RUNTIME_MAP int efi_runtime_map_init(struct kobject *); From patchwork Fri Jun 2 13:52:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 101262 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp205144obc; Fri, 2 Jun 2017 06:55:42 -0700 (PDT) X-Received: by 10.84.169.36 with SMTP id g33mr67676plb.0.1496411742829; Fri, 02 Jun 2017 06:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496411742; cv=none; d=google.com; s=arc-20160816; b=kqx274xGWx9cE2qNFf31VrMC3YQPYd/o/qUHdlQJtu3ZyVMamGH4XnaO6UELZwXJTT 8Flkrkr3Us0N+uX/tBVnuK6b5NE2vJee19RxuIj83V+GFkRDcmZIK814F5UQzzIm6pBn u7B/KFVaxTQQi0TEe4Y7rkVRkwI2f6cSOfyehXok0OTkYIK2HSb/fzgfGfAphhRv+t8d r4cQbjs3JplPZp0fiU3IHR1EVuPDHw606TDyfTolknKihcka/P8T/TBhkIGmEjDBBBbj 86XGlWgHlepJB+6x7yWDYQoDk499O/YlpjkLDArUqCpzzZUhlpXkHtF3gz2gJRMguOMc lqzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=j1yqrCYELjELx7ZTjaA+uToVdfJldYzToUaelzbKHa8=; b=hN9d9ETmErOVbW71kV83Nsmc8V9H9VUAL59DqmhqdlWmf0GoGxOlLVmtEd+eS2lLP4 rODP/ZiPRN/3DGtc7XWatmRXspO+ZJY9iOD8Lg29HMuf6kYNuT9H1U/oCxRB3TusCWKF pJ+SkVbyazhrAWNRirbBQxcL44dDbuK8cCqlbSNNObEaYnEfcC399Xrs9aBOd4CQ5UP6 p3pfA5oLlCk5KVXFDVg1Mi3xEStqjcbyvQ56edrnrl+gspmjR19jgLbFyS2/swF0Ps32 RaXvM+R8R7+gLvYepZ3zAtqhcH6yJ1EgdaMg/0A727QI+bbWhVj6+wW+7iIa7GzHlCnh o/Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si3183385pgj.43.2017.06.02.06.55.42; Fri, 02 Jun 2017 06:55:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751622AbdFBNzS (ORCPT + 2 others); Fri, 2 Jun 2017 09:55:18 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:37155 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751597AbdFBNzO (ORCPT ); Fri, 2 Jun 2017 09:55:14 -0400 Received: by mail-wm0-f48.google.com with SMTP id d127so27568852wmf.0 for ; Fri, 02 Jun 2017 06:55:13 -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=mPhgzxjHAPxa9HA9SJDfDOor8UpO7bC102tKT0TV7m8=; b=WeHXDuuvqK1yS8dk05qVl1GtLp+z/e9s8gQM91ghMR4nwBaMfkYcyBQ+4o83M2LK6k zamhKXtpdYSVUn7EGW/H3T3zH27+FMQaHXhgvlhrbP2RrAgQQ421pZW5qhVqdEQV+M8Q 8HWFpkaTMjpycGlLTNxiSNWPiMo7hdSfL5o64= 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=mPhgzxjHAPxa9HA9SJDfDOor8UpO7bC102tKT0TV7m8=; b=gqqONFODlbUPpsE6A5gPs/H8v8BfOJYOzx/I5cwiAKnhQS9ppksg16NBNXZ5Z6yQ2C Wjj0ijEtOdhMJEH/9hXBlQqWKb3zwh5qAksTZcqJt8jBkmX9CaMZnJXFvcRTTaDt+mL2 6vxfP/Boi3KceH/i5fE99XZfCDNO0+lhD6IDlhlBQAySK/sZbV9z4U6B2sIhpVzSP/gU pD7/e3FAoCp1q+CNvM2FD50gXMYmFKPo7wCX1v5rG7Eqzh0+//SrSkQILoFaKq/KuneY 1LKr8BdYPQM5nLQsE+uyF9P/dxto3XQe/EXxhxe3fsfp4eXJ2oOj7tbC4K9vNtRBf8fz 0eeA== X-Gm-Message-State: AODbwcC2xtg/dexIbu33oU3WXlPc0+8Z+QgugXbo6o8hmwRquUX2ScH2 HERp4wvqgo2xYkwBPbRfSA== X-Received: by 10.80.136.229 with SMTP id d92mr6303563edd.119.1496411707838; Fri, 02 Jun 2017 06:55:07 -0700 (PDT) Received: from localhost.localdomain ([105.151.155.95]) by smtp.gmail.com with ESMTPSA id g48sm9756076edc.8.2017.06.02.06.55.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:55:07 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Geliang Tang , Ard Biesheuvel , linux-kernel@vger.kernel.org, Matt Fleming Subject: [PATCH 11/13] efi/efi_test: Use memdup_user() helper Date: Fri, 2 Jun 2017 13:52:05 +0000 Message-Id: <20170602135207.21708-12-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170602135207.21708-1-ard.biesheuvel@linaro.org> References: <20170602135207.21708-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Geliang Tang Use memdup_user() helper instead of open-coding to simplify the code. Signed-off-by: Geliang Tang Acked-by: Ivan Hu Cc: Ard Biesheuvel Signed-off-by: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/test/efi_test.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c index 8cd578f62059..08129b7b80ab 100644 --- a/drivers/firmware/efi/test/efi_test.c +++ b/drivers/firmware/efi/test/efi_test.c @@ -71,18 +71,13 @@ copy_ucs2_from_user_len(efi_char16_t **dst, efi_char16_t __user *src, if (!access_ok(VERIFY_READ, src, 1)) return -EFAULT; - buf = kmalloc(len, GFP_KERNEL); - if (!buf) { + buf = memdup_user(src, len); + if (IS_ERR(buf)) { *dst = NULL; - return -ENOMEM; + return PTR_ERR(buf); } *dst = buf; - if (copy_from_user(*dst, src, len)) { - kfree(buf); - return -EFAULT; - } - return 0; }