Skip to content

KVM: x86/pmu: Clean up emulated PMC event handling

Sean Christopherson kvm lkml 2 versions – Applied

Status from this message: Applied to kvm-x86 pmu, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 2 repliesApplied
  2. v16 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- Collect reviews. [Dapeng]
- Emulate overflow *after* pausing perf event. [Mingwei]

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/6KVM: x86/pmu: Move PMU reset logic to common x86 codearch/x86/include/asm/kvm-x86-pmu-ops.h arch/x86/kvm/pmu.c arch/x86/kvm/pmu.h +2 more+40 -560 replies
2/6KVM: x86/pmu: Reset the PMU, i.e. stop counters, before refreshingarch/x86/kvm/pmu.c+22 -130 replies
3/6KVM: x86/pmu: Stop calling kvm_pmu_reset() at RESET (it's redundant)arch/x86/kvm/pmu.c arch/x86/kvm/pmu.h arch/x86/kvm/x86.c+1 -30 replies
4/6KVM: x86/pmu: Remove manual clearing of fields in kvm_pmu_init()arch/x86/kvm/pmu.c+0 -20 replies
5/6KVM: x86/pmu: Update sample period in pmc_write_counter()arch/x86/kvm/pmu.c arch/x86/kvm/pmu.h arch/x86/kvm/svm/pmu.c +1 more+28 -270 replies
6/6KVM: x86/pmu: Track emulated counter events instead of previous counterarch/x86/include/asm/kvm_host.h arch/x86/kvm/pmu.c arch/x86/kvm/pmu.h+53 -151 reply

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by.

PatchDapeng MiMingwei Zhang
1/6R-b
2/6R-b
3/6R-b
4/6R-b
5/6R-b
6/6R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/6] KVM: x86/pmu: Clean up emulated PMC event handling

The ultimate goal of this series is to track emulated counter events using a dedicated variable instead of trying to track the previous counter value. Tracking the previous counter value is flawed as it takes a snapshot at every emulated event, but only checks for overflow prior to VM-Enter, i.e. KVM could miss an overflow if KVM ever supports emulating event types that can occur multiple times in a single VM-Exit.

And as Mingwei root caused, emulating overflow while the perf event is running can result in duplicate overflow events, e.g. if the perf event overflows between taking and checking the snapshot. This bug is largely masked now that KVM correctly sets LVT_MASK when delivering PMIs, but it's still a bug, e.g. could cause problems if there are other side effects.

Patches 1-5 are (some loosely, some tightly) related fixes and cleanups to simplify the emulated counter approach implementation. The fixes are tagged for stable as usersepace could cause some weirdness around perf events, but I doubt any real world VMM is actually affected.

Dapeng, I intentionally omitted your Reviewed-by from the last patch as the change from v1 isn't trivial.

v2:
- Collect reviews. [Dapeng]
- Emulate overflow *after* pausing perf event. [Mingwei]

v1: https://lore.kernel.org/all/[email protected]

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(-)

base-commit: 45b890f7689eb0aba454fc5831d2d79763781677

Signature · 1 line
2.42.0.869.gea05f2083d-goog