[v2,2/3] x86/realmode: add trampoline reference structure

Message ID 20221122163810.29752-3-jgross@suse.com
State New
Headers
Series x86/realmode: use a dummy trampoline for Xen PV guests |

Commit Message

Juergen Gross Nov. 22, 2022, 4:38 p.m. UTC
  Add a new struct trampoline_ref containing the relevant pointers for
handling the realmode trampoline. Use a central pointer for accessing
this new structure in preparation of adding support of replacing it
with a dummy trampoline.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/include/asm/realmode.h | 12 +++++++++++-
 arch/x86/realmode/init.c        | 13 +++++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)
  

Patch

diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
index 1eb3d4232e81..778d6cb1db6c 100644
--- a/arch/x86/include/asm/realmode.h
+++ b/arch/x86/include/asm/realmode.h
@@ -14,6 +14,13 @@ 
 #include <linux/types.h>
 #include <asm/io.h>
 
+/* Pointers for installing the realmode trampoline. */
+struct trampoline_ref {
+	unsigned char *blob;
+	unsigned char *blob_end;
+	unsigned char *relocs;
+};
+
 /* This must match data at realmode/rm/header.S */
 struct real_mode_header {
 	u32	text_start;
@@ -56,6 +63,8 @@  struct trampoline_header {
 };
 
 extern struct real_mode_header *real_mode_header;
+extern struct trampoline_ref *real_mode_trampoline __initdata;
+
 extern unsigned char real_mode_blob_end[];
 
 extern unsigned long initial_code;
@@ -78,7 +87,8 @@  extern unsigned char secondary_startup_64_no_verify[];
 
 static inline size_t real_mode_size_needed(void)
 {
-	return PAGE_ALIGN(real_mode_blob_end - real_mode_blob);
+	return PAGE_ALIGN(real_mode_trampoline->blob_end -
+			  real_mode_trampoline->blob);
 }
 
 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 37a3658efaa0..5a670a9ed2f7 100644
--- a/arch/x86/realmode/init.c
+++ b/arch/x86/realmode/init.c
@@ -12,6 +12,15 @@ 
 #include <asm/sev.h>
 
 struct real_mode_header *real_mode_header;
+
+static __initdata struct trampoline_ref realmode_trampoline = {
+	.blob = real_mode_blob,
+	.blob_end = real_mode_blob_end,
+	.relocs = real_mode_relocs,
+};
+
+struct trampoline_ref *real_mode_trampoline __initdata = &realmode_trampoline;
+
 u32 *trampoline_cr4_features;
 
 /* Hold the pgd entry used on booting additional CPUs */
@@ -111,12 +120,12 @@  static void __init setup_real_mode(void)
 	if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
 		set_memory_decrypted((unsigned long)base, size >> PAGE_SHIFT);
 
-	memcpy(base, real_mode_blob, size);
+	memcpy(base, real_mode_trampoline->blob, size);
 
 	phys_base = __pa(base);
 	real_mode_seg = phys_base >> 4;
 
-	rel = (u32 *) real_mode_relocs;
+	rel = (u32 *) real_mode_trampoline->relocs;
 
 	/* 16-bit segment relocations. */
 	count = *rel++;