kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Move vcpu_args_set into perf_test_util
@ 2021-08-05 17:28 David Matlack
  2021-08-06 11:55 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: David Matlack @ 2021-08-05 17:28 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Ben Gardon, Andrew Jones, David Matlack

perf_test_util is used to set up KVM selftests where vCPUs touch a
region of memory. The guest code is implemented in perf_test_util.c (not
the calling selftests). The guest code requires a 1 parameter, the
vcpuid, which has to be set by calling vcpu_args_set(vm, vcpu_id, 1,
vcpu_id).

Today all of the selftests that use perf_test_util are making this call.
Instead, perf_test_util should just do it. This will save some code but
more importantly prevents mistakes since totally non-obvious that this
needs to be called and failing to do so results in vCPUs not accessing
the right regions of memory.

Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/access_tracking_perf_test.c        | 2 --
 tools/testing/selftests/kvm/demand_paging_test.c               | 1 -
 tools/testing/selftests/kvm/dirty_log_perf_test.c              | 1 -
 tools/testing/selftests/kvm/lib/perf_test_util.c               | 2 ++
 tools/testing/selftests/kvm/memslot_modification_stress_test.c | 1 -
 5 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
index e2baa187a21e..72714573ba4f 100644
--- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
+++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
@@ -222,8 +222,6 @@ static void *vcpu_thread_main(void *arg)
 	int vcpu_id = vcpu_args->vcpu_id;
 	int current_iteration = -1;
 
-	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
-
 	while (spin_wait_for_next_iteration(&current_iteration)) {
 		switch (READ_ONCE(iteration_work)) {
 		case ITERATION_ACCESS_MEMORY:
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index b74704305835..950f2eb634e6 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -52,7 +52,6 @@ static void *vcpu_worker(void *data)
 	struct timespec start;
 	struct timespec ts_diff;
 
-	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
 	run = vcpu_state(vm, vcpu_id);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
index 80cbd3a748c0..ef45a133560f 100644
--- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
@@ -44,7 +44,6 @@ static void *vcpu_worker(void *data)
 	struct perf_test_vcpu_args *vcpu_args = (struct perf_test_vcpu_args *)data;
 	int vcpu_id = vcpu_args->vcpu_id;
 
-	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
 	run = vcpu_state(vm, vcpu_id);
 
 	while (!READ_ONCE(host_quit)) {
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index b488f4aefea8..f6aa81af3e6f 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -140,6 +140,8 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
 			vcpu_gpa = guest_test_phys_mem;
 		}
 
+		vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
+
 		pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
 			 vcpu_id, vcpu_gpa, vcpu_gpa +
 			 (vcpu_args->pages * perf_test_args.guest_page_size));
diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
index 98351ba0933c..b6f7cc298e4d 100644
--- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
+++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
@@ -45,7 +45,6 @@ static void *vcpu_worker(void *data)
 	struct kvm_vm *vm = perf_test_args.vm;
 	struct kvm_run *run;
 
-	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
 	run = vcpu_state(vm, vcpu_id);
 
 	/* Let the guest access its memory until a stop signal is received */
-- 
2.32.0.554.ge1b32706d8-goog


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

* Re: [PATCH] KVM: selftests: Move vcpu_args_set into perf_test_util
  2021-08-05 17:28 [PATCH] KVM: selftests: Move vcpu_args_set into perf_test_util David Matlack
@ 2021-08-06 11:55 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-08-06 11:55 UTC (permalink / raw)
  To: David Matlack; +Cc: kvm, Ben Gardon, Andrew Jones

On 05/08/21 19:28, David Matlack wrote:
> perf_test_util is used to set up KVM selftests where vCPUs touch a
> region of memory. The guest code is implemented in perf_test_util.c (not
> the calling selftests). The guest code requires a 1 parameter, the
> vcpuid, which has to be set by calling vcpu_args_set(vm, vcpu_id, 1,
> vcpu_id).
> 
> Today all of the selftests that use perf_test_util are making this call.
> Instead, perf_test_util should just do it. This will save some code but
> more importantly prevents mistakes since totally non-obvious that this
> needs to be called and failing to do so results in vCPUs not accessing
> the right regions of memory.
> 
> Signed-off-by: David Matlack <dmatlack@google.com>

Queued, thanks.

Paolo

> ---
>   tools/testing/selftests/kvm/access_tracking_perf_test.c        | 2 --
>   tools/testing/selftests/kvm/demand_paging_test.c               | 1 -
>   tools/testing/selftests/kvm/dirty_log_perf_test.c              | 1 -
>   tools/testing/selftests/kvm/lib/perf_test_util.c               | 2 ++
>   tools/testing/selftests/kvm/memslot_modification_stress_test.c | 1 -
>   5 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
> index e2baa187a21e..72714573ba4f 100644
> --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
> +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
> @@ -222,8 +222,6 @@ static void *vcpu_thread_main(void *arg)
>   	int vcpu_id = vcpu_args->vcpu_id;
>   	int current_iteration = -1;
>   
> -	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
> -
>   	while (spin_wait_for_next_iteration(&current_iteration)) {
>   		switch (READ_ONCE(iteration_work)) {
>   		case ITERATION_ACCESS_MEMORY:
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index b74704305835..950f2eb634e6 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -52,7 +52,6 @@ static void *vcpu_worker(void *data)
>   	struct timespec start;
>   	struct timespec ts_diff;
>   
> -	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
>   	run = vcpu_state(vm, vcpu_id);
>   
>   	clock_gettime(CLOCK_MONOTONIC, &start);
> diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
> index 80cbd3a748c0..ef45a133560f 100644
> --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
> @@ -44,7 +44,6 @@ static void *vcpu_worker(void *data)
>   	struct perf_test_vcpu_args *vcpu_args = (struct perf_test_vcpu_args *)data;
>   	int vcpu_id = vcpu_args->vcpu_id;
>   
> -	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
>   	run = vcpu_state(vm, vcpu_id);
>   
>   	while (!READ_ONCE(host_quit)) {
> diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> index b488f4aefea8..f6aa81af3e6f 100644
> --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> @@ -140,6 +140,8 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
>   			vcpu_gpa = guest_test_phys_mem;
>   		}
>   
> +		vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
> +
>   		pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
>   			 vcpu_id, vcpu_gpa, vcpu_gpa +
>   			 (vcpu_args->pages * perf_test_args.guest_page_size));
> diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> index 98351ba0933c..b6f7cc298e4d 100644
> --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> @@ -45,7 +45,6 @@ static void *vcpu_worker(void *data)
>   	struct kvm_vm *vm = perf_test_args.vm;
>   	struct kvm_run *run;
>   
> -	vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
>   	run = vcpu_state(vm, vcpu_id);
>   
>   	/* Let the guest access its memory until a stop signal is received */
> 


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

end of thread, other threads:[~2021-08-06 11:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 17:28 [PATCH] KVM: selftests: Move vcpu_args_set into perf_test_util David Matlack
2021-08-06 11:55 ` 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).