Skip to content
Permalink
Like-Xu/KVM-x8…
Switch branches/tags

Commits on Jan 24, 2022

  1. KVM: x86/cpuid: Exclude unpermitted xfeatures sizes at KVM_GET_SUPPOR…

    …TED_CPUID
    
    With the help of xstate_get_guest_group_perm(), KVM can exclude unpermitted
    xfeatures in cpuid.0xd.0.eax, in which case the corresponding xfeatures
    sizes should also be matched to the permitted xfeatures.
    
    Fixing this inconsistency by introducing a local variable with the same
    name also helps to fix cpuid.0xd.1.ebx and later leaf-by-leaf queries.
    
    Fixes: 445ecdf ("kvm: x86: Exclude unpermitted xfeatures at KVM_GET_SUPPORTED_CPUID")
    Signed-off-by: Like Xu <likexu@tencent.com>
    Like Xu authored and intel-lab-lkp committed Jan 24, 2022

Commits on Jan 20, 2022

  1. docs: kvm: fix WARNINGs from api.rst

    Use the api number 134 for KVM_GET_XSAVE2, instead of 42, which has been
    used by KVM_GET_XSAVE.
    Also, fix the WARNINGs of the underlines being too short.
    
    Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
    Signed-off-by: Wei Wang <wei.w.wang@intel.com>
    Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
    Message-Id: <20220120045003.315177-1-wei.w.wang@intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    wei-w-wang authored and bonzini committed Jan 20, 2022
  2. selftests: kvm/x86: Fix the warning in lib/x86_64/processor.c

    The following warning appears when executing
    make -C tools/testing/selftests/kvm
    
    include/x86_64/processor.h:290:2: warning: 'ecx' may be used uninitialized in this
    function [-Wmaybe-uninitialized]
      asm volatile("cpuid"
      ^~~
    lib/x86_64/processor.c:1523:21: note: 'ecx' was declared here
      uint32_t eax, ebx, ecx, edx, max_ext_leaf;
    
    Just initialize ecx to remove this warning.
    
    Fixes: c8cc43c ("selftests: KVM: avoid failures due to reserved HyperTransport region")
    Signed-off-by: Jinrong Liang <cloudliang@tencent.com>
    Message-Id: <20220119140325.59369-1-cloudliang@tencent.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Jinrong Liang authored and bonzini committed Jan 20, 2022
  3. selftests: kvm/x86: Fix the warning in pmu_event_filter_test.c

    The following warning appears when executing
    make -C tools/testing/selftests/kvm
    
    x86_64/pmu_event_filter_test.c: In function 'vcpu_supports_intel_br_retired':
    x86_64/pmu_event_filter_test.c:241:28: warning: variable 'cpuid' set but not used [-Wunused-but-set-variable]
      241 |         struct kvm_cpuid2 *cpuid;
          |                            ^~~~~
    x86_64/pmu_event_filter_test.c: In function 'vcpu_supports_amd_zen_br_retired':
    x86_64/pmu_event_filter_test.c:258:28: warning: variable 'cpuid' set but not used [-Wunused-but-set-variable]
      258 |         struct kvm_cpuid2 *cpuid;
          |                            ^~~~~
    
    Just delete the unused variables to stay away from warnings.
    
    Fixes: dc7e75b ("selftests: kvm/x86: Add test for KVM_SET_PMU_EVENT_FILTER")
    Signed-off-by: Jinrong Liang <cloudliang@tencent.com>
    Message-Id: <20220119133910.56285-1-cloudliang@tencent.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Jinrong Liang authored and bonzini committed Jan 20, 2022

Commits on Jan 19, 2022

  1. kvm: selftests: Do not indent with spaces

    Some indentation with spaces crept in, likely due to terminal-based
    cut and paste.  Clean it up.
    
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    bonzini committed Jan 19, 2022
  2. kvm: selftests: sync uapi/linux/kvm.h with Linux header

    KVM_CAP_XSAVE2 is out of sync due to a conflict.  Copy the whole
    file while at it.
    
    Reported-by: Yang Zhong <yang.zhong@intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    bonzini committed Jan 19, 2022
  3. selftests: kvm: add amx_test to .gitignore

    amx_test's binary should be present in the .gitignore file for the git
    to ignore it.
    
    Fixes: bf70636 ("selftest: kvm: Add amx selftest")
    Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
    Message-Id: <20220118122053.1941915-1-usama.anjum@collabora.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    musamaanjum authored and bonzini committed Jan 19, 2022
  4. KVM: SVM: Nullify vcpu_(un)blocking() hooks if AVIC is disabled

    Nullify svm_x86_ops.vcpu_(un)blocking if AVIC/APICv is disabled as the
    hooks are necessary only to clear the vCPU's IsRunning entry in the
    Physical APIC and to update IRTE entries if the VM has a pass-through
    device attached.
    
    Opportunistically rename the helpers to clarify their AVIC relationship.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-24-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  5. KVM: SVM: Move svm_hardware_setup() and its helpers below svm_x86_ops

    Move svm_hardware_setup() below svm_x86_ops so that KVM can modify ops
    during setup, e.g. the vcpu_(un)blocking hooks can be nullified if AVIC
    is disabled or unsupported.
    
    No functional change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-23-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  6. KVM: SVM: Drop AVIC's intermediate avic_set_running() helper

    Drop avic_set_running() in favor of calling avic_vcpu_{load,put}()
    directly, and modify the block+put path to use preempt_disable/enable()
    instead of get/put_cpu(), as it doesn't actually care about the current
    pCPU associated with the vCPU.  Opportunistically add lockdep assertions
    as being preempted in avic_vcpu_put() would lead to consuming stale data,
    even though doing so _in the current code base_ would not be fatal.
    
    Add a much needed comment explaining why svm_vcpu_blocking() needs to
    unload the AVIC and update the IRTE _before_ the vCPU starts blocking.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-22-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  7. KVM: VMX: Don't do full kick when handling posted interrupt wakeup

    When waking vCPUs in the posted interrupt wakeup handling, do exactly
    that and no more.  There is no need to kick the vCPU as the wakeup
    handler just needs to get the vCPU task running, and if it's in the guest
    then it's definitely running.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-21-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  8. KVM: VMX: Fold fallback path into triggering posted IRQ helper

    Move the fallback "wake_up" path into the helper to trigger posted
    interrupt helper now that the nested and non-nested paths are identical.
    
    No functional change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-20-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  9. KVM: VMX: Pass desired vector instead of bool for triggering posted IRQ

    Refactor the posted interrupt helper to take the desired notification
    vector instead of a bool so that the callers are self-documenting.
    
    No functional change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-19-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  10. KVM: VMX: Don't do full kick when triggering posted interrupt "fails"

    Replace the full "kick" with just the "wake" in the fallback path when
    triggering a virtual interrupt via a posted interrupt fails because the
    guest is not IN_GUEST_MODE.  If the guest transitions into guest mode
    between the check and the kick, then it's guaranteed to see the pending
    interrupt as KVM syncs the PIR to IRR (and onto GUEST_RVI) after setting
    IN_GUEST_MODE.  Kicking the guest in this case is nothing more than an
    unnecessary VM-Exit (and host IRQ).
    
    Opportunistically update comments to explain the various ordering rules
    and barriers at play.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-17-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  11. KVM: SVM: Skip AVIC and IRTE updates when loading blocking vCPU

    Don't bother updating the Physical APIC table or IRTE when loading a vCPU
    that is blocking, i.e. won't be marked IsRun{ning}=1, as the pCPU is
    queried if and only if IsRunning is '1'.  If the vCPU was migrated, the
    new pCPU will be picked up when avic_vcpu_load() is called by
    svm_vcpu_unblocking().
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-15-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  12. KVM: SVM: Use kvm_vcpu_is_blocking() in AVIC load to handle preemption

    Use kvm_vcpu_is_blocking() to determine whether or not the vCPU should be
    marked running during avic_vcpu_load().  Drop avic_is_running, which
    really should have been named "vcpu_is_not_blocking", as it tracked if
    the vCPU was blocking, not if it was actually running, e.g. it was set
    during svm_create_vcpu() when the vCPU was obviously not running.
    
    This is technically a teeny tiny functional change, as the vCPU will be
    marked IsRunning=1 on being reloaded if the vCPU is preempted between
    svm_vcpu_blocking() and prepare_to_rcuwait().  But that's a benign change
    as the vCPU will be marked IsRunning=0 when KVM voluntarily schedules out
    the vCPU.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-14-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  13. KVM: SVM: Remove unnecessary APICv/AVIC update in vCPU unblocking path

    Remove handling of KVM_REQ_APICV_UPDATE from svm_vcpu_unblocking(), it's
    no longer needed as it was made obsolete by commit df7e482 ("KVM:
    SVM: call avic_vcpu_load/avic_vcpu_put when enabling/disabling AVIC").
    Prior to that commit, the manual check was necessary to ensure the AVIC
    stuff was updated by avic_set_running() when a request to enable APICv
    became pending while the vCPU was blocking, as the request handling
    itself would not do the update.  But, as evidenced by the commit, that
    logic was flawed and subject to various races.
    
    Now that svm_refresh_apicv_exec_ctrl() does avic_vcpu_load/put() in
    response to an APICv status change, drop the manual check in the
    unblocking path.
    
    Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-13-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  14. KVM: SVM: Don't bother checking for "running" AVIC when kicking for IPIs

    Drop the avic_vcpu_is_running() check when waking vCPUs in response to a
    VM-Exit due to incomplete IPI delivery.  The check isn't wrong per se, but
    it's not 100% accurate in the sense that it doesn't guarantee that the vCPU
    was one of the vCPUs that didn't receive the IPI.
    
    The check isn't required for correctness as blocking == !running in this
    context.
    
    From a performance perspective, waking a live task is not expensive as the
    only moderately costly operation is a locked operation to temporarily
    disable preemption.  And if that is indeed a performance issue,
    kvm_vcpu_is_blocking() would be a better check than poking into the AVIC.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-12-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  15. KVM: SVM: Signal AVIC doorbell iff vCPU is in guest mode

    Signal the AVIC doorbell iff the vCPU is running in the guest.  If the vCPU
    is not IN_GUEST_MODE, it's guaranteed to pick up any pending IRQs on the
    next VMRUN, which unconditionally processes the vIRR.
    
    Add comments to document the logic.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211208015236.1616697-11-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  16. KVM: x86: Remove defunct pre_block/post_block kvm_x86_ops hooks

    Drop kvm_x86_ops' pre/post_block() now that all implementations are nops.
    
    No functional change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-10-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  17. KVM: x86: Unexport LAPIC's switch_to_{hv,sw}_timer() helpers

    Unexport switch_to_{hv,sw}_timer() now that common x86 handles the
    transitions.
    
    No functional change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-9-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  18. KVM: VMX: Move preemption timer <=> hrtimer dance to common x86

    Handle the switch to/from the hypervisor/software timer when a vCPU is
    blocking in common x86 instead of in VMX.  Even though VMX is the only
    user of a hypervisor timer, the logic and all functions involved are
    generic x86 (unless future CPUs do something completely different and
    implement a hypervisor timer that runs regardless of mode).
    
    Handling the switch in common x86 will allow for the elimination of the
    pre/post_blocks hooks, and also lets KVM switch back to the hypervisor
    timer if and only if it was in use (without additional params).  Add a
    comment explaining why the switch cannot be deferred to kvm_sched_out()
    or kvm_vcpu_block().
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-8-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  19. KVM: Move x86 VMX's posted interrupt list_head to vcpu_vmx

    Move the seemingly generic block_vcpu_list from kvm_vcpu to vcpu_vmx, and
    rename the list and all associated variables to clarify that it tracks
    the set of vCPU that need to be poked on a posted interrupt to the wakeup
    vector.  The list is not used to track _all_ vCPUs that are blocking, and
    the term "blocked" can be misleading as it may refer to a blocking
    condition in the host or the guest, where as the PI wakeup case is
    specifically for the vCPUs that are actively blocking from within the
    guest.
    
    No functional change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-7-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  20. KVM: Drop unused kvm_vcpu.pre_pcpu field

    Remove kvm_vcpu.pre_pcpu as it no longer has any users.  No functional
    change intended.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-6-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  21. KVM: VMX: Handle PI descriptor updates during vcpu_put/load

    Move the posted interrupt pre/post_block logic into vcpu_put/load
    respectively, using the kvm_vcpu_is_blocking() to determining whether or
    not the wakeup handler needs to be set (and unset).  This avoids updating
    the PI descriptor if halt-polling is successful, reduces the number of
    touchpoints for updating the descriptor, and eliminates the confusing
    behavior of intentionally leaving a "stale" PI.NDST when a blocking vCPU
    is scheduled back in after preemption.
    
    The downside is that KVM will do the PID update twice if the vCPU is
    preempted after prepare_to_rcuwait() but before schedule(), but that's a
    rare case (and non-existent on !PREEMPT kernels).
    
    The notable wart is the need to send a self-IPI on the wakeup vector if
    an outstanding notification is pending after configuring the wakeup
    vector.  Ideally, KVM would just do a kvm_vcpu_wake_up() in this case,
    but the scheduler doesn't support waking a task from its preemption
    notifier callback, i.e. while the task is right in the middle of
    being scheduled out.
    
    Note, setting the wakeup vector before halt-polling is not necessary:
    once the pending IRQ will be recorded in the PIR, kvm_vcpu_has_events()
    will detect this (via kvm_cpu_get_interrupt(), kvm_apic_get_interrupt(),
    apic_has_interrupt_for_ppr() and finally vmx_sync_pir_to_irr()) and
    terminate the polling.
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
    Message-Id: <20211208015236.1616697-5-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  22. Merge branch 'kvm-pi-raw-spinlock' into HEAD

    Bring in fix for VT-d posted interrupts before further changing the code in 5.17.
    
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    bonzini committed Jan 19, 2022
  23. KVM: avoid warning on s390 in mark_page_dirty

    Avoid warnings on s390 like
    [ 1801.980931] CPU: 12 PID: 117600 Comm: kworker/12:0 Tainted: G            E     5.17.0-20220113.rc0.git0.32ce2abb03cf.300.fc35.s390x+next #1
    [ 1801.980938] Workqueue: events irqfd_inject [kvm]
    [...]
    [ 1801.981057] Call Trace:
    [ 1801.981060]  [<000003ff805f0f5c>] mark_page_dirty_in_slot+0xa4/0xb0 [kvm]
    [ 1801.981083]  [<000003ff8060e9fe>] adapter_indicators_set+0xde/0x268 [kvm]
    [ 1801.981104]  [<000003ff80613c24>] set_adapter_int+0x64/0xd8 [kvm]
    [ 1801.981124]  [<000003ff805fb9aa>] kvm_set_irq+0xc2/0x130 [kvm]
    [ 1801.981144]  [<000003ff805f8d86>] irqfd_inject+0x76/0xa0 [kvm]
    [ 1801.981164]  [<0000000175e56906>] process_one_work+0x1fe/0x470
    [ 1801.981173]  [<0000000175e570a4>] worker_thread+0x64/0x498
    [ 1801.981176]  [<0000000175e5ef2c>] kthread+0x10c/0x110
    [ 1801.981180]  [<0000000175de73c8>] __ret_from_fork+0x40/0x58
    [ 1801.981185]  [<000000017698440a>] ret_from_fork+0xa/0x40
    
    when writing to a guest from an irqfd worker as long as we do not have
    the dirty ring.
    
    Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
    Reluctantly-acked-by: David Woodhouse <dwmw@amazon.co.uk>
    Message-Id: <20220113122924.740496-1-borntraeger@linux.ibm.com>
    Fixes: 2efd61a ("KVM: Warn if mark_page_dirty() is called without an active vCPU")
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    borntraeger authored and bonzini committed Jan 19, 2022
  24. KVM: selftests: Add a test to force emulation with a pending exception

    Add a VMX specific test to verify that KVM doesn't explode if userspace
    attempts KVM_RUN when emulation is required with a pending exception.
    KVM VMX's emulation support for !unrestricted_guest punts exceptions to
    userspace instead of attempting to synthesize the exception with all the
    correct state (and stack switching, etc...).
    
    Punting is acceptable as there's never been a request to support
    injecting exceptions when emulating due to invalid state, but KVM has
    historically assumed that userspace will do the right thing and either
    clear the exception or kill the guest.  Deliberately do the opposite and
    attempt to re-enter the guest with a pending exception and emulation
    required to verify KVM continues to punt the combination to userspace,
    e.g. doesn't explode, WARN, etc...
    
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211228232437.1875318-3-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  25. KVM: VMX: Reject KVM_RUN if emulation is required with pending exception

    Reject KVM_RUN if emulation is required (because VMX is running without
    unrestricted guest) and an exception is pending, as KVM doesn't support
    emulating exceptions except when emulating real mode via vm86.  The vCPU
    is hosed either way, but letting KVM_RUN proceed triggers a WARN due to
    the impossible condition.  Alternatively, the WARN could be removed, but
    then userspace and/or KVM bugs would result in the vCPU silently running
    in a bad state, which isn't very friendly to users.
    
    Originally, the bug was hit by syzkaller with a nested guest as that
    doesn't require kvm_intel.unrestricted_guest=0.  That particular flavor
    is likely fixed by commit cd0e615 ("KVM: nVMX: Synthesize
    TRIPLE_FAULT for L2 if emulation is required"), but it's trivial to
    trigger the WARN with a non-nested guest, and userspace can likely force
    bad state via ioctls() for a nested guest as well.
    
    Checking for the impossible condition needs to be deferred until KVM_RUN
    because KVM can't force specific ordering between ioctls.  E.g. clearing
    exception.pending in KVM_SET_SREGS doesn't prevent userspace from setting
    it in KVM_SET_VCPU_EVENTS, and disallowing KVM_SET_VCPU_EVENTS with
    emulation_required would prevent userspace from queuing an exception and
    then stuffing sregs.  Note, if KVM were to try and detect/prevent the
    condition prior to KVM_RUN, handle_invalid_guest_state() and/or
    handle_emulation_failure() would need to be modified to clear the pending
    exception prior to exiting to userspace.
    
     ------------[ cut here ]------------
     WARNING: CPU: 6 PID: 137812 at arch/x86/kvm/vmx/vmx.c:1623 vmx_queue_exception+0x14f/0x160 [kvm_intel]
     CPU: 6 PID: 137812 Comm: vmx_invalid_nes Not tainted 5.15.2-7cc36c3e14ae-pop torvalds#279
     Hardware name: ASUS Q87M-E/Q87M-E, BIOS 1102 03/03/2014
     RIP: 0010:vmx_queue_exception+0x14f/0x160 [kvm_intel]
     Code: <0f> 0b e9 fd fe ff ff 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00
     RSP: 0018:ffffa45c83577d38 EFLAGS: 00010202
     RAX: 0000000000000003 RBX: 0000000080000006 RCX: 0000000000000006
     RDX: 0000000000000000 RSI: 0000000000010002 RDI: ffff9916af734000
     RBP: ffff9916af734000 R08: 0000000000000000 R09: 0000000000000000
     R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000006
     R13: 0000000000000000 R14: ffff9916af734038 R15: 0000000000000000
     FS:  00007f1e1a47c740(0000) GS:ffff99188fb80000(0000) knlGS:0000000000000000
     CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
     CR2: 00007f1e1a6a8008 CR3: 000000026f83b005 CR4: 00000000001726e0
     Call Trace:
      kvm_arch_vcpu_ioctl_run+0x13a2/0x1f20 [kvm]
      kvm_vcpu_ioctl+0x279/0x690 [kvm]
      __x64_sys_ioctl+0x83/0xb0
      do_syscall_64+0x3b/0xc0
      entry_SYSCALL_64_after_hwframe+0x44/0xae
    
    Reported-by: syzbot+82112403ace4cbd780d8@syzkaller.appspotmail.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>
    Message-Id: <20211228232437.1875318-2-seanjc@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    sean-jc authored and bonzini committed Jan 19, 2022
  26. selftests: kvm/x86: Add test for KVM_SET_PMU_EVENT_FILTER

    Verify that the PMU event filter works as expected.
    
    Note that the virtual PMU doesn't work as expected on AMD Zen CPUs (an
    intercepted rdmsr is counted as a retired branch instruction), but the
    PMU event filter does work.
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Message-Id: <20220115052431.447232-7-jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    jsmattsonjr authored and bonzini committed Jan 19, 2022
  27. selftests: kvm/x86: Introduce x86_model()

    Extract the x86 model number from CPUID.01H:EAX.
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Message-Id: <20220115052431.447232-6-jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    jsmattsonjr authored and bonzini committed Jan 19, 2022
  28. selftests: kvm/x86: Export x86_family() for use outside of processor.c

    Move this static inline function to processor.h, so that it can be
    used in individual tests, as needed.
    
    Opportunistically replace the bare 'unsigned' with 'unsigned int.'
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Message-Id: <20220115052431.447232-5-jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    jsmattsonjr authored and bonzini committed Jan 19, 2022
  29. selftests: kvm/x86: Introduce is_amd_cpu()

    Replace the one ad hoc "AuthenticAMD" CPUID vendor string comparison
    with a new function, is_amd_cpu().
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Message-Id: <20220115052431.447232-4-jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    jsmattsonjr authored and bonzini committed Jan 19, 2022
  30. selftests: kvm/x86: Parameterize the CPUID vendor string check

    Refactor is_intel_cpu() to make it easier to reuse the bulk of the
    code for other vendors in the future.
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Message-Id: <20220115052431.447232-3-jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    jsmattsonjr authored and bonzini committed Jan 19, 2022
  31. KVM: x86/pmu: Use binary search to check filtered events

    The PMU event filter may contain up to 300 events. Replace the linear
    search in reprogram_gp_counter() with a binary search.
    
    Signed-off-by: Jim Mattson <jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Message-Id: <20220115052431.447232-2-jmattson@google.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    jsmattsonjr authored and bonzini committed Jan 19, 2022
Older