[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALMp9eR-eniyvu_zsqUHidoDX9V=eAA2zJXKPHdUT6SOY+EQrA@mail.gmail.com>
Date: Thu, 9 Dec 2021 10:53:40 -0800
From: Jim Mattson <jmattson@...gle.com>
To: Paolo Bonzini <pbonzini@...hat.com>
Cc: Like Xu <like.xu.linux@...il.com>,
Sean Christopherson <seanjc@...gle.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Joerg Roedel <joro@...tes.org>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Like Xu <likexu@...cent.com>
Subject: Re: [PATCH v2 1/6] KVM: x86/pmu: Setup pmc->eventsel for fixed PMCs
On Thu, Dec 9, 2021 at 10:49 AM Paolo Bonzini <pbonzini@...hat.com> 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.
:-)
Powered by blists - more mailing lists