linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: fix triple fault if ept=0 in dirty_log_test
@ 2021-06-22 13:55 Hou Wenlong
  2021-06-22 16:42 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Hou Wenlong @ 2021-06-22 13:55 UTC (permalink / raw)
  To: kvm; +Cc: linux-kselftest, pbonzini, shuah

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 shadowpaing, 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>
---
 tools/testing/selftests/kvm/lib/kvm_util.c         | 4 ----
 tools/testing/selftests/kvm/lib/x86_64/processor.c | 3 +++
 tools/testing/selftests/kvm/steal_time.c           | 2 --
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index a2b732cf96ea..8ea854d7822d 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -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;
 
 		vm_vcpu_add_default(vm, vcpuid, guest_code);
-
-#ifdef __x86_64__
-		vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
-#endif
 	}
 
 	return vm;
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index efe235044421..595322b24e4c 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -600,6 +600,9 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
 	/* Setup the MP state */
 	mp_state.mp_state = 0;
 	vcpu_set_mp_state(vm, vcpuid, &mp_state);
+
+	/* Setup supported CPUIDs */
+	vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
 }
 
 /*
diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index fcc840088c91..a6fe75cb9a6e 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -73,8 +73,6 @@ static void steal_time_init(struct kvm_vm *vm)
 	for (i = 0; i < NR_VCPUS; ++i) {
 		int ret;
 
-		vcpu_set_cpuid(vm, i, kvm_get_supported_cpuid());
-
 		/* ST_GPA_BASE is identity mapped */
 		st_gva[i] = (void *)(ST_GPA_BASE + i * STEAL_TIME_SIZE);
 		sync_global_to_guest(vm, st_gva[i]);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: selftests: fix triple fault if ept=0 in dirty_log_test
  2021-06-22 13:55 [PATCH] KVM: selftests: fix triple fault if ept=0 in dirty_log_test Hou Wenlong
@ 2021-06-22 16:42 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-06-22 16:42 UTC (permalink / raw)
  To: Hou Wenlong, kvm; +Cc: linux-kselftest, shuah

On 22/06/21 15:55, Hou Wenlong wrote:
> 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 shadowpaing, 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>
> ---
>   tools/testing/selftests/kvm/lib/kvm_util.c         | 4 ----
>   tools/testing/selftests/kvm/lib/x86_64/processor.c | 3 +++
>   tools/testing/selftests/kvm/steal_time.c           | 2 --
>   3 files changed, 3 insertions(+), 6 deletions(-)

Queued, but this is missing:

diff --git a/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c b/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
index 5f8dd74d415f..fd309fb9e2c4 100644
--- a/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
+++ b/tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
@@ -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);
  	else
  		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)

Paolo

> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index a2b732cf96ea..8ea854d7822d 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -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;
>   
>   		vm_vcpu_add_default(vm, vcpuid, guest_code);
> -
> -#ifdef __x86_64__
> -		vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
> -#endif
>   	}
>   
>   	return vm;
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> index efe235044421..595322b24e4c 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> @@ -600,6 +600,9 @@ void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code)
>   	/* Setup the MP state */
>   	mp_state.mp_state = 0;
>   	vcpu_set_mp_state(vm, vcpuid, &mp_state);
> +
> +	/* Setup supported CPUIDs */
> +	vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
>   }
>   
>   /*
> diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
> index fcc840088c91..a6fe75cb9a6e 100644
> --- a/tools/testing/selftests/kvm/steal_time.c
> +++ b/tools/testing/selftests/kvm/steal_time.c
> @@ -73,8 +73,6 @@ static void steal_time_init(struct kvm_vm *vm)
>   	for (i = 0; i < NR_VCPUS; ++i) {
>   		int ret;
>   
> -		vcpu_set_cpuid(vm, i, kvm_get_supported_cpuid());
> -
>   		/* ST_GPA_BASE is identity mapped */
>   		st_gva[i] = (void *)(ST_GPA_BASE + i * STEAL_TIME_SIZE);
>   		sync_global_to_guest(vm, st_gva[i]);
> 


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-22 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 13:55 [PATCH] KVM: selftests: fix triple fault if ept=0 in dirty_log_test Hou Wenlong
2021-06-22 16:42 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).