[PATCH 06/14] efi/capsule: Allocate whole capsule into virtual memory

Jan Kiszka

From: Austin Christ <austinwc@...>

commit 6862e6ad95e984991a6ceec592cf67831658f928 upstream.

According to UEFI 2.6 section 7.5.3, the capsule should be in contiguous
virtual memory and firmware may consume the capsule immediately. To
correctly implement this functionality, the kernel driver needs to vmap
the entire capsule at the time it is made available to firmware.

The virtual allocation of the capsule update has been changed from kmap,
which was only allocating the first page of the update, to vmap, and
allocates the entire data payload.

Signed-off-by: Austin Christ <austinwc@...>
Signed-off-by: Matt Fleming <matt@...>
Reviewed-by: Matt Fleming <matt@...>
Reviewed-by: Lee, Chun-Yi <jlee@...>
Cc: <stable@...> # v4.7
Cc: Andy Lutomirski <luto@...>
Cc: Ard Biesheuvel <ard.biesheuvel@...>
Cc: Borislav Petkov <bp@...>
Cc: Brian Gerst <brgerst@...>
Cc: Bryan O'Donoghue <pure.logic@...>
Cc: Denys Vlasenko <dvlasenk@...>
Cc: H. Peter Anvin <hpa@...>
Cc: Josh Poimboeuf <jpoimboe@...>
Cc: Kweh Hock Leong <hock.leong.kweh@...>
Cc: Linus Torvalds <torvalds@...>
Cc: Peter Zijlstra <peterz@...>
Cc: Thomas Gleixner <tglx@...>
Cc: linux-efi@...
Link: http://lkml.kernel.org/r/1470912120-22831-3-git-send-email-matt@codeblueprint.co.uk
Signed-off-by: Ingo Molnar <mingo@...>
drivers/firmware/efi/capsule-loader.c | 8 +++++---
drivers/firmware/efi/capsule.c | 6 +++---
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c
index c99c24bc79b0..9ae6c116c474 100644
--- a/drivers/firmware/efi/capsule-loader.c
+++ b/drivers/firmware/efi/capsule-loader.c
@@ -16,6 +16,7 @@
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/efi.h>
+#include <linux/vmalloc.h>


@@ -108,14 +109,15 @@ static ssize_t efi_capsule_submit_update(struct capsule_info *cap_info)
int ret;
void *cap_hdr_temp;

- cap_hdr_temp = kmap(cap_info->pages[0]);
+ cap_hdr_temp = vmap(cap_info->pages, cap_info->index,
if (!cap_hdr_temp) {
- pr_debug("%s: kmap() failed\n", __func__);
+ pr_debug("%s: vmap() failed\n", __func__);
return -EFAULT;

ret = efi_capsule_update(cap_hdr_temp, cap_info->pages);
- kunmap(cap_info->pages[0]);
+ vunmap(cap_hdr_temp);
if (ret) {
pr_err("%s: efi_capsule_update() failed\n", __func__);
return ret;
diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c
index 61e51249ef40..1106773468b2 100644
--- a/drivers/firmware/efi/capsule.c
+++ b/drivers/firmware/efi/capsule.c
@@ -194,9 +194,9 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule,
* map the capsule described by @capsule with its data in @pages and
* send it to the firmware via the UpdateCapsule() runtime service.
- * @capsule must be a virtual mapping of the first page in @pages
- * (@pages[0]) in the kernel address space. That is, a
- * capsule_header_t that describes the entire contents of the capsule
+ * @capsule must be a virtual mapping of the complete capsule update in the
+ * kernel address space, as the capsule can be consumed immediately.
+ * A capsule_header_t that describes the entire contents of the capsule
* must be at the start of the first data page.
* Even though this function will validate that the firmware supports