Skip to content

arm64: KVM: add SPE profiling support

Andrew Murray kvm kvmarm linux-arm-kernel lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest18 patches 59 repliesIn review

Changes since v2 from the cover letter

- Rebased on v5.5-rc2
- Renamed kvm_spe structure 'irq' member to 'irq_num'
- Added irq_level to kvm_spe structure
- Clear PMBSR service bit on save to avoid spurious interrupts
- Update kvmtool headers to 5.4
- Enabled SPE in KVM init features
- No longer trap and emulate
- Add support for guest/host exclusion flags
- Fix virq support for SPE
- Adjusted sysreg_elx_s macros with merged clang build support

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/18dt-bindings: ARM SPE: highlight the need for PPI partitions on heterogeneous systemsDocumentation/devicetree/bindings/arm/spe-pmu.txt+3 -20 replies
2/18arm64: KVM: reset E2PB correctly in MDCR_EL2 when exiting the guest(VHE)arch/arm64/kvm/hyp/switch.c+1 -33 replies
3/18arm64: KVM: define SPE data structure for each vcpuarch/arm64/include/asm/kvm_host.h arch/arm64/kvm/Kconfig include/kvm/arm_spe.h+28 -02 replies
4/18arm64: KVM: add SPE system registers to sys_reg_descsarch/arm64/include/asm/kvm_host.h arch/arm64/kvm/sys_regs.c+23 -00 replies
5/18arm64: KVM/VHE: enable the use PMSCR_EL12 on VHE systemsarch/arm64/include/asm/sysreg.h arch/arm64/kvm/hyp/debug-sr.c+4 -30 replies
6/18arm64: KVM: split debug save restore across vm/traps activationarch/arm64/include/asm/kvm_hyp.h arch/arm64/kvm/hyp/debug-sr.c arch/arm64/kvm/hyp/switch.c+28 -150 replies
7/18arm64: KVM/debug: drop pmscr_el1 and use sys_regs[PMSCR_EL1] in kvm_cpu_contextarch/arm64/include/asm/kvm_host.h arch/arm64/kvm/hyp/debug-sr.c+15 -130 replies
8/18arm64: KVM: add support to save/restore SPE profiling buffer controlsarch/arm64/kvm/hyp/debug-sr.c+43 -84 replies
9/18arm64: KVM: enable conditional save/restore full SPE profiling buffer controlsarch/arm64/kvm/hyp/debug-sr.c include/kvm/arm_spe.h+22 -1718 replies
10/18arm64: KVM/debug: use EL1&0 stage 1 translation regimearch/arm64/kvm/hyp/switch.c+2 -04 replies
11/18KVM: arm64: don't trap Statistical Profiling controls to EL2arch/arm64/kvm/debug.c+0 -28 replies
12/18KVM: arm64: add a new vcpu device control group for SPEv1Documentation/virt/kvm/devices/vcpu.txt arch/arm64/include/asm/kvm_host.h arch/arm64/include/uapi/asm/kvm.h +7 more+253 -12 replies
13/18perf: arm_spe: Add KVM structure for obtaining IRQ infodrivers/perf/arm_spe_pmu.c include/kvm/arm_spe.h+29 -02 replies
14/18KVM: arm64: spe: Provide guest virtual interrupts for SPEinclude/kvm/arm_spe.h virt/kvm/arm/arm.c virt/kvm/arm/spe.c+81 -17 replies
15/18perf: arm_spe: Handle guest/host exclusion flagsdrivers/perf/arm_spe_pmu.c+3 -04 replies
16/18KVM: arm64: enable SPE supportvirt/kvm/arm/arm.c+4 -00 replies
17/18update_headers: Sync kvm UAPI headers with linux v5.5-rc2arm/aarch32/include/asm/kvm.h arm/aarch64/include/asm/kvm.h include/linux/kvm.h +1 more+37 -40 replies
18/18kvm: add a vcpu feature for SPEv1 supportMakefile arm/aarch64/arm-cpu.c arm/aarch64/include/kvm/kvm-config-arch.h +5 more+97 -20 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 00/18] arm64: KVM: add SPE profiling support

This series implements support for allowing KVM guests to use the Arm Statistical Profiling Extension (SPE).

It has been tested on a model to ensure that both host and guest can simultaneously use SPE with valid data. E.g.

