Re: [PATCH kvm/queue v2 3/3] KVM: x86/pmu: Setup the {inte|amd}_event_mapping[] when hardware_setup

From: Like Xu
Date: Tue Feb 08 2022 - 06:26:49 EST


On 1/2/2022 8:28 pm, Paolo Bonzini wrote:
On 1/17/22 09:53, Like Xu wrote:
+
+    for (i = 0; i < PERF_COUNT_HW_MAX; i++) {
+        config = perf_get_hw_event_config(i) & 0xFFFFULL;
+
+        kernel_hw_events[i] = (struct kvm_event_hw_type_mapping){
+            .eventsel = config & ARCH_PERFMON_EVENTSEL_EVENT,
+            .unit_mask = (config & ARCH_PERFMON_EVENTSEL_UMASK) >> 8,
+            .event_type = i,
+        };

Should event_type be PERF_COUNT_HW_MAX if config is zero?

Emm, we do not assume that the hardware event encoded with "eventsel=0 && unit_mask=0"
(in this case, config is zero) are illegal.

If perf core puts this encoded event into "enum perf_hw_id" table as this part is out of the scope of
KVM, we have to setup with a valid event_type value instead of PERF_COUNT_HW_MAX.

In this proposal, the returned perf_hw_id from kvm_x86_ops.pmu_ops->pmc_perf_hw_id()
is only valid and used if "pmc->eventsel & 0xFFFFULL" is non-zero, otherwise the
reprogram_gp_counter() will fall back to use PERF_TYPE_RAW type.

Please let me know if you need more clarification on this change.


Thanks,

Paolo