linux/arch/x86/kvm
Sean Christopherson 4cdf351d36 KVM: SVM: Update EFER software model on CR0 trap for SEV-ES
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>
2023-12-08 13:37:05 -05:00
..
mmu Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
svm KVM: SVM: Update EFER software model on CR0 trap for SEV-ES 2023-12-08 13:37:05 -05:00
vmx KVM SVM changes for 6.7: 2023-10-31 10:22:43 -04:00
.gitignore KVM: x86: use a separate asm-offsets.c file 2022-11-09 12:10:17 -05:00
cpuid.c KVM x86 Xen changes for 6.7: 2023-10-31 10:21:42 -04:00
cpuid.h KVM: x86: Add SBPB support 2023-10-04 15:19:32 -07:00
debugfs.c KVM: Set file_operations.owner appropriately for all such structures 2023-12-01 08:12:17 -08:00
emulate.c KVM: x86: Remove break statements that will never be executed 2023-08-17 11:28:00 -07:00
fpu.h KVM: x86: Move FPU register accessors into fpu.h 2021-06-17 13:09:24 -04:00
governed_features.h KVM: nSVM: Use KVM-governed feature framework to track "vNMI enabled" 2023-08-17 11:43:31 -07:00
hyperv.c KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space 2023-10-17 16:41:02 -07:00
hyperv.h KVM: x86: Hyper-V invariant TSC control 2022-12-29 15:33:29 -05:00
i8254.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
i8254.h KVM: x86: PIT: Preserve state of speaker port data bit 2022-06-08 13:06:20 -04:00
i8259.c KVM: x86: Fix poll command 2023-06-01 13:44:13 -07:00
ioapic.c KVM: x86/ioapic: Resample the pending state of an IRQ when unmasking 2023-03-27 10:13:28 -04:00
ioapic.h x86/kvm: remove unused ack_notifier callbacks 2021-11-18 07:05:57 -05:00
irq_comm.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
irq.c KVM: x86: Unify pr_fmt to use module name for all KVM modules 2022-12-29 15:47:35 -05:00
irq.h x86/kvm: remove unused ack_notifier callbacks 2021-11-18 07:05:57 -05:00
Kconfig KVM: x86: Add CONFIG_KVM_MAX_NR_VCPUS to allow up to 4096 vCPUs 2023-09-28 09:25:19 -07:00
kvm_cache_regs.h KVM: x86: Add helpers to query individual CR0/CR4 bits 2023-03-22 10:10:53 -07:00
kvm_emulate.h KVM: x86: Remove x86_emulate_ops::guest_has_long_mode 2023-08-02 15:47:27 -07:00
kvm_onhyperv.c KVM: x86/mmu: Move filling of Hyper-V's TLB range struct into Hyper-V code 2023-04-10 15:17:29 -07:00
kvm_onhyperv.h s390: 2023-05-01 12:06:20 -07:00
kvm-asm-offsets.c KVM: SVM: move MSR_IA32_SPEC_CTRL save/restore to assembly 2022-11-09 12:25:53 -05:00
lapic.c KVM x86 APIC changes for 6.7: 2023-10-31 10:11:19 -04:00
lapic.h KVM: x86: Split out logic to generate "readable" APIC regs mask to helper 2023-01-24 10:04:35 -08:00
Makefile KVM: x86: Introduce .hv_inject_synthetic_vmexit_post_tlb_flush() nested hook 2022-11-18 12:59:13 -05:00
mmu.h KVM: x86/mmu: Add helpers to return if KVM honors guest MTRRs 2023-10-09 14:34:57 -07:00
mtrr.c KVM: x86/mmu: Zap SPTEs on MTRR update iff guest MTRRs are honored 2023-10-09 14:35:14 -07:00
pmu.c KVM: x86/pmu: Synthesize at most one PMI per VM-exit 2023-09-25 14:42:52 -07:00
pmu.h KVM: x86/pmu: Truncate counter value to allowed width on write 2023-09-25 14:30:44 -07:00
reverse_cpuid.h KVM: x86: Advertise AMX-COMPLEX CPUID to userspace 2023-08-03 15:40:17 -07:00
smm.c KVM: x86: Remove redundant vcpu->arch.cr0 assignments 2023-09-27 12:57:48 -07:00
smm.h KVM: x86: smm: preserve interrupt shadow in SMRAM 2022-11-09 12:31:26 -05:00
trace.h KVM: x86/xen: Add CPL to Xen hypercall tracepoint 2022-11-28 13:31:01 -05:00
tss.h
x86.c KVM fixes for 6.7-rcN: 2023-12-08 13:13:45 -05:00
x86.h KVM: x86: Refine calculation of guest wall clock to use a single TSC read 2023-10-05 19:36:16 -07:00
xen.c KVM x86 Xen changes for 6.7: 2023-10-31 10:21:42 -04:00
xen.h KVM: x86/xen: update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present 2023-01-24 10:05:20 -08:00