Skip to content
Snippets Groups Projects
Commit f3a6888f authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov
Browse files

KVM: nVMX: Attempt to load PERF_GLOBAL_CTRL on nVMX xfer iff it exists

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2119111



commit 4496a6f9
Author: Sean Christopherson <seanjc@google.com>
Date:   Fri Jul 22 22:44:08 2022 +0000

    KVM: nVMX: Attempt to load PERF_GLOBAL_CTRL on nVMX xfer iff it exists

    Attempt to load PERF_GLOBAL_CTRL during nested VM-Enter/VM-Exit if and
    only if the MSR exists (according to the guest vCPU model).  KVM has very
    misguided handling of VM_{ENTRY,EXIT}_LOAD_IA32_PERF_GLOBAL_CTRL and
    attempts to force the nVMX MSR settings to match the vPMU model, i.e. to
    hide/expose the control based on whether or not the MSR exists from the
    guest's perspective.

    KVM's modifications fail to handle the scenario where the vPMU is hidden
    from the guest _after_ being exposed to the guest, e.g. by userspace
    doing multiple KVM_SET_CPUID2 calls, which is allowed if done before any
    KVM_RUN.  nested_vmx_pmu_refresh() is called if and only if there's a
    recognized vPMU, i.e. KVM will leave the bits in the allow state and then
    ultimately reject the MSR load and WARN.

    KVM should not force the VMX MSRs in the first place.  KVM taking control
    of the MSRs was a misguided attempt at mimicking what commit 5f76f6f5
    ("KVM: nVMX: Do not expose MPX VMX controls when guest MPX disabled",
    2018-10-01) did for MPX.  However, the MPX commit was a workaround for
    another KVM bug and not something that should be imitated (and it should
    never been done in the first place).

    In other words, KVM's ABI _should_ be that userspace has full control
    over the MSRs, at which point triggering the WARN that loading the MSR
    must not fail is trivial.

    The intent of the WARN is still valid; KVM has consistency checks to
    ensure that vmcs12->{guest,host}_ia32_perf_global_ctrl is valid.  The
    problem is that '0' must be considered a valid value at all times, and so
    the simple/obvious solution is to just not actually load the MSR when it
    does not exist.  It is userspace's responsibility to provide a sane vCPU
    model, i.e. KVM is well within its ABI and Intel's VMX architecture to
    skip the loads if the MSR does not exist.

    Fixes: 03a8871a ("KVM: nVMX: Expose load IA32_PERF_GLOBAL_CTRL VM-{Entry,Exit} control")
    Cc: stable@vger.kernel.org
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Message-Id: <20220722224409.1336532-5-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>

Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
parent 4f1c5a07
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment