From patchwork Wed Aug 30 19:13:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 111343 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp1410633qge; Wed, 30 Aug 2017 12:14:46 -0700 (PDT) X-Received: by 10.98.33.24 with SMTP id h24mr2608007pfh.213.1504120486057; Wed, 30 Aug 2017 12:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504120486; cv=none; d=google.com; s=arc-20160816; b=wL8nLtKPX0qMopI2dmGG+l1QkZ83cGRX6ixVNaeMsp+5BKJF2K0HKRLxJoz6/fWKnh qyqwLWhk4yzSi81lgoW/qQYUDvB92Z6quWBlBYjwpfIjALG820H36eMGqZGa5X5fXbD5 WKGnCI+42XOwjGXmO951HGg0CvbQgETMSx2ojaycw748qLbeQF4fKS7Rc3DbqAGgq74t RacGBnb5eKZeRiFl47h3T2tibTdAdzgZcMrI/mq5GUeLUaslNpPIT+C9+JYCDlSlHfPn pRDV862KJ2jdSze9ZrLCsU6QPmIuU8Ner7pJ73nRlHorrgHvAQCFoU/LmGzGcV5y6R5q ONqA== 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=/vkx5dyXkOC49xCFjOBelqmaFHlZKq/UzKwfA3QgCyY=; b=nF8IbW8PkFFAC6Ge9/Ui8MEH++e5E3OVQQ1b1zPpqiYkXV1uoM8PC3fLeHpRTPPBOz tC7rvD6lSeLkTTxtASPxkZYnODcZcEN2SLPO740CEaooAWbFkUh1eTvXe74e9H+MwZzr nFglR4vj6nba2cwefWy7QiDjvt7aAu85iO+nQcWX9Hf1N5WoTF5+EBRT/38mSujvN/sS UTOsDP6x7Ihy6IKxCPIMKR1RROlHV3mXb3mnjlNrm15MrNzUbd3/qF3nwXXjotQKnZC9 NitkffZ43Hb4ewKSUzQmwAemBwjJKD6VrHkU4VQeOxcC/WXuOY69vGT8A0W90WwUBZpW 4RmA== 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.45; Wed, 30 Aug 2017 12:14:46 -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 S1750885AbdH3TOp (ORCPT + 2 others); Wed, 30 Aug 2017 15:14:45 -0400 Received: from goliath.siemens.de ([192.35.17.28]:55350 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750860AbdH3TOp (ORCPT ); Wed, 30 Aug 2017 15:14:45 -0400 Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id v7UJDwGb006371 (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 v7UJDvsA004213; Wed, 30 Aug 2017 21:13:58 +0200 From: Jan Kiszka To: Ben Hutchings Cc: cip-dev@lists.cip-project.org, Linus Torvalds , Peter Zijlstra , Thomas Gleixner , linux-efi@vger.kernel.org Subject: [PATCH 11/14] efi/capsule-loader: Use a cached copy of the capsule header Date: Wed, 30 Aug 2017 21:13:53 +0200 Message-Id: <77c3d7dfbafc5d23298ef751b68e3484d6939dae.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 82c3768b8d68c40ecde92338899c838b7c674ffb upstream. Instead of kmapping the capsule data twice, copy the capsule header into the capsule info struct we keep locally. This is an improvement by itself, but will also enable handling of non-standard header formats more easily. Signed-off-by: Ard Biesheuvel Reviewed-by: Matt Fleming Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20170602135207.21708-7-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/capsule-loader.c | 41 +++++++++++++++-------------------- 1 file changed, 17 insertions(+), 24 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 37d3f6ec2d28..5b012a467d7d 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -21,13 +21,13 @@ #define NO_FURTHER_WRITE_ACTION -1 struct capsule_info { - bool header_obtained; - int reset_type; - long index; - size_t count; - size_t total_size; - struct page **pages; - size_t page_bytes_remain; + 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; }; /** @@ -56,7 +56,6 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) static int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff, size_t hdr_bytes) { - efi_capsule_header_t *cap_hdr; size_t pages_needed; int ret; void *temp_page; @@ -66,8 +65,9 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, return 0; /* Reset back to the correct offset of header */ - cap_hdr = kbuff - cap_info->count; - pages_needed = ALIGN(cap_hdr->imagesize, PAGE_SIZE) >> PAGE_SHIFT; + kbuff -= cap_info->count; + memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); + pages_needed = ALIGN(cap_info->header.imagesize, PAGE_SIZE) / PAGE_SIZE; if (pages_needed == 0) { pr_err("invalid capsule size"); @@ -75,15 +75,16 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, } /* Check if the capsule binary supported */ - ret = efi_capsule_supported(cap_hdr->guid, cap_hdr->flags, - cap_hdr->imagesize, + ret = efi_capsule_supported(cap_info->header.guid, + cap_info->header.flags, + cap_info->header.imagesize, &cap_info->reset_type); if (ret) { pr_err("capsule not supported\n"); return ret; } - cap_info->total_size = cap_hdr->imagesize; + cap_info->total_size = cap_info->header.imagesize; temp_page = krealloc(cap_info->pages, pages_needed * sizeof(void *), GFP_KERNEL | __GFP_ZERO); @@ -91,7 +92,6 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, return -ENOMEM; cap_info->pages = temp_page; - cap_info->header_obtained = true; return 0; } @@ -104,15 +104,8 @@ static int efi_capsule_setup_info(struct capsule_info *cap_info, static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info) { int ret; - void *cap_hdr_temp; - cap_hdr_temp = vmap(cap_info->pages, cap_info->index, - VM_MAP, PAGE_KERNEL); - if (!cap_hdr_temp) - return -ENOMEM; - - ret = efi_capsule_update(cap_hdr_temp, cap_info->pages); - vunmap(cap_hdr_temp); + ret = efi_capsule_update(&cap_info->header, cap_info->pages); if (ret) { pr_err("capsule update failed\n"); return ret; @@ -192,7 +185,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, cap_info->page_bytes_remain -= write_byte; /* Setup capsule binary info structure */ - if (!cap_info->header_obtained) { + if (cap_info->header.headersize == 0) { ret = efi_capsule_setup_info(cap_info, kbuff, cap_info->count + write_byte); if (ret) @@ -203,7 +196,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, kunmap(page); /* Submit the full binary to efi_capsule_update() API */ - if (cap_info->header_obtained && + if (cap_info->header.headersize > 0 && cap_info->count >= cap_info->total_size) { if (cap_info->count > cap_info->total_size) { pr_err("capsule upload size exceeded header defined size\n");