KVM: selftests: Randomly force emulation on x86 writes from guest code
authorSean Christopherson <seanjc@google.com>
Thu, 14 Mar 2024 18:54:58 +0000 (11:54 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 29 Apr 2024 19:50:43 +0000 (12:50 -0700)
commit87aa264cd89d068f2455fc6e240d4015f6234204
tree670571dd49bd72e7c71cec76251c51f3790bcc26
parent2f2bc6af6aa8cc07f84291d625f7113fd13d68e5
KVM: selftests: Randomly force emulation on x86 writes from guest code

Override vcpu_arch_put_guest() to randomly force emulation on supported
accesses.  Force emulation of LOCK CMPXCHG as well as a regular MOV to
stress KVM's emulation of atomic accesses, which has a unique path in
KVM's emulator.

Arbitrarily give all the decisions 50/50 odds; absent much, much more
sophisticated infrastructure for generating random numbers, it's highly
unlikely that doing more than a coin flip with affect selftests' ability
to find KVM bugs.

This is effectively a regression test for commit 910c57dfa4d1 ("KVM: x86:
Mark target gfn of emulated atomic instruction as dirty").

Link: https://lore.kernel.org/r/20240314185459.2439072-6-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h