KVM: selftests: fix triple fault if ept=0 in dirty_log_test
authorHou Wenlong <houwenlong93@linux.alibaba.com>
Tue, 22 Jun 2021 13:55:32 +0000 (21:55 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 24 Jun 2021 08:31:16 +0000 (04:31 -0400)
commite5830fb13b8cad5e3bdf84f0f7a3dcb4f4d9bcbb
treeb3a21925d45712d798b62314f52b3f7ab65c3621
parent18f63b15b0283d6f37be3174e2c7b6f2d6ed91cf
KVM: selftests: fix triple fault if ept=0 in dirty_log_test

Commit 22f232d134e1 ("KVM: selftests: x86: Set supported CPUIDs on
default VM") moved vcpu_set_cpuid into vm_create_with_vcpus, but
dirty_log_test doesn't use it to create vm. So vcpu's CPUIDs is
not set, the guest's pa_bits in kvm would be smaller than the
value queried by userspace.

However, the dirty track memory slot is in the highest GPA, the
reserved bits in gpte would be set with wrong pa_bits.
For shadow paging, page fault would fail in permission_fault and
be injected into guest. Since guest doesn't have idt, it finally
leads to vm_exit for triple fault.

Move vcpu_set_cpuid into vm_vcpu_add_default to set supported
CPUIDs on default vcpu, since almost all tests need it.

Fixes: 22f232d134e1 ("KVM: selftests: x86: Set supported CPUIDs on default VM")
Signed-off-by: Hou Wenlong <houwenlong93@linux.alibaba.com>
Message-Id: <411ea2173f89abce56fc1fca5af913ed9c5a89c9.1624351343.git.houwenlong93@linux.alibaba.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/lib/kvm_util.c
tools/testing/selftests/kvm/lib/x86_64/processor.c
tools/testing/selftests/kvm/steal_time.c
tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c