Patch "x86/boot/64: Clear most of CR4 in startup_64(), except PAE, MCE and LA57" has been added to the 6.8-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    x86/boot/64: Clear most of CR4 in startup_64(), except PAE, MCE and LA57

to the 6.8-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     x86-boot-64-clear-most-of-cr4-in-startup_64-except-p.patch
and it can be found in the queue-6.8 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 39126f93b3fb57b2216a9f80af1626c9d959a68e
Author: Ard Biesheuvel <ardb@xxxxxxxxxx>
Date:   Wed Apr 10 17:13:55 2024 +0200

    x86/boot/64: Clear most of CR4 in startup_64(), except PAE, MCE and LA57
    
    [ Upstream commit a0025f587c685e5ff842fb0194036f2ca0b6eaf4 ]
    
    The early 64-bit boot code must be entered with a 1:1 mapping of the
    bootable image, but it cannot operate without a 1:1 mapping of all the
    assets in memory that it accesses, and therefore, it creates such
    mappings for all known assets upfront, and additional ones on demand
    when a page fault happens on a memory address.
    
    These mappings are created with the global bit G set, as the flags used
    to create page table descriptors are based on __PAGE_KERNEL_LARGE_EXEC
    defined by the core kernel, even though the context where these mappings
    are used is very different.
    
    This means that the TLB maintenance carried out by the decompressor is
    not sufficient if it is entered with CR4.PGE enabled, which has been
    observed to happen with the stage0 bootloader of project Oak. While this
    is a dubious practice if no global mappings are being used to begin
    with, the decompressor is clearly at fault here for creating global
    mappings and not performing the appropriate TLB maintenance.
    
    Since commit:
    
      f97b67a773cd84b ("x86/decompressor: Only call the trampoline when changing paging levels")
    
    CR4 is no longer modified by the decompressor if no change in the number
    of paging levels is needed. Before that, CR4 would always be set to a
    consistent value with PGE cleared.
    
    So let's reinstate a simplified version of the original logic to put CR4
    into a known state, and preserve the PAE, MCE and LA57 bits, none of
    which can be modified freely at this point (PAE and LA57 cannot be
    changed while running in long mode, and MCE cannot be cleared when
    running under some hypervisors).
    
    This effectively clears PGE and works around the project Oak bug.
    
    Fixes: f97b67a773cd84b ("x86/decompressor: Only call the trampoline when ...")
    Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
    Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
    Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20240410151354.506098-2-ardb+git@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index bf4a10a5794f1..1dcb794c5479e 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -398,6 +398,11 @@ SYM_CODE_START(startup_64)
 	call	sev_enable
 #endif
 
+	/* Preserve only the CR4 bits that must be preserved, and clear the rest */
+	movq	%cr4, %rax
+	andl	$(X86_CR4_PAE | X86_CR4_MCE | X86_CR4_LA57), %eax
+	movq	%rax, %cr4
+
 	/*
 	 * configure_5level_paging() updates the number of paging levels using
 	 * a trampoline in 32-bit addressable memory if the current number does




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux