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>
Subject: [PATCH 05/11] x86/boot: Share the switch to 64-bit mode between SIPI and S3 paths
Date: Fri, 4 Dec 2026 20:50:38 +0000 [thread overview]
Message-ID: <20261204205045.596093-6-freddy77@gmail.com> (raw)
In-Reply-To: <20261204205045.596093-1-freddy77@gmail.com>
The S3 wakeup path duplicated the protected mode to 64-bit mode switch
of the SIPI path: CR4, CR3, IA32_MISC_ENABLE, PAT, EFER and CR0 are set
up the same way, with the same values (0x80050033 is the same CR0 value
the SIPI path builds from the X86_CR0_* constants).
Move this into common_64, entered with DS set to BOOT_DS_TRAMP and EBP
pointing to the 64-bit address to jump to, which is the only difference
left between the two paths. The S3 data is moved after the code.
There are two functional changes for S3:
- The FPU is now initialised, as on the SIPI path. Firmware can leave
it in any state, and the old code even had a "fpu init?" note.
- WBINVD before enabling paging is dropped. Caches are flushed with
ACPI_FLUSH_CPU_CACHE() before entering S3, and CR0.CD/NW are already
cleared by the first write to CR0 in real mode, so caches are enabled
with nothing stale to write back. The SIPI path, which has the same
requirements, never had it.
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
---
xen/arch/x86/boot/trampoline.S | 38 ++++++++++++++++---
xen/arch/x86/boot/wakeup.S | 69 +++++-----------------------------
2 files changed, 41 insertions(+), 66 deletions(-)
diff --git a/xen/arch/x86/boot/trampoline.S b/xen/arch/x86/boot/trampoline.S
index c34ca9beae..c52c27795d 100644
--- a/xen/arch/x86/boot/trampoline.S
+++ b/xen/arch/x86/boot/trampoline.S
@@ -59,10 +59,20 @@ GLOBAL(entry_SIPI16)
.code32
trampoline_protmode_entry:
+ mov $bootsym(high_start_address), %ebp
+
/* Set up a few descriptors: on entry only CS is guaranteed good. */
mov $BOOT_DS_TRAMP, %eax
mov %eax,%ds
+ /*
+ * Common path to 64-bit mode, used by SIPI and S3.
+ * On entry:
+ * - DS is BOOT_DS_TRAMP;
+ * - EBP is the trampoline offset of the 64-bit address to jump to;
+ * - EBX is passed on unchanged.
+ */
+common_64:
/* Set up FPU. */
fninit
@@ -101,26 +111,42 @@ trampoline_protmode_entry:
or bootsym(trampoline_efer), %eax
wrmsr
+ /* Enable paging */
mov $(X86_CR0_PG | X86_CR0_AM | X86_CR0_WP | X86_CR0_NE |\
X86_CR0_ET | X86_CR0_MP | X86_CR0_PE), %eax
mov %eax,%cr0
- /* Now in compatibility mode. Long-jump into 64-bit mode. */
- mov $BOOT_DS, %eax
- mov %eax, %ds
- mov %eax, %es
+ /*
+ * Now in compatibility mode. Load the target address before
+ * switching DS: (%ebp) would use SS, which isn't set up on the SIPI
+ * path.
+ */
+ mov %ebp, %eax
+ mov 4(%eax), %edx
+ mov (%eax), %eax
+
+ /* Load correct selectors */
+ mov $BOOT_DS, %ecx
+ mov %ecx, %ds
+ mov %ecx, %es
+
+ /* Long-jump into 64-bit mode. */
ljmp $BOOT_CS64,$bootsym_rel(start64,6)
.code64
start64:
+ movl %eax, %eax
+ shl $32, %rdx
+ or %rdx, %rax
/* Jump to high mappings. */
- movabs $(abs___high_start + XEN_VIRT_START), %rdi
- jmpq *%rdi
+ jmpq *%rax
#include "video.h"
#include "wakeup.S"
.balign 8
+high_start_address:
+ .quad abs___high_start + XEN_VIRT_START
.word 0
idt_48: .word 0, 0, 0 # base = limit = 0
diff --git a/xen/arch/x86/boot/wakeup.S b/xen/arch/x86/boot/wakeup.S
index 6d24ab2bdd..ecbf2852d8 100644
--- a/xen/arch/x86/boot/wakeup.S
+++ b/xen/arch/x86/boot/wakeup.S
@@ -101,12 +101,6 @@ bogus_real_magic:
movw $0x0e00 + 'B', %fs:(0x12)
jmp 1b
- .align 4
-real_magic: .long 0x12345678
-video_mode: .word 0
-GLOBAL(video_flags)
- .byte 0
-
.code32
# Now in protect mode, with paging disabled
@@ -126,64 +120,19 @@ wakeup_32:
mov %ss:(%eax), %eax
cmp $0x9abcdef0, %eax
jne bogus_saved_magic
-
- /* fpu init? */
-
- /* Initialise CR4. */
- mov $X86_CR4_PAE, %ecx
- mov %ecx, %cr4
-
- /* Load pagetable base register */
- mov $abs_idle_pg_table, %eax
- add bootsym(trampoline_xen_phys_start), %eax
- mov %eax,%cr3
-
- /* Reapply IA32_MISC_ENABLE modifications from early_init_intel(). */
- mov bootsym(trampoline_misc_enable_off), %esi
- mov bootsym(trampoline_misc_enable_off + 4), %edi
- mov %esi, %eax
- or %edi, %eax
- jz 1f
- mov $MSR_IA32_MISC_ENABLE, %ecx
- rdmsr
- not %esi
- not %edi
- and %esi, %eax
- and %edi, %edx
- wrmsr
-1:
- /* Set up PAT before enabling paging. */
- mov $XEN_MSR_PAT & 0xffffffff, %eax
- mov $XEN_MSR_PAT >> 32, %edx
- mov $MSR_IA32_CR_PAT, %ecx
- wrmsr
-
- /* Set up EFER (Extended Feature Enable Register). */
- movl $MSR_EFER,%ecx
- rdmsr
- or bootsym(trampoline_efer), %eax
- wrmsr
-
- wbinvd
-
- /* Enable paging and flush prefetch queue */
- mov $0x80050033,%eax /* hi-to-lo: PG,AM,WP,NE,ET,MP,PE */
- mov %eax,%cr0
- jmp 1f
-1:
- /* Now in compatibility mode. Long-jump to 64-bit mode */
- mov $BOOT_DS, %eax
- mov %eax, %ds
- ljmp $BOOT_CS64, $bootsym_rel(wakeup_64,6)
+ mov $bootsym(s3_start_address), %ebp
+ jmp common_64
FUNC_LOCAL(bogus_saved_magic, 0)
movw $0x0e00 + 'S', %ss:0xb8014
jmp bogus_saved_magic
END(bogus_saved_magic)
- .code64
-wakeup_64:
- /* Jump to high mappings and the higher-level wakeup code. */
- movabs $(abs_s3_resume + XEN_VIRT_START), %rbx
- jmp *%rbx
+ .align 8
+s3_start_address:
+ .quad abs_s3_resume + XEN_VIRT_START
+real_magic: .long 0x12345678
+video_mode: .word 0
+GLOBAL(video_flags)
+ .byte 0
--
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 ` [PATCH 02/11] x86/boot: Avoid PE relocations in the trampoline Frediano Ziglio
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 ` Frediano Ziglio [this message]
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-6-freddy77@gmail.com \
--to=freddy77@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.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.