Skip to content

Upgrade intel vPMU version to 5

Xiong Zhang kvm 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest9 patches 8 repliesIn review
  2. v19 patches 17 repliesSuperseded

Changes in v2 from the cover letter

* vLBR release bug not only happens in Freeze_LBR_On_PMI, but also happens on generic case. So the first commit fixes this bug. (Like Xu)
* Add new PERF_GLOBAL_STATUS_SET and PERF_GLOBAL_STATUS_INUSE MSRs into msrs_to_save_pmu[] (Like Xu)
* If INUSE_PMI bit is set, no need to write it again. (Like Xu)
* Get Fixed Counter enumeration from host for nested vPMU, but I marked it as Todo to wait for perf driver fixed counter bitmap supporting.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9KVM: x86/PMU: Delay vLBR release to the vcpu next sched-inarch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+19 -50 replies
2/9KVM: x86/pmu: Don't release vLBR casued by vPMIarch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+13 -52 replies
3/9KVM: x85/pmu: Add Streamlined FREEZE_LBR_ON_PMI for vPMU v4arch/x86/include/asm/msr-index.h arch/x86/kvm/pmu.c arch/x86/kvm/vmx/pmu_intel.c +1 more+57 -82 replies
4/9KVM: x86/pmu: Add PERF_GLOBAL_STATUS_SET MSR emulationarch/x86/include/asm/msr-index.h arch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/x86.c+18 -00 replies
5/9KVM: x86/pmu: Add MSR_CORE_PERF_GLOBAL_INUSE emulationarch/x86/include/asm/msr-index.h arch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/x86.c+68 -10 replies
6/9KVM: x86/pmu: Add Intel PMU supported fixed counters maskarch/x86/include/asm/kvm_host.h arch/x86/kvm/pmu.h arch/x86/kvm/svm/pmu.c +1 more+52 -310 replies
7/9KVM: x86/pmu: Add fixed counter enumeration for pmu v5arch/x86/kvm/cpuid.c+9 -10 replies
8/9KVM: x86/pmu: Upgrade pmu version to 5 on intel processorarch/x86/kvm/pmu.h+1 -10 replies
9/9KVM: selftests: Add fixed counters enumeration test casetools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c+79 -00 replies

Reviews trailers per patch

2 of 9 patches have a Reviewed-by or Acked-by.

PatchDapeng Mi
1/9
2/9
3/9R-b
4/9
5/9
6/9R-b
7/9
8/9
9/9

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/9] Upgrade intel vPMU version to 5

Intel recent processors have supported Architectural Performance Monitoring Version 5, while Intel vPMU still keeps on version 2. In order to use new PMU features introduced in version 4 and 5, this patchset upgrades vPMU version to 5.

Go through PMU features from version 3 to 5, the following features are supported by this patchset:
1. Streamlined Freeze LBR on PMI on version 4. This feature adds a new bit IA32_MSR_PERF_GLOBAL_STATUS.LBR_FRZ[58], it will be set when PMI happens and LBR stack is forzen. This bit also serves as a control to enable LBR stack. SW should clear this bit at the end of PMI handler to enable LBR stack.
2. IA32_PERF_GLOBAL_STATUS_RESET MSR on version 4. its address is inherited from IA32_PERF_GLOBAL_OVF_CTRL MSR, and they have the same function to clear individual bits in IA32_PERF_GLOBAL_STATUS MSR.
3. IA32_PERF_GLOBAL_STATUS_SET MSR on version 4. it allows software to set individual bits in IA32_PERF_GLOBAL_STATUS MSR.
4. IA32_PERF_GLOBAL_INUSE MSR on version 4. It provides an "InUse" bit for each programmable performance counter and fixed counter in the processor. Additionally, it includes an indicator if the PMI mechanisam has been used.
5. Fixed Counter Enumeration on version 5. CPUID.0AH.ECX provides a bit mask which enumerates the supported Fixed Counters in a processor.

For each added feature, the kvm emulation is straightforward and reflects vPMU state, please see each feature's emulation code in the following commits, a kvm unit test case or kernel selftests is added to verify this feature's emultion. Kernel doesn't use feature 3 and 4, so designed kvm unit test case is the only verification method for feature 3 and 4. I'm afraid that I miss something for these features, especially the user case for these features.

While the following features are not supported:
1. AnyThread counting: it is added in v3, and deprecated in v5. so this feature isn't supported.
2. Streamlined Freeze_PerfMon_On_PMI on version 4. Since legacy Freeze_PerMon_On_PMI on version 2 isn't supported and community think this feature has problems on native[1], so this feature's emulation isn't supported.
3. IA32_PERF_GLOBAL_STATUS.ASCI[bit 60] on version 4. This new bit relates to SGX, and will be emulated by SGX developer.
4. Domain Seperation on version 5. When INV flag in IA32_PERFEVTSELx is used, a counter stops counting when logical processor exits the C0 ACPI C-state. Guest ACPI C-state is vague, KVM has little information about guest ACPI C-state. So this feature's emulation isn't supported.

Changes since v1:
* vLBR release bug not only happens in Freeze_LBR_On_PMI, but also happens on generic case. So the first commit fixes this bug. (Like Xu)
* Add new PERF_GLOBAL_STATUS_SET and PERF_GLOBAL_STATUS_INUSE MSRs into msrs_to_save_pmu[] (Like Xu)
* If INUSE_PMI bit is set, no need to write it again. (Like Xu)
* Get Fixed Counter enumeration from host for nested vPMU, but I marked it as Todo to wait for perf driver fixed counter bitmap supporting.

Reference:
[1]: perf/intel: Remove Perfmon-v4 counter_freezing support
https://lore.kernel.org/all/[email protected]/

Like Xu (1):
KVM: x86/pmu: Add Intel PMU supported fixed counters mask

Xiong Zhang (8):
KVM: x86/PMU: Delay vLBR release to the vcpu next sched-in
KVM: x86/pmu: Don't release vLBR casued by vPMI
KVM: x85/pmu: Add Streamlined FREEZE_LBR_ON_PMI for vPMU v4
KVM: x86/pmu: Add PERF_GLOBAL_STATUS_SET MSR emulation
KVM: x86/pmu: Add MSR_CORE_PERF_GLOBAL_INUSE emulation
KVM: x86/pmu: Add fixed counter enumeration for pmu v5
KVM: x86/pmu: Upgrade pmu version to 5 on intel processor
KVM: selftests: Add fixed counters enumeration test case

 arch/x86/include/asm/kvm_host.h               |   1 -
 arch/x86/include/asm/msr-index.h              |   6 +
 arch/x86/kvm/cpuid.c                          |  10 +-
 arch/x86/kvm/pmu.c                            |   8 -
 arch/x86/kvm/pmu.h                            |  14 +-
 arch/x86/kvm/svm/pmu.c                        |   1 -
 arch/x86/kvm/vmx/pmu_intel.c                  | 205 +++++++++++++++---
 arch/x86/kvm/vmx/vmx.c                        |  19 +-
 arch/x86/kvm/vmx/vmx.h                        |   8 +
 arch/x86/kvm/x86.c                            |   1 +
 .../selftests/kvm/x86_64/vmx_pmu_caps_test.c  |  79 +++++++
 11 files changed, 308 insertions(+), 44 deletions(-)

base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d

Signature · 1 line
2.34.1