[PATCH v4 0/5] KVM: x86: Intel LBR related perf cleanups

Sean Christopherson posted 5 patches 3 years, 7 months ago
There is a newer version of this series
arch/x86/events/intel/lbr.c       |  6 +---
arch/x86/include/asm/perf_event.h | 55 ++++++++-----------------------
arch/x86/kvm/vmx/capabilities.h   | 39 ++--------------------
arch/x86/kvm/vmx/vmx.c            | 37 ++++++++++++++++++---
4 files changed, 49 insertions(+), 88 deletions(-)
[PATCH v4 0/5] KVM: x86: Intel LBR related perf cleanups
Posted by Sean Christopherson 3 years, 7 months ago
Fix a bug where KVM incorrectly advertises PMU_CAP_LBR_FMT to userspace if
perf has disabled LBRs, e.g. because probing one or more LBR MSRs during
setup hit a #GP.

The non-KVM patches remove unnecessary stubs and unreachable error paths,
which allows for a cleaner fix for said bug (backporting is unlikely to be
necessary/requested).

v4
 - Make vmx_get_perf_capabilities() non-inline to avoid references to
   x86_perf_get_lbr() when CPU_SUP_INTEL=n. [kernel test robot]

v3:
 - https://lore.kernel.org/all/20220831000051.4015031-1-seanjc@google.com
 - Drop patches for bug #1 (already merged).
 - Drop misguided "clean up the capability check" patch. [Like]

v2:
 - https://lore.kernel.org/all/20220803192658.860033-1-seanjc@google.com
 - Add patches to fix bug #2. [Like]
 - Add a patch to clean up the capability check.
 - Tweak the changelog for the PMU refresh bug fix to call out that
   KVM should disallow changing feature MSRs after KVM_RUN. [Like]

v1: https://lore.kernel.org/all/20220727233424.2968356-1-seanjc@google.com

Sean Christopherson (5):
  perf/x86/core: Remove unnecessary stubs provided for KVM-only helpers
  perf/x86/core: Drop the unnecessary return value from
    x86_perf_get_lbr()
  KVM: VMX: Move vmx_get_perf_capabilities() definition to vmx.c
  KVM: VMX: Fold vmx_supported_debugctl() into vcpu_supported_debugctl()
  KVM: VMX: Advertise PMU LBRs if and only if perf supports LBRs

 arch/x86/events/intel/lbr.c       |  6 +---
 arch/x86/include/asm/perf_event.h | 55 ++++++++-----------------------
 arch/x86/kvm/vmx/capabilities.h   | 39 ++--------------------
 arch/x86/kvm/vmx/vmx.c            | 37 ++++++++++++++++++---
 4 files changed, 49 insertions(+), 88 deletions(-)


base-commit: 372d07084593dc7a399bf9bee815711b1fb1bcf2
-- 
2.37.2.789.g6183377224-goog
Re: [PATCH v4 0/5] KVM: x86: Intel LBR related perf cleanups
Posted by Peter Zijlstra 3 years, 7 months ago
On Thu, Sep 01, 2022 at 05:32:53PM +0000, Sean Christopherson wrote:

> Sean Christopherson (5):
>   perf/x86/core: Remove unnecessary stubs provided for KVM-only helpers
>   perf/x86/core: Drop the unnecessary return value from
>     x86_perf_get_lbr()
>   KVM: VMX: Move vmx_get_perf_capabilities() definition to vmx.c
>   KVM: VMX: Fold vmx_supported_debugctl() into vcpu_supported_debugctl()
>   KVM: VMX: Advertise PMU LBRs if and only if perf supports LBRs

These look good to me; how do you want this routed, if through the KVM
tree:

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Re: [PATCH v4 0/5] KVM: x86: Intel LBR related perf cleanups
Posted by Sean Christopherson 3 years, 6 months ago
On Thu, Sep 08, 2022, Peter Zijlstra wrote:
> On Thu, Sep 01, 2022 at 05:32:53PM +0000, Sean Christopherson wrote:
> 
> > Sean Christopherson (5):
> >   perf/x86/core: Remove unnecessary stubs provided for KVM-only helpers
> >   perf/x86/core: Drop the unnecessary return value from
> >     x86_perf_get_lbr()
> >   KVM: VMX: Move vmx_get_perf_capabilities() definition to vmx.c
> >   KVM: VMX: Fold vmx_supported_debugctl() into vcpu_supported_debugctl()
> >   KVM: VMX: Advertise PMU LBRs if and only if perf supports LBRs
> 
> These look good to me; how do you want this routed, if through the KVM
> tree:
> 
> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Thanks!  If you don't anticipate conflicts in the perf headers, I'll take 'em
through KVM, patch 01 introduced a new warning that I need to resolve (hopefully
it doesn't throw a wrench into things).
Re: [PATCH v4 0/5] KVM: x86: Intel LBR related perf cleanups
Posted by Sean Christopherson 3 years, 6 months ago
On Sat, Sep 17, 2022, Sean Christopherson wrote:
> On Thu, Sep 08, 2022, Peter Zijlstra wrote:
> > On Thu, Sep 01, 2022 at 05:32:53PM +0000, Sean Christopherson wrote:
> > 
> > > Sean Christopherson (5):
> > >   perf/x86/core: Remove unnecessary stubs provided for KVM-only helpers
> > >   perf/x86/core: Drop the unnecessary return value from
> > >     x86_perf_get_lbr()
> > >   KVM: VMX: Move vmx_get_perf_capabilities() definition to vmx.c
> > >   KVM: VMX: Fold vmx_supported_debugctl() into vcpu_supported_debugctl()
> > >   KVM: VMX: Advertise PMU LBRs if and only if perf supports LBRs
> > 
> > These look good to me; how do you want this routed, if through the KVM
> > tree:
> > 
> > Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> 
> Thanks!  If you don't anticipate conflicts in the perf headers, I'll take 'em
> through KVM, patch 01 introduced a new warning that I need to resolve (hopefully
> it doesn't throw a wrench into things).

Rats, patch 01 is flat out wrong.  The stubs for Intel and AMD are necessary
because KVM_{AMD,INTEL} don't strictly require CPU_SUP_{AMD/INTEL}.  KVM_AMD
doesn't have any CPU_SUP_* requirement (which probably should be fixed), and
KVM_INTEL effectively require INTEL || CENTAUR || ZHAOXIN.

x86_perf_get_lbr() can still be cleaned up to fix KVM's benign bug of not checking
the result by zeroing the structure when LBRs are unsupported.

v5 incoming...