Relax the check on the allowed instruction count range in the PMC overflow testcase for AMD CPUs (all of which overcount instructions retired due to treating VMRUN as retiring in guest context). Empirically, modern CPUs can overcount by ~150 instructions, which seems high, but is reasonable when considering the main loop executes one million nops. Arbitrarily allow for an "extra" 199 VM-Exits in the loop, expressed as a function of the number of nops in the loop (the "per 5000" math was derived from wanting to allow for ~200 VM-Exits). Opportunistically drop the "allow undercounting by 1", which presumably was a workaround for the VMRUN overcounting behavior (which is now addressed by tagging AMD CPUs as having pmu.errata.instructions_retired_overcount=true). Opportunistically use the same logic for Intel CPUs. While hitting Intel's errata is apparently less common (doesn't happen on every VM-Exit?), trying to precisely validate the counts when they are known to be buggy doesn't add much value. E.g. if an overcounting CPU happened to generate 14 extra events, odds are good the allowed count would simply be increased. Reported-by: Sandipan Das Closes: https://lore.kernel.org/all/2dd84890-3c21-4942-a9e4-8e07408620d3@amd.com Signed-off-by: Sean Christopherson --- x86/pmu.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/x86/pmu.c b/x86/pmu.c index 483f2f1f..a54eb384 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -578,14 +578,16 @@ static void check_counter_overflow(void) cnt.config &= ~EVNTSEL_INT; idx = event_to_global_idx(&cnt); __measure(&cnt, cnt.count); - if (pmu.is_intel) { - if (pmu.errata.instructions_retired_overcount) - report(cnt.count < 14, "cntr-%d", i); - else - report(cnt.count == 1, "cntr-%d", i); - } + + /* + * If the CPU overcounts instructions retired on asynchronous + * VM-Exits, arbitrarily allow for one VM-Exit per 5000 nops in + * the measurement loop. + */ + if (pmu.errata.instructions_retired_overcount) + report(cnt.count < N / 5000, "cntr-%d", i); else - report(cnt.count == 0xffffffffffff || cnt.count < 7, "cntr-%d", i); + report(cnt.count == 1, "cntr-%d", i); report(check_irq() == (i % 2), "irq-%d", i); base-commit: af828383c365d2baa2449dbb3ae2f5cc826f8036 -- 2.56.0.rc1.315.gc6ed9934b7-goog