KVM: selftests: Extend x86's sync_regs_test to check for CR4 races
authorMichal Luczaj <mhal@rbox.co>
Fri, 28 Jul 2023 00:12:58 +0000 (02:12 +0200)
committerSean Christopherson <seanjc@google.com>
Wed, 2 Aug 2023 20:33:17 +0000 (13:33 -0700)
commitae895cbe613a5b193f3953c90c075306bfa4d30b
tree980a4f0a631adb15bdadef1903265196646f0de2
parent0d033770d43a7aa36025bcef9a60da7fb750f735
KVM: selftests: Extend x86's sync_regs_test to check for CR4 races

Attempt to modify vcpu->run->s.regs _after_ the sanity checks performed by
KVM_CAP_SYNC_REGS's arch/x86/kvm/x86.c:sync_regs().  This can lead to some
nonsensical vCPU states accompanied by kernel splats, e.g. disabling PAE
while long mode is enabled makes KVM all kinds of confused:

 WARNING: CPU: 0 PID: 1142 at arch/x86/kvm/mmu/paging_tmpl.h:358 paging32_walk_addr_generic+0x431/0x8f0 [kvm]

 arch/x86/kvm/mmu/paging_tmpl.h:
 KVM_BUG_ON(is_long_mode(vcpu) && !is_pae(vcpu), vcpu->kvm)

Signed-off-by: Michal Luczaj <mhal@rbox.co>
Link: https://lore.kernel.org/r/20230728001606.2275586-3-mhal@rbox.co
[sean: see link]
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/x86_64/sync_regs_test.c