x86/pmu: Relax overcounting checks to allow for 1 VM-Exit per 5000 nops
Sean Christopherson
reviewerPATCH 1/1 x86/pmu: Relax overcounting checks to allow for 1 VM-Exit per 5000 nops
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.
--- x86/pmu.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
x86/pmu.c +9 -7
@@ -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
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
Quoted 10 lines · Sean Christopherson
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).
[...]
Applied to kvm-x86 next. Sorry for rushing this in, I want to get a pull request sent to Paolo before LPC (getting the fixes into the main repo isn't urgent, I just don't want to forget about this stuff for many more weeks).
[1/1] x86/pmu: Relax overcounting checks to allow for 1 VM-Exit per 5000 nops
https://github.com/kvm-x86/kvm-unit-tests/commit/1aaec1f90618