linux_dsm_epyc7002/arch/x86/kvm
Sean Christopherson 68cda40d9f KVM: nVMX: Tweak handling of failure code for nested VM-Enter failure
Use an enum for passing around the failure code for a failed VM-Enter
that results in VM-Exit to provide a level of indirection from the final
resting place of the failure code, vmcs.EXIT_QUALIFICATION.  The exit
qualification field is an unsigned long, e.g. passing around
'u32 exit_qual' throws up red flags as it suggests KVM may be dropping
bits when reporting errors to L1.  This is a red herring because the
only defined failure codes are 0, 2, 3, and 4, i.e. don't come remotely
close to overflowing a u32.

Setting vmcs.EXIT_QUALIFICATION on entry failure is further complicated
by the MSR load list, which returns the (1-based) entry that failed, and
the number of MSRs to load is a 32-bit VMCS field.  At first blush, it
would appear that overflowing a u32 is possible, but the number of MSRs
that can be loaded is hardcapped at 4096 (limited by MSR_IA32_VMX_MISC).

In other words, there are two completely disparate types of data that
eventually get stuffed into vmcs.EXIT_QUALIFICATION, neither of which is
an 'unsigned long' in nature.  This was presumably the reasoning for
switching to 'u32' when the related code was refactored in commit
ca0bde28f2 ("kvm: nVMX: Split VMCS checks from nested_vmx_run()").

Using an enum for the failure code addresses the technically-possible-
but-will-never-happen scenario where Intel defines a failure code that
doesn't fit in a 32-bit integer.  The enum variables and values will
either be automatically sized (gcc 5.4 behavior) or be subjected to some
combination of truncation.  The former case will simply work, while the
latter will trigger a compile-time warning unless the compiler is being
particularly unhelpful.

Separating the failure code from the failed MSR entry allows for
disassociating both from vmcs.EXIT_QUALIFICATION, which avoids the
conundrum where KVM has to choose between 'u32 exit_qual' and tracking
values as 'unsigned long' that have no business being tracked as such.
To cement the split, set vmcs12->exit_qualification directly from the
entry error code or failed MSR index instead of bouncing through a local
variable.

Opportunistically rename the variables in load_vmcs12_host_state() and
vmx_set_nested_state() to call out that they're ignored, set exit_reason
on demand on nested VM-Enter failure, and add a comment in
nested_vmx_load_msr() to call out that returning 'i + 1' can't wrap.

No functional change intended.

Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Jim Mattson <jmattson@google.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Message-Id: <20200511220529.11402-1-sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-15 12:07:31 -04:00
..
mmu KVM: x86/mmu: Capture TDP level when updating CPUID 2020-05-13 12:15:14 -04:00
svm KVM: x86/mmu: Capture TDP level when updating CPUID 2020-05-13 12:15:14 -04:00
vmx KVM: nVMX: Tweak handling of failure code for nested VM-Enter failure 2020-05-15 12:07:31 -04:00
cpuid.c KVM: x86/mmu: Capture TDP level when updating CPUID 2020-05-13 12:15:14 -04:00
cpuid.h KVM: x86: Fix BUILD_BUG() in __cpuid_entry_get_reg() w/ CONFIG_UBSAN=y 2020-03-31 10:51:45 -04:00
debugfs.c KVM: no need to check return value of debugfs_create functions 2019-08-05 12:55:49 +02:00
emulate.c KVM: x86: handle wrap around 32-bit address space 2020-05-13 12:14:59 -04:00
hyperv.c Merge branch 'kvm-amd-fixes' into HEAD 2020-05-13 12:14:05 -04:00
hyperv.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 499 2019-06-19 17:09:53 +02:00
i8254.c KVM: x86: Fix print format and coding style 2020-03-16 17:57:08 +01:00
i8254.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
i8259.c KVM: x86: Refactor picdev_write() to prevent Spectre-v1/L1TF attacks 2020-01-27 19:59:37 +01:00
ioapic.c kvm: ioapic: Restrict lazy EOI update to edge-triggered interrupts 2020-05-04 12:29:05 -04:00
ioapic.h KVM: X86: Move irrelevant declarations out of ioapic.h 2020-01-08 17:33:14 +01:00
irq_comm.c KVM: x86: don't notify userspace IOAPIC on edge-triggered interrupt EOI 2020-02-21 18:04:57 +01:00
irq.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 320 2019-06-05 17:37:05 +02:00
irq.h KVM: X86: Move irrelevant declarations out of ioapic.h 2020-01-08 17:33:14 +01:00
Kconfig vhost: refine vhost and vringh kconfig 2020-04-01 12:06:26 -04:00
kvm_cache_regs.h KVM: VMX: Add proper cache tracking for CR0 2020-05-13 12:15:12 -04:00
kvm_emulate.h ARM: 2020-04-02 15:13:15 -07:00
lapic.c kvm: Replace vcpu->swait with rcuwait 2020-05-13 12:14:56 -04:00
lapic.h KVM: x86: Return updated timer current count register from KVM_GET_LAPIC 2020-04-15 12:08:40 -04:00
Makefile kvm: Disable objtool frame pointer checking for vmenter.S 2020-04-20 17:11:19 -04:00
mmu_audit.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 499 2019-06-19 17:09:53 +02:00
mmu.h KVM: x86: Copy kvm_x86_ops by value to eliminate layer of indirection 2020-03-31 10:48:08 -04:00
mmutrace.h KVM: x86: fix incorrect comparison in trace event 2020-02-20 18:13:44 +01:00
mtrr.c KVM: x86: Protect MSR-based index computations in fixed_msr_to_seg_unit() from Spectre-v1/L1TF attacks 2020-01-27 19:59:39 +01:00
pmu.c KVM: x86: Copy kvm_x86_ops by value to eliminate layer of indirection 2020-03-31 10:48:08 -04:00
pmu.h KVM: x86: Copy kvm_x86_ops by value to eliminate layer of indirection 2020-03-31 10:48:08 -04:00
trace.h ARM: 2020-04-02 15:13:15 -07:00
tss.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
x86.c KVM: x86: Save L1 TSC offset in 'struct kvm_vcpu_arch' 2020-05-13 12:15:04 -04:00
x86.h KVM: x86: Introduce KVM_REQ_TLB_FLUSH_CURRENT to flush current ASID 2020-04-21 09:12:53 -04:00