Skip to content

Commit de60613

Browse files
kirylbp3tk0v
authored andcommitted
x86/kexec: Keep CR4.MCE set during kexec for TDX guest
TDX guests run with MCA enabled (CR4.MCE=1b) from the very start. If that bit is cleared during CR4 register reprogramming during boot or kexec flows, a #VE exception will be raised which the guest kernel cannot handle. Therefore, make sure the CR4.MCE setting is preserved over kexec too and avoid raising any #VEs. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7b46a89 commit de60613

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

arch/x86/kernel/relocate_kernel_64.S

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
#include <linux/linkage.h>
8+
#include <linux/stringify.h>
9+
#include <asm/alternative.h>
810
#include <asm/page_types.h>
911
#include <asm/kexec.h>
1012
#include <asm/processor-flags.h>
@@ -145,14 +147,15 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
145147
* Set cr4 to a known state:
146148
* - physical address extension enabled
147149
* - 5-level paging, if it was enabled before
150+
* - Machine check exception on TDX guest, if it was enabled before.
151+
* Clearing MCE might not be allowed in TDX guests, depending on setup.
152+
*
153+
* Use R13 that contains the original CR4 value, read in relocate_kernel().
154+
* PAE is always set in the original CR4.
148155
*/
149-
movl $X86_CR4_PAE, %eax
150-
testq $X86_CR4_LA57, %r13
151-
jz .Lno_la57
152-
orl $X86_CR4_LA57, %eax
153-
.Lno_la57:
154-
155-
movq %rax, %cr4
156+
andl $(X86_CR4_PAE | X86_CR4_LA57), %r13d
157+
ALTERNATIVE "", __stringify(orl $X86_CR4_MCE, %r13d), X86_FEATURE_TDX_GUEST
158+
movq %r13, %cr4
156159

157160
/* Flush the TLB (needed?) */
158161
movq %r9, %cr3

0 commit comments

Comments
 (0)