Message ID | 20240106010106.25772-1-kirill.shutemov@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-18439-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6553537dyb; Fri, 5 Jan 2024 17:01:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLSMxf6XDjLkhUPS0Drj+E5wh79E993JAJfYQe3K4MmZi3gl7LXm0NhjE/ZzeeIE1qn8Yc X-Received: by 2002:a50:9fe9:0:b0:556:ef38:9b04 with SMTP id c96-20020a509fe9000000b00556ef389b04mr71128edf.122.1704502901270; Fri, 05 Jan 2024 17:01:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704502901; cv=none; d=google.com; s=arc-20160816; b=BimflLUQ9Hx9xfiJ08QQ2M6AjTzoLid4nkTpK3QndLcqtraRY83g41Px+A1jROxark Q4uAB4aftzTMFpN3syIVsf8jTydip23+dDzk3pliUuckbryFSmecBo1cT7udyTdFNp4+ 1/6eoGES4AgSkGd0G/R8tY/Wx7RgRYyIZjpygD1npZsV0mxpZN/GIzhST3+ZauaxyMGC DlLAxEVUnNdoA2YI4/0riyQXlOJf7L0w1K4b5s4/kpQQJCCrINYh2KGzkU5Fi2hd2b4i ESMz5/GwFQhPIYDhVHSMkVqzIvHuX7qn5v2qqx02Z2+HjEQx0vUF48kTaxd+OxsEIrgw I+lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=eCPy0hQ2f0k7hkHNSRzLtbQHA9i2zHJpzaV7uzaKi9g=; fh=OoRKjb2TylHnyV/boMqmij9jZddb+zOyNbbkz0GZ8TQ=; b=ZKl5OQ+D58sAUZ4sVsXxygYmragoM9ioB61FadGqWpKUWU9iwYgQ81cux+KH/rQ8S+ Pv9eEn21kqcQCb7IX5/Ght4N0S4ngjgNHPZv6CXDrACArgJTT7ZUSt+XlsD4rAydMOd1 w2Nia2YonHal1ipWAqYnqkDCpgGNQuOti4KTHKMxYoA29RAUKUctnnJ+zxxzQeOJgTj5 NmYNXpu2imj3RTVj1rPK4ekfMPqhztjrjtDtC82WPJ7VhkntBYS/oF9dzfBGTcDWGIqB +j36m0/0Tml/4DWIcDDkHCJHM8zg+JIGXmNmwlayViQNY+RPvRxteG7DIEnsVJMaLVnl JwuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ULgII3CR; spf=pass (google.com: domain of linux-kernel+bounces-18439-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18439-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dg1-20020a0564021d0100b005538b4a4f59si1030064edb.263.2024.01.05.17.01.41 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 17:01:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18439-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ULgII3CR; spf=pass (google.com: domain of linux-kernel+bounces-18439-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18439-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CEF641F2405B for <ouuuleilei@gmail.com>; Sat, 6 Jan 2024 01:01:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C75817CB; Sat, 6 Jan 2024 01:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ULgII3CR" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98D6610E6 for <linux-kernel@vger.kernel.org>; Sat, 6 Jan 2024 01:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704502882; x=1736038882; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wmlcIE799KGQUnfz1DYFtpYVFNSZFElEdlaTVp14/gc=; b=ULgII3CRg99wOUO95ctWkqCjvV+fj8AFllkkDhw16tXSKLy9R+9q+KY5 YNzXNB3v5CbOQnHzZXmkOOA0sILRy3BPl9u0CFmykjAcoZ3PlMCEokZ90 +FxIVy6gQqDNd12nFl9gzszCHzCoKLrwJaJ52hvcCZv+zk7kpJzTuvJbC 4cfqvPfmPu+/ypH4c/KNsz5n6Ue2FvG9N3SMP/a+7zD290MW6bX0gByDV qUvhg5gerkB3UgD8qxqOgaB/nVE5gcHPddOB8ehK0XnQ4ofs8BljZSXXO VcihSccOoMP4sKw4GvX20/A995S/aaXEhZ1X49LyFF58msQJbDRyXZP1h Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10944"; a="377770416" X-IronPort-AV: E=Sophos;i="6.04,335,1695711600"; d="scan'208";a="377770416" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 17:01:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,335,1695711600"; d="scan'208";a="29259174" Received: from mflierl-xps15.amr.corp.intel.com (HELO box.shutemov.name) ([10.252.36.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 17:01:19 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 221D110A57B; Sat, 6 Jan 2024 04:01:16 +0300 (+03) From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> To: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com> Cc: x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Andi Kleen <ak@linux.intel.com>, Sean Christopherson <seanjc@google.com> Subject: [PATCH] x86/trampoline: Bypass compat mode in trampoline_start64() if not needed Date: Sat, 6 Jan 2024 04:01:06 +0300 Message-ID: <20240106010106.25772-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787300834265038026 X-GMAIL-MSGID: 1787300834265038026 |
Series |
x86/trampoline: Bypass compat mode in trampoline_start64() if not needed
|
|
Commit Message
Kirill A. Shutemov
Jan. 6, 2024, 1:01 a.m. UTC
The trampoline_start64() vector is used when a secondary CPU starts in 64-bit mode. The current implementation directly enters compatibility mode. It is necessary to disable paging and re-enable it in the correct paging mode: either 4- or 5-level, depending on the configuration. The X86S[1] ISA does not support compatibility mode in ring 0, and paging cannot be disabled. The trampoline_start64() function is reworked to only enter compatibility mode if it is necessary to change the paging mode. If the CPU is already in the desired paging mode, it will proceed in long mode. This change will allow a secondary CPU to boot on an X86S machine as long as the CPU is already in the correct paging mode. In the future, there will be a mechanism to switch between paging modes without disabling paging. [1] https://www.intel.com/content/www/us/en/developer/articles/technical/envisioning-future-simplified-architecture.html Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Reviewed-by: Andi Kleen <ak@linux.intel.com> Cc: Sean Christopherson <seanjc@google.com> --- arch/x86/realmode/rm/trampoline_64.S | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
Comments
Hi Kirill, kernel test robot noticed the following build errors: [auto build test ERROR on tip/master] [also build test ERROR on tip/x86/core tip/auto-latest linus/master v6.7-rc8 next-20240105] [cannot apply to bp/for-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Kirill-A-Shutemov/x86-trampoline-Bypass-compat-mode-in-trampoline_start64-if-not-needed/20240106-090311 base: tip/master patch link: https://lore.kernel.org/r/20240106010106.25772-1-kirill.shutemov%40linux.intel.com patch subject: [PATCH] x86/trampoline: Bypass compat mode in trampoline_start64() if not needed config: x86_64-kexec (https://download.01.org/0day-ci/archive/20240107/202401070610.WkJiWgWO-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240107/202401070610.WkJiWgWO-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202401070610.WkJiWgWO-lkp@intel.com/ All errors (new ones prefixed by >>): as: arch/x86/realmode/rm/trampoline_64.o: unsupported relocation type: 0x185 arch/x86/realmode/rm/trampoline_64.S: Assembler messages: >> arch/x86/realmode/rm/trampoline_64.S:225: Error: cannot represent relocation type BFD_RELOC_X86_64_32S as: arch/x86/realmode/rm/trampoline_64.o: unsupported relocation type: 0x185 arch/x86/realmode/rm/trampoline_64.S:231: Error: cannot represent relocation type BFD_RELOC_X86_64_32S vim +225 arch/x86/realmode/rm/trampoline_64.S 211 212 SYM_CODE_START(trampoline_start64) 213 /* 214 * APs start here on a direct transfer from 64-bit BIOS with identity 215 * mapped page tables. Load the kernel's GDT in order to gear down to 216 * 32-bit mode (to handle 4-level vs. 5-level paging), and to (re)load 217 * segment registers. Load the zero IDT so any fault triggers a 218 * shutdown instead of jumping back into BIOS. 219 */ 220 lidt tr_idt(%rip) 221 lgdt tr_gdt64(%rip) 222 223 /* Check if paging mode has to be changed */ 224 movq %cr4, %rax > 225 xorq pa_tr_cr4, %rax 226 andq $X86_CR4_LA57, %rax 227 jnz .L_switch_paging 228 229 /* Paging mode is correct proceed in 64-bit mode */ 230 231 LOCK_AND_LOAD_REALMODE_ESP lock_pa=1 232 233 movw $__KERNEL_DS, %dx 234 movl %edx, %ss 235 addl $pa_real_mode_base, %esp 236 movl %edx, %ds 237 movl %edx, %es 238 movl %edx, %fs 239 movl %edx, %gs 240 241 movl $pa_trampoline_pgd, %eax 242 movq %rax, %cr3 243 244 jmpq *tr_start(%rip) 245 .L_switch_paging: 246 /* 247 * To switch between 4- and 5-level paging modes, it is necessary 248 * to disable paging. This must be done in the compatibility mode. 249 */ 250 ljmpl *tr_compat(%rip) 251 SYM_CODE_END(trampoline_start64) 252 253 .section ".rodata","a" 254 # Duplicate the global descriptor table 255 # so the kernel can live anywhere 256 .balign 16 257 SYM_DATA_START(tr_gdt) 258 .short tr_gdt_end - tr_gdt - 1 # gdt limit 259 .long pa_tr_gdt 260 .short 0 261 .quad 0x00cf9b000000ffff # __KERNEL32_CS 262 .quad 0x00af9b000000ffff # __KERNEL_CS 263 .quad 0x00cf93000000ffff # __KERNEL_DS 264 SYM_DATA_END_LABEL(tr_gdt, SYM_L_LOCAL, tr_gdt_end) 265
diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S index c9f76fae902e..70c6dff658e6 100644 --- a/arch/x86/realmode/rm/trampoline_64.S +++ b/arch/x86/realmode/rm/trampoline_64.S @@ -220,6 +220,33 @@ SYM_CODE_START(trampoline_start64) lidt tr_idt(%rip) lgdt tr_gdt64(%rip) + /* Check if paging mode has to be changed */ + movq %cr4, %rax + xorq pa_tr_cr4, %rax + andq $X86_CR4_LA57, %rax + jnz .L_switch_paging + + /* Paging mode is correct proceed in 64-bit mode */ + + LOCK_AND_LOAD_REALMODE_ESP lock_pa=1 + + movw $__KERNEL_DS, %dx + movl %edx, %ss + addl $pa_real_mode_base, %esp + movl %edx, %ds + movl %edx, %es + movl %edx, %fs + movl %edx, %gs + + movl $pa_trampoline_pgd, %eax + movq %rax, %cr3 + + jmpq *tr_start(%rip) +.L_switch_paging: + /* + * To switch between 4- and 5-level paging modes, it is necessary + * to disable paging. This must be done in the compatibility mode. + */ ljmpl *tr_compat(%rip) SYM_CODE_END(trampoline_start64)