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 21219606A32D for ; Fri, 4 Dec 2026 20:51:23 +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=hJS55UZg Received: from list by lists.xenproject.org with outflank-mailman.1514947.1705645 (Exim 4.92) (envelope-from ) id 1xZaF9-0004Bk-5U; Fri, 04 Dec 2026 20:50:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1514947.1705645; Fri, 04 Dec 2026 20:50:59 +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-0004Bc-1b; Fri, 04 Dec 2026 20:50:59 +0000 Received: by outflank-mailman (input) for mailman id 1514947; Fri, 04 Dec 2026 20:50:57 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaF7-0003mw-FF for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 20:50:57 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xZaF6-001bMw-Ku for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 21:50:56 +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-12 for ; Fri, 04 Dec 2026 21:50:56 +0100 Received: from [209.85.128.50] (helo=mail-wm1-f50.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b1327b0-5bcc-0a2a45010019-d1558032b885-3 for ; Fri, 04 Dec 2026 21:50:56 +0100 Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so13596245e9.2 for ; Fri, 04 Dec 2026 12:50:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:50:55 -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=1796417456; x=1797022256; 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=I7MEd9ZNyflhiAke01D+1oLfLQbgho7UF4gYsagP9Jk=; b=hJS55UZgqxoIFSLGjlLEKzgpLKWm8cuvIKdkCPUWgYAzJAbUnSr456HRQ2kHpzNSQm j9cKiXAAU6NLtlXfMDcxn9zKwg21Rf7K2WoCWmhmWV9kXuncWB31NDe17uHeyZwpvqF0 iBIY31aMSjFaVczYRN0CxljntBHLbJZNdToF1UDLc2F41KAdhh0mMXI4F3BullvNmfLn ij7ebMl5r57/0eUJjW6glM7LbNvAS6TFDFQz4Iq0uyDCEsy+PtbYfxMCxvGhctrQirOf HHeQlecnPvA3RvQ7U8y7dWpRH+HoPSvXb1T40CVfVWxAI1i67MQhCQWtgyWsjuGoYBlF T//w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417456; x=1797022256; 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=I7MEd9ZNyflhiAke01D+1oLfLQbgho7UF4gYsagP9Jk=; b=nXwb5rGBij5MneqPNqZLvj+cUklCjMzBL9ySj+gc0eHwxOjN4kOS6M+hYBxHR2Y7wa 7qeoB6HRWej67xPjBvVNF+ZLgN5hBMUxzm9dZg//3prIwUATIYJUjCqEr+1e3xGF+I+B 9Vl4bB4K/Ywwp9ulFUYmzVfYS7SwJDzVgQ8FWR55jMf2y8tP8imI5o3O0Vz1Wnf4TfjQ mDhQ8rv/aYq8VnJnGqLLZPu7ltg3/2jJnW8hHG9p0l30wn1+Dy4FwbgmXww9CoVWZbF4 LxIzFvq7gmMqXzrae8BPvdukFHNSO07ZS8iaeGH1qiWvRSoUToxfzizq5ddh2Y4J9DzX ORrQ== X-Gm-Message-State: APuU4Z9/3qiQOp2A2cfVQfkqMfS+ZHBMp87P/+Ps8NGfaDisVl9G+umw TNDCU9HWw37V0/q6iNhp7Vg6NdwqL7QpACIY4v+Zj0SWNjVkQrkGs3hE1zkApUAf X-Gm-Gg: AZFdTZeFp4LI18gmD61VGi5Be1RDObkdlscmfqfLbmqS8xIjZ2YFr8oBivOTdBraX0S YCHd0VtBTilkfRt3grbPZx5cRryv672PUvbJYuawSQ/keq7COFC0C90oe6UI/6gnDhK8TrjnoKt ufXuPLomQT9K926oKFHlL1ln1SjodKw7NmW+QRuyIhTeGIWrVBNlN4TEq4WipV5m+zqGaIqMNo+ d86poEemPBDrwMQA+voiinDBwcnqL9y0hvIYcMq6qWYdD4MxTABqgum/x2eddf6YwWmR+MubbPp 5FmdG7iS3rZJUpKHzPCaZS7cGXcpy3UhANtWCzR1qgVNBeB6FwRnZE2hxKlCgSf4UarOkvruKT0 lGjqXC0n8NX5fKITdF7VN0D7yRT0GL+AmQVeOGmWJEaDl2aKUwqvUpAoC6qyily7x018GY+jpKJ /zm7/oP8yd+DNX9L9/IBp0ZOmqEyROU215A6+yQUTO+eS3RVsWa5dAQacNz6V0rBs1TMDvjgItr OuQ1/GZf2l90OQgobPDh0nsP/oEUnfuOciVRsDbjEnjxRJrp6nbBJ3YQM8t0vmuv7t6f2KSaLAg e90SUNxokXEeFLdFY8+S3uZhFlWSxYGyPi42ATw3INhSozv6GElD98ejdOSg//mMUgUGx2OBSCI f3/JE7aHrSBFk7iBWiupMRoT44hWUMMsavQx7mWmMayWM X-Received: by 2002:a05:600d:82f2:b0:4bb:6a5a:7834 with SMTP id 5b1f17b1804b1-4bbeb8ae149mr62683195e9.20.1796417455917; Fri, 04 Dec 2026 12:50:55 -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 , "Daniel P. Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH 02/11] x86/boot: Avoid PE relocations in the trampoline Date: Fri, 4 Dec 2026 20:50:35 +0000 Message-ID: <20261204205045.596093-3-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/1796417456-BE0D55FD-F4027AA8/0/0 X-purgate-type: clean X-purgate-size: 4268 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 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 --- 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