On Thu, Nov 09, 2023, Jim Mattson wrote: > On Thu, Nov 9, 2023 at 10:24 AM Konstantin Khorenko <khorenko@xxxxxxxxxxxxx> wrote: > > --- > > arch/x86/kvm/pmu.c | 26 ++++++++++++++++++++++++++ > > 1 file changed, 26 insertions(+) > > > > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c > > index 9ae07db6f0f6..290d407f339b 100644 > > --- a/arch/x86/kvm/pmu.c > > +++ b/arch/x86/kvm/pmu.c > > @@ -731,12 +731,38 @@ static inline bool cpl_is_matched(struct kvm_pmc *pmc) > > return (static_call(kvm_x86_get_cpl)(pmc->vcpu) == 0) ? select_os : select_user; > > } > > > > +static inline bool guest_pmu_is_enabled(struct kvm_pmu *pmu) > > +{ > > + /* > > + * Currently VMs do not have PMU settings in configs which defaults > > + * to "pmu=off". > > + * > > + * For Intel currently this means pmu->version will be 0. > > + * For AMD currently PMU cannot be disabled: > > Isn't that what KVM_PMU_CAP_DISABLE is for? Yeah, see my response. KVM doesn't clear the metadata, so internally it looks like the PMU is enabled even though it's effectively disabled from the guest's perspective.