[GIT,PULL] KVM: x86: PMU changes for 6.8

Message ID 20240104193303.3175844-7-seanjc@google.com
State New
Headers
Series [GIT,PULL] KVM: x86: PMU changes for 6.8 |

Pull-request

https://github.com/kvm-x86/linux.git tags/kvm-x86-pmu-6.8

Message

Sean Christopherson Jan. 4, 2024, 7:33 p.m. UTC
  PMU fixes and cleanups.  The highlight is a fix for a double-overflow PMI bug
when KVM manually emulates counter events, which was made mostly benign by
commit a16eb25b09c0 ("KVM: x86: Mask LVTPC when handling a PMI"), but is still
a bug.

Note, the "Track emulated counter events instead of previous counter" fix
breaks the PMU KVM-Unit-Test due to a long-standing "bug" in perf[*].  If need
be, it's trivial to fudge around the shortcomings in the KUT code, I just
haven't carved out time to push things along.

[*] https://lore.kernel.org/all/20231107183605.409588-1-seanjc@google.com

The following changes since commit e9e60c82fe391d04db55a91c733df4a017c28b2f:

  selftests/kvm: fix compilation on non-x86_64 platforms (2023-11-21 11:58:25 -0500)

are available in the Git repository at:

  https://github.com/kvm-x86/linux.git tags/kvm-x86-pmu-6.8

for you to fetch changes up to fd89499a5151d197ba30f7b801f6d8f4646cf446:

  KVM: x86/pmu: Track emulated counter events instead of previous counter (2023-11-30 12:52:55 -0800)

----------------------------------------------------------------
KVM x86 PMU changes for 6.8:

 - Fix a variety of bugs where KVM fail to stop/reset counters and other state
   prior to refreshing the vPMU model.

 - Fix a double-overflow PMU bug by tracking emulated counter events using a
   dedicated field instead of snapshotting the "previous" counter.  If the
   hardware PMC count triggers overflow that is recognized in the same VM-Exit
   that KVM manually bumps an event count, KVM would pend PMIs for both the
   hardware-triggered overflow and for KVM-triggered overflow.

----------------------------------------------------------------
Sean Christopherson (6):
      KVM: x86/pmu: Move PMU reset logic to common x86 code
      KVM: x86/pmu: Reset the PMU, i.e. stop counters, before refreshing
      KVM: x86/pmu: Stop calling kvm_pmu_reset() at RESET (it's redundant)
      KVM: x86/pmu: Remove manual clearing of fields in kvm_pmu_init()
      KVM: x86/pmu: Update sample period in pmc_write_counter()
      KVM: x86/pmu: Track emulated counter events instead of previous counter

 arch/x86/include/asm/kvm-x86-pmu-ops.h |   2 +-
 arch/x86/include/asm/kvm_host.h        |  17 +++-
 arch/x86/kvm/pmu.c                     | 140 +++++++++++++++++++++++++++------
 arch/x86/kvm/pmu.h                     |  47 +----------
 arch/x86/kvm/svm/pmu.c                 |  17 ----
 arch/x86/kvm/vmx/pmu_intel.c           |  22 ------
 arch/x86/kvm/x86.c                     |   1 -
 7 files changed, 137 insertions(+), 109 deletions(-)
  

Comments

Paolo Bonzini Jan. 8, 2024, 12:57 p.m. UTC | #1
On Thu, Jan 4, 2024 at 8:33 PM Sean Christopherson <seanjc@google.com> wrote:
>
> PMU fixes and cleanups.  The highlight is a fix for a double-overflow PMI bug
> when KVM manually emulates counter events, which was made mostly benign by
> commit a16eb25b09c0 ("KVM: x86: Mask LVTPC when handling a PMI"), but is still
> a bug.
>
> Note, the "Track emulated counter events instead of previous counter" fix
> breaks the PMU KVM-Unit-Test due to a long-standing "bug" in perf[*].  If need
> be, it's trivial to fudge around the shortcomings in the KUT code, I just
> haven't carved out time to push things along.
>
> [*] https://lore.kernel.org/all/20231107183605.409588-1-seanjc@google.com
>
> The following changes since commit e9e60c82fe391d04db55a91c733df4a017c28b2f:
>
>   selftests/kvm: fix compilation on non-x86_64 platforms (2023-11-21 11:58:25 -0500)
>
> are available in the Git repository at:
>
>   https://github.com/kvm-x86/linux.git tags/kvm-x86-pmu-6.8
>
> for you to fetch changes up to fd89499a5151d197ba30f7b801f6d8f4646cf446:
>
>   KVM: x86/pmu: Track emulated counter events instead of previous counter (2023-11-30 12:52:55 -0800)

Pulled, thanks.

Paolo

> ----------------------------------------------------------------
> KVM x86 PMU changes for 6.8:
>
>  - Fix a variety of bugs where KVM fail to stop/reset counters and other state
>    prior to refreshing the vPMU model.
>
>  - Fix a double-overflow PMU bug by tracking emulated counter events using a
>    dedicated field instead of snapshotting the "previous" counter.  If the
>    hardware PMC count triggers overflow that is recognized in the same VM-Exit
>    that KVM manually bumps an event count, KVM would pend PMIs for both the
>    hardware-triggered overflow and for KVM-triggered overflow.
>
> ----------------------------------------------------------------
> Sean Christopherson (6):
>       KVM: x86/pmu: Move PMU reset logic to common x86 code
>       KVM: x86/pmu: Reset the PMU, i.e. stop counters, before refreshing
>       KVM: x86/pmu: Stop calling kvm_pmu_reset() at RESET (it's redundant)
>       KVM: x86/pmu: Remove manual clearing of fields in kvm_pmu_init()
>       KVM: x86/pmu: Update sample period in pmc_write_counter()
>       KVM: x86/pmu: Track emulated counter events instead of previous counter
>
>  arch/x86/include/asm/kvm-x86-pmu-ops.h |   2 +-
>  arch/x86/include/asm/kvm_host.h        |  17 +++-
>  arch/x86/kvm/pmu.c                     | 140 +++++++++++++++++++++++++++------
>  arch/x86/kvm/pmu.h                     |  47 +----------
>  arch/x86/kvm/svm/pmu.c                 |  17 ----
>  arch/x86/kvm/vmx/pmu_intel.c           |  22 ------
>  arch/x86/kvm/x86.c                     |   1 -
>  7 files changed, 137 insertions(+), 109 deletions(-)
>