OpenCloudOS-Kernel/arch/x86
Sean Christopherson dea8cfe773 KVM: SVM: Update EFER software model on CR0 trap for SEV-ES
commit 4cdf351d3630a640ab6a05721ef055b9df62277f upstream.

In general, activating long mode involves setting the EFER_LME bit in
the EFER register and then enabling the X86_CR0_PG bit in the CR0
register. At this point, the EFER_LMA bit will be set automatically by
hardware.

In the case of SVM/SEV guests where writes to CR0 are intercepted, it's
necessary for the host to set EFER_LMA on behalf of the guest since
hardware does not see the actual CR0 write.

In the case of SEV-ES guests where writes to CR0 are trapped instead of
intercepted, the hardware *does* see/record the write to CR0 before
exiting and passing the value on to the host, so as part of enabling
SEV-ES support commit f1c6366e30 ("KVM: SVM: Add required changes to
support intercepts under SEV-ES") dropped special handling of the
EFER_LMA bit with the understanding that it would be set automatically.

However, since the guest never explicitly sets the EFER_LMA bit, the
host never becomes aware that it has been set. This becomes problematic
when userspace tries to get/set the EFER values via
KVM_GET_SREGS/KVM_SET_SREGS, since the EFER contents tracked by the host
will be missing the EFER_LMA bit, and when userspace attempts to pass
the EFER value back via KVM_SET_SREGS it will fail a sanity check that
asserts that EFER_LMA should always be set when X86_CR0_PG and EFER_LME
are set.

Fix this by always inferring the value of EFER_LMA based on X86_CR0_PG
and EFER_LME, regardless of whether or not SEV-ES is enabled.

Fixes: f1c6366e30 ("KVM: SVM: Add required changes to support intercepts under SEV-ES")
Reported-by: Peter Gonda <pgonda@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210507165947.2502412-2-seanjc@google.com>
[A two year old patch that was revived after we noticed the failure in
 KVM_SET_SREGS and a similar patch was posted by Michael Roth.  This is
 Sean's patch, but with Michael's more complete commit message. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-12-13 18:45:34 +01:00
..
boot x86/sev: Check for user-space IOIO pointing to kernel space 2023-10-17 10:58:16 +02:00
coco x86/tdx: Allow 32-bit emulation by default 2023-12-13 18:45:02 +01:00
configs - The first, cleanup part of the microcode loader reorg tglx has been 2023-08-28 15:55:20 -07:00
crypto crypto: x86/sha - load modules based on CPU features 2023-11-28 17:19:56 +00:00
entry x86/entry: Do not allow external 0x80 interrupts 2023-12-13 18:45:02 +01:00
events perf/x86/lbr: Filter vsyscall addresses 2023-10-08 12:25:18 +02:00
hyperv x86/hyperv: Add common print prefix "Hyper-V" in hv_init 2023-09-22 18:43:09 +00:00
ia32 x86/signal/32: Merge native and compat 32-bit signal code 2022-10-19 09:58:49 +02:00
include x86/entry: Convert INT 0x80 emulation to IDTENTRY 2023-12-13 18:45:02 +01:00
kernel x86/CPU/AMD: Check vendor in the AMD microcode callback 2023-12-13 18:45:33 +01:00
kvm KVM: SVM: Update EFER software model on CR0 trap for SEV-ES 2023-12-13 18:45:34 +01:00
lib iov_iter, x86: Be consistent about the __user tag on copy_mc_to_user() 2023-11-20 11:58:52 +01:00
math-emu x86/fpu: Include asm/fpu/regset.h 2023-05-18 11:56:18 -07:00
mm x86/coco: Disable 32-bit emulation by default on TDX and SEV 2023-12-13 18:45:02 +01:00
net bpf, x64: Fix tailcall infinite loop 2023-11-20 11:58:55 +01:00
pci x86/PCI: Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4 2023-11-28 17:19:56 +00:00
platform efi/x86: Move EFI runtime call setup/teardown helpers out of line 2023-09-11 06:37:50 +00:00
power x86/topology: Remove CPU0 hotplug option 2023-05-15 13:44:49 +02:00
purgatory x86/purgatory: Remove LTO flags 2023-09-17 09:49:03 +02:00
ras
realmode x86/realmode: Make stack lock work in trampoline_compat() 2023-05-30 14:11:47 +02:00
tools ELF: fix all "Elf" typos 2023-04-08 13:45:37 -07:00
um um: Hard-code the result of 'uname -s' 2023-08-26 22:40:37 +02:00
video Merge drm/drm-next into drm-misc-next 2023-07-24 15:44:47 +02:00
virt/vmx/tdx
xen x86/entry: Convert INT 0x80 emulation to IDTENTRY 2023-12-13 18:45:02 +01:00
.gitignore
Kbuild
Kconfig efi/x86: Ensure that EFI_RUNTIME_MAP is enabled for kexec 2023-09-11 06:37:50 +00:00
Kconfig.assembler x86/shstk: Add Kconfig option for shadow stack 2023-07-11 14:12:18 -07:00
Kconfig.cpu x86/cpu: Remove X86_FEATURE_NAMES 2023-05-15 20:03:08 +02:00
Kconfig.debug docs: move x86 documentation into Documentation/arch/ 2023-03-30 12:58:51 -06:00
Makefile Kbuild updates for v6.6 2023-09-05 11:01:47 -07:00
Makefile.postlink x86/build: Avoid relocation information in final vmlinux 2023-06-14 19:54:40 +02:00
Makefile.um um: Only disable SSE on clang to work around old GCC bugs 2023-04-04 09:57:05 +02:00
Makefile_32.cpu