From: Yosry Ahmed <yosry@kernel.org>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: Jim Mattson <jmattson@google.com>,
kvm@vger.kernel.org, Yosry Ahmed <yosry@kernel.org>
Subject: [kvm-unit-tests PATCH 0/3] x86/pmu: Restore emulated instruction test coverage on AMD
Date: Thu, 26 Nov 2026 00:48:28 +0000 [thread overview]
Message-ID: <20261126004831.2712453-1-yosry@kernel.org> (raw)
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
next reply other threads:[~2026-11-26 0:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 0:48 Yosry Ahmed [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126004831.2712453-1-yosry@kernel.org \
--to=yosry@kernel.org \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox