From: Thorsten Blum <blum@kernel.org>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Dexuan Cui <decui@microsoft.com>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
Michael Kelley <mhklinux@outlook.com>,
"Pratyush Yadav (Google)" <pratyush@kernel.org>,
Yunhong Jiang <yunhong.jiang@linux.intel.com>
Cc: Thorsten Blum <blum@kernel.org>,
Ricardo Neri <ricardo.neri-calderon@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] x86/realmode: Consolidate real-mode blob size calculation
Date: Sat, 14 Nov 2026 00:33:04 +0100 [thread overview]
Message-ID: <20261113233306.4295-3-blum@kernel.org> (raw)
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
reply other threads:[~2026-11-13 23:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261113233306.4295-3-blum@kernel.org \
--to=blum@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhklinux@outlook.com \
--cc=mingo@redhat.com \
--cc=pratyush@kernel.org \
--cc=ricardo.neri-calderon@linux.intel.com \
--cc=rppt@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=yunhong.jiang@linux.intel.com \
/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
all inboxes | Powered by JetHome®