]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Split vcpu_set_nested_state() into two helpers
authorSean Christopherson <seanjc@google.com>
Tue, 15 Feb 2022 18:08:45 +0000 (10:08 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 11 Jun 2022 14:15:16 +0000 (10:15 -0400)
Split vcpu_nested_state_set() into a wrapper that asserts, and an inner
helper that does not.  Passing a bool is all kinds of awful as it's
unintuitive for readers and requires returning an 'int' from a function
that for most users can never return anything other than "success".

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/include/kvm_util_base.h
tools/testing/selftests/kvm/lib/kvm_util.c
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c

index f6984b0c38168ae09b4c4bc3d0bf3ec72690702c..314d971c1f06cfb655e21375b34c72721e8bfe57 100644 (file)
@@ -261,8 +261,10 @@ void vcpu_events_set(struct kvm_vm *vm, uint32_t vcpuid,
 #ifdef __x86_64__
 void vcpu_nested_state_get(struct kvm_vm *vm, uint32_t vcpuid,
                           struct kvm_nested_state *state);
-int vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
-                         struct kvm_nested_state *state, bool ignore_error);
+int __vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
+                           struct kvm_nested_state *state);
+void vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
+                          struct kvm_nested_state *state);
 #endif
 void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid);
 
index bab4ab297fcc9ba952a770c3746d5ea9e2b3ccf3..7b339f98070b6e18d566130ee7560d7f7ce67acd 100644 (file)
@@ -1826,22 +1826,22 @@ void vcpu_nested_state_get(struct kvm_vm *vm, uint32_t vcpuid,
                ret, errno);
 }
 
-int vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
-                         struct kvm_nested_state *state, bool ignore_error)
+int __vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
+                           struct kvm_nested_state *state)
 {
        struct vcpu *vcpu = vcpu_find(vm, vcpuid);
-       int ret;
 
        TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid);
 
-       ret = ioctl(vcpu->fd, KVM_SET_NESTED_STATE, state);
-       if (!ignore_error) {
-               TEST_ASSERT(ret == 0,
-                       "KVM_SET_NESTED_STATE failed, ret: %i errno: %i",
-                       ret, errno);
-       }
+       return ioctl(vcpu->fd, KVM_SET_NESTED_STATE, state);
+}
 
-       return ret;
+void vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
+                          struct kvm_nested_state *state)
+{
+       int ret = __vcpu_nested_state_set(vm, vcpuid, state);
+
+       TEST_ASSERT(!ret, "KVM_SET_NESTED_STATE failed, ret: %i errno: %i", ret, errno);
 }
 #endif
 
index 5827b9bae4682c178d497a61ef9fdae8d3db204c..af3b60eb35ecb62ade84d50dc7bb1d4d46a3b1b3 100644 (file)
@@ -29,7 +29,7 @@ bool have_evmcs;
 
 void test_nested_state(struct kvm_vm *vm, struct kvm_nested_state *state)
 {
-       vcpu_nested_state_set(vm, VCPU_ID, state, false);
+       vcpu_nested_state_set(vm, VCPU_ID, state);
 }
 
 void test_nested_state_expect_errno(struct kvm_vm *vm,
@@ -38,7 +38,7 @@ void test_nested_state_expect_errno(struct kvm_vm *vm,
 {
        int rv;
 
-       rv = vcpu_nested_state_set(vm, VCPU_ID, state, true);
+       rv = __vcpu_nested_state_set(vm, VCPU_ID, state);
        TEST_ASSERT(rv == -1 && errno == expected_errno,
                "Expected %s (%d) from vcpu_nested_state_set but got rv: %i errno: %s (%d)",
                strerror(expected_errno), expected_errno, rv, strerror(errno),