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 9DC06606A322 for ; Fri, 4 Dec 2026 20:51:22 +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=mBbU5q9R Received: from list by lists.xenproject.org with outflank-mailman.1514955.1705711 (Exim 4.92) (envelope-from ) id 1xZaFE-0005ko-NX; Fri, 04 Dec 2026 20:51:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1514955.1705711; Fri, 04 Dec 2026 20:51:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaFE-0005j0-Gs; Fri, 04 Dec 2026 20:51:04 +0000 Received: by outflank-mailman (input) for mailman id 1514955; Fri, 04 Dec 2026 20:51:02 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaFC-00059M-DP for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 20:51:02 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xZaFB-0097Kn-PE for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 21:51:01 +0100 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b1327a9-2eae-0a2a0a5409dd-0a2a4506d68e-14 for ; Fri, 04 Dec 2026 21:51:01 +0100 Received: from [209.85.221.53] (helo=mail-wr1-f53.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b1327b5-195a-0a2a45060019-d155dd35f0a1-3 for ; Fri, 04 Dec 2026 21:51:01 +0100 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-491971ac844so1253524f8f.2 for ; Fri, 04 Dec 2026 12:51:01 -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.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:51:00 -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=1796417461; x=1797022261; 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=pSeT+fMQBrzim6ra4e+kr4RZ/WyBcRzBEJDGqcP5lEc=; b=mBbU5q9RVwmAXU0wIl3aK8cLf4cqjdOfgtbkn3A+CGu8ggSWi9D1T7ZwpKlLrp455j 6WWUuPri6X6/E/80lFpV8DCHpgFL+UtHrVGP4Dcu8vkO7U8uoqIZCdC8PJgGNMsRTBvj sMByEO9B6Cssb1WyaCo9VhxqGE6u/tbV9MbGAEDoHxi/W21CD1CgRqHSRjroBoJhQNf3 3H2spxAsGwzXwo4BANqv6syorHQSYe/UnE+InQCPLuL2FefIb2zAob5NIvwVmpDuIPKh KlrIwrqclamAiqBw9ziw/01T88JjsUrF2H1i13wlZ76+YZrnmHGHVfJWJJD6DPDglVTL o2ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417461; x=1797022261; 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=pSeT+fMQBrzim6ra4e+kr4RZ/WyBcRzBEJDGqcP5lEc=; b=YmtkFPynvT6sBMPt7WN+dLkQAaZSb9qemfB3TymtX8/ufIbC/a8tiK+WzhapG/NVGZ xIZxDo0bpuRqsBNOVtR+OE50Dz2NCrCLEH49xEOdT8Guohe2Rs5hZ0F4uOdPD3IrMTKB BJmGeGJAxm+5LLHb/t3xXN6y5D/n7zpxZDCqsUdKgibAYFF5HE9mTTF359ar44aZMMTS Kud2UyKrDx0xGTY7ZCpVhmMSSpR4ZOMs1r5WvMFSsgwBKYqU3wvquDy2rZZzDl0sBIyn LIxV8kI626r+7gykqkUpLF9I/MSJk8gwnFi955+DBk1kzZ/ElR2kpLVO0ScCqsaBXntS tHPQ== X-Gm-Message-State: AB4q+uGcO7kZg/rdnzG6Ujfhj9xDYrjNExd4f3xh1Uu+RfPia1kOh2GQ PEI0TIOUww30v7u8eAeI7AZtiLd7ngWVOTE55ftLpeya4w1qJlispi4PICeHGXLO X-Gm-Gg: AZFdTZdiVAk3i/AudxEsKO/yOrdIQ5xKWmZqboaRGxHaYP/ZOhiPBeI92BCAJ0HRNg4 oW+TqbUAGLT7HpE2bq0msFrpaQUkx84zvQ+vMB/1fJfSw7sdmgXGrFlq/t7+Is3AEv0J7vmOjh+ lNLMMscQZ/deGWKXzKLJ5EoPDCymBtPuMDvP6NwknY5HgcVRu/ALv/PjyKRSKPaNcObwBes1MgA h3Lqta92kwugptDwYNGUZt9AR9jHSKYZOovVOny3j3KyCEXkLbjyM52Nb0epEcaheWLoH1fwNnw DwltXECNlXEsgGAxyBokzQx+GGQPDwi5vJbNpUXuYbf+2v0mgmcVnDoeummBg7jxNkc1RtBz2aK ZCjGp8nI+ToT3hiUa/xLHIYvofODgJIYGp2ullgpZOAWv0Lh5dHcl/Ipj8WRMgMOTFtgLA5ENt8 olfVYi2hLtO2Ui4+lAuUwnYNtjLNG1IEXJCa2e/67eTBrd8xFGJmRsdPJ08q3EbWC8xENy9YB3w Ui4T9Ogp7KG8tlXv4gzncMuWpXU/FEZRvxp6bv/TSkNkxb3NDIsnfBUq42hly6vq4BDa0vyQ/Tj tLxgGN5T1RCRH5ObnEkzdw8tdB7tnYRVpQ8w6KnEJb5dyjLSUMFRPl6jr29UtFMCOLrlue1y42W vl3NZE9hhPp0bufKMsucyRvw= X-Received: by 2002:a05:6000:26cb:b0:4ce:31be:15d with SMTP id ffacd0b85a97d-4d1e8db7990mr7059878f8f.11.1796417461086; Fri, 04 Dec 2026 12:51:01 -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 , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini , "Claude Opus 5 . 5" Subject: [PATCH 10/11] x86/boot: Assemble the trampoline separately from head.S Date: Fri, 4 Dec 2026 20:50:43 +0000 Message-ID: <20261204205045.596093-11-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-16d1c6/1796417461-1FCCD77B-A229AF14/0/0 X-purgate-type: clean X-purgate-size: 12532 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 trampoline is included in head.S, so head.S can reference any of its symbols, including local labels, and the two share all the assembler state. Assemble trampoline.S as its own object, so only its global symbols are visible outside it. The definitions used by both (ENTRY(), GLOBAL() and the boot GDT selectors usable by head.S) move to a new boot.h header. head.S uses trampoline_gdt while the trampoline is still part of the Xen image, where the descriptors with a base relocated to the trampoline are not valid yet. Define their selectors only in the trampoline, after BOOT_GDT_LAST, and limit the GDT loaded by head.S to the valid descriptors, so using them there faults. A build time check keeps the GDT layout in sync with the selectors. trampoline_gdt is now a global symbol, and the offset of the boot code head.S jumps to is exported as an absolute symbol, as head.S can no longer compute label differences inside the trampoline. The build time checks now run on trampoline.o, which contains both the trampoline and the references to the abs_* symbols. No change in the generated trampoline. Signed-off-by: Frediano Ziglio Co-Authored-By: Claude Opus 5.5 --- xen/arch/x86/Makefile | 2 +- xen/arch/x86/boot/.gitignore | 2 +- xen/arch/x86/boot/Makefile | 7 ++-- xen/arch/x86/boot/boot.h | 26 +++++++++++++++ xen/arch/x86/boot/head.S | 33 +++---------------- xen/arch/x86/boot/trampoline.S | 48 +++++++++++++++++++++++++++- xen/tools/check-abs-symbols.sh | 10 +++--- xen/tools/check-trampoline-relocs.sh | 2 +- 8 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 xen/arch/x86/boot/boot.h diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index a90d15748d..7ce9e5fd94 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -117,7 +117,7 @@ LAST_LINKING_PASS := 2 # The trampoline relies on the abs_* symbols being absolute. final-image-check-y = \ - $(SHELL) $(srctree)/tools/check-abs-symbols.sh $(1) $(obj)/boot/head.o + $(SHELL) $(srctree)/tools/check-abs-symbols.sh $(1) $(obj)/boot/trampoline.o final-image-check-$(CONFIG_XEN_IBT) += && $(SHELL) $(srctree)/tools/check-endbr.sh $(1) include scripts/Makefile.link diff --git a/xen/arch/x86/boot/.gitignore b/xen/arch/x86/boot/.gitignore index fb669b2eae..e983602db0 100644 --- a/xen/arch/x86/boot/.gitignore +++ b/xen/arch/x86/boot/.gitignore @@ -3,4 +3,4 @@ /built-in-32.*.bin /built-in-32.*.map /built-in-32.S -/head.trampoline-checked +/trampoline.checked diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile index 2e2e903a88..7600226398 100644 --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -1,4 +1,5 @@ obj-bin-y += head.o +obj-bin-y += trampoline.o obj-bin-y += built-in-32.o obj-bin-y += $(obj64) @@ -21,11 +22,11 @@ cmd_check_trampoline = \ OBJDUMP="$(OBJDUMP)" $(SHELL) $(srctree)/tools/check-trampoline-relocs.sh $< && \ touch $@ -$(obj)/head.trampoline-checked: $(obj)/head.o \ - $(srctree)/tools/check-trampoline-relocs.sh FORCE +$(obj)/trampoline.checked: $(obj)/trampoline.o \ + $(srctree)/tools/check-trampoline-relocs.sh FORCE $(call if_changed,check_trampoline) -extra-y += head.trampoline-checked +extra-y += trampoline.checked CFLAGS_x86_32 := $(subst -m64,-m32 -march=i686,$(XEN_TREEWIDE_CFLAGS)) $(call cc-options-add,CFLAGS_x86_32,CC,$(EMBEDDED_EXTRA_CFLAGS)) diff --git a/xen/arch/x86/boot/boot.h b/xen/arch/x86/boot/boot.h new file mode 100644 index 0000000000..e388250050 --- /dev/null +++ b/xen/arch/x86/boot/boot.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Definitions shared between head.S and the trampoline, which are assembled + * separately. + */ +#ifndef X86_BOOT_BOOT_H +#define X86_BOOT_BOOT_H + +#define ENTRY(name) \ + .align CONFIG_FUNCTION_ALIGNMENT, CODE_FILL; \ + GLOBAL(name) +#define GLOBAL(name) \ + .globl name; \ + .hidden name; \ + name: + +/* + * Selectors in trampoline_gdt usable while it is still part of the Xen image, + * as head.S does. + */ +#define BOOT_CS32 0x0008 +#define BOOT_CS64 0x0010 +#define BOOT_DS 0x0018 +#define BOOT_GDT_LAST BOOT_DS + +#endif /* X86_BOOT_BOOT_H */ diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 853bf27a59..8253b68158 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -12,13 +12,7 @@ #include -#define ENTRY(name) \ - .align CONFIG_FUNCTION_ALIGNMENT, CODE_FILL; \ - GLOBAL(name) -#define GLOBAL(name) \ - .globl name; \ - .hidden name; \ - name: +#include "boot.h" .section .text.header, "ax", @progbits .code32 @@ -26,14 +20,6 @@ #define sym_offs(sym) ((sym) - __XEN_VIRT_START) #define sym_esi(sym) sym_offs(sym)(%esi) -#define BOOT_CS32 0x0008 -#define BOOT_CS64 0x0010 -#define BOOT_DS 0x0018 -#define BOOT_PSEUDORM_CS 0x0020 -#define BOOT_PSEUDORM_DS 0x0028 -#define BOOT_CS32_TRAMP 0x0030 -#define BOOT_DS_TRAMP 0x0038 - #define MB2_HT(name) (MULTIBOOT2_HEADER_TAG_##name) #define MB2_TT(name) (MULTIBOOT2_TAG_TYPE_##name) @@ -144,7 +130,8 @@ multiboot2_header: .word 0 gdt_boot_descr: - .word .Ltrampoline_gdt_end - trampoline_gdt - 1 + /* Only the descriptors usable while part of the Xen image. */ + .word BOOT_GDT_LAST + 8 - 1 gdt_boot_base: .long sym_offs(trampoline_gdt) .long 0 /* Needed for 64-bit lgdt */ @@ -703,23 +690,11 @@ trampoline_setup: /* Switch to low-memory stack which lives at the end of trampoline region. */ mov sym_esi(trampoline_phys), %edi lea TRAMPOLINE_SIZE(%edi), %esp - lea trampoline_boot_cpu_entry-trampoline_start(%edi), %eax + lea trampoline_boot_cpu_entry_offset(%edi), %eax pushl $BOOT_CS32 push %eax /* Jump into the relocated trampoline. */ lret - /* - * The trampoline is never written to while part of the Xen image: the - * data also used from outside has a writable copy (see GLOBAL_COPY()), - * and relocations are applied when it is placed in low memory. This - * allows it to live in .init.text. - */ - .section .init.trampoline, "ax", @progbits -ENTRY(trampoline_start) -#include "trampoline.S" - .subsection TRAMP_LAST -ENTRY(trampoline_end) - #include "x86_64.S" diff --git a/xen/arch/x86/boot/trampoline.S b/xen/arch/x86/boot/trampoline.S index df193fb67f..d389694162 100644 --- a/xen/arch/x86/boot/trampoline.S +++ b/xen/arch/x86/boot/trampoline.S @@ -14,7 +14,28 @@ * after suspend, bringup code for secondary cpus). The permanent parts should * not reference any temporary low memory trampoline parts as those parts are * not guaranteed to persist. + * + * The trampoline is assembled separately from head.S, so only its global + * symbols are visible outside. + */ + +#include +#include +#include +#include +#include + +#include "boot.h" + +/* + * Selectors in trampoline_gdt following the ones in boot.h. These descriptors + * have a base relocated to the trampoline, so they are only valid once it is + * placed, and only usable from the trampoline. */ +#define BOOT_PSEUDORM_CS (BOOT_GDT_LAST + 0x08) +#define BOOT_PSEUDORM_DS (BOOT_GDT_LAST + 0x10) +#define BOOT_CS32_TRAMP (BOOT_GDT_LAST + 0x18) +#define BOOT_DS_TRAMP (BOOT_GDT_LAST + 0x20) /* NB. bootsym() is usable in real mode, via BOOT_PSEUDORM_DS or via BOOT_DS_TRAMP. */ /* The weird multiplication is to catch symbols from other sections. */ @@ -64,6 +85,15 @@ #define TRAMP_BOOT_DATA 5 #define TRAMP_LAST TRAMP_BOOT_DATA + /* + * The trampoline is never written to while part of the Xen image: the + * data also used from outside has a writable copy (see GLOBAL_COPY()), + * and relocations are applied when it is placed in low memory. This + * allows it to live in .init.text. + */ + .section .init.trampoline, "ax", @progbits +ENTRY(trampoline_start) + /* Start of the data with a writable copy, see GLOBAL_COPY(). */ .pushsection .init.trampoline, TRAMP_PERM_EXT_DATA .balign 8 @@ -193,7 +223,7 @@ high_start_address: .word 0 idt_48: .word 0, 0, 0 # base = limit = 0 -trampoline_gdt: +GLOBAL(trampoline_gdt) .word 0 /* 0x0000: unused (reused for GDTR) */ gdt_48: .word .Ltrampoline_gdt_end - trampoline_gdt - 1 @@ -202,11 +232,18 @@ gdt_48: .quad 0x00cf9b000000ffff /* 0x0008: ring 0 code, 32-bit mode */ .quad 0x00af9b000000ffff /* 0x0010: ring 0 code, 64-bit mode */ .quad 0x00cf93000000ffff /* 0x0018: ring 0 data */ +.Ltrampoline_gdt_image_end: .quad 0x00009b000000ffff /* 0x0020: real-mode code @ BOOT_TRAMPOLINE */ .quad 0x000093000000ffff /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */ .quad 0x00cf9b000000ffff /* 0x0030: ring 0 code, 32-bit mode @ BOOT_TRAMPOLINE */ .quad 0x00cf93000000ffff /* 0x0038: ring 0 data @ BOOT_TRAMPOLINE */ .Ltrampoline_gdt_end: + .if .Ltrampoline_gdt_image_end - trampoline_gdt != BOOT_GDT_LAST + 8 + .error "trampoline_gdt doesn't match BOOT_GDT_LAST" + .endif + .if .Ltrampoline_gdt_end - trampoline_gdt != BOOT_DS_TRAMP + 8 + .error "trampoline_gdt doesn't match the trampoline selectors" + .endif /* Relocations for trampoline Real Mode segments. */ .pushsection .trampoline_rel, "a" @@ -389,3 +426,12 @@ GLOBAL(l_trampoline_data_end) .org trampoline_data_start + (l_trampoline_data_end - l_trampoline_data_start) GLOBAL(trampoline_data_end) .popsection + + .subsection TRAMP_LAST +ENTRY(trampoline_end) + +/* For head.S, to jump into the boot code once the trampoline is placed. */ + .globl trampoline_boot_cpu_entry_offset + .hidden trampoline_boot_cpu_entry_offset + .set trampoline_boot_cpu_entry_offset, \ + trampoline_boot_cpu_entry - trampoline_start diff --git a/xen/tools/check-abs-symbols.sh b/xen/tools/check-abs-symbols.sh index 3db5a8e01d..f3801dd50d 100755 --- a/xen/tools/check-abs-symbols.sh +++ b/xen/tools/check-abs-symbols.sh @@ -1,16 +1,16 @@ #!/bin/sh # -# Usage ./$0 image head.o +# Usage ./$0 image trampoline.o # # The trampoline references Xen symbols only through the abs_* symbols defined # in the linker script. These must be ABSOLUTE symbols, so that references to # them are fully resolved at link time and don't produce base relocations in # xen.efi. # -# Check that every abs_* symbol referenced by head.o is present in the final -# image with absolute type. Checking presence matters for PE images, where a -# non-absolute symbol with a value below the image base isn't representable and -# is silently dropped from the symbol table. +# Check that every abs_* symbol referenced by trampoline.o is present in the +# final image with absolute type. Checking presence matters for PE images, +# where a non-absolute symbol with a value below the image base isn't +# representable and is silently dropped from the symbol table. # set -e diff --git a/xen/tools/check-trampoline-relocs.sh b/xen/tools/check-trampoline-relocs.sh index 5b79f88698..85085e51f5 100755 --- a/xen/tools/check-trampoline-relocs.sh +++ b/xen/tools/check-trampoline-relocs.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Usage ./$0 head.o +# Usage ./$0 trampoline.o # # The trampoline must not need relocations in the final binary. For PE, the # loader applies base relocations to the whole image before any Xen code runs, -- 2.43.0