All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
	linux-efi@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 1/2] efi/libstub/arm64: avoid copying the kernel unnecessarily
Date: Thu, 26 Mar 2020 17:59:04 +0100	[thread overview]
Message-ID: <20200326165905.2240-2-ardb@kernel.org> (raw)
In-Reply-To: <20200326165905.2240-1-ardb@kernel.org>

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@kernel.org>
---
 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


WARNING: multiple messages have this Message-ID (diff)
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: mark.rutland@arm.com, catalin.marinas@arm.com,
	linux-efi@vger.kernel.org, will@kernel.org,
	Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 1/2] efi/libstub/arm64: avoid copying the kernel unnecessarily
Date: Thu, 26 Mar 2020 17:59:04 +0100	[thread overview]
Message-ID: <20200326165905.2240-2-ardb@kernel.org> (raw)
In-Reply-To: <20200326165905.2240-1-ardb@kernel.org>

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@kernel.org>
---
 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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-03-26 16:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26 16:59 [PATCH 0/2] efi/arm64: execute the kernel in place if possible Ard Biesheuvel
2020-03-26 16:59 ` Ard Biesheuvel
2020-03-26 16:59 ` Ard Biesheuvel [this message]
2020-03-26 16:59   ` [PATCH 1/2] efi/libstub/arm64: avoid copying the kernel unnecessarily Ard Biesheuvel
2020-03-26 16:59 ` [PATCH 2/2] efi/arm64: increase the PE/COFF alignment so the kernel can run in place Ard Biesheuvel
2020-03-26 16:59   ` Ard Biesheuvel
2020-03-28 14:06   ` Arvind Sankar
2020-03-28 14:06     ` Arvind Sankar
2020-03-28 14:10     ` Ard Biesheuvel
2020-03-28 14:10       ` Ard Biesheuvel
2020-03-27 13:19 ` [PATCH 0/2] efi/arm64: execute the kernel in place if possible Jonathan Cameron
2020-03-27 13:19   ` Jonathan Cameron
2020-03-27 16:39   ` Ard Biesheuvel
2020-03-27 16:39     ` Ard Biesheuvel

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=20200326165905.2240-2-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=will@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.