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 4C9C0606A32C 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=gAkVa96b Received: from list by lists.xenproject.org with outflank-mailman.1514956.1705718 (Exim 4.92) (envelope-from ) id 1xZaFF-0005vX-HC; Fri, 04 Dec 2026 20:51:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1514956.1705718; Fri, 04 Dec 2026 20:51:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaFF-0005tH-6G; Fri, 04 Dec 2026 20:51:05 +0000 Received: by outflank-mailman (input) for mailman id 1514956; Fri, 04 Dec 2026 20:51:03 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZaFD-0005J9-32 for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 20:51:03 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xZaFC-001bMw-Ff for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 21:51:02 +0100 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b1327b6-8faa-0a2a0a5109dd-0a2a450c9fba-0 for ; Fri, 04 Dec 2026 21:51:02 +0100 Received: from [209.85.221.43] (helo=mail-wr1-f43.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b1327b6-f479-0a2a450c0019-d155dd2bc48f-3 for ; Fri, 04 Dec 2026 21:51:02 +0100 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4a7b8abe209so946044f8f.0 for ; Fri, 04 Dec 2026 12:51:02 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:51:01 -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=1796417462; x=1797022262; 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=nNqxr0/EDnYKYEM50OM9dvvqXGmWXWAkmyAO7sLOJnM=; b=gAkVa96beNu7sHWTYc/SSoHBYDNhwgZRkkJGcKyXQJa8O+nzexJ6oMnabBhDVBY5uZ ZvSkIgjCMn3sA3XFyQ4n64i62lQxZ7GK1RN1p73o7aOj7ODzNkwVyuNprQx1nlTmKYQi tPLO2AjhlFrP6aE5FflZcoOxFpgsziNxojBKRI8Y4tPU9Kz1woC7sK9FEbiqwBLVOMEz bdlsIe3SNzcDL53b+3eF9sa0q9RRozqFtvn9KkN34VCmohLoTlpUKJKbOaZzC5qVVhPL 9h+nPHgmqLptDcBJI52+Uuv1rcoKLnIyea3uWpSOzvw5ELAx/Ej6XUOPjhhZhNGl3IQQ gmqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417462; x=1797022262; 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=nNqxr0/EDnYKYEM50OM9dvvqXGmWXWAkmyAO7sLOJnM=; b=tMfmZSsY+gYXPqxhZVkpxqVTzQ9AjXfMJGh6+2KcYMElADnVahNdOW0OrryaXgvc3T H0PI5yf1XSWGqCb3dNSaLz+EmtxgccJMXZTQbl5H3nwBZXNXGeuzMQ0H8gZSfukcgJHF 6YeGGBFquPXD0cH+uxhM7/jtORbSQJVAaEB7PoPmP+B6imYSUc4M8rVN0nJQt7XYDRlx cPSVgqW6n5pfQWMcqqPKTqrev3iIMdJANZjUQs9cuPb/+HxVBtgvb/CR8U/EhNxNqPPr Baay7Sxc+tUrmvR8asks8rTKr2uYa4p2unPLT/rqf3kDJEZhYMx6rvfGTUMV16ESO0ns fUHg== X-Gm-Message-State: AB4q+uHIWRy8WRvRgQudPRoVFj/pC2QneXisnMw7YXeax/s+ub5pj5eW 6ZPIux/x/4kbS09LLNTO+yiY+CoITsJ0jRESTj7UvW2Z9KQVz3lBgH12p0zwIayw X-Gm-Gg: AZFdTZfty93getTLzsbnh1bAe97DNEaenY1olk/ATQICKHUd3UV369A1jPtKn6QkBYs xIkZYruZwZSRrzI0hnGhgL5g9pN+fHccNKv/eZSGGPsfavTRChDxpxGGBt+TXin3nGuIjfJJIgQ 0W9ZcxpmxcVwDfAdexeEHa1HsZQMdnxGjBAzp4r+ToO5n8fOG5EYObfxfQ82h3bnVBqMZ3bNlCX IyqRGwFyavnpNfI6JzbEbnIcsi/asbgHKSD3hfu2TW47gfSrmzblNLvKsOqTWrylzXrqUlAXPNy ARLMpohHlMWVgBIkGXwA24Km9+Io4j4wHOG00zfmH1XlASKPM3tdRmzsfjz+phTRuBRn8emszL1 vfSbf+FpBXlxU/cmjmvOMYUqXGuOtr+ebZq4dZIs0JzmnCuByuUe5zlgBgp+55U2zcQm9LcspkC b31LcdGyvhieYJEnNWEO8AzscVrSD/LMYKelLBrIdTvdAXFkX/nhr0gXWcExD98UCFOQGT/1LgH lE9WLsqk+N57Gjc+oGBbpSN09WoIhhQGzMwMm3vSBxOG+2S9HkhJUIju7OXdp/Ly0Q3vond422G NuPBkurqMQ3ddKO0nWKSkxH+lG68K9ZLyQtUh1q3S3dnE2Pu1ARVn14CjCqw9eaHSEsUVwm/j2W ihFUDwUbFjFEasZFnQi+RpR4= X-Received: by 2002:a05:6000:4609:b0:4a9:760f:1824 with SMTP id ffacd0b85a97d-4d1e909a7d0mr5267470f8f.21.1796417461777; 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 , Lukasz Hawrylko , "Daniel P. Smith" , =?UTF-8?q?Mateusz=20M=C3=B3wka?= , "Claude Opus 5 . 5" Subject: [PATCH 11/11] x86/boot: Check the kind of symbols passed to the bootsym helpers Date: Fri, 4 Dec 2026 20:50:44 +0000 Message-ID: <20261204205045.596093-12-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-d25034/1796417462-50D3CA5B-E46A6AAC/0/0 X-purgate-type: clean X-purgate-size: 4348 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 bootsym_phys() must be used for code in the trampoline, while bootsym_data_phys(), and so bootsym(), must be used for data with a writable copy. Using the wrong one compiles, but gives a wrong address. Add is_function(), comparing the type of the address of a symbol with the type of the symbol after decay, which only match for functions, and check the symbols at build time. bootsym_phys() was also used for trampoline_start and trampoline_end, which are arrays; use trampoline_phys directly for them. Signed-off-by: Frediano Ziglio Co-Authored-By: Claude Opus 5.5 --- xen/arch/x86/include/asm/trampoline.h | 17 ++++++++++++----- xen/arch/x86/setup.c | 6 ++++-- xen/arch/x86/tboot.c | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/include/asm/trampoline.h b/xen/arch/x86/include/asm/trampoline.h index 37a91c28ca..d15d3c61a1 100644 --- a/xen/arch/x86/include/asm/trampoline.h +++ b/xen/arch/x86/include/asm/trampoline.h @@ -111,6 +111,7 @@ #ifndef __ASSEMBLER__ #include +#include #include /* @@ -141,21 +142,27 @@ extern char trampoline_data_base[]; */ extern uint32_t trampoline_phys; +/* Whether x is a function, as opposed to an object. */ +#define is_function(x) \ + __builtin_types_compatible_p(typeof(&(x)), typeof((void)0, (x))) + /* * Calculate the physical address of a symbol in the trampoline. * - * bootsym_phys() is for code symbols (entry points, trampoline_start[] and - * trampoline_end[]), bootsym_data_phys() for data with a writable copy - * (defined with GLOBAL_COPY()). Specifying other symbols will compile but + * bootsym_phys() is for functions (the entry points), bootsym_data_phys() for + * data with a writable copy (defined with GLOBAL_COPY()), which is checked at + * build time. Specifying other symbols of the right kind will compile but * malfunction when used, as will using these helpers before the trampoline * is placed. */ #define bootsym_phys(sym) \ - (trampoline_phys + ((unsigned long)&(sym) - \ + (BUILD_BUG_ON_ZERO(!is_function(sym)) + \ + trampoline_phys + ((unsigned long)&(sym) - \ (unsigned long)trampoline_start)) #define bootsym_data_phys(sym) \ - (trampoline_phys + ((unsigned long)&(sym) - \ + (BUILD_BUG_ON_ZERO(is_function(sym)) + \ + trampoline_phys + ((unsigned long)&(sym) - \ (unsigned long)trampoline_data_base)) /* Given a trampoline data symbol, construct a pointer to it in the directmap. */ diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 17f4f9de4f..33f975c328 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -2266,11 +2266,13 @@ __initcall(init_xen_cap_info); int __hwdom_init remove_xen_ranges(struct rangeset *r) { + unsigned long tramp_end = + trampoline_phys + (trampoline_end - trampoline_start); int rc; /* S3 resume code (and other real mode trampoline code) */ - rc = rangeset_remove_range(r, PFN_DOWN(bootsym_phys(trampoline_start)), - PFN_DOWN(bootsym_phys(trampoline_end) - 1)); + rc = rangeset_remove_range(r, PFN_DOWN(trampoline_phys), + PFN_DOWN(tramp_end - 1)); if ( rc ) return rc; diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index 180da67d6c..576131603d 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -328,7 +328,7 @@ void tboot_shutdown(uint32_t shutdown_type) */ g_tboot_shared->num_mac_regions = 3; /* S3 resume code (and other real mode trampoline code) */ - g_tboot_shared->mac_regions[0].start = bootsym_phys(trampoline_start); + g_tboot_shared->mac_regions[0].start = trampoline_phys; g_tboot_shared->mac_regions[0].size = trampoline_end - trampoline_start; /* hypervisor .text + .rodata */ g_tboot_shared->mac_regions[1].start = (uint64_t)__pa(&_stext); -- 2.43.0