[PATCH 1/2] efi/libstub/arm64: avoid copying the kernel unnecessarily

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the UEFI firmware has loaded the kernel at the right alignment, and
we are running a relocatable kernel, there is no point in copying the
kernel to a different place in memory, and instead, we can just run it
in place.

Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
 drivers/firmware/efi/libstub/arm64-stub.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index 9254cd8ab2d3..d263f504dcf0 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -104,6 +104,15 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
 					  (u32)phys_seed);
 
 		*image_addr = *reserve_addr + offset;
+	} else if (IS_ENABLED(CONFIG_RELOCATABLE) &&
+		   IS_ALIGNED((u64)_text - TEXT_OFFSET, EFI_KIMG_ALIGN)) {
+		/*
+		 * If we are relocatable and were loaded at a suitable offset,
+		 * there is no need to do anything and we can just execute in
+		 * place.
+		 */
+		*image_addr = (u64)_text;
+		return EFI_SUCCESS;
 	} else {
 		/*
 		 * Else, try a straight allocation at the preferred offset.
-- 
2.17.1




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux