From: Frediano Ziglio <freddy77@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: "Frediano Ziglio" <freddy77@gmail.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger@xenproject.org>,
"Teddy Astie" <teddy.astie@vates.tech>,
"Daniel P. Smith" <dpsmith@apertussolutions.com>,
"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
Subject: [PATCH 02/11] x86/boot: Avoid PE relocations in the trampoline
Date: Fri, 4 Dec 2026 20:50:35 +0000 [thread overview]
Message-ID: <20261204205045.596093-3-freddy77@gmail.com> (raw)
In-Reply-To: <20261204205045.596093-1-freddy77@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2026-12-04 20:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 20:50 [PATCH 00/11] x86/boot: Improve trampoline code Frediano Ziglio
2026-12-04 20:50 ` [PATCH 01/11] x86/boot: Prevent some possible firmware misbehaviour Frediano Ziglio
2026-12-04 20:50 ` Frediano Ziglio [this message]
2026-12-04 20:50 ` [PATCH 03/11] x86/boot: Check at build time that the trampoline needs no relocations Frediano Ziglio
2026-12-04 20:50 ` [PATCH 04/11] x86/boot: Reduce relocations in the trampoline Frediano Ziglio
2026-12-04 20:50 ` [PATCH 05/11] x86/boot: Share the switch to 64-bit mode between SIPI and S3 paths Frediano Ziglio
2026-12-04 20:50 ` [PATCH 06/11] x86/boot: Use stack to remove a relocation from trampoline code Frediano Ziglio
2026-12-04 20:50 ` [PATCH 07/11] x86/boot: Apply relocations in the trampoline after the copy Frediano Ziglio
2026-12-04 20:50 ` [PATCH 08/11] x86/boot: Group trampoline code and data using subsections Frediano Ziglio
2026-12-04 20:50 ` [PATCH 09/11] x86/boot: Use a writable copy of the trampoline data Frediano Ziglio
2026-12-04 20:50 ` [PATCH 10/11] x86/boot: Assemble the trampoline separately from head.S Frediano Ziglio
2026-12-04 20:50 ` [PATCH 11/11] x86/boot: Check the kind of symbols passed to the bootsym helpers Frediano Ziglio
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=20261204205045.596093-3-freddy77@gmail.com \
--to=freddy77@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=dpsmith@apertussolutions.com \
--cc=jbeulich@suse.com \
--cc=marmarek@invisiblethingslab.com \
--cc=roger@xenproject.org \
--cc=teddy.astie@vates.tech \
--cc=xen-devel@lists.xenproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.