From: tip-bot for Ard Biesheuvel <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: ard.biesheuvel@linaro.org, matt@codeblueprint.co.uk,
hpa@zytor.com, mingo@kernel.org, torvalds@linux-foundation.org,
tglx@linutronix.de, linux-kernel@vger.kernel.org,
peterz@infradead.org
Subject: [tip:efi/core] efi/capsule-loader: Use a cached copy of the capsule header
Date: Mon, 5 Jun 2017 10:12:38 -0700 [thread overview]
Message-ID: <tip-82c3768b8d68c40ecde92338899c838b7c674ffb@git.kernel.org> (raw)
In-Reply-To: <20170602135207.21708-7-ard.biesheuvel@linaro.org>
Commit-ID: 82c3768b8d68c40ecde92338899c838b7c674ffb
Gitweb: http://git.kernel.org/tip/82c3768b8d68c40ecde92338899c838b7c674ffb
Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
AuthorDate: Fri, 2 Jun 2017 13:52:00 +0000
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 5 Jun 2017 17:50:40 +0200
efi/capsule-loader: Use a cached copy of the capsule header
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 <ard.biesheuvel@linaro.org>
Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20170602135207.21708-7-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
drivers/firmware/efi/capsule-loader.c | 41 +++++++++++++++--------------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c
index 37d3f6e..5b012a4 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");
next prev parent reply other threads:[~2017-06-05 17:17 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-02 13:51 [GIT PULL 00/13] First batch of EFI updates for v4.13 Ard Biesheuvel
2017-06-02 13:51 ` [PATCH 01/13] x86/efi: Clean up efi CR3 save/restore Ard Biesheuvel
2017-06-05 15:40 ` Ingo Molnar
2017-06-05 16:03 ` Ard Biesheuvel
2017-06-05 16:14 ` Andy Lutomirski
2017-06-02 13:51 ` [PATCH 02/13] efi/capsule: Fix return code on failing kmap/vmap Ard Biesheuvel
2017-06-05 17:10 ` [tip:efi/core] " tip-bot for Jan Kiszka
2017-06-02 13:51 ` [PATCH 03/13] efi/capsule: Remove pr_debug on ENOMEM or EFAULT Ard Biesheuvel
2017-06-05 17:10 ` [tip:efi/core] efi/capsule: Remove pr_debug() " tip-bot for Jan Kiszka
2017-06-02 13:51 ` [PATCH 04/13] efi/capsule: Clean up pr_err/info messages Ard Biesheuvel
2017-06-05 17:11 ` [tip:efi/core] efi/capsule: Clean up pr_err/_info() messages tip-bot for Jan Kiszka
2017-06-02 13:51 ` [PATCH 05/13] efi/capsule: Adjust return type of efi_capsule_setup_info Ard Biesheuvel
2017-06-05 17:12 ` [tip:efi/core] efi/capsule: Adjust return type of efi_capsule_setup_info() tip-bot for Jan Kiszka
2017-06-02 13:52 ` [PATCH 06/13] efi/capsule-loader: Use a cached copy of the capsule header Ard Biesheuvel
2017-06-05 17:12 ` tip-bot for Ard Biesheuvel [this message]
2017-06-02 13:52 ` [PATCH 07/13] efi/capsule: Remove NULL test on kmap() Ard Biesheuvel
2017-06-05 17:13 ` [tip:efi/core] " tip-bot for Fabian Frederick
2017-06-02 13:52 ` [PATCH 08/13] efi/capsule-loader: Redirect calls to efi_capsule_setup_info via weak alias Ard Biesheuvel
2017-06-05 17:13 ` [tip:efi/core] efi/capsule-loader: Redirect calls to efi_capsule_setup_info() " tip-bot for Ard Biesheuvel
2017-06-02 13:52 ` [PATCH 09/13] efi/capsule-loader: Use page addresses rather than struct page pointers Ard Biesheuvel
2017-06-05 17:14 ` [tip:efi/core] " tip-bot for Ard Biesheuvel
2017-06-02 13:52 ` [PATCH 10/13] efi/capsule: Add support for Quark security header Ard Biesheuvel
2017-06-05 15:50 ` Ingo Molnar
2017-06-05 16:00 ` Ard Biesheuvel
2017-06-05 16:11 ` Ingo Molnar
2017-06-05 17:14 ` [tip:efi/core] " tip-bot for Jan Kiszka
2017-06-02 13:52 ` [PATCH 11/13] efi/efi_test: Use memdup_user() helper Ard Biesheuvel
2017-06-05 17:15 ` [tip:efi/core] " tip-bot for Geliang Tang
2017-06-02 13:52 ` [PATCH 12/13] x86/efi: Add EFI_PGT_DUMP support for x86_32 and kexec Ard Biesheuvel
2017-06-05 17:16 ` [tip:efi/core] x86/efi: Extend CONFIG_EFI_PGT_DUMP support to x86_32 and kexec as well tip-bot for Sai Praneeth
2017-06-02 13:52 ` [PATCH 13/13] efi: arm: enable DMI/SMBIOS Ard Biesheuvel
2017-06-05 17:16 ` [tip:efi/core] efi/arm: Enable DMI/SMBIOS tip-bot for Ard Biesheuvel
2017-06-05 8:15 ` [GIT PULL 00/13] First batch of EFI updates for v4.13 Ard Biesheuvel
2017-06-05 9:07 ` Ingo Molnar
2017-06-05 9:35 ` Ard Biesheuvel
2017-06-05 15:53 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-82c3768b8d68c40ecde92338899c838b7c674ffb@git.kernel.org \
--to=tipbot@zytor.com \
--cc=ard.biesheuvel@linaro.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=matt@codeblueprint.co.uk \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox