Re: [PATCH v2 1/6] KVM: x86/pmu: Setup pmc->eventsel for fixed PMCs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 9, 2021 at 10:49 AM Paolo Bonzini <pbonzini@xxxxxxxxxx> wrote:
>
> On 12/6/21 20:57, Jim Mattson wrote:
> >> +
> >> +       for (i = 0; i < pmu->nr_arch_fixed_counters; i++) {
> >> +               pmc = &pmu->fixed_counters[i];
> >> +               event = fixed_pmc_events[array_index_nospec(i, size)];
> > How do we know that i < size? For example, Ice Lake supports 4 fixed
> > counters, but fixed_pmc_events only has three entries.
>
> We don't, and it's a preexisting bug in intel_pmu_refresh.  Either we hack around it like
>
> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> index 1b7456b2177b..6f03c8bf1bc2 100644
> --- a/arch/x86/kvm/vmx/pmu_intel.c
> +++ b/arch/x86/kvm/vmx/pmu_intel.c
> @@ -500,8 +500,9 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
>                 pmu->nr_arch_fixed_counters = 0;
>         } else {
>                 pmu->nr_arch_fixed_counters =
> -                       min_t(int, edx.split.num_counters_fixed,
> -                             x86_pmu.num_counters_fixed);
> +                       min3(ARRAY_SIZE(fixed_pmc_events),
> +                            (size_t) edx.split.num_counters_fixed,
> +                            (size_t) x86_pmu.num_counters_fixed);
>                 edx.split.bit_width_fixed = min_t(int,
>                         edx.split.bit_width_fixed, x86_pmu.bit_width_fixed);
>                 pmu->counter_bitmask[KVM_PMC_FIXED] =
>
> or we modify find_fixed_event and its caller to support PERF_TYPE_RAW
> counters, and then add support for the IceLake TOPDOWN.SLOTS fixed
> counter.
>
> What's your preference?

As Like points out, KVM_GET_SUPPORTED_CPUID indicates that only three
fixed counters are supported. So, per the KVM contract, if userspace
configures four in the guest cpuid info, all bets are off. I don't
like that contract, but changing it means introducing KVM_SET_CPUID3.
:-)



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux