Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH 0/3] x86/pmu: Restore emulated instruction test coverage on AMD
@ 2026-11-26  0:48 Yosry Ahmed
  2026-11-26  0:48 ` [kvm-unit-tests PATCH 1/3] x86/pmu: Mask emulated instruction count deltas to the counter width Yosry Ahmed
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yosry Ahmed @ 2026-11-26  0:48 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Jim Mattson, kvm, Yosry Ahmed

Since commit 7999ff1d28b0 ("x86/pmu: Treat all AMD CPUs as having
instruction/branch overcount errata"), check_emulated_instr() only
checks that the instructions and branches counts are at least the
expected counts on AMD. That always passes, because AMD counts each
VMRUN as a retired instruction and branch in guest mode, and the 10
synchronous VM-Exits in the measured window alone are enough to reach
the expected counts (and overflow the counters), even if KVM doesn't
account for any of the emulated instructions.

Patch 1 fixes a false pass in the ">=" checks when a counter doesn't
wrap, which predates the errata change but now affects all AMD CPUs.

Patch 2 accounts for the synchronous VMRUNs in the expected counts and
presets on AMD, so that the checks fail if KVM undercounts emulated
instructions.

Patch 3 adds a check that the difference between the instructions and
branches counts is exact on AMD. Every VMRUN adds one to both counts,
so the difference is precise regardless of asynchronous VM-Exits, which
catches KVM over- or undercounting instructions vs. branches unevenly.

Tested on AMD Turin with KVM's mediated and perf-based vPMUs, and on
Intel Granite Rapids, with and without injected (simulated) KVM
miscounting to verify that the new checks catch it. With the perf-based
vPMU on AMD, "emulated instruction: branch counter overflow" fails with
and without this series, due to a KVM/perf issue with periods of 1:
https://lore.kernel.org/all/20231107183605.409588-1-seanjc@google.com/

Yosry Ahmed (3):
  x86/pmu: Mask emulated instruction count deltas to the counter width
  x86/pmu: Account for VMRUNs in emulated instruction checks on AMD
  x86/pmu: Check emulated instruction/branch count difference on AMD

 x86/pmu.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 7 deletions(-)

-- 
2.56.1.911.g883d8bcb20-goog


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

end of thread, other threads:[~2026-11-26  0:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  0:48 [kvm-unit-tests PATCH 0/3] x86/pmu: Restore emulated instruction test coverage on AMD Yosry Ahmed
2026-11-26  0:48 ` [kvm-unit-tests PATCH 1/3] x86/pmu: Mask emulated instruction count deltas to the counter width Yosry Ahmed
2026-11-26  0:48 ` [kvm-unit-tests PATCH 2/3] x86/pmu: Account for VMRUNs in emulated instruction checks on AMD Yosry Ahmed
2026-11-26  0:48 ` [kvm-unit-tests PATCH 3/3] x86/pmu: Check emulated instruction/branch count difference " Yosry Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox