]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: selftests: Add a test for x86's fastops emulation
authorSean Christopherson <seanjc@google.com>
Tue, 6 May 2025 01:12:50 +0000 (18:12 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 8 May 2025 14:16:44 +0000 (07:16 -0700)
commit5e9ac644c40f8315877343034d1d6a8e056bd1dc
tree1d61d733f66144182270ce0e83aea415794712ec
parentada014f5fc676bf16327c252587e0c856234bc13
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.

Link: https://lore.kernel.org/r/20250506011250.1089254-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/Makefile.kvm
tools/testing/selftests/kvm/x86/fastops_test.c [new file with mode: 0644]