From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1D1F606A330 for ; Fri, 4 Dec 2026 20:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=l2Tvizms Received: from list by lists.xenproject.org with outflank-mailman.1514950.1705660 (Exim 4.92) (envelope-from ) id 1xZaFA-0004Qq-6n; Fri, 04 Dec 2026 20:51:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1514950.1705660; Fri, 04 Dec 2026 20:51:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaF9-0004PP-UO; Fri, 04 Dec 2026 20:50:59 +0000 Received: by outflank-mailman (input) for mailman id 1514950; Fri, 04 Dec 2026 20:50:59 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaF9-0004Bb-1Z for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 20:50:59 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xZaF8-001bMw-Eh for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 21:50:58 +0100 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b132796-8faa-0a2a0a5109dd-0a2a4501ca56-14 for ; Fri, 04 Dec 2026 21:50:58 +0100 Received: from [209.85.221.49] (helo=mail-wr1-f49.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b1327b2-5bcc-0a2a45010019-d155dd31e128-3 for ; Fri, 04 Dec 2026 21:50:58 +0100 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-48dee593f18so1394030f8f.3 for ; Fri, 04 Dec 2026 12:50:58 -0800 (PST) Received: from localhost.localdomain (89.246.200.146.dyn.plus.net. [146.200.246.89]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17426821asm6895228f8f.45.2026.12.04.12.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:50:57 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796417458; x=1797022258; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pV/j8CwxnJoSQXnEI/4W/6kDoWx6N+5awiytpzPLoHA=; b=l2TvizmsrGXOFLTsaD/KnfJFffVVrzWkEg9UV/9nq6ODrUdIDT6wkl7txfyCL7K4yU 0x6d+NQZhpUQo6Ukz08bmOc4YQcKfA45rHZZ4ySJ6ia/39OeTQdR84o2dd6Kw01GH/r7 3DBeggq0rw1fyIWOPNLZFtHO2r53Idc30k8F8gq8DnMumAbcEh47WcPnyQhzWC8GiAdY 5Nb58/+w/oJ+yZEuMTXUasIo3zq/3T7Y6Xr8PppEI0NxELwlTAfpcIAYg2RcqhRIxukb 1IVMfgr+JL+2EQTjKxn4lw9FJX7NIpayuuygO4MYvJix8DRyOXIUQMMPaIrP39qlGgdT yaDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417458; x=1797022258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pV/j8CwxnJoSQXnEI/4W/6kDoWx6N+5awiytpzPLoHA=; b=gywmmgdidLgA6r25wIGu54A7DSV8iOEPMQRmyCwpNd04wh3UC9EohYc0ZypTeL6Fh9 MTBWk4R9tuuJhsYuYDF67y4o1lbgookre1Mf9TNcBdFYrb2JB13b3XUtDihOYRqBPIvw x/mYElWhZ6xefkW6fzArvsF8pOAZUhrhT/x8NOAI2jjbN/FKczCnCF8xmzpXVuRR6Thu CqVycw4E+NmtdnaB9j6Hm1RVioCTEQCpW/loACTMsXsp4kccf7JO83l6DHgVXsO8nrUV MLAFrbZWQPzyU+tRo90866yir6hey5GCmUzwF26Nhhw72PByHkvjx5YEp2N5GjoqOfRB 6/Fw== X-Gm-Message-State: AB4q+uGGKn+fTtAafEWp98KTvD9rVwb0Masg/wLSFSdnDTn/uR5YRoAV ReRi7AI56wCaGLE7iovGA3xstu2Wf/4S/9BvJGG7MjhcqrnTjsB5cvqfdpgmbr2e X-Gm-Gg: AZFdTZcJ0mhlIi5RSQd0BBxvgOO7ifDWl8isQdOC5BG+u/+D08F+RgBDTuW2Pra5AH2 fOXdPinVkJ0Uj3KVnvD1BKKPuEZDKYbwrlev1J/wSqWL46TrSNxmCw1Haau+svGVphqIILzdnUm URLAjaz4Bl6LoUdj6ZowGNQkg8nalXTSRDrMl7PdmL6aEl+BtBEwMboXd27PLXua0EJneCwY4uA F8TvMzHd/Yi2HlatfN7RahyrO41z/Qy5miOW8tjWdE7wj2h+jBxziNqyk5c181ymv7aWe5oo3gh MMKj+bQLpBs9b1/RGgAf/lRI5h+0nOyXrgTU/2fPzBWX44fg7ijkAM2QRGybYGbAq4Nij3Kzk7D yMosjwIoLFjkSQXHH+Gzk8I7AJSm7pkpQFpkhNo9tMOG7IXUIIZ8R3KJf3dOdWuBnsYIt3ZRULb 8nbtpdz/a2KY+ErqH3Ii+cm6XLRXAQ4VPtcr/oxZ7mmEPOhopovZszmb/SZM0AQ9ds01mnrgqz1 Yfjluf5BQqhql5tzTE6R9F4+qYXfwMU2awIX8Va6hjY/8XuLRVftEusGHgiKVHdB1Fa+nFBdaGL Ho3RpCwa8URKxy4PM8W4VdymwcwNhfJMJipgQ+/gsXxv92OGZBdzIQNu/IzMLx1IOp8BGOPsU68 fF4BXurGh7RsofIWKYMJ5Cok= X-Received: by 2002:a05:6000:2f87:b0:4a6:4ac6:d950 with SMTP id ffacd0b85a97d-4d1ebca0b25mr6330472f8f.39.1796417457739; Fri, 04 Dec 2026 12:50:57 -0800 (PST) Sender: Frediano Ziglio From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie 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 Message-ID: <20261204205045.596093-6-freddy77@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204205045.596093-1-freddy77@gmail.com> References: <20261204205045.596093-1-freddy77@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-d62444/1796417458-4D75C5FD-2ADA0AB0/0/0 X-purgate-type: clean X-purgate-size: 6325 X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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