KVM: selftests: Add a test for x86's fastops emulation
Sean Christopherson
maintainerPATCH 1/1 KVM: selftests: Add a test for x86's fastops emulation
Add a test to verify KVM's fastops emulation via forced emulation. KVM's so called "fastop" infrastructure executes the to-be-emulated instruction directly on hardware instead of manually emulating the instruction in software, using various shenanigans to glue together the emulator context and CPU state, e.g. to get RFLAGS fed into the instruction and back out for the emulator.
Add testcases for all instructions that are low hanging fruit. While the primary goal of the selftest is to validate the glue code, a secondary goal is to ensure "emulation" matches hardware exactly, including for arithmetic flags that are architecturally undefined. While arithmetic flags may be *architecturally* undefined, their behavior is deterministic for a given CPU (likely a given uarch, and possibly even an entire family or class of CPUs). I.e. KVM has effectively been emulating underlying hardware behavior for years.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../testing/selftests/kvm/x86/fastops_test.c | 165 ++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86/fastops_test.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -66,6 +66,7 @@ TEST_GEN_PROGS_x86 += x86/cr4_cpuid_sync_test TEST_GEN_PROGS_x86 += x86/dirty_log_page_splitting_test TEST_GEN_PROGS_x86 += x86/feature_msrs_test TEST_GEN_PROGS_x86 += x86/exit_on_emulation_failure_test +TEST_GEN_PROGS_x86 += x86/fastops_test TEST_GEN_PROGS_x86 += x86/fix_hypercall_test TEST_GEN_PROGS_x86 += x86/hwcr_msr_test TEST_GEN_PROGS_x86 += x86/hyperv_clock
tools/testing/selftests/kvm/x86/fastops_test.c new file +165 -0
165 lines not on this page · raw message
base-commit: 661b7ddb2d10258b53106d7c39c309806b00a99c
Signature · 1 line
2.49.0.967.g6a0df3ecc3-goog
Sean Christopherson
maintainerQuoted 8 lines · Sean Christopherson
Add a test to verify KVM's fastops emulation via forced emulation. KVM's so called "fastop" infrastructure executes the to-be-emulated instruction directly on hardware instead of manually emulating the instruction in software, using various shenanigans to glue together the emulator context and CPU state, e.g. to get RFLAGS fed into the instruction and back out for the emulator.
[...]
Applied quickly to kvm-x86 selftests to make it easier to test's PeterZ's fastops changes, and to get early test coverage on more hardware (in case my assertion that undefined arithmetic flags are deterministic proves to be wrong).
[1/1] KVM: selftests: Add a test for x86's fastops emulation
https://github.com/kvm-x86/linux/commit/5e9ac644c40f