]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
KVM: selftests: Handle Intel Atom errata that leads to PMU event overcount
authordongsheng <dongsheng.x.zhang@intel.com>
Fri, 19 Sep 2025 21:46:48 +0000 (14:46 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 23 Sep 2025 15:38:59 +0000 (08:38 -0700)
commitc435978e4ffe87c6baee1290118039187eafc698
treed8d4947482c8f611c40abdf6f36786e6bc2a1d42
parent2922b595886575ebef46e65a0d4c8a857c5cd464
KVM: selftests: Handle Intel Atom errata that leads to PMU event overcount

Add a PMU errata framework and use it to relax precise event counts on
Atom platforms that overcount "Instruction Retired" and "Branch Instruction
Retired" events, as the overcount issues on VM-Exit/VM-Entry are impossible
to prevent from userspace, e.g. the test can't prevent host IRQs.

Setup errata during early initialization and automatically sync the mask
to VMs so that tests can check for errata without having to manually
manage host=>guest variables.

For Intel Atom CPUs, the PMU events "Instruction Retired" or
"Branch Instruction Retired" may be overcounted for some certain
instructions, like FAR CALL/JMP, RETF, IRET, VMENTRY/VMEXIT/VMPTRLD
and complex SGX/SMX/CSTATE instructions/flows.

The detailed information can be found in the errata (section SRF7):
https://edc.intel.com/content/www/us/en/design/products-and-solutions/processors-and-chipsets/sierra-forest/xeon-6700-series-processor-with-e-cores-specification-update/errata-details/

For the Atom platforms before Sierra Forest (including Sierra Forest),
Both 2 events "Instruction Retired" and "Branch Instruction Retired" would
be overcounted on these certain instructions, but for Clearwater Forest
only "Instruction Retired" event is overcounted on these instructions.

Signed-off-by: dongsheng <dongsheng.x.zhang@intel.com>
Co-developed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Tested-by: Yi Lai <yi1.lai@intel.com>
Co-developed-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Link: https://lore.kernel.org/r/20250919214648.1585683-6-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86/pmu.h
tools/testing/selftests/kvm/lib/x86/pmu.c
tools/testing/selftests/kvm/lib/x86/processor.c
tools/testing/selftests/kvm/x86/pmu_counters_test.c
tools/testing/selftests/kvm/x86/pmu_event_filter_test.c