Skip to content

KVM: arm64: Expose PMMIR_EL1.SLOTS to guests

Congkai Tan kvm kvmarm linux-arm-kernel linux-doc linux-kselftest lkml sashiko-reviews 3 versions – Applied

Status from this message: Applied to next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest4 patches 3 repliesApplied
  2. v23 patches 2 repliesSuperseded
  3. v11 patch 5 repliesSuperseded

Changes in v3 from the cover letter

- Reordered so the KVM_ARM_VCPU_PMU_V3_STRICT flag / KVM_CAP exposure comes last (now patch 4), after the flag-guarded behavior patches.
- Reworked on top of Oliver Upton's refinements (thanks!):
* Move the NULL-arm_pmu check into kvm_arm_pmu_v3_init() (returns -ENXIO) instead of failing at the first KVM_RUN, and report zero counters from kvm_arm_pmu_get_max_counters() before a PMU is set.
* Documentation and -ENXIO ordering notes for the PMU device attributes (SET_PMU must precede INIT/FILTER).
- New patch (Oliver): ignore userspace writes to PMCR_EL0.N under the strict flag and require the KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS attribute, since PMCR_EL0.N is context-dependent under NV.
- Advertise the KVM_CAP_ARM_PMU_V3_STRICT capability.
- Documentation fixes in api.rst (the flag Requires KVM_ARM_VCPU_PMU_V3).

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/4KVM: arm64: Expose PMMIR_EL1.SLOTS under strict PMUv3 UAPIarch/arm64/include/asm/kvm_host.h arch/arm64/include/uapi/asm/kvm.h arch/arm64/kvm/pmu-emul.c +3 more+81 -21 reply
2/4KVM: arm64: Advertise STALL_SLOT* in PMCEID1 under strict PMUv3 UAPIarch/arm64/kvm/pmu-emul.c+13 -120 replies
3/4KVM: arm64: Ignore writes to PMCR_EL0.N when using strict UAPIarch/arm64/kvm/sys_regs.c+1 -00 replies
4/4KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_STRICT vCPU featureDocumentation/virt/kvm/api.rst Documentation/virt/kvm/devices/vcpu.rst arch/arm64/include/asm/kvm_host.h +3 more+54 -80 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchGeoff BlakeHaris OkanovicStanislav SpassovFuad Tabba
SeriesR-b T-b
1/4R-b R-b R-b
2/4R-b R-b R-b
3/4R-b R-b
4/4R-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v3 thread

Cover letter [PATCH v3 0/4] KVM: arm64: Expose PMMIR_EL1.SLOTS to guests

Today when the perf tool runs in a guest on cores with PMUv3p4, it fails to parse the default metrics with "Failure to read '#slots'", since perf can only read 0 from sysfs caps/slots, which is backed by PMMIR_EL1.SLOTS that KVM traps as RAZ/WI.

Taking into account backward compatibility and heterogeneous systems, the exposure of PMMIR_EL1.SLOTS is gated behind a new vCPU feature flag:

- Patch 1 exposes PMMIR_EL1.SLOTS of the selected PMU under the (as yet unsettable) KVM_ARM_VCPU_PMU_V3_STRICT flag, and adds userspace get/set for PMMIR_EL1 so that SLOTS can be reset to 0 for backward compatibility.
- Patch 2 stops masking STALL_SLOT* in PMCEID1 under the flag.
- Patch 3 makes strict-mode userspace configure the number of event counters via the KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS attribute rather than PMCR_EL0.N, whose meaning is context-dependent under NV.
- Patch 4 adds the KVM_ARM_VCPU_PMU_V3_STRICT flag itself: when set, KVM does not create a default PMU during vCPU init, and the VMM must select one explicitly via KVM_ARM_VCPU_PMU_V3_SET_PMU before the first KVM_RUN. This flips the gate on and can serve as an umbrella flag for future PMUv3 UAPI changes.

When the flag is not set, behaviors are unchanged.

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

v2 -> v3 changes:
- Reordered so the KVM_ARM_VCPU_PMU_V3_STRICT flag / KVM_CAP exposure comes last (now patch 4), after the flag-guarded behavior patches.
- Reworked on top of Oliver Upton's refinements (thanks!):
* Move the NULL-arm_pmu check into kvm_arm_pmu_v3_init() (returns -ENXIO) instead of failing at the first KVM_RUN, and report zero counters from kvm_arm_pmu_get_max_counters() before a PMU is set.
* Documentation and -ENXIO ordering notes for the PMU device attributes (SET_PMU must precede INIT/FILTER).
- New patch (Oliver): ignore userspace writes to PMCR_EL0.N under the strict flag and require the KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS attribute, since PMCR_EL0.N is context-dependent under NV.
- Advertise the KVM_CAP_ARM_PMU_V3_STRICT capability.
- Documentation fixes in api.rst (the flag Requires KVM_ARM_VCPU_PMU_V3).

Congkai Tan (3):
KVM: arm64: Expose PMMIR_EL1.SLOTS under strict PMUv3 UAPI
KVM: arm64: Advertise STALL_SLOT* in PMCEID1 under strict PMUv3 UAPI
KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_STRICT vCPU feature

Oliver Upton (1):
KVM: arm64: Ignore writes to PMCR_EL0.N when using strict UAPI

 Documentation/virt/kvm/api.rst                | 11 ++++
 Documentation/virt/kvm/devices/vcpu.rst       | 11 +++-
 arch/arm64/include/asm/kvm_host.h             |  5 +-
 arch/arm64/include/uapi/asm/kvm.h             |  1 +
 arch/arm64/kvm/arm.c                          | 19 ++++--
 arch/arm64/kvm/pmu-emul.c                     | 54 ++++++++++++----
 arch/arm64/kvm/sys_regs.c                     | 64 ++++++++++++++++++-
 include/kvm/arm_pmu.h                         |  4 ++
 include/uapi/linux/kvm.h                      |  1 +
 .../selftests/kvm/arm64/get-reg-list.c        |  1 +
 10 files changed, 149 insertions(+), 22 deletions(-)

base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda

Signature · 1 line
2.50.1