Commit e5830fb1 authored by Hou Wenlong's avatar Hou Wenlong Committed by Paolo Bonzini

KVM: selftests: fix triple fault if ept=0 in dirty_log_test

Commit 22f232d1 ("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: 22f232d1 ("KVM: selftests: x86: Set supported CPUIDs on default VM")
Signed-off-by: default avatarHou Wenlong <houwenlong93@linux.alibaba.com>
Message-Id: <411ea2173f89abce56fc1fca5af913ed9c5a89c9.1624351343.git.houwenlong93@linux.alibaba.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 18f63b15
...@@ -375,10 +375,6 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus, ...@@ -375,10 +375,6 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
uint32_t vcpuid = vcpuids ? vcpuids[i] : i; uint32_t vcpuid = vcpuids ? vcpuids[i] : i;
vm_vcpu_add_default(vm, vcpuid, guest_code); vm_vcpu_add_default(vm, vcpuid, guest_code);
#ifdef __x86_64__
vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
#endif
} }
return vm; return vm;
......
...@@ -600,6 +600,9 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) ...@@ -600,6 +600,9 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
/* Setup the MP state */ /* Setup the MP state */
mp_state.mp_state = 0; mp_state.mp_state = 0;
vcpu_set_mp_state(vm, vcpuid, &mp_state); vcpu_set_mp_state(vm, vcpuid, &mp_state);
/* Setup supported CPUIDs */
vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
} }
/* /*
......
...@@ -73,8 +73,6 @@ static void steal_time_init(struct kvm_vm *vm) ...@@ -73,8 +73,6 @@ static void steal_time_init(struct kvm_vm *vm)
for (i = 0; i < NR_VCPUS; ++i) { for (i = 0; i < NR_VCPUS; ++i) {
int ret; int ret;
vcpu_set_cpuid(vm, i, kvm_get_supported_cpuid());
/* ST_GPA_BASE is identity mapped */ /* ST_GPA_BASE is identity mapped */
st_gva[i] = (void *)(ST_GPA_BASE + i * STEAL_TIME_SIZE); st_gva[i] = (void *)(ST_GPA_BASE + i * STEAL_TIME_SIZE);
sync_global_to_guest(vm, st_gva[i]); sync_global_to_guest(vm, st_gva[i]);
......
...@@ -102,8 +102,6 @@ static void add_x86_vcpu(struct kvm_vm *vm, uint32_t vcpuid, bool bsp_code) ...@@ -102,8 +102,6 @@ static void add_x86_vcpu(struct kvm_vm *vm, uint32_t vcpuid, bool bsp_code)
vm_vcpu_add_default(vm, vcpuid, guest_bsp_vcpu); vm_vcpu_add_default(vm, vcpuid, guest_bsp_vcpu);
else else
vm_vcpu_add_default(vm, vcpuid, guest_not_bsp_vcpu); vm_vcpu_add_default(vm, vcpuid, guest_not_bsp_vcpu);
vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
} }
static void run_vm_bsp(uint32_t bsp_vcpu) static void run_vm_bsp(uint32_t bsp_vcpu)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment