kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/10] target/i386/kvm/pmu: PMU Enhancement, Bugfix and Cleanup
@ 2025-03-02 22:00 Dongli Zhang
  2025-03-02 22:00 ` [PATCH v2 01/10] target/i386: disable PerfMonV2 when PERFCORE unavailable Dongli Zhang
                   ` (9 more replies)
  0 siblings, 10 replies; 63+ messages in thread
From: Dongli Zhang @ 2025-03-02 22:00 UTC (permalink / raw)
  To: qemu-devel, kvm
  Cc: pbonzini, zhao1.liu, mtosatti, sandipan.das, babu.moger, likexu,
	like.xu.linux, zhenyuw, groug, khorenko, alexander.ivanov, den,
	davydov-max, xiaoyao.li, dapeng1.mi, joe.jin

Would you mind suggesting how we can move forward with this patchset as:

(1) One patch for kvm_arch_pre_create_vcpu() is picked from Xiaoyao's
patchset.
(2) Dapeng is working on mediated passthrough vPMU QEMU patches. This
patchset doesn't support mediated passthrough vPMU.

This patchset addresses four bugs related to AMD PMU virtualization.

1. The PerfMonV2 is still available if PERCORE if disabled via
"-cpu host,-perfctr-core".

2. The VM 'cpuid' command still returns PERFCORE although "-pmu" is
configured.

3. The third issue is that using "-cpu host,-pmu" does not disable AMD PMU
virtualization. When using "-cpu EPYC" or "-cpu host,-pmu", AMD PMU
virtualization remains enabled. On the VM's Linux side, you might still
see:

[    0.510611] Performance Events: Fam17h+ core perfctr, AMD PMU driver.

instead of:

[    0.596381] Performance Events: PMU not available due to virtualization, using software events only.
[    0.600972] NMI watchdog: Perf NMI watchdog permanently disabled

To address this, KVM_CAP_PMU_CAPABILITY is used to set KVM_PMU_CAP_DISABLE
when "-pmu" is configured.

4. The fourth issue is that unreclaimed performance events (after a QEMU
system_reset) in KVM may cause random, unwanted, or unknown NMIs to be
injected into the VM.

The AMD PMU registers are not reset during QEMU system_reset.

(1) If the VM is reset (e.g., via QEMU system_reset or VM kdump/kexec) while
running "perf top", the PMU registers are not disabled properly.

(2) Despite x86_cpu_reset() resetting many registers to zero, kvm_put_msrs()
does not handle AMD PMU registers, causing some PMU events to remain
enabled in KVM.

(3) The KVM kvm_pmc_speculative_in_use() function consistently returns true,
preventing the reclamation of these events. Consequently, the
kvm_pmc->perf_event remains active.

(4) After a reboot, the VM kernel may report the following error:

[    0.092011] Performance Events: Fam17h+ core perfctr, Broken BIOS detected, complain to your hardware vendor.
[    0.092023] [Firmware Bug]: the BIOS has corrupted hw-PMU resources (MSR c0010200 is 530076)

(5) In the worst case, the active kvm_pmc->perf_event may inject unknown
NMIs randomly into the VM kernel:

[...] Uhhuh. NMI received for unknown reason 30 on CPU 0.

To resolve these issues, we propose resetting AMD PMU registers during the
VM reset process


Changed since v1:
  - Use feature_dependencies for CPUID_EXT3_PERFCORE and
    CPUID_8000_0022_EAX_PERFMON_V2.
  - Remove CPUID_EXT3_PERFCORE when !cpu->enable_pmu.
  - Pick kvm_arch_pre_create_vcpu() patch from Xiaoyao Li.
  - Use "-pmu" but not a global "pmu-cap-disabled" for KVM_PMU_CAP_DISABLE.
  - Also use sysfs kvm.enable_pmu=N to determine if PMU is supported.
  - Some changes to PMU register limit calculation.


Xiaoyao Li (1):
  kvm: Introduce kvm_arch_pre_create_vcpu()

Dongli Zhang (9):
  target/i386: disable PerfMonV2 when PERFCORE unavailable
  target/i386: disable PERFCORE when "-pmu" is configured
  target/i386/kvm: set KVM_PMU_CAP_DISABLE if "-pmu" is configured
  target/i386/kvm: extract unrelated code out of kvm_x86_build_cpuid()
  target/i386/kvm: rename architectural PMU variables
  target/i386/kvm: query kvm.enable_pmu parameter
  target/i386/kvm: reset AMD PMU registers during VM reset
  target/i386/kvm: support perfmon-v2 for reset
  target/i386/kvm: don't stop Intel PMU counters

 accel/kvm/kvm-all.c        |   5 +
 include/system/kvm.h       |   1 +
 target/arm/kvm.c           |   5 +
 target/i386/cpu.c          |   8 +
 target/i386/cpu.h          |  12 ++
 target/i386/kvm/kvm.c      | 348 ++++++++++++++++++++++++++++++++++------
 target/loongarch/kvm/kvm.c |   5 +
 target/mips/kvm.c          |   5 +
 target/ppc/kvm.c           |   5 +
 target/riscv/kvm/kvm-cpu.c |   5 +
 target/s390x/kvm/kvm.c     |   5 +
 11 files changed, 357 insertions(+), 47 deletions(-)

