Skip to content

KVM: x86/pmu: Add support for AMD Host-Only/Guest-Only bits

Jim Mattson kvm linux-kselftest linux-perf-users lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest5 patches 3 repliesIn review
  2. v25 patches 4 repliesSuperseded
  3. v16 patches 13 repliesSuperseded

Changes in v3 from the cover letter

* Dropped the svm_enter_guest_mode() and svm_leave_guest_mode() wrappers introduced in v2 [Yosry]
* Introduced a generic nested_transition callback in kvm_x86_ops to avoid confusing SVM-specific wrappers and unnecessary code replication
* Fixed a latent bug with L2 stack alignment, which was triggered by a movdqa instruction in l2_guest_code() that referenced the L2 stack. Note that l2_guest_code() expects the stack to be 16-byte misaligned at function entry. It was not.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5KVM: x86/pmu: Introduce amd_pmu_set_eventsel_hw()arch/x86/kvm/svm/pmu.c+7 -20 replies
2/5KVM: x86/pmu: Disable Host-Only/Guest-Only events as appropriate for vCPU statearch/x86/include/asm/perf_event.h arch/x86/kvm/svm/pmu.c+20 -02 replies
3/5KVM: x86/pmu: Refresh Host-Only/Guest-Only eventsel at nested transitionsarch/x86/include/asm/kvm-x86-ops.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/kvm_cache_regs.h +4 more+26 -01 reply
4/5KVM: x86/pmu: Allow Host-Only/Guest-Only bits with nSVM and mediated PMUarch/x86/kvm/svm/pmu.c+3 -00 replies
5/5KVM: selftests: x86: Add svm_pmu_host_guest_test for Host-Only/Guest-Only bitstools/testing/selftests/kvm/Makefile.kvm tools/testing/selftests/kvm/include/x86/pmu.h tools/testing/selftests/kvm/include/x86/processor.h +1 more+208 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/5] KVM: x86/pmu: Add support for AMD Host-Only/Guest-Only bits

This series adds support for AMD's Host-Only and Guest-Only performance counter eventsel bits in KVM's mediated PMU passthrough implementation.

These bits allow an nSVM-enabled guest to configure performance counters that count only during L1 execution (Host-Only) or only during L2 execution (Guest-Only).

KVM updates the hardware event selector ENABLE bit at the following state transitions to ensure counters only count in the appropriate mode:

- EFER.SVME changes: Enable/disable Guest-Only counters
- Nested VMRUN: Disable Host-Only, enable Guest-Only counters
- Nested VMEXIT: Enable Host-Only, disable Guest-Only counters

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

v2: https://lore.kernel.org/kvm/[email protected]/

v2 -> v3:
* Dropped the svm_enter_guest_mode() and svm_leave_guest_mode() wrappers introduced in v2 [Yosry]
* Introduced a generic nested_transition callback in kvm_x86_ops to avoid confusing SVM-specific wrappers and unnecessary code replication
* Fixed a latent bug with L2 stack alignment, which was triggered by a movdqa instruction in l2_guest_code() that referenced the L2 stack. Note that l2_guest_code() expects the stack to be 16-byte misaligned at function entry. It was not.

Jim Mattson (5):
KVM: x86/pmu: Introduce amd_pmu_set_eventsel_hw()
KVM: x86/pmu: Disable Host-Only/Guest-Only events as appropriate for
vCPU state
KVM: x86/pmu: Refresh Host-Only/Guest-Only eventsel at nested
transitions
KVM: x86/pmu: Allow Host-Only/Guest-Only bits with nSVM and mediated
PMU
KVM: selftests: x86: Add svm_pmu_host_guest_test for
Host-Only/Guest-Only bits

 arch/x86/include/asm/kvm-x86-ops.h            |   1 +
 arch/x86/include/asm/kvm_host.h               |   2 +
 arch/x86/include/asm/perf_event.h             |   2 +
 arch/x86/kvm/kvm_cache_regs.h                 |   2 +
 arch/x86/kvm/svm/pmu.c                        |  42 +++-
 arch/x86/kvm/svm/svm.c                        |   3 +
 arch/x86/kvm/svm/svm.h                        |   5 +
 arch/x86/kvm/x86.c                            |   1 +
 tools/testing/selftests/kvm/Makefile.kvm      |   1 +
 tools/testing/selftests/kvm/include/x86/pmu.h |   6 +
 .../selftests/kvm/include/x86/processor.h     |   2 +
 .../kvm/x86/svm_pmu_host_guest_test.c         | 199 ++++++++++++++++++
 12 files changed, 264 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86/svm_pmu_host_guest_test.c
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog