mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/realmode: Consolidate real-mode blob size calculation
@ 2026-11-13 23:33 Thorsten Blum
  0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-11-13 23:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Dexuan Cui, Mike Rapoport (Microsoft),
	Michael Kelley, Pratyush Yadav (Google),
	Yunhong Jiang
  Cc: Thorsten Blum, Ricardo Neri, linux-kernel

rmpiggy.S page-aligns both real_mode_blob and real_mode_blob_end. Their
difference is therefore already page-aligned and does not require
ALIGN() or PAGE_ALIGN().

Since the real-mode blob size is calculated in three different places,
add the real_mode_blob_size() helper and use it in
real_mode_size_needed(), setup_real_mode(), and
set_real_mode_permissions().

No functional change.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
This patch depends on the following patch, which has been acked by hpa
but hasn't been merged yet:
https://lore.kernel.org/r/20261108210215.407893-3-blum@kernel.org/

 arch/x86/include/asm/realmode.h | 8 +++++++-
 arch/x86/realmode/init.c        | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
index e406a1e92c63..ba377a5c4450 100644
--- a/arch/x86/include/asm/realmode.h
+++ b/arch/x86/include/asm/realmode.h
@@ -78,12 +78,18 @@ extern unsigned char secondary_startup_64[];
 extern unsigned char secondary_startup_64_no_verify[];
 #endif
 
+static __always_inline size_t real_mode_blob_size(void)
+{
+	/* rmpiggy.S page-aligns both ends of the blob. */
+	return real_mode_blob_end - real_mode_blob;
+}
+
 static __always_inline size_t real_mode_size_needed(void)
 {
 	if (real_mode_header)
 		return 0;	/* already allocated. */
 
-	return ALIGN(real_mode_blob_end - real_mode_blob, PAGE_SIZE);
+	return real_mode_blob_size();
 }
 
 static inline void set_real_mode_mem(phys_addr_t mem)
diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
index 65110b2ee1a1..23c5111ceea4 100644
--- a/arch/x86/realmode/init.c
+++ b/arch/x86/realmode/init.c
@@ -96,7 +96,7 @@ static void __init setup_real_mode(void)
 	unsigned char *base;
 	unsigned long phys_base;
 	struct trampoline_header *trampoline_header;
-	size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob);
+	size_t size = real_mode_blob_size();
 #ifdef CONFIG_X86_64
 	u64 *trampoline_pgd;
 	u64 efer;
@@ -187,7 +187,7 @@ static void __init setup_real_mode(void)
 static void __init set_real_mode_permissions(void)
 {
 	unsigned char *base = (unsigned char *) real_mode_header;
-	size_t size = PAGE_ALIGN(real_mode_blob_end - real_mode_blob);
+	size_t size = real_mode_blob_size();
 
 	size_t ro_size =
 		PAGE_ALIGN(real_mode_header->ro_end) -

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
prerequisite-patch-id: 65b53ab526487dba9029340376ea5a469c8a50dc

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-13 23:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 23:33 [PATCH] x86/realmode: Consolidate real-mode blob size calculation Thorsten Blum

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

all inboxes | Powered by JetHome®