kvmtool issues several ioctls when configuring the PMU, and each of them can fail for different reasons. Be more specific about the ioctl that failed when that happens. Signed-off-by: Alexandru Elisei --- arm64/pmu.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/arm64/pmu.c b/arm64/pmu.c index e15244b51c1f..1f583c16d119 100644 --- a/arm64/pmu.c +++ b/arm64/pmu.c @@ -12,6 +12,24 @@ #include "asm/pmu.h" +static const char *pmu_attr_names[] = { + [KVM_ARM_VCPU_PMU_V3_IRQ] = "KVM_ARM_VCPU_PMU_V3_IRQ", + [KVM_ARM_VCPU_PMU_V3_INIT] = "KVM_ARM_VCPU_PMU_V3_INIT", + [KVM_ARM_VCPU_PMU_V3_FILTER] = "KVM_ARM_VCPU_PMU_V3_FILTER", + [KVM_ARM_VCPU_PMU_V3_SET_PMU] = "KVM_ARM_VCPU_PMU_V3_SET_PMU", + [KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS] = "KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTER", +}; + +static const char *pmu_get_attr_name(u64 attr) +{ + switch (attr) { + case KVM_ARM_VCPU_PMU_V3_IRQ ... KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS: + return pmu_attr_names[attr]; + default: + return "UNKNOWN"; + } +} + static bool pmu_has_attr(struct kvm_cpu *vcpu, u64 attr) { struct kvm_device_attr pmu_attr = { @@ -32,13 +50,12 @@ static void set_pmu_attr(struct kvm_cpu *vcpu, void *addr, u64 attr) }; int ret; - if (pmu_has_attr(vcpu, attr)) { - ret = ioctl(vcpu->vcpu_fd, KVM_SET_DEVICE_ATTR, &pmu_attr); - if (ret) - die_perror("PMU KVM_SET_DEVICE_ATTR"); - } else { - die_perror("PMU KVM_HAS_DEVICE_ATTR"); - } + if (!pmu_has_attr(vcpu, attr)) + die_perror("KVM_HAS_DEVICE_ATTR(%s)", pmu_get_attr_name(attr)); + + ret = ioctl(vcpu->vcpu_fd, KVM_SET_DEVICE_ATTR, &pmu_attr); + if (ret) + die_perror("KVM_SET_DEVICE_ATTR(%s)", pmu_get_attr_name(attr)); } #define SYS_EVENT_SOURCE "/sys/bus/event_source/devices/" -- 2.53.0