From patchwork Fri Jun 2 13:52:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 101258 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp205132obc; Fri, 2 Jun 2017 06:55:41 -0700 (PDT) X-Received: by 10.84.217.222 with SMTP id d30mr56294plj.80.1496411741080; 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=vxpxjCyg6thYfmo+0UjqmLwYr4af96MNfss2Us3Duz+RGMHguwXwwfYVkv0iiV42mM CQVBsyrB7qOnz0UTH7zIS7es0geBOl05weiDL84aJ/Y3NdpuNZtdwKi9xKQ0zfI59NDw 7UlvWQrbGvSWLJ9C7tq88ttBYPf5R+CqTmw7jSfakDWm9gzHz3B1Ebjaw+LBkSt8sM+M /mluc9fq5m2yTO3inh8BSnKmmFfgLNx+K/0XVDyLtTKjM0m77iYO3bZUKzDh+3iTY8hk mEQu2nlHjM1hs0Ob6A+DRMXcSErPjfu3J1eBiKT9vt2dZkP47fmHUjXKMU76Nu0TN/BG ycxQ== 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=OVqajGRdNBqJ2J2JvoZaWIUxgTkr1401/IW2fU8bKbY=; b=Voi1hib2Z+LsDIIgVd2jSPkx9r+3dv5mI/NFVA4FWejzTSRWm9Kw4SjW0bv7by+E/R 25eG3SP1OfZgCXZOmbLUE9wTjCkbV3Xpz5tp0RQ1gqJOEsji3BqkwKBMfH1EfC5gfZZw 4sGIwbOzNU/F5mmoSjE/f47Jm2F3Xvyw6jfQ2Q/H7oy0VyfjHx0RRGS7J8USPSqtE+Et N0YuiUO80zKs6VKCke9+DpaaUB+sDdNF389YRXLVHPOEw1DOp4zYLyMW8PkWB2B0nJ6R 1aTajRoKZCxGMk5hwA5ADZK+Dx18hI2cDjaqJ3OMO2oB+V20HzOd7A6LBOnsqeiFbCT0 QBug== ARC-Authentication-Results: i=1; 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 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.40; Fri, 02 Jun 2017 06:55:41 -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 S1751608AbdFBNzO (ORCPT + 25 others); Fri, 2 Jun 2017 09:55:14 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:37086 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751561AbdFBNzL (ORCPT ); Fri, 2 Jun 2017 09:55:11 -0400 Received: by mail-wm0-f50.google.com with SMTP id d127so27565974wmf.0 for ; Fri, 02 Jun 2017 06:55:00 -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=OVqajGRdNBqJ2J2JvoZaWIUxgTkr1401/IW2fU8bKbY=; b=aGMyLR0IM7P0un+Po5YXX/NcJFjhO++cqyOim8omw+7jm4M3E/04PdlPgGqvUFErJX wxlpy2CqieTGPs3Ms8yYClROgdzsvK8iJ+vzEYqi249PAioyJUiqNLgaVHU9mapK8xXe 4K8XguX2Y6F/l/K3+cj0fwj4n8UdvkNt0jyDU= 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=OVqajGRdNBqJ2J2JvoZaWIUxgTkr1401/IW2fU8bKbY=; b=Z0hOewjK7p5RSV3wNytGP4G1/fAhyZZSBaTuqmoRBpcQvSLYDANsaaAxqMVUFRkzDW 5ZygSp5ClkwUaHLeFemNMPG5XcKuIV18IQBIu0Ael6M3mLnboDAk0ksBaK6sIrBLdtbO S4nNEGKG5d6EeQshBxJMxBvTtHAVN54jfMx5ALhIpFOuI5gsj9Vv7zxK2t0+hsgyxGFC vYpycqtyy3U7mg2TwuKq6wdXKNrhJ7hHdta8q50LsmEtd9hv1y6T0RGIW4Gq0T4S8jgY Np564stmsA9ssvseBwfU9IRSF86TJ7UYrdktQIFRnrjE8yExZRRXiIH51mzisbeAR35B xwvg== X-Gm-Message-State: AODbwcA29/m0gtHhnJg7pR3kHWjhXcBmpMMGEyjKbOmQ2UFrHmke0PRP i6ZE5tuC0N1eyptm X-Received: by 10.80.169.161 with SMTP id n30mr6249187edc.43.1496411699928; Fri, 02 Jun 2017 06:54:59 -0700 (PDT) Received: from localhost.localdomain ([105.151.155.95]) by smtp.gmail.com with ESMTPSA id g48sm9756076edc.8.2017.06.02.06.54.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:54:59 -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 08/13] efi/capsule-loader: Redirect calls to efi_capsule_setup_info via weak alias Date: Fri, 2 Jun 2017 13:52:02 +0000 Message-Id: <20170602135207.21708-9-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To allow platform specific code to hook into the capsule loading routines, indirect calls to efi_capsule_setup_info() via a weak alias of __efi_capsule_setup_info(), allowing platforms to redefine the former but still use the latter. Cc: Matt Fleming Tested-by: "Bryan O'Donoghue" Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 56 +++++++++++++++++------------------ include/linux/efi.h | 12 ++++++++ 2 files changed, 39 insertions(+), 29 deletions(-) -- 2.9.3 diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index 2357bcdcb44d..cbc3526953d5 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -20,16 +20,6 @@ #define NO_FURTHER_WRITE_ACTION -1 -struct capsule_info { - efi_capsule_header_t header; - int reset_type; - long index; - size_t count; - size_t total_size; - struct page **pages; - size_t page_bytes_remain; -}; - /** * efi_free_all_buff_pages - free all previous allocated buffer pages * @cap_info: pointer to current instance of capsule_info structure @@ -46,28 +36,13 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) cap_info->index = NO_FURTHER_WRITE_ACTION; } -/** - * efi_capsule_setup_info - obtain the efi capsule header in the binary and - * setup capsule_info structure - * @cap_info: pointer to current instance of capsule_info structure - * @kbuff: a mapped first page buffer pointer - * @hdr_bytes: the total received number of bytes for efi header - **/ -static int efi_capsule_setup_info(struct capsule_info *cap_info, - void *kbuff, size_t hdr_bytes) +int __efi_capsule_setup_info(struct capsule_info *cap_info) { size_t pages_needed; int ret; void *temp_page; - /* Only process data block that is larger than efi header size */ - if (hdr_bytes < sizeof(efi_capsule_header_t)) - return 0; - - /* Reset back to the correct offset of header */ - kbuff -= cap_info->count; - memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); - pages_needed = ALIGN(cap_info->header.imagesize, PAGE_SIZE) / PAGE_SIZE; + pages_needed = ALIGN(cap_info->total_size, PAGE_SIZE) / PAGE_SIZE; if (pages_needed == 0) { pr_err("invalid capsule size"); @@ -84,7 +59,6 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, return ret; } - cap_info->total_size = cap_info->header.imagesize; temp_page = krealloc(cap_info->pages, pages_needed * sizeof(void *), GFP_KERNEL | __GFP_ZERO); @@ -97,6 +71,30 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, } /** + * efi_capsule_setup_info - obtain the efi capsule header in the binary and + * setup capsule_info structure + * @cap_info: pointer to current instance of capsule_info structure + * @kbuff: a mapped first page buffer pointer + * @hdr_bytes: the total received number of bytes for efi header + * + * Platforms with non-standard capsule update mechanisms can override + * this __weak function so they can perform any required capsule + * image munging. See quark_quirk_function() for an example. + **/ +int __weak efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff, + size_t hdr_bytes) +{ + /* Only process data block that is larger than efi header size */ + if (hdr_bytes < sizeof(efi_capsule_header_t)) + return 0; + + memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); + cap_info->total_size = cap_info->header.imagesize; + + return __efi_capsule_setup_info(cap_info); +} + +/** * efi_capsule_submit_update - invoke the efi_capsule_update API once binary * upload done * @cap_info: pointer to current instance of capsule_info structure @@ -182,7 +180,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, /* Setup capsule binary info structure */ if (cap_info->header.headersize == 0) { - ret = efi_capsule_setup_info(cap_info, kbuff, + ret = efi_capsule_setup_info(cap_info, kbuff - cap_info->count, cap_info->count + write_byte); if (ret) goto fail_unmap; diff --git a/include/linux/efi.h b/include/linux/efi.h index ec36f42a2add..a7379a2b5680 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -137,6 +137,18 @@ struct efi_boot_memmap { #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE 0x00020000 #define EFI_CAPSULE_INITIATE_RESET 0x00040000 +struct capsule_info { + efi_capsule_header_t header; + int reset_type; + long index; + size_t count; + size_t total_size; + struct page **pages; + size_t page_bytes_remain; +}; + +int __efi_capsule_setup_info(struct capsule_info *cap_info); + /* * Allocation types for calls to boottime->allocate_pages. */