]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
KVM: selftests: Add test to verify TRIPLE_FAULT on invalid L2 guest state
authorSean Christopherson <seanjc@google.com>
Tue, 7 Dec 2021 19:30:06 +0000 (19:30 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 20 Dec 2021 13:06:55 +0000 (08:06 -0500)
commitab1ef34416a65ba11f66ae6435fcf0251cb46fd4
tree8a40f93357afea6576590203cc99ab7318ea942c
parent0ff29701ffad9a5d5a24344d8b09f3af7b96ffda
KVM: selftests: Add test to verify TRIPLE_FAULT on invalid L2 guest state

Add a selftest to attempt to enter L2 with invalid guests state by
exiting to userspace via I/O from L2, and then using KVM_SET_SREGS to set
invalid guest state (marking TR unusable is arbitrary chosen for its
relative simplicity).

This is a regression test for a bug introduced by commit c8607e4a086f
("KVM: x86: nVMX: don't fail nested VM entry on invalid guest state if
!from_vmentry"), which incorrectly set vmx->fail=true when L2 had invalid
guest state and ultimately triggered a WARN due to nested_vmx_vmexit()
seeing vmx->fail==true while attempting to synthesize a nested VM-Exit.

The is also a functional test to verify that KVM sythesizes TRIPLE_FAULT
for L2, which is somewhat arbitrary behavior, instead of emulating L2.
KVM should never emulate L2 due to invalid guest state, as it's
architecturally impossible for L1 to run an L2 guest with invalid state
as nested VM-Enter should always fail, i.e. L1 needs to do the emulation.
Stuffing state via KVM ioctl() is a non-architctural, out-of-band case,
hence the TRIPLE_FAULT being rather arbitrary.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20211207193006.120997-5-seanjc@google.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/.gitignore
tools/testing/selftests/kvm/Makefile
tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_state.c [new file with mode: 0644]