[PATCH kvmtool 9/9] arm64: Add support for KVM_ARM_VCPU_PMU_V3_SET_PMU

2021-11-15 Thread Alexandru Elisei
The KVM_ARM_VCPU_PMU_V3_CTRL(KVM_ARM_VCPU_PMU_V3_SET_PMU) VCPU ioctl is used to assign a physical PMU to the events that KVM creates when emulating the PMU for that VCPU. This is useful on heterogeneous systems, when there is more than one hardware PMU present. The assumption that is made in the i

[PATCH kvmtool 8/9] update_headers.sh: Sync headers with Linux v5.16-rc1 + SET_PMU attribute

2021-11-15 Thread Alexandru Elisei
Signed-off-by: Alexandru Elisei --- arm/aarch64/include/asm/kvm.h | 57 - include/linux/kvm.h | 441 +- powerpc/include/asm/kvm.h | 10 + x86/include/asm/kvm.h | 64 - 4 files changed, 558 insertions(+), 14 deletions(-) diff --git

[PATCH kvmtool 7/9] util: Add cpulist_parse()

2021-11-15 Thread Alexandru Elisei
Add the function cpulist_parse(), which creates a cpumask_t from a cpulist. The function will be necessary to parse the cpulist of CPUs associated with a particular PMU. Signed-off-by: Alexandru Elisei --- Makefile| 1 + include/linux/bitmap.h | 25 + include/linux/bitops

[PATCH kvmtool 6/9] util: Add basic cpumask functions

2021-11-15 Thread Alexandru Elisei
Add a handful of basic cpumask functions, some of which will be used when dealing with different PMUs on heterogeneous systems. Signed-off-by: Alexandru Elisei --- arm/aarch32/include/asm/kernel.h | 8 arm/aarch64/include/asm/kernel.h | 8 include/linux/bitmap.h | 2

[PATCH kvmtool 5/9] arm64: Rework set_pmu_attr()

2021-11-15 Thread Alexandru Elisei
By the time kvmtool generates the DTB node for the PMU, the KVM_ARM_VCPU_PMU_V3 VCPU feature is already set by kvm_cpu__arch_init(). KVM refuses to run a VCPU if the PMU hasn't been initialized. A PMU cannot be initialized if the interrupt ID hasn't been set by userspace. As a consequence, kvmtool

[PATCH kvmtool 4/9] arm: Make the PMUv3 emulation code arm64 specific

2021-11-15 Thread Alexandru Elisei
KVM for aarch32 does not exist anymore, PMUv3 is a hardware feature present only on aarch64 CPUs, the command line option to enable the feature for a VCPU is aarch64 specific, the PMU code is called only from an aarch64 function and it compiles to an empty stub when ARCH=arm. There is no reason to

[PATCH kvmtool 3/9] arm: Get rid of the ARM_VCPU_FEATURE_FLAGS() macro

2021-11-15 Thread Alexandru Elisei
The ARM_VCPU_FEATURE_FLAGS() macro sets a feature bit in a rather convoluted way: if cpu_id is 0, then bit KVM_ARM_VCPU_POWER_OFF is 0, otherwise is set to 1. There's really no need for this indirection, especially considering that the macro has been changed to return the same value for both the ar

[PATCH kvmtool 2/9] arm: Move arch specific VCPU features to the arch specific function

2021-11-15 Thread Alexandru Elisei
KVM_CAP_ARM_EL1_32BIT and KVM_CAP_ARM_PMU_V3 are arm64 specific features. They are set based on arm64 specific command line options and they target arm64 hardware features. It makes little sense for kvmtool to set the features in the code that is shared between arm and arm64. Move the logic to set

[PATCH kvmtool 0/9] arm64: Improve PMU support on heterogeneous systems

2021-11-15 Thread Alexandru Elisei
The series can be found at [1], and the Linux patches that this series is based on at [2]. The series adds support for the KVM_ARM_VCPU_PMU_V3_SET_PMU PMU attribute, which allows userspace to set a PMU for a VCPU. This PMU is used by KVM when creating perf events to emulate the guest PMU. Without

[PATCH kvmtool 1/9] linux/err.h: Add missing stdbool.h include

2021-11-15 Thread Alexandru Elisei
Add missing header stdbool.h to avoid errors like this one, which can happen if the including file doesn't include stdbool.h: include/linux/err.h:33:15: error: type defaults to ‘int’ in declaration of ‘bool’ [-Werror=implicit-int] 33 | static inline bool __must_check IS_ERR(__force const void

[PATCH 4/4] KVM: arm64: Refuse to run VCPU if the PMU doesn't match the physical CPU

2021-11-15 Thread Alexandru Elisei
Userspace can assign a PMU to a VCPU with the KVM_ARM_VCPU_PMU_V3_SET_PMU device ioctl. If the VCPU is scheduled on a physical CPU which has a different PMU, the perf events needed to emulate a guest PMU won't be scheduled in and the guest performance counters will stop counting. Treat it as an use

[PATCH 3/4] KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_SET_PMU attribute

2021-11-15 Thread Alexandru Elisei
When KVM creates an event and there are more than one PMUs present on the system, perf_init_event() will go through the list of available PMUs and will choose the first one that can create the event. The order of the PMUs in the PMU list depends on the probe order, which can change under various ci

[PATCH 2/4] KVM: arm64: Keep a list of probed PMUs

2021-11-15 Thread Alexandru Elisei
The ARM PMU driver calls kvm_host_pmu_init() after probing to tell KVM that a hardware PMU is available for guest emulation. Heterogeneous systems can have more than one PMU present, and the callback gets called multiple times, once for each of them. Keep track of all the PMUs available to KVM, as

[PATCH 1/4] perf: Fix wrong name in comment for struct perf_cpu_context

2021-11-15 Thread Alexandru Elisei
Commit 0793a61d4df8 ("performance counters: core code") added the perf subsystem (then called Performance Counters) to Linux, creating the struct perf_cpu_context. The comment for the struct referred to it as a "struct perf_counter_cpu_context". Commit cdd6c482c9ff ("perf: Do the big rename: Perfo

[PATCH 0/4] KVM: arm64: Improve PMU support on heterogeneous systems

2021-11-15 Thread Alexandru Elisei
(CC'ing Peter Maydell in case this might be of interest to qemu) The series can be found at [x], and the kvmtool support at [2]. At the moment, the experience of running a virtual machine with a PMU on a heterogeneous systems (where there are different PMUs), varies from just works, if the VCPUs