Advertise LBR support to userspace via MSR_IA32_PERF_CAPABILITIES if and
only if perf fully supports LBRs. Perf may disable LBRs (by zeroing the
number of LBRs) even on platforms the allegedly support LBRs, e.g. if
probing any LBR MSRs during setup fails.
Fixes: be635e34c284 ("KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES")
Reported-by: Like Xu <like.xu.linux@gmail.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/vmx/capabilities.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h
index c5e5dfef69c7..d2fdaf888d33 100644
--- a/arch/x86/kvm/vmx/capabilities.h
+++ b/arch/x86/kvm/vmx/capabilities.h
@@ -404,6 +404,7 @@ static inline bool vmx_pebs_supported(void)
static inline u64 vmx_get_perf_capabilities(void)
{
u64 perf_cap = PMU_CAP_FW_WRITES;
+ struct x86_pmu_lbr lbr;
u64 host_perf_cap = 0;
if (!enable_pmu)
@@ -412,7 +413,9 @@ static inline u64 vmx_get_perf_capabilities(void)
if (boot_cpu_has(X86_FEATURE_PDCM))
rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
- perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
+ x86_perf_get_lbr(&lbr);
+ if (lbr.nr)
+ perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
if (vmx_pebs_supported()) {
perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK;
--
2.37.2.672.g94769d06f0-goog
Hi Sean,
I love your patch! Yet something to improve:
[auto build test ERROR on 372d07084593dc7a399bf9bee815711b1fb1bcf2]
url: https://github.com/intel-lab-lkp/linux/commits/Sean-Christopherson/KVM-x86-Intel-LBR-related-perf-cleanups/20220831-080309
base: 372d07084593dc7a399bf9bee815711b1fb1bcf2
config: i386-randconfig-s001 (https://download.01.org/0day-ci/archive/20220831/202208311831.zQ4oCG1b-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/094f42374997562fff3f9f9637ec9aa8257490a0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sean-Christopherson/KVM-x86-Intel-LBR-related-perf-cleanups/20220831-080309
git checkout 094f42374997562fff3f9f9637ec9aa8257490a0
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 prepare
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
In file included from arch/x86/kernel/../kvm/vmx/vmx.h:11,
from arch/x86/kernel/asm-offsets.c:22:
arch/x86/kernel/../kvm/vmx/capabilities.h: In function 'vmx_get_perf_capabilities':
>> arch/x86/kernel/../kvm/vmx/capabilities.h:416:9: error: implicit declaration of function 'x86_perf_get_lbr' [-Werror=implicit-function-declaration]
416 | x86_perf_get_lbr(&lbr);
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:117: arch/x86/kernel/asm-offsets.s] Error 1
make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1207: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:222: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/x86_perf_get_lbr +416 arch/x86/kernel/../kvm/vmx/capabilities.h
403
404 static inline u64 vmx_get_perf_capabilities(void)
405 {
406 u64 perf_cap = PMU_CAP_FW_WRITES;
407 struct x86_pmu_lbr lbr;
408 u64 host_perf_cap = 0;
409
410 if (!enable_pmu)
411 return 0;
412
413 if (boot_cpu_has(X86_FEATURE_PDCM))
414 rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
415
> 416 x86_perf_get_lbr(&lbr);
417 if (lbr.nr)
418 perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
419
420 if (vmx_pebs_supported()) {
421 perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK;
422 if ((perf_cap & PERF_CAP_PEBS_FORMAT) < 4)
423 perf_cap &= ~PERF_CAP_PEBS_BASELINE;
424 }
425
426 return perf_cap;
427 }
428
--
0-DAY CI Kernel Test Service
https://01.org/lkp
On Wed, Aug 31, 2022, kernel test robot wrote: > Hi Sean, > > I love your patch! Yet something to improve: > > [auto build test ERROR on 372d07084593dc7a399bf9bee815711b1fb1bcf2] > > url: https://github.com/intel-lab-lkp/linux/commits/Sean-Christopherson/KVM-x86-Intel-LBR-related-perf-cleanups/20220831-080309 > base: 372d07084593dc7a399bf9bee815711b1fb1bcf2 > config: i386-randconfig-s001 (https://download.01.org/0day-ci/archive/20220831/202208311831.zQ4oCG1b-lkp@intel.com/config) > compiler: gcc-11 (Debian 11.3.0-5) 11.3.0 > reproduce: > # apt-get install sparse > # sparse version: v0.6.4-39-gce1a6720-dirty > # https://github.com/intel-lab-lkp/linux/commit/094f42374997562fff3f9f9637ec9aa8257490a0 > git remote add linux-review https://github.com/intel-lab-lkp/linux > git fetch --no-tags linux-review Sean-Christopherson/KVM-x86-Intel-LBR-related-perf-cleanups/20220831-080309 > git checkout 094f42374997562fff3f9f9637ec9aa8257490a0 > # save the config file > mkdir build_dir && cp config build_dir/.config > make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 prepare > > If you fix the issue, kindly add following tag where applicable > Reported-by: kernel test robot <lkp@intel.com> > > All errors (new ones prefixed by >>): > > In file included from arch/x86/kernel/../kvm/vmx/vmx.h:11, > from arch/x86/kernel/asm-offsets.c:22: Argh, KVM's "internal" vmx.h gets included by arch/x86/kernel/asm-offsets.c even when KVM is disabled, and vmx_get_perf_capabilities() is oddly inlined there. The simple fix is to move the definition of vmx_get_perf_capabilities() into vmx.c. Long term, I want to figure out a way to break the dependency on asm-offsets. I ran afoul of this a week ago for something else, but couldn't figure an easy solution and it wasn't (yet) a blocking issue.
Hi Sean,
I love your patch! Yet something to improve:
[auto build test ERROR on 372d07084593dc7a399bf9bee815711b1fb1bcf2]
url: https://github.com/intel-lab-lkp/linux/commits/Sean-Christopherson/KVM-x86-Intel-LBR-related-perf-cleanups/20220831-080309
base: 372d07084593dc7a399bf9bee815711b1fb1bcf2
config: x86_64-randconfig-a012 (https://download.01.org/0day-ci/archive/20220831/202208311746.VAzmtgNx-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/094f42374997562fff3f9f9637ec9aa8257490a0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sean-Christopherson/KVM-x86-Intel-LBR-related-perf-cleanups/20220831-080309
git checkout 094f42374997562fff3f9f9637ec9aa8257490a0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 prepare
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
In file included from arch/x86/kernel/asm-offsets.c:22:
In file included from arch/x86/kernel/../kvm/vmx/vmx.h:11:
>> arch/x86/kernel/../kvm/vmx/capabilities.h:416:2: error: implicit declaration of function 'x86_perf_get_lbr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
x86_perf_get_lbr(&lbr);
^
1 error generated.
make[2]: *** [scripts/Makefile.build:117: arch/x86/kernel/asm-offsets.s] Error 1
make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1207: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:222: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/x86_perf_get_lbr +416 arch/x86/kernel/../kvm/vmx/capabilities.h
403
404 static inline u64 vmx_get_perf_capabilities(void)
405 {
406 u64 perf_cap = PMU_CAP_FW_WRITES;
407 struct x86_pmu_lbr lbr;
408 u64 host_perf_cap = 0;
409
410 if (!enable_pmu)
411 return 0;
412
413 if (boot_cpu_has(X86_FEATURE_PDCM))
414 rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
415
> 416 x86_perf_get_lbr(&lbr);
417 if (lbr.nr)
418 perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT;
419
420 if (vmx_pebs_supported()) {
421 perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK;
422 if ((perf_cap & PERF_CAP_PEBS_FORMAT) < 4)
423 perf_cap &= ~PERF_CAP_PEBS_BASELINE;
424 }
425
426 return perf_cap;
427 }
428
--
0-DAY CI Kernel Test Service
https://01.org/lkp
© 2016 - 2026 Red Hat, Inc.