OSDN Git Service

KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_SET_PMU attribute
authorAlexandru Elisei <alexandru.elisei@arm.com>
Thu, 27 Jan 2022 16:17:58 +0000 (16:17 +0000)
committerMarc Zyngier <maz@kernel.org>
Tue, 8 Feb 2022 17:51:21 +0000 (17:51 +0000)
commit6ee7fca2a4a023b14aa1f1f3c4f6c833116116ef
treeebdd88fbcc0e271e78a68e2bba91bc1b29367a41
parentdb858060b1a788fba03711793dcaff19ea43286c
KVM: arm64: Add KVM_ARM_VCPU_PMU_V3_SET_PMU attribute

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 this list depends on the probe order, which can change under various
circumstances, for example if the order of the PMU nodes change in the DTB
or if asynchronous driver probing is enabled on the kernel command line
(with the driver_async_probe=armv8-pmu option).

Another consequence of this approach is that on heteregeneous systems all
virtual machines that KVM creates will use the same PMU. This might cause
unexpected behaviour for userspace: when a VCPU is executing on the
physical CPU that uses this default PMU, PMU events in the guest work
correctly; but when the same VCPU executes on another CPU, PMU events in
the guest will suddenly stop counting.

Fortunately, perf core allows user to specify on which PMU to create an
event by using the perf_event_attr->type field, which is used by
perf_init_event() as an index in the radix tree of available PMUs.

Add the KVM_ARM_VCPU_PMU_V3_CTRL(KVM_ARM_VCPU_PMU_V3_SET_PMU) VCPU
attribute to allow userspace to specify the arm_pmu that KVM will use when
creating events for that VCPU. KVM will make no attempt to run the VCPU on
the physical CPUs that share the PMU, leaving it up to userspace to manage
the VCPU threads' affinity accordingly.

To ensure that KVM doesn't expose an asymmetric system to the guest, the
PMU set for one VCPU will be used by all other VCPUs. Once a VCPU has run,
the PMU cannot be changed in order to avoid changing the list of available
events for a VCPU, or to change the semantics of existing events.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220127161759.53553-6-alexandru.elisei@arm.com
Documentation/virt/kvm/devices/vcpu.rst
arch/arm64/include/uapi/asm/kvm.h
arch/arm64/kvm/pmu-emul.c
tools/arch/arm64/include/uapi/asm/kvm.h