From patchwork Wed Apr 5 09:23:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96798 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp173423qgd; Wed, 5 Apr 2017 02:23:54 -0700 (PDT) X-Received: by 10.99.130.193 with SMTP id w184mr28054696pgd.157.1491384234285; Wed, 05 Apr 2017 02:23:54 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si20066378pfg.225.2017.04.05.02.23.54; Wed, 05 Apr 2017 02:23:54 -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 S933038AbdDEJXs (ORCPT + 2 others); Wed, 5 Apr 2017 05:23:48 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:37008 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932632AbdDEJXn (ORCPT ); Wed, 5 Apr 2017 05:23:43 -0400 Received: by mail-wm0-f47.google.com with SMTP id x124so8377086wmf.0 for ; Wed, 05 Apr 2017 02:23:43 -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=alxxoFbPwvSxDrH1mzruD6c5Eas1tu9JSKFFxVouSNY=; b=Ze449Ktui7WWoAHwDv1hX5WF57qsG3yZ58vv2b0sNbpXr2cYrNoGSanqkL2hqMfwNR HWbbiMwoEejnwak2RHT2nTZo5EN8Xteu61HsdnLctmhSM5KBCKuYFsKWdoRj1/l0M3kK adNnKOmQ6nKhYOqjcUjGqWuUtG8E9nMeM7alA= 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=alxxoFbPwvSxDrH1mzruD6c5Eas1tu9JSKFFxVouSNY=; b=hXFl50OCIpw6SpGCb1kGamAlonYim9J21NE8ZNsgAGJsOojr0PPbyfRrN3uB6ykVIg xPMejUIhHFG9OKw0N8W6fKKGG4OH4HXRRCaYEyYpGd6uA6ENT5biBPShJuDNWvQUZJoq X3cmCvqZto/aagyqozPdLXFDgwQWuLPntV0u4tIDqpVNLFA8n0GE9Va9I/aNnnfBWhPN k8PyiBM8OXrc9WIEW9jxELaxP+klCP7r8AypGILeP1xrApTs8D2BRgQdrOuZYcvnj7ab zoxgQtutakxz8zFR24jmjSXXODCTctRzuNbXOU+Uc0lIOMqlJrPfNBdf31Xm/XS1GkzO nLbg== X-Gm-Message-State: AFeK/H1DiAWZDgxBA5FKgr11LdczMlIrD6dhoHiP/lWaOJxTGLMi5ohhh4n1ambhqNZPtTHH X-Received: by 10.28.14.138 with SMTP id 132mr12906568wmo.141.1491384222152; Wed, 05 Apr 2017 02:23:42 -0700 (PDT) Received: from localhost.localdomain ([160.163.145.113]) by smtp.gmail.com with ESMTPSA id b66sm23935271wrd.29.2017.04.05.02.23.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 02:23:41 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk, andy.shevchenko@gmail.com, pure.logic@nexus-software.ie, hock.leong.kweh@intel.com, bp@alien8.de, sascha.weisenberger@siemens.com, jan.kiszka@siemens.com, Ard Biesheuvel Subject: [PATCH 6/8] efi/capsule-loader: indirect calls to efi_capsule_setup_info via weak alias Date: Wed, 5 Apr 2017 10:23:15 +0100 Message-Id: <20170405092317.27921-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170405092317.27921-1-ard.biesheuvel@linaro.org> References: <20170405092317.27921-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 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. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 52 +++++++++----------- include/linux/efi.h | 12 +++++ 2 files changed, 35 insertions(+), 29 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 5b012a467d7d..d68a1ecebbf3 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,26 @@ 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 + **/ +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 +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. */