[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 02/11] x86/boot: Avoid PE relocations in the trampoline



Use linker script to generate absolute symbols which do not
need relocations in the final binary.

In debug mode check the trampoline has no relocations for PE
executables.

This avoids having to write into text section for relocating to higher
addresses.

Signed-off-by: Frediano Ziglio <freddy77@xxxxxxxxx>
---
 xen/arch/x86/boot/trampoline.S |  4 ++--
 xen/arch/x86/boot/wakeup.S     |  6 +++---
 xen/arch/x86/efi/efi-boot.h    |  8 ++++++++
 xen/arch/x86/xen.lds.S         | 15 +++++++++++++++
 4 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/xen/arch/x86/boot/trampoline.S b/xen/arch/x86/boot/trampoline.S
index a92e399fbe..0be6fe0006 100644
--- a/xen/arch/x86/boot/trampoline.S
+++ b/xen/arch/x86/boot/trampoline.S
@@ -72,7 +72,7 @@ trampoline_protmode_entry:
         mov     %ecx,%cr4
 
         /* Load pagetable base register. */
-        mov     $sym_offs(idle_pg_table),%eax
+        mov     $abs_idle_pg_table, %eax
         add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
         mov     %eax,%cr3
 
@@ -112,7 +112,7 @@ trampoline_protmode_entry:
         .code64
 start64:
         /* Jump to high mappings. */
-        movabs  $__high_start, %rdi
+        movabs  $(abs___high_start + XEN_VIRT_START), %rdi
         jmpq    *%rdi
 
 #include "video.h"
diff --git a/xen/arch/x86/boot/wakeup.S b/xen/arch/x86/boot/wakeup.S
index 1f5af77745..fb9b3da205 100644
--- a/xen/arch/x86/boot/wakeup.S
+++ b/xen/arch/x86/boot/wakeup.S
@@ -116,7 +116,7 @@ wakeup_32:
         mov     $bootsym_rel(wakeup_stack, 4, %esp)
 
         # check saved magic again
-        mov     $sym_offs(saved_magic),%eax
+        mov     $abs_saved_magic, %eax
         add     bootsym_rel(trampoline_xen_phys_start, 4, %eax)
         mov     (%eax), %eax
         cmp     $0x9abcdef0, %eax
@@ -129,7 +129,7 @@ wakeup_32:
         mov     %ecx, %cr4
 
         /* Load pagetable base register */
-        mov     $sym_offs(idle_pg_table),%eax
+        mov     $abs_idle_pg_table, %eax
         add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
         mov     %eax,%cr3
 
@@ -178,5 +178,5 @@ END(bogus_saved_magic)
         .code64
 wakeup_64:
         /* Jump to high mappings and the higher-level wakeup code. */
-        movabs  $s3_resume, %rbx
+        movabs  $(abs_s3_resume + XEN_VIRT_START), %rbx
         jmp     *%rbx
diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 8bca03a66b..2baecb20b4 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -82,6 +82,14 @@ static void __init efi_arch_relocate_image(unsigned long 
delta)
             unsigned long addr = xen_phys_start + base_relocs->rva +
                                  (base_relocs->entries[i] & 0xfff);
 
+#ifdef CONFIG_DEBUG
+            char *pp = (char *) addr;
+
+            if ( (base_relocs->entries[i] >> 12) != PE_BASE_RELOC_ABS &&
+                 pp >= trampoline_start && pp < trampoline_end )
+                blexit(L"Relocations in trampoline");
+#endif
+
             switch ( base_relocs->entries[i] >> 12 )
             {
             case PE_BASE_RELOC_ABS:
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index e25863f331..9d8da60455 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -328,6 +328,21 @@ SECTIONS
   } PHDR(text)
   _end = . ;
 
+  /*
+   * Symbols used by the trampoline, as offsets from the start of the image.
+   *
+   * Being absolute, references to them are fully resolved at link time and
+   * don't produce base relocations in the PE binary, so the trampoline (which
+   * is in a text section) doesn't need to be written to when Xen is relocated.
+   *
+   * 32-bit unpaged code has to add trampoline_xen_phys_start to get a physical
+   * address, 64-bit code has to add XEN_VIRT_START to get a virtual one.
+   */
+  abs_idle_pg_table = ABSOLUTE(idle_pg_table - __XEN_VIRT_START);
+  abs_saved_magic = ABSOLUTE(saved_magic - __XEN_VIRT_START);
+  abs_s3_resume = ABSOLUTE(s3_resume - __XEN_VIRT_START);
+  abs___high_start = ABSOLUTE(__high_start - __XEN_VIRT_START);
+
   __2M_rwdata_end = ALIGN(SECTION_ALIGN);
 
 #ifdef EFI
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.