linux-stable/arch/x86
Tom Lendacky 100cd6d0e5 x86/head/64: Switch to KERNEL_CS as soon as new GDT is installed
[ Upstream commit a37f2699c3 ]

The call to startup_64_setup_env() will install a new GDT but does not
actually switch to using the KERNEL_CS entry until returning from the
function call.

Commit bcce829083 ("x86/sev: Detect/setup SEV/SME features earlier in
boot") moved the call to sme_enable() earlier in the boot process and in
between the call to startup_64_setup_env() and the switch to KERNEL_CS.
An SEV-ES or an SEV-SNP guest will trigger #VC exceptions during the call
to sme_enable() and if the CS pushed on the stack as part of the exception
and used by IRETQ is not mapped by the new GDT, then problems occur.
Today, the current CS when entering startup_64 is the kernel CS value
because it was set up by the decompressor code, so no issue is seen.

However, a recent patchset that looked to avoid using the legacy
decompressor during an EFI boot exposed this bug. At entry to startup_64,
the CS value is that of EFI and is not mapped in the new kernel GDT. So
when a #VC exception occurs, the CS value used by IRETQ is not valid and
the guest boot crashes.

Fix this issue by moving the block that switches to the KERNEL_CS value to
be done immediately after returning from startup_64_setup_env().

Fixes: bcce829083 ("x86/sev: Detect/setup SEV/SME features earlier in boot")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Joerg Roedel <jroedel@suse.de>
Link: https://lore.kernel.org/all/6ff1f28af2829cc9aea357ebee285825f90a431f.1684340801.git.thomas.lendacky%40amd.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-06-21 16:00:51 +02:00
..
boot x86/sev: Add SEV-SNP guest feature negotiation support 2023-02-01 08:34:50 +01:00
coco x86/tdx: Panic on bad configs that #VE on "private" memory access 2022-11-01 16:02:40 -07:00
configs x86/defconfig: Enable CONFIG_DEBUG_WX=y 2022-09-02 10:41:42 +02:00
crypto crypto: x86/ghash - fix unaligned access in ghash_setkey() 2023-03-10 09:32:51 +01:00
entry x86/vdso: Conditionally export __vdso_sgx_enter_enclave() 2022-12-21 17:48:01 +01:00
events perf/x86/uncore: Correct the number of CHAs on SPR 2023-05-30 14:03:19 +01:00
hyperv x86/hyperv: Remove unregister syscore call from Hyper-V cleanup 2022-12-31 13:32:56 +01:00
ia32
include perf/x86/core: Zero @lbr instead of returning -1 in x86_perf_get_lbr() stub 2023-05-17 11:53:27 +02:00
kernel x86/head/64: Switch to KERNEL_CS as soon as new GDT is installed 2023-06-21 16:00:51 +02:00
kvm KVM: x86: Account fastpath-only VM-Exits in vCPU stats 2023-06-09 10:34:27 +02:00
lib x86: fix clear_user_rep_good() exception handling annotation 2023-05-17 11:53:59 +02:00
math-emu
mm x86/mtrr: Revert 90b926e68f ("x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case") 2023-06-09 10:34:22 +02:00
net bpf: Revert ("Fix dispatcher patchable function entry to 5 bytes nop") 2022-11-04 23:13:08 +01:00
pci x86/pci/xen: populate MSI sysfs entries 2023-05-30 14:03:22 +01:00
platform EFI updates for v6.1 2022-10-09 08:56:54 -07:00
power x86/pm: Add enumeration check before spec MSRs save/restore setup 2022-11-21 14:16:16 +01:00
purgatory purgatory: fix disabling debug info 2023-04-26 14:28:42 +02:00
ras
realmode x86/boot: Skip realmode init code when running as Xen PV guest 2022-12-31 13:32:16 +01:00
tools x86/tools/relocs: Ignore __kcfi_typeid_ relocations 2022-09-26 10:13:15 -07:00
um x86: um: vdso: Add '%rcx' and '%r11' to the syscall clobber list 2023-03-11 13:55:22 +01:00
video
virt/vmx/tdx
xen x86/PVH: avoid 32-bit build warning when obtaining VGA console info 2023-04-06 12:10:58 +02:00
.gitignore x86/purgatory: Omit use of bin2c 2022-07-25 10:32:32 +02:00
Kbuild
Kconfig x86/apic: Handle no CONFIG_X86_X2APIC on systems with x2APIC enabled by BIOS 2022-12-31 13:32:58 +01:00
Kconfig.assembler
Kconfig.cpu
Kconfig.debug arch: make TRACE_IRQFLAGS_NMI_SUPPORT generic 2022-06-23 15:39:21 +01:00
Makefile x86/build: Move '-mindirect-branch-cs-prefix' out of GCC-only block 2023-02-09 11:28:13 +01:00
Makefile.um um: Only disable SSE on clang to work around old GCC bugs 2023-05-01 08:26:27 +09:00
Makefile_32.cpu