Linux EFI development
 help / color / mirror / Atom feed
* [PATCH] efi/capsule-loader: Replace kmap() with kmap_local_page()
@ 2026-09-04 15:31 Danish Khateeb
  2026-09-10  7:38 ` Ard Biesheuvel
  0 siblings, 1 reply; 2+ messages in thread
From: Danish Khateeb @ 2026-09-04 15:31 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: Ilias Apalodimas, linux-efi, linux-kernel, Danish Khateeb

kmap() is deprecated in favour of kmap_local_page(), as described in
Documentation/mm/highmem.rst.

The conversion is safe here. efi_capsule_write() maps the page and
releases it within the same call, on both the success and the fail_unmap
error path, so the mapping never escapes the thread that created it and
the stack-based unmap ordering is preserved. No atomic context is
involved: the page is allocated with alloc_page(GFP_KERNEL) just above,
and the copy_from_user() performed while the page is mapped is fine
because faults are permitted in a local kmap region.
efi_capsule_setup_info() also runs while the mapping is live, but only
reads through the pointer.

kunmap_local() is handed a pointer that has been advanced into the page,
which is fine as it masks the address back down to the page boundary.

Build-tested only, on i386 with CONFIG_HIGHMEM=y -- where
kmap_local_page() actually establishes a mapping rather than returning
the direct-map address -- and on x86_64. No new gcc or sparse warnings.

Assisted-by: LLM sparse
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
---
 drivers/firmware/efi/capsule-loader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c
index 8e8f81f0a5a0..e423df3438da 100644
--- a/drivers/firmware/efi/capsule-loader.c
+++ b/drivers/firmware/efi/capsule-loader.c
@@ -197,7 +197,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff,
 		page = cap_info->pages[cap_info->index - 1];
 	}
 
-	kbuff = kmap(page);
+	kbuff = kmap_local_page(page);
 	kbuff += PAGE_SIZE - cap_info->page_bytes_remain;
 
 	/* Copy capsule binary data from user space to kernel space buffer */
@@ -217,7 +217,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff,
 	}
 
 	cap_info->count += write_byte;
-	kunmap(page);
+	kunmap_local(kbuff);
 
 	/* Submit the full binary to efi_capsule_update() API */
 	if (cap_info->header.headersize > 0 &&
@@ -236,7 +236,7 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff,
 	return write_byte;
 
 fail_unmap:
-	kunmap(page);
+	kunmap_local(kbuff);
 failed:
 	efi_free_all_buff_pages(cap_info);
 	return ret;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] efi/capsule-loader: Replace kmap() with kmap_local_page()
  2026-09-04 15:31 [PATCH] efi/capsule-loader: Replace kmap() with kmap_local_page() Danish Khateeb
@ 2026-09-10  7:38 ` Ard Biesheuvel
  0 siblings, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2026-09-10  7:38 UTC (permalink / raw)
  To: Danish Khateeb; +Cc: Ilias Apalodimas, linux-efi, linux-kernel


On Fri, 4 Sep 2026, at 17:31, Danish Khateeb wrote:
> kmap() is deprecated in favour of kmap_local_page(), as described in
> Documentation/mm/highmem.rst.
>
> The conversion is safe here. efi_capsule_write() maps the page and
> releases it within the same call, on both the success and the fail_unmap
> error path, so the mapping never escapes the thread that created it and
> the stack-based unmap ordering is preserved. No atomic context is
> involved: the page is allocated with alloc_page(GFP_KERNEL) just above,
> and the copy_from_user() performed while the page is mapped is fine
> because faults are permitted in a local kmap region.
> efi_capsule_setup_info() also runs while the mapping is live, but only
> reads through the pointer.
>
> kunmap_local() is handed a pointer that has been advanced into the page,
> which is fine as it masks the address back down to the page boundary.
>
> Build-tested only, on i386 with CONFIG_HIGHMEM=y -- where
> kmap_local_page() actually establishes a mapping rather than returning
> the direct-map address -- and on x86_64. No new gcc or sparse warnings.
>
> Assisted-by: LLM sparse
> Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
> ---
>  drivers/firmware/efi/capsule-loader.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>

Queued up in efi/next - thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-10  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 15:31 [PATCH] efi/capsule-loader: Replace kmap() with kmap_local_page() Danish Khateeb
2026-09-10  7:38 ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox