KVM: x86/pmu: Fix the warning in perf_get_x86_pmu_capability()
PATCH 1/1 KVM: x86/pmu: Fix the warning in perf_get_x86_pmu_capability()
When load KVM module in Intel hybrid platforms, the warning below is observed.
<4>[ 10.973827] ------------[ cut here ]------------ <4>[ 10.973841] WARNING: arch/x86/events/core.c:3089 at perf_get_x86_pmu_capability+0xd/0xc0, CPU#15: (udev-worker)/386 ... <4>[ 10.974028] Call Trace: <4>[ 10.974030] <TASK> <4>[ 10.974033] ? kvm_init_pmu_capability+0x2b/0x190 [kvm] <4>[ 10.974154] kvm_x86_vendor_init+0x1b0/0x1a40 [kvm] <4>[ 10.974248] vmx_init+0xdb/0x260 [kvm_intel] <4>[ 10.974278] ? __pfx_vt_init+0x10/0x10 [kvm_intel] <4>[ 10.974296] vt_init+0x12/0x9d0 [kvm_intel] <4>[ 10.974309] ? __pfx_vt_init+0x10/0x10 [kvm_intel] <4>[ 10.974322] do_one_initcall+0x60/0x3f0 <4>[ 10.974335] do_init_module+0x97/0x2b0 <4>[ 10.974345] load_module+0x2d08/0x2e30 <4>[ 10.974349] ? __kernel_read+0x158/0x2f0 <4>[ 10.974370] ? kernel_read_file+0x2b1/0x320 <4>[ 10.974381] init_module_from_file+0x96/0xe0 <4>[ 10.974384] ? init_module_from_file+0x96/0xe0 <4>[ 10.974399] idempotent_init_module+0x117/0x330 <4>[ 10.974415] __x64_sys_finit_module+0x73/0xe0
The root cause is the helper perf_get_x86_pmu_capability() is called unconditionally but it's supposed to be called only on non-hybrid platforms.
This patch fixes this warning by only calling perf_get_x86_pmu_capability() on non-hybrid platforms.
--- arch/x86/kvm/pmu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/kvm/pmu.c +5 -3
@@ -108,16 +108,18 @@ void kvm_init_pmu_capability(const struct kvm_pmu_ops *pmu_ops)bool is_intel = boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ;int min_nr_gp_ctrs = pmu_ops->MIN_NR_GP_COUNTERS; -perf_get_x86_pmu_capability (&kvm_host_pmu); -/* * Hybrid PMUs don't play nice with virtualization without careful * configuration by userspace, and KVM's APIs for reporting supported * vPMU features do not account for hybrid PMUs. Disable vPMU support * for hybrid PMUs until KVM gains a way to let userspace opt-in. */ -if (cpu_feature_enabled (X86_FEATURE_HYBRID_CPU )) +if (cpu_feature_enabled (X86_FEATURE_HYBRID_CPU )) { enable_pmu = false; +memset (&kvm_host_pmu,0 ,sizeof (kvm_host_pmu)); + }else { +perf_get_x86_pmu_capability (&kvm_host_pmu); + }if (enable_pmu) {/*
Signature · 1 line
2.34.1
Quoted 4 lines · Dapeng Mi
When load KVM module in Intel hybrid platforms, the warning below is observed.
[...]
Applied to kvm-x86 fixes, with a different shortlog and changelog. I wanted to call out that the fix is for hybrid CPUs, and that snapshotting PMU capabilities for non-hybrid CPUs even if enable_pmu=false is intentional.
Thanks much!
[1/1] KVM: x86/pmu: Don't try to get perf capabilities for hybrid CPUs
https://github.com/kvm-x86/linux/commit/034417c1439a