From patchwork Wed Aug 30 19:13:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 111342 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp1410443qge; Wed, 30 Aug 2017 12:14:36 -0700 (PDT) X-Received: by 10.99.42.203 with SMTP id q194mr2481371pgq.378.1504120476822; Wed, 30 Aug 2017 12:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504120476; cv=none; d=google.com; s=arc-20160816; b=tt8TgtZnjsnKDKbXuA1jpPItY0FSvsrRNOrIJUgNoMsQnIrw/pLc3Bz6AqSEishDEz CbmoHOXnj7zJXHTxSwlDKTqraZd31m0/3gMf03W61kP6q/wAxE9bK3fis8YX5NwNPn8t k9twRLCGVGuYB5k63xDVJLu0WEXApvipcraNXYnADcmaWcg6fGtfyhkFYHNWD7ZMTK2Z 7ljJv71pRzDWpEsKJD7kmgUFnoiNH0h9FkFcAd0cClJsdYNpJh83iuvnb4ob72+RsmsT c0kSlHr+4KtjGolDTnt6aMeYvXAjGYyJF7NC5mqXFKGbQ4EljmQPHFhipUy0z3RPeCB0 iXEg== 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:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=GNx9QMUzUuaqR+/FPZMfhKsEFOmUxTJ0g+jkS+7G+XA=; b=qwg0OL8LvE0OEe9Ov3jxwseIHwUEJmg51kIQ6ZZd1zLIaAlTgoD+CFXCjo1NodZ6Vc YoCKumy4TAZfMDDWAL4d9J7yWc9PLXAsgpqKWeC2FjEhJTN+rI+ICE6vG0hwu0H0vvj0 4QQelpwgRgkTVOopuR1n5ihvoJtExgVoH3NWw3U/P/EKGPqnOb//QcHJzcn1z6tNhRjG th/LwpJPVdHkON9gsWEiQn/grjK7tTW06/vZsa4QAvvgYYpMHsaagESxCpZoXueF66Ge 8gzdEHoxfL3tmkQuNQiKoUYTB1PAtUi5PNkZjm1v4VQ57xj4MHVk2m2sFfYB3e+7bJY/ FiHg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i188si2899624pgc.79.2017.08.30.12.14.36; Wed, 30 Aug 2017 12:14:36 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750814AbdH3TOg (ORCPT + 2 others); Wed, 30 Aug 2017 15:14:36 -0400 Received: from david.siemens.de ([192.35.17.14]:48989 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750794AbdH3TOf (ORCPT ); Wed, 30 Aug 2017 15:14:35 -0400 Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id v7UJDwg5025196 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Aug 2017 21:13:58 +0200 Received: from md1f2u6c.ww002.siemens.net.net ([139.25.68.37]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id v7UJDvsB004213; Wed, 30 Aug 2017 21:13:58 +0200 From: Jan Kiszka To: Ben Hutchings Cc: cip-dev@lists.cip-project.org, Linus Torvalds , Matt Fleming , Peter Zijlstra , Thomas Gleixner , linux-efi@vger.kernel.org Subject: [PATCH 12/14] efi/capsule-loader: Redirect calls to efi_capsule_setup_info() via weak alias Date: Wed, 30 Aug 2017 21:13:54 +0200 Message-Id: <643351f334592960d2fa1a2d2eecf9c8df25745f.1504120436.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Ard Biesheuvel commit 3fabd628d5ea24b02ddb1230ffca1df0f779f84e upstream. 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. Tested-by: Bryan O'Donoghue Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Matt Fleming Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20170602135207.21708-9-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/capsule-loader.c | 56 +++++++++++++++++------------------ include/linux/efi.h | 12 ++++++++ 2 files changed, 39 insertions(+), 29 deletions(-) -- 2.12.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 5b012a467d7d..f7fdeab0bc37 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 @@ -186,7 +184,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 5a0b8f7a54c8..b386097e45bc 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -129,6 +129,18 @@ typedef struct { #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. */