$ perf record -e arm_spe/ts_enable=1,pa_enable=1,pct_enable=1/ \
        dd if=/dev/zero of=/dev/null count=1000
$ perf report --dump-raw-trace > spe_buf.txt

As we save and restore the SPE context, the guest can access the SPE registers directly, thus in this version of the series we remove the trapping and emulation.

In the previous series of this support, when KVM SPE isn't supported (e.g. via CONFIG_KVM_ARM_SPE) we were able to return a value of 0 to all reads of the SPE registers - as we can no longer do this there isn't a mechanism to prevent the guest from using SPE - thus I'm keen for feedback on the best way of resolving this.

It appears necessary to pin the entire guest memory in order to provide guest SPE access - otherwise it is possible for the guest to receive Stage-2 faults.

The last two extra patches are for the kvmtool if someone wants to play with it.

Changes since v2:
- Rebased on v5.5-rc2
- Renamed kvm_spe structure 'irq' member to 'irq_num'
- Added irq_level to kvm_spe structure
- Clear PMBSR service bit on save to avoid spurious interrupts
- Update kvmtool headers to 5.4
- Enabled SPE in KVM init features
- No longer trap and emulate
- Add support for guest/host exclusion flags
- Fix virq support for SPE
- Adjusted sysreg_elx_s macros with merged clang build support

Andrew Murray (4):
KVM: arm64: don't trap Statistical Profiling controls to EL2
perf: arm_spe: Add KVM structure for obtaining IRQ info
KVM: arm64: spe: Provide guest virtual interrupts for SPE
perf: arm_spe: Handle guest/host exclusion flags

Sudeep Holla (12):
dt-bindings: ARM SPE: highlight the need for PPI partitions on
heterogeneous systems
arm64: KVM: reset E2PB correctly in MDCR_EL2 when exiting the
guest(VHE)
arm64: KVM: define SPE data structure for each vcpu
arm64: KVM: add SPE system registers to sys_reg_descs
arm64: KVM/VHE: enable the use PMSCR_EL12 on VHE systems
arm64: KVM: split debug save restore across vm/traps activation
arm64: KVM/debug: drop pmscr_el1 and use sys_regs[PMSCR_EL1] in
kvm_cpu_context
arm64: KVM: add support to save/restore SPE profiling buffer controls
arm64: KVM: enable conditional save/restore full SPE profiling buffer
controls
arm64: KVM/debug: use EL1&0 stage 1 translation regime
KVM: arm64: add a new vcpu device control group for SPEv1
KVM: arm64: enable SPE support
KVMTOOL: update_headers: Sync kvm UAPI headers with linux v5.5-rc2
KVMTOOL: kvm: add a vcpu feature for SPEv1 support

 .../devicetree/bindings/arm/spe-pmu.txt       |   5 +-
 Documentation/virt/kvm/devices/vcpu.txt       |  28 +++
 arch/arm64/include/asm/kvm_host.h             |  18 +-
 arch/arm64/include/asm/kvm_hyp.h              |   6 +-
 arch/arm64/include/asm/sysreg.h               |   1 +
 arch/arm64/include/uapi/asm/kvm.h             |   4 +
 arch/arm64/kvm/Kconfig                        |   7 +
 arch/arm64/kvm/Makefile                       |   1 +
 arch/arm64/kvm/debug.c                        |   2 -
 arch/arm64/kvm/guest.c                        |   6 +
 arch/arm64/kvm/hyp/debug-sr.c                 | 105 +++++---
 arch/arm64/kvm/hyp/switch.c                   |  18 +-
 arch/arm64/kvm/reset.c                        |   3 +
 arch/arm64/kvm/sys_regs.c                     |  11 +
 drivers/perf/arm_spe_pmu.c                    |  26 ++
 include/kvm/arm_spe.h                         |  82 ++++++
 include/uapi/linux/kvm.h                      |   1 +
 virt/kvm/arm/arm.c                            |  10 +-
 virt/kvm/arm/spe.c                            | 234 ++++++++++++++++++
 19 files changed, 521 insertions(+), 47 deletions(-)
 create mode 100644 include/kvm/arm_spe.h
 create mode 100644 virt/kvm/arm/spe.c
Signature · 1 line
2.21.0