base-commit: b69801dd6b1eb4d107f7c2f643adf0a4e3ec9124

Thank you very much!

Dongli Zhang


^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2025-04-16  8:17 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-02 22:00 [PATCH v2 00/10] target/i386/kvm/pmu: PMU Enhancement, Bugfix and Cleanup Dongli Zhang
2025-03-02 22:00 ` [PATCH v2 01/10] target/i386: disable PerfMonV2 when PERFCORE unavailable Dongli Zhang
2025-03-04 14:40   ` Xiaoyao Li
2025-03-04 22:53     ` dongli.zhang
2025-03-05  1:38       ` Xiaoyao Li
2025-03-05 14:20   ` Zhao Liu
2025-03-07  7:24   ` Sandipan Das
2025-03-02 22:00 ` [PATCH v2 02/10] target/i386: disable PERFCORE when "-pmu" is configured Dongli Zhang
2025-03-03  1:59   ` Xiaoyao Li
2025-03-03 18:45     ` dongli.zhang
2025-03-04  6:11       ` Xiaoyao Li
2025-03-06 16:50   ` Zhao Liu
2025-03-06 17:47     ` dongli.zhang
2025-03-07  7:41       ` Zhao Liu
2025-03-02 22:00 ` [PATCH v2 03/10] [DO NOT MERGE] kvm: Introduce kvm_arch_pre_create_vcpu() Dongli Zhang
2025-03-05 14:46   ` Zhao Liu
2025-03-05 21:53     ` dongli.zhang
2025-03-07  7:52       ` Zhao Liu
2025-03-07  8:40         ` Xiaoyao Li
2025-03-02 22:00 ` [PATCH v2 04/10] target/i386/kvm: set KVM_PMU_CAP_DISABLE if "-pmu" is configured Dongli Zhang
2025-03-04  7:59   ` Xiaoyao Li
2025-03-05  1:22     ` Sean Christopherson
2025-03-05  1:35       ` Xiaoyao Li
2025-03-05 14:41     ` Zhao Liu
2025-03-05 20:13       ` dongli.zhang
2025-03-05 14:44   ` Zhao Liu
2025-03-02 22:00 ` [PATCH v2 05/10] target/i386/kvm: extract unrelated code out of kvm_x86_build_cpuid() Dongli Zhang
2025-03-05  7:03   ` Mi, Dapeng
2025-03-07  9:15   ` Zhao Liu
2025-03-07 22:47     ` Dongli Zhang
2025-03-10  3:55       ` Zhao Liu
2025-03-02 22:00 ` [PATCH v2 06/10] target/i386/kvm: rename architectural PMU variables Dongli Zhang
2025-03-05  7:07   ` Mi, Dapeng
2025-03-07  9:19   ` Zhao Liu
2025-03-07 22:49     ` Dongli Zhang
2025-03-02 22:00 ` [PATCH v2 07/10] target/i386/kvm: query kvm.enable_pmu parameter Dongli Zhang
2025-03-10  6:14   ` Zhao Liu
2025-03-10 15:41     ` Dongli Zhang
2025-03-10 16:49     ` Dongli Zhang
2025-03-02 22:00 ` [PATCH v2 08/10] target/i386/kvm: reset AMD PMU registers during VM reset Dongli Zhang
2025-03-05  7:33   ` Mi, Dapeng
2025-03-05 11:41   ` Francesco Lavra
2025-03-05 19:05     ` dongli.zhang
2025-03-07  7:38   ` Sandipan Das
2025-03-10  7:47   ` Zhao Liu
2025-03-10 16:39     ` Dongli Zhang
2025-03-11 13:51       ` Zhao Liu
2025-03-11 19:52         ` Dongli Zhang
2025-03-12  8:30           ` Zhao Liu
2025-03-12 22:17             ` Dongli Zhang
2025-03-28  6:29   ` ewanhai
2025-03-28 16:42     ` Dongli Zhang
2025-03-31  3:55       ` ewanhai
2025-03-31 19:16         ` Dongli Zhang
2025-04-01  3:35           ` Ewan Hai
2025-04-07  8:51             ` Zhao Liu
2025-04-07  9:33               ` Ewan Hai
2025-04-16  8:17                 ` Mi, Dapeng
2025-03-02 22:00 ` [PATCH v2 09/10] target/i386/kvm: support perfmon-v2 for reset Dongli Zhang
2025-03-02 22:00 ` [PATCH v2 10/10] target/i386/kvm: don't stop Intel PMU counters Dongli Zhang
2025-03-05  7:35   ` Mi, Dapeng
2025-03-05 19:00     ` dongli.zhang
2025-03-06  1:38       ` Mi, Dapeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).