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 304B1606A330 for ; Fri, 4 Dec 2026 20:51:19 +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=cY/tJ10p Received: from list by lists.xenproject.org with outflank-mailman.1514946.1705631 (Exim 4.92) (envelope-from ) id 1xZaF7-0003p3-Vn; Fri, 04 Dec 2026 20:50:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1514946.1705631; Fri, 04 Dec 2026 20:50:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaF7-0003nz-Pk; Fri, 04 Dec 2026 20:50:57 +0000 Received: by outflank-mailman (input) for mailman id 1514946; Fri, 04 Dec 2026 20:50:56 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaF6-0003mk-A4 for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 20:50:56 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xZaF5-00GVsz-Fu for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 21:50:55 +0100 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b13278a-bab6-0a2a0a5309dd-0a2a450bc204-34 for ; Fri, 04 Dec 2026 21:50:55 +0100 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b1327af-b7e8-0a2a450b0019-d155dd2edc65-3 for ; Fri, 04 Dec 2026 21:50:55 +0100 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso1465511f8f.0 for ; Fri, 04 Dec 2026 12:50:55 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:50:54 -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:Message-ID:Date:Subject:Cc:To:From:Sender" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796417455; x=1797022255; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QjWYY2yahKVVNqPSQovrxz+FTyeL5LXdr8popNQgvsc=; b=cY/tJ10pkMh0278xZjV2g+KiN5gtlywUdGsmCBA1s4hgc9uQseYBfQ66l6Bxk8UUgh +byaii6z6/LR89HVmrHLg+gGh6OAZ2UBKQitT1NKM3Baq4lR6IPQZW+rpakuDXTJLnfe xDVMByqhe7iQceUJhc97T+YRx7GqR6hfgn46L/B5dJGxCSGLY4jr6E9QMWerH2KHzqiP Wyf5oZeZDg3w/D7MPLrGJymJw4kd2Df/DRHBBB3GEcvoXUwkezM0yIiawh70bg3IdYEj d01MLhV6lgpsarshNs+xj7PiZgCMaz2QWRAXUNNkmiPkxQ/sPzLIqSntrdmqLGgArkIj 4Ngw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417455; x=1797022255; h=content-transfer-encoding:mime-version: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=QjWYY2yahKVVNqPSQovrxz+FTyeL5LXdr8popNQgvsc=; b=kp/y+5yk05kSpIuevs5hiBUTqi2K+K2EQkigy8UhzgsDOavE/eXv/cpEGmS/to+JHt raKulY7qnabuQCKH4xnM9IEz7czB3iK8hWpIZByhRMYrTzaLk6HUri53QjhGufxGfMs+ EYn+D/1/ECt5FM2VE5G6m6OIwbA9KE3fCcOoV0wuG+em1PFo7MShB9TOxRoHoHqCGJqn HyKQjLurbamRuVs5qkTn7Q5QCFGitgbi56AlCHLQQkRDqYkhk/dlIMsPob+k+wn/JiK5 ve69IpL3+MDvuqJbaWGl7luZnBYmZ8xANlvi7kWumIYy1v5HpHhZ4IIENoBdT9fV5M8C 5wvg== X-Gm-Message-State: AB4q+uHBxvUlm66zfYPnokkxysh5H4B3G7Rn8+xPvQcj+QhTBnu8G2fo DizJe64+8T+agJultcHylvGw8AZtfDIdV36jPeP9peG2MXlF/9a3qkEkF0J56avj X-Gm-Gg: AZFdTZfPAPyrhojLnoGfD9ZFQsmiqhXZ4Ff88/NgfT1W0NavpxlsXmct+Z2F5RPQAEV AwGDrUgLMj97WtzBMGXOKE+KGVBg3vmjEe4XgMgYY76Dsv8XZhUAxIix8BMPu99rdgYuhAM+pnC gVdg/eNxv8P+hi2mgvZtwqrz0gWBzFkpY6TZGyAmKXFhnp3sNbBRtXrEy8kj/4iW5ajYsC7L/OL bagrSGkHozWXPUg2vGi37Tjd4N/3xIfktBKW9YSXjBBXYFva9NUyl6BnJg0Bo6EYPYwZUowfRlt w8KvA1fX+3IoZEqybL7w1NT+5/Y2GunuzLdCLPF3nKRBNm9rDARivQzXTsKwfGwIcQxRRgZfupl XvA+4kKNmYHeIURtwq8L0nnY3MQyLm8e12cXWAQZN9e8hq5+5y7EXKmUetMjS9OHOZC6m8E841x /fc5cMCqUno1reUQKwmchJpZQC2TXuLhF4s/vgW7Eyew9g582nyrIFq79oW9Y3t6RMRYRKql/u1 3nAaWhl0EFvN70rD948BlXs+LZuYENfLKNvLHUt1C1CqpW1PQroZ5Hyx5vZMd0fkd5zcdjpO9+m gfZiPdqgc24nIGyv7iasm5h+zxfLUPwP41/jlAF/DCC04qmaGpa02pYcuObfJRZyI9SX0MvJZrV h6gNNCn5yO7aCunRWaiqarLE= X-Received: by 2002:a5d:6f05:0:b0:48e:6419:ddf2 with SMTP id ffacd0b85a97d-4d1e909a636mr6267318f8f.17.1796417454665; Fri, 04 Dec 2026 12:50:54 -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?= , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Lukasz Hawrylko , =?UTF-8?q?Mateusz=20M=C3=B3wka?= Subject: [PATCH 00/11] x86/boot: Improve trampoline code Date: Fri, 4 Dec 2026 20:50:33 +0000 Message-ID: <20261204205045.596093-1-freddy77@gmail.com> X-Mailer: git-send-email 2.43.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-42698a/1796417455-184CB9EA-7B7E46B8/0/0 X-purgate-type: clean X-purgate-size: 3615 X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,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 This series collect different attempts and idea to improve trampoline code. Most of the changes improve relocation handling: - binary relocations on the final binary causes issues with PE format (used for EFI firmwares) as our code need to relocate from loader position to final one. To fix that use absolute symbols generated by the linker script. Checks are added to avoid adding back other relocations; - apply relocations after the copy to lower memory. This avoids writing into code section; - use a copy of the data section inside the trampoline in the final binary executable to avoid changing the original trampoline; - trampoline code is back in the final binary code section for EFI builds. General improvements: - add some checks and cleanup in the code handling S3 resume; - reuse code to switch to 64 bit, almost identical besides useless differences. Added safety: - assembly bootsym macro now assure symbols are in the same section; - C bootsym* macros check for symbol type; - check there are no relocation inside the trampoline in the final binary (mentioned above); - compile trampoline in a separate object to avoid head.S to access unwanted symbols in the trampoline. Frediano Ziglio (11): x86/boot: Prevent some possible firmware misbehaviour x86/boot: Avoid PE relocations in the trampoline x86/boot: Check at build time that the trampoline needs no relocations x86/boot: Reduce relocations in the trampoline x86/boot: Share the switch to 64-bit mode between SIPI and S3 paths x86/boot: Use stack to remove a relocation from trampoline code x86/boot: Apply relocations in the trampoline after the copy x86/boot: Group trampoline code and data using subsections x86/boot: Use a writable copy of the trampoline data x86/boot: Assemble the trampoline separately from head.S x86/boot: Check the kind of symbols passed to the bootsym helpers xen/arch/arm/efi/efi-boot.h | 4 + xen/arch/x86/Makefile | 5 +- xen/arch/x86/boot/.gitignore | 1 + xen/arch/x86/boot/Makefile | 20 +- xen/arch/x86/boot/boot.h | 26 +++ xen/arch/x86/boot/build32.lds.S | 8 +- xen/arch/x86/boot/cmdline.c | 2 +- xen/arch/x86/boot/copy-trampoline.c | 67 +++++++ xen/arch/x86/boot/edd.S | 26 +-- xen/arch/x86/boot/head.S | 52 +---- xen/arch/x86/boot/mem.S | 12 +- xen/arch/x86/boot/reloc-trampoline.c | 34 ---- xen/arch/x86/boot/trampoline.S | 242 +++++++++++++++++++----- xen/arch/x86/boot/video.S | 24 ++- xen/arch/x86/boot/wakeup.S | 114 ++++------- xen/arch/x86/efi/efi-boot.h | 21 +- xen/arch/x86/efi/mbi2.c | 4 + xen/arch/x86/include/asm/boot-helpers.h | 3 +- xen/arch/x86/include/asm/trampoline.h | 51 ++++- xen/arch/x86/setup.c | 6 +- xen/arch/x86/tboot.c | 2 +- xen/arch/x86/xen.lds.S | 33 +++- xen/common/efi/boot.c | 1 + xen/tools/check-abs-symbols.sh | 50 +++++ xen/tools/check-trampoline-relocs.sh | 47 +++++ 25 files changed, 604 insertions(+), 251 deletions(-) create mode 100644 xen/arch/x86/boot/boot.h create mode 100644 xen/arch/x86/boot/copy-trampoline.c delete mode 100644 xen/arch/x86/boot/reloc-trampoline.c create mode 100755 xen/tools/check-abs-symbols.sh create mode 100755 xen/tools/check-trampoline-relocs.sh -- 2.43.0