[PATCH] x86/realmode: Consolidate real-mode blob size calculation
From: Thorsten Blum
Date: Fri Nov 13 2026 - 18:34:57 EST
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@xxxxxxxxxx>
---
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@xxxxxxxxxx/
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