From patchwork Wed Feb 11 14:32:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1813 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820448; bh=VoBN+4t6ae1Yk5ZtQFUWjyabu515OerHEu6yUwXmOwQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=emSwUE9eK7ric1w7d9ZR0yxuDOUu2tB5UScgb7MV5mRVXnrmNvS2F3N0l0CtJPDOg YltSG7X4AZzovZct9FJz6Fis/2EBg4CnxKS9ntk0MHeB6Agg8VwGlBSLKepSCTnmtL nm+Y0FjpZOf/jiCW6mJZeXO17NKOsw3X/faxnLD6jVvTaPh+kGvSr2+JP496KInphe 03TqoeS2kypGC87D9liiynSLHTy4AbqjVJl5xZvGv9mpw0nMLd7wYTZoLrbrCRIvTM FGRzBj91NtfAmzVSBvJjAVJmH6n5+gXn8u1+xZmkar/A5RGSiRvYsoyS8/5EO12sRQ ry4zFYP5dpYPA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 55678699BF for ; Wed, 11 Feb 2026 07:34:08 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id C4NTZUKTbHxs for ; Wed, 11 Feb 2026 07:34:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820448; bh=VoBN+4t6ae1Yk5ZtQFUWjyabu515OerHEu6yUwXmOwQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=emSwUE9eK7ric1w7d9ZR0yxuDOUu2tB5UScgb7MV5mRVXnrmNvS2F3N0l0CtJPDOg YltSG7X4AZzovZct9FJz6Fis/2EBg4CnxKS9ntk0MHeB6Agg8VwGlBSLKepSCTnmtL nm+Y0FjpZOf/jiCW6mJZeXO17NKOsw3X/faxnLD6jVvTaPh+kGvSr2+JP496KInphe 03TqoeS2kypGC87D9liiynSLHTy4AbqjVJl5xZvGv9mpw0nMLd7wYTZoLrbrCRIvTM FGRzBj91NtfAmzVSBvJjAVJmH6n5+gXn8u1+xZmkar/A5RGSiRvYsoyS8/5EO12sRQ ry4zFYP5dpYPA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3CA7F69A8A for ; Wed, 11 Feb 2026 07:34:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820446; bh=Hx6N4IiF5JT+/T/DoRagvs+YDCQTom+jIVWa53HMqK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XypH6zhMunn6gBik+bJhZ9nV9KPxEpRNY5hhc+yWrRszc1+rKoUo8zqJY8Oow+V6C +vnVLYqJOVyucRTXHLZTGw9Ndp12TMmxOTDjGhxw78T9cO0g3VrOXae+s2hvQ/QaWz jFflc8UonhqAhWJL1+po+60p1Q58jINw7cRMk13tJHOWTpnZI0AqhdKBwUM48uw60X xK2qhykw6TFnOx6lk9YobNvMCVvDM5+pgqd/lViAQbL/8gOXnaxFSjda8vhDub5DkG fPPAzhU9VeHTN+flhPlcHKWvNq0waTBz/OCgsrj1bece3WLjFPdx3sZZSyv9Ds1lKI xnWs9vx5iK7pg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2F43C69A89; Wed, 11 Feb 2026 07:34:06 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id f0voE_6B1KNG; Wed, 11 Feb 2026 07:34:06 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820441; bh=FzIdtEMa3TXZHF0XOXcsuG1YkXPH3AFfMOBls7V2IS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HxLYs6ugBE5Ueftz8cHCfFzsn1GYTOIrR76sIWXQ7IZvgzwEL7zc8DMHwTLH15pS2 QoMwq/SWz0FxULGPGG0Ko0BqQUppJ+a/vHZZ1c9T1NiVZKnEbGWPWYqhQ38TsZ8BCH VLhUUbwY5efAr95/1L5FD7cmauBSRAuLmC2xswe7+wFe5iJwaEda6Kl19Pg/9uk6kR E5kM2xCmfrB3Qcq4Fla5ZO9Gl+sNRKysIDPaWF7rvDbuhAkwU1vzUiU0rQdGV3ODrb +IiinfoAtpIlL/+BhXGNrBXnzo4thhXt537m9BjsNyMN3EUR84JqF487ekbO2ubhSc XJr6SKclLtZNQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 247B8699BF; Wed, 11 Feb 2026 07:34:01 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 11 Feb 2026 07:32:50 -0700 Message-ID: <20260211143309.1183113-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211143309.1183113-1-sjg@u-boot.org> References: <20260211143309.1183113-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 2LUGN4NN3ZPN7R6BLLIZD3TIAGOYO3HS X-Message-ID-Hash: 2LUGN4NN3ZPN7R6BLLIZD3TIAGOYO3HS X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/12] x86: Use MSR_FS_BASE for gd pointer on x86_64 List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The x86_64 global data pointer currently relies on a writable global_data_ptr variable in the .data section, which needs RAM to be available before relocation. Use MSR_FS_BASE to hold the address of gd->arch.gd_addr instead, mirroring how 32-bit x86 uses the FS segment descriptor base. Remove the global_data_ptr variable from misc.c and update arch_setup_gd() to call set_gd(). Separate the EFI_APP and X86_64 cases in global_data.h so each has its own set_gd() implementation. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- arch/x86/cpu/x86_64/misc.c | 12 ++---------- arch/x86/include/asm/global_data.h | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/arch/x86/cpu/x86_64/misc.c b/arch/x86/cpu/x86_64/misc.c index fc449ca4ed6..cb953a92eee 100644 --- a/arch/x86/cpu/x86_64/misc.c +++ b/arch/x86/cpu/x86_64/misc.c @@ -5,21 +5,13 @@ */ #include +#include DECLARE_GLOBAL_DATA_PTR; -/* - * Global declaration of gd. - * - * As we write to it before relocation we have to make sure it is not put into - * a .bss section which may overlap a .rela section. Initialization forces it - * into a .data section which cannot overlap any .rela section. - */ -struct global_data *global_data_ptr = (struct global_data *)~0; - void arch_setup_gd(gd_t *new_gd) { - global_data_ptr = new_gd; + set_gd(new_gd); } int misc_init_r(void) diff --git a/arch/x86/include/asm/global_data.h b/arch/x86/include/asm/global_data.h index 0d9fa823121..1b614067f76 100644 --- a/arch/x86/include/asm/global_data.h +++ b/arch/x86/include/asm/global_data.h @@ -10,6 +10,7 @@ #ifndef __ASSEMBLY__ #include +#include #include #include #include @@ -137,9 +138,8 @@ struct arch_global_data { #include #ifndef __ASSEMBLY__ -# if defined(CONFIG_EFI_APP) || CONFIG_IS_ENABLED(X86_64) +# if defined(CONFIG_EFI_APP) -/* TODO(sjg@chromium.org): Consider using a fixed register for gd on x86_64 */ #define gd global_data_ptr static inline void set_gd(volatile gd_t *gd_ptr) @@ -166,6 +166,28 @@ static inline notrace gd_t *get_fs_gd_ptr(void) #define gd get_fs_gd_ptr() +#if CONFIG_IS_ENABLED(X86_64) +/* + * On x86_64, use MSR_FS_BASE to hold the address of gd->arch.gd_addr, mirroring + * how 32-bit x86 uses the FS segment descriptor base. This avoids the need for + * a writable global_data_ptr variable, which would require the .data section to + * be in RAM before relocation. + */ +static inline void set_gd(volatile gd_t *gd_ptr) +{ + gd_t *p = (gd_t *)gd_ptr; + unsigned long addr; + + p->arch.gd_addr = p; + addr = (unsigned long)&p->arch.gd_addr; + asm volatile("wrmsr" : : + "c" (MSR_FS_BASE), + "a" ((unsigned int)addr), + "d" ((unsigned int)(addr >> 32)) + : "memory"); +} +#endif + #define DECLARE_GLOBAL_DATA_PTR # endif