Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] x86/pmu: Relax precise count check for emulated instructions on AMD
@ 2026-07-15  6:28 Sandipan Das
  2026-09-30 20:18 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Sandipan Das @ 2026-07-15  6:28 UTC (permalink / raw)
  To: kvm
  Cc: Sean Christopherson, Paolo Bonzini, Dapeng Mi,
	Nikunj A . Dadhania, Manali Shukla, Sandipan Das

check_emulated_instr() expects the retired instruction and branch
counts to match the expected values exactly when a global control MSR
is available. This does not hold on AMD processors because VMRUN is
counted as a retired instruction and branch in guest context. The exact
comparison therefore fails, with the surplus varying with how many
asynchronous #VMEXITs occur while the measured code runs.

Hence, gate the precise comparison on pmu.is_intel and fall back to the
lower-bound check, mirroring how adjust_events_range() already handles
the same VMRUN behaviour.

Signed-off-by: Sandipan Das <sandipan.das@amd.com>
---
 x86/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/x86/pmu.c b/x86/pmu.c
index b262ea59..2b8d1b5b 100644
--- a/x86/pmu.c
+++ b/x86/pmu.c
@@ -786,12 +786,12 @@ static void check_emulated_instr(void)
 
 	// Check that the end count - start count is at least the expected
 	// number of instructions and branches.
-	if (has_perf_global_ctrl && !pmu.errata.instructions_retired_overcount)
+	if (pmu.is_intel && has_perf_global_ctrl && !pmu.errata.instructions_retired_overcount)
 		report(instr_cnt.count - instr_start == KVM_FEP_INSNS, "instruction count");
 	else
 		report(instr_cnt.count - instr_start >= KVM_FEP_INSNS, "instruction count");
 
-	if (has_perf_global_ctrl && !pmu.errata.branches_retired_overcount)
+	if (pmu.is_intel && has_perf_global_ctrl && !pmu.errata.branches_retired_overcount)
 		report(brnch_cnt.count - brnch_start == KVM_FEP_BRANCHES, "branch count");
 	else
 		report(brnch_cnt.count - brnch_start >= KVM_FEP_BRANCHES, "branch count");
-- 
2.53.0


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

end of thread, other threads:[~2026-09-30 20:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15  6:28 [kvm-unit-tests PATCH] x86/pmu: Relax precise count check for emulated instructions on AMD Sandipan Das
2026-09-30 20:18 ` Sean Christopherson

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