From: "tip-bot2 for Ard Biesheuvel" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
Tom Lendacky <thomas.lendacky@amd.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/boot] x86/startup_64: Simplify CR4 handling in startup code
Date: Mon, 04 Mar 2024 22:09:05 -0000 [thread overview]
Message-ID: <170959014519.398.9871521957540564245.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20240227151907.387873-12-ardb+git@google.com>
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: dada8587068c820ba5e5d09b9c32d8bc28c4dbe6
Gitweb: https://git.kernel.org/tip/dada8587068c820ba5e5d09b9c32d8bc28c4dbe6
Author: Ard Biesheuvel <ardb@kernel.org>
AuthorDate: Tue, 27 Feb 2024 16:19:09 +01:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 04 Mar 2024 18:11:34 +01:00
x86/startup_64: Simplify CR4 handling in startup code
When paging is enabled, the CR4.PAE and CR4.LA57 control bits cannot be
changed, and so they can simply be preserved rather than reason about
whether or not they need to be set. CR4.MCE should be preserved unless
the kernel was built without CONFIG_X86_MCE, in which case it must be
cleared.
CR4.PSE should be set explicitly, regardless of whether or not it was
set before.
CR4.PGE is set explicitly, and then cleared and set again after
programming CR3 in order to flush TLB entries based on global
translations. This makes the first assignment redundant, and can
therefore be omitted. So clear PGE by omitting it from the preserve
mask, and set it again explicitly after switching to the new page
tables.
[ bp: Document the exact operation of CR4.PGE ]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Tested-by: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/r/20240227151907.387873-12-ardb+git@google.com
---
arch/x86/kernel/head_64.S | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 86136a7..54207e7 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -185,6 +185,16 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
addq $(init_top_pgt - __START_KERNEL_map), %rax
1:
+ /*
+ * Create a mask of CR4 bits to preserve. Omit PGE in order to flush
+ * global 1:1 translations from the TLBs.
+ *
+ * From the SDM:
+ * "If CR4.PGE is changing from 0 to 1, there were no global TLB
+ * entries before the execution; if CR4.PGE is changing from 1 to 0,
+ * there will be no global TLB entries after the execution."
+ */
+ movl $(X86_CR4_PAE | X86_CR4_LA57), %edx
#ifdef CONFIG_X86_MCE
/*
* Preserve CR4.MCE if the kernel will enable #MC support.
@@ -193,20 +203,13 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
* configured will crash the system regardless of the CR4.MCE value set
* here.
*/
- movq %cr4, %rcx
- andl $X86_CR4_MCE, %ecx
-#else
- movl $0, %ecx
+ orl $X86_CR4_MCE, %edx
#endif
+ movq %cr4, %rcx
+ andl %edx, %ecx
- /* Enable PAE mode, PSE, PGE and LA57 */
- orl $(X86_CR4_PAE | X86_CR4_PSE | X86_CR4_PGE), %ecx
-#ifdef CONFIG_X86_5LEVEL
- testb $1, __pgtable_l5_enabled(%rip)
- jz 1f
- orl $X86_CR4_LA57, %ecx
-1:
-#endif
+ /* Even if ignored in long mode, set PSE uniformly on all logical CPUs. */
+ btsl $X86_CR4_PSE_BIT, %ecx
movq %rcx, %cr4
/* Setup early boot stage 4-/5-level pagetables. */
@@ -223,14 +226,10 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
movq %rax, %cr3
/*
- * Do a global TLB flush after the CR3 switch to make sure the TLB
- * entries from the identity mapping are flushed.
+ * Set CR4.PGE to re-enable global translations.
*/
- movq %cr4, %rcx
- movq %rcx, %rax
- xorq $X86_CR4_PGE, %rcx
+ btsl $X86_CR4_PGE_BIT, %ecx
movq %rcx, %cr4
- movq %rax, %cr4
/* Ensure I am executing from virtual addresses */
movq $1f, %rax
next prev parent reply other threads:[~2024-03-04 22:09 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 15:19 [PATCH v7 0/9] x86: Confine early 1:1 mapped " Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 1/9] x86/startup_64: Simplify CR4 handling in " Ard Biesheuvel
2024-02-28 13:45 ` Borislav Petkov
2024-02-29 22:36 ` Ard Biesheuvel
2024-03-04 22:09 ` tip-bot2 for Ard Biesheuvel [this message]
2024-02-27 15:19 ` [PATCH v7 2/9] x86/startup_64: Defer assignment of 5-level paging global variables Ard Biesheuvel
2024-02-28 20:55 ` Borislav Petkov
2024-03-01 10:01 ` Ard Biesheuvel
2024-03-01 16:09 ` Borislav Petkov
2024-03-01 17:09 ` Ard Biesheuvel
2024-03-01 17:33 ` Borislav Petkov
2024-03-01 19:13 ` Tom Lendacky
2024-03-03 19:26 ` Borislav Petkov
2024-03-03 21:56 ` Ard Biesheuvel
2024-03-03 22:10 ` Borislav Petkov
2024-03-04 22:09 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 3/9] x86/startup_64: Simplify calculation of initial page table address Ard Biesheuvel
2024-02-28 21:27 ` Borislav Petkov
2024-03-04 22:09 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 4/9] x86/startup_64: Simplify virtual switch on primary boot Ard Biesheuvel
2024-02-29 10:37 ` Borislav Petkov
2024-02-29 22:36 ` Ard Biesheuvel
2024-03-01 16:12 ` Borislav Petkov
2024-03-04 22:09 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 5/9] efi/libstub: Add generic support for parsing mem_encrypt= Ard Biesheuvel
2024-03-01 16:16 ` Borislav Petkov
2024-03-04 22:09 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 6/9] x86/boot: Move mem_encrypt= parsing to the decompressor Ard Biesheuvel
2024-03-01 19:16 ` Borislav Petkov
2024-03-01 23:46 ` Ard Biesheuvel
2024-03-02 14:51 ` Borislav Petkov
2024-03-04 22:09 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 7/9] x86/sme: Move early SME kernel encryption handling into .head.text Ard Biesheuvel
2024-03-04 22:08 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 8/9] x86/sev: Move early startup code into .head.text section Ard Biesheuvel
2024-03-04 22:08 ` [tip: x86/boot] " tip-bot2 for Ard Biesheuvel
2024-02-27 15:19 ` [PATCH v7 9/9] x86/startup_64: Drop global variables keeping track of LA57 state Ard Biesheuvel
2024-03-01 19:20 ` Borislav Petkov
2024-03-01 23:55 ` Ard Biesheuvel
2024-03-02 15:17 ` Borislav Petkov
2024-03-02 15:32 ` Ard Biesheuvel
2024-03-02 18:22 ` Borislav Petkov
2024-03-04 17:07 ` [PATCH v7 0/9] x86: Confine early 1:1 mapped startup code Tom Lendacky
2024-03-04 19:13 ` Ard Biesheuvel
2024-03-04 22:41 ` Tom Lendacky
2024-03-05 8:46 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=170959014519.398.9871521957540564245.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®