OSDN Git Service

KVM: selftests: Move vcpu_args_set into perf_test_util
authorDavid Matlack <dmatlack@google.com>
Thu, 5 Aug 2021 17:28:21 +0000 (17:28 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 6 Aug 2021 14:01:40 +0000 (10:01 -0400)
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>
Message-Id: <20210805172821.2622793-1-dmatlack@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/access_tracking_perf_test.c
tools/testing/selftests/kvm/demand_paging_test.c
tools/testing/selftests/kvm/dirty_log_perf_test.c
tools/testing/selftests/kvm/lib/perf_test_util.c
tools/testing/selftests/kvm/memslot_modification_stress_test.c

index 3e23b21..71e277c 100644 (file)
@@ -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:
index 61266a7..e79c1b6 100644 (file)
@@ -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);
index 034458d..3c30d00 100644 (file)
@@ -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)) {
index aebb223..0ef80db 100644 (file)
@@ -150,6 +150,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));
index 8a9c6cc..4cfcafe 100644 (file)
@@ -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 */