linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org, will@kernel.org,
	catalin.marinas@arm.com, mark.rutland@arm.com,
	broonie@Kernel.org, Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 3/6] arm64: image: Add code size to the image header
Date: Tue,  4 Apr 2023 17:19:56 +0200	[thread overview]
Message-ID: <20230404151959.2774612-4-ardb@kernel.org> (raw)
In-Reply-To: <20230404151959.2774612-1-ardb@kernel.org>

In order for loaders to be able to create a preliminary mapping of the
image without having to rely on mappings that have both write and
execute permissions, it is necessary to expose the size of the leading
part of the image consisting of .text, .rodata and .inittext.

So add this information to the arm64 bare metal boot header.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 Documentation/arm64/booting.rst |  3 ++-
 arch/arm64/include/asm/image.h  |  3 ++-
 arch/arm64/kernel/head.S        |  3 ++-
 arch/arm64/kernel/image.h       | 10 +++++++---
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/Documentation/arm64/booting.rst b/Documentation/arm64/booting.rst
index ffeccdd6bdac9442..4d6966833c8c7472 100644
--- a/Documentation/arm64/booting.rst
+++ b/Documentation/arm64/booting.rst
@@ -79,7 +79,8 @@ The decompressed kernel image contains a 64-byte header as follows::
   u64 text_offset;		/* Image load offset, little endian */
   u64 image_size;		/* Effective Image size, little endian */
   u64 flags;			/* kernel flags, little endian */
-  u64 res2	= 0;		/* reserved */
+  u32 code_size;		/* Image code size, little endian */
+  u32 res2	= 0;		/* reserved */
   u64 res3	= 0;		/* reserved */
   u64 res4	= 0;		/* reserved */
   u32 magic	= 0x644d5241;	/* Magic number, little endian, "ARM\x64" */
diff --git a/arch/arm64/include/asm/image.h b/arch/arm64/include/asm/image.h
index c2b13213c7207c02..5361694c5a7b4956 100644
--- a/arch/arm64/include/asm/image.h
+++ b/arch/arm64/include/asm/image.h
@@ -47,7 +47,8 @@ struct arm64_image_header {
 	__le64 text_offset;
 	__le64 image_size;
 	__le64 flags;
-	__le64 res2;
+	__le32 code_size;
+	__le32 res2;
 	__le64 res3;
 	__le64 res4;
 	__le32 magic;
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index b98970907226b36c..8f684a2e8f05ac7e 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -62,7 +62,8 @@
 	.quad	0				// Image load offset from start of RAM, little-endian
 	le64sym	_kernel_size_le			// Effective size of kernel image, little-endian
 	le64sym	_kernel_flags_le		// Informative flags, little-endian
-	.quad	0				// reserved
+	.long	_kernel_codesize_le		// Size of leading text/rodata/inittext region, LE
+	.long	0				// reserved
 	.quad	0				// reserved
 	.quad	0				// reserved
 	.ascii	ARM64_IMAGE_MAGIC		// Magic number
diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h
index 7bc3ba8979019182..4c08409b2129d510 100644
--- a/arch/arm64/kernel/image.h
+++ b/arch/arm64/kernel/image.h
@@ -34,6 +34,9 @@
 #define DATA_LE32(data) ((data) & 0xffffffff)
 #endif
 
+#define DEFINE_IMAGE_LE32(sym, data)				\
+	sym = DATA_LE32((data) & 0xffffffff)
+
 #define DEFINE_IMAGE_LE64(sym, data)				\
 	sym##_lo32 = DATA_LE32((data) & 0xffffffff);		\
 	sym##_hi32 = DATA_LE32((data) >> 32)
@@ -60,8 +63,9 @@
  * regardless of the endianness of the kernel. While constant values could be
  * endian swapped in head.S, all are done here for consistency.
  */
-#define HEAD_SYMBOLS						\
-	DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text);	\
-	DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
+#define HEAD_SYMBOLS								\
+	DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text);			\
+	DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);			\
+	DEFINE_IMAGE_LE32(_kernel_codesize_le, __initdata_begin - _text);
 
 #endif /* __ARM64_KERNEL_IMAGE_H */
-- 
2.39.2


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

  parent reply	other threads:[~2023-04-04 15:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04 15:19 [PATCH 0/6] arm64/efi/zboot: Clean up and enable BTI annotation Ard Biesheuvel
2023-04-04 15:19 ` [PATCH 1/6] efi/pe: Import new BTI/IBT header flags from the spec Ard Biesheuvel
2023-04-04 15:19 ` [PATCH 2/6] arm64: efi: Enable BTI codegen and add PE/COFF annotation Ard Biesheuvel
2023-04-05 16:33   ` Mark Brown
2023-04-04 15:19 ` Ard Biesheuvel [this message]
2023-04-04 15:19 ` [PATCH 4/6] efi/zboot: Add BSS padding before compression Ard Biesheuvel
2023-04-04 15:19 ` [PATCH 5/6] efi/zboot: Set forward edge CFI compat header flag if supported Ard Biesheuvel
2023-04-04 15:19 ` [PATCH 6/6] efi/zboot: arm64: Grab code size from image header 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=20230404151959.2774612-4-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=broonie@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).