In a preparation to introduce dirty-ring support in dirty_log_perf_test,
add a helper to detect the Dirty-ring capability and replace the checking
of individual capabilities in the dirty_log_test.

Suggested-by: Sean Christopherson <[email protected]>
Signed-off-by: Leonardo Bras <[email protected]>
---
 tools/testing/selftests/kvm/include/kvm_util.h | 11 +++++++++++
 tools/testing/selftests/kvm/dirty_log_test.c   |  3 +--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/kvm_util.h 
b/tools/testing/selftests/kvm/include/kvm_util.h
index 5a7a455b5387..a89758e66a68 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -300,20 +300,31 @@ static inline int get_kvm_param_integer(const char *param)
        return kvm_get_module_param_integer("kvm", param);
 }
 
 unsigned int kvm_check_cap(long cap);
 
 static inline bool kvm_has_cap(long cap)
 {
        return kvm_check_cap(cap);
 }
 
+static inline long kvm_get_dirty_ring_cap(void)
+{
+       if (kvm_has_cap(KVM_CAP_DIRTY_LOG_RING_ACQ_REL))
+               return KVM_CAP_DIRTY_LOG_RING_ACQ_REL;
+
+       if (kvm_has_cap(KVM_CAP_DIRTY_LOG_RING))
+               return KVM_CAP_DIRTY_LOG_RING;
+
+       return 0;
+}
+
 /*
  * Use the "inner", double-underscore macro when reporting errors from within
  * other macros so that the name of ioctl() and not its literal numeric value
  * is printed on error.  The "outer" macro is strongly preferred when reporting
  * errors "directly", i.e. without an additional layer of macros, as it reduces
  * the probability of passing in the wrong string.
  */
 #define __KVM_IOCTL_ERROR(_name, _ret) __KVM_SYSCALL_ERROR(_name, _ret)
 #define KVM_IOCTL_ERROR(_ioctl, _ret) __KVM_IOCTL_ERROR(#_ioctl, _ret)
 
diff --git a/tools/testing/selftests/kvm/dirty_log_test.c 
b/tools/testing/selftests/kvm/dirty_log_test.c
index af5eb0334a74..558a71d631da 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -284,22 +284,21 @@ static void default_after_vcpu_run(struct kvm_vcpu *vcpu)
 
        TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC,
                    "Invalid guest sync status: exit_reason=%s",
                    exit_reason_str(run->exit_reason));
 
        vcpu_handle_sync_stop();
 }
 
 static bool dirty_ring_supported(void)
 {
-       return (kvm_has_cap(KVM_CAP_DIRTY_LOG_RING) ||
-               kvm_has_cap(KVM_CAP_DIRTY_LOG_RING_ACQ_REL));
+       return kvm_get_dirty_ring_cap();
 }
 
 static void dirty_ring_create_vm_done(struct kvm_vm *vm)
 {
        u64 pages;
        u32 limit;
 
        /*
         * We rely on vcpu exit due to full dirty ring state. Adjust
         * the ring buffer size to ensure we're able to reach the
-- 
2.55.0


Reply via email to