summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2022-06-13 16:19:40 +0000
committerPaolo Bonzini <pbonzini@redhat.com>2022-06-14 12:44:46 -0400
commitad125f309850b9cf2ba4f39729c5cc827595fac4 (patch)
treeca8fb7f421b1af37becb90e2c0955a4fb3e3ead5 /tools/testing/selftests/kvm
parent4f48e2e737451365bc81c3b6283036a9079bcc24 (diff)
downloadlinux-next-ad125f309850b9cf2ba4f39729c5cc827595fac4.tar.gz
KVM: selftests: Call a dummy helper in VM/vCPU ioctls() to enforce type
Replace the goofy static_assert on the size of the @vm/@vcpu parameters with a call to a dummy helper, i.e. let the compiler naturally complain about an incompatible type instead of homebrewing a poor replacement. Reported-by: Andrew Jones <drjones@redhat.com> Fixes: fcba483e8246 ("KVM: selftests: Sanity check input to ioctls() at build time") Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20220613161942.1586791-3-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm')
-rw-r--r--tools/testing/selftests/kvm/include/kvm_util_base.h57
1 files changed, 31 insertions, 26 deletions
diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h
index cdaea2383543..7ebfc8c7de17 100644
--- a/tools/testing/selftests/kvm/include/kvm_util_base.h
+++ b/tools/testing/selftests/kvm/include/kvm_util_base.h
@@ -186,50 +186,55 @@ static inline bool kvm_has_cap(long cap)
ioctl(fd, cmd, arg); \
})
-#define __kvm_ioctl(kvm_fd, cmd, arg) \
+#define __kvm_ioctl(kvm_fd, cmd, arg) \
kvm_do_ioctl(kvm_fd, cmd, arg)
-#define _kvm_ioctl(kvm_fd, cmd, name, arg) \
-({ \
- int ret = __kvm_ioctl(kvm_fd, cmd, arg); \
- \
- TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
+#define _kvm_ioctl(kvm_fd, cmd, name, arg) \
+({ \
+ int ret = __kvm_ioctl(kvm_fd, cmd, arg); \
+ \
+ TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
})
#define kvm_ioctl(kvm_fd, cmd, arg) \
_kvm_ioctl(kvm_fd, cmd, #cmd, arg)
-#define __vm_ioctl(vm, cmd, arg) \
-({ \
- static_assert(sizeof(*(vm)) == sizeof(struct kvm_vm), ""); \
- kvm_do_ioctl((vm)->fd, cmd, arg); \
+static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { }
+
+#define __vm_ioctl(vm, cmd, arg) \
+({ \
+ static_assert_is_vm(vm); \
+ kvm_do_ioctl((vm)->fd, cmd, arg); \
})
-#define _vm_ioctl(vm, cmd, name, arg) \
-({ \
- int ret = __vm_ioctl(vm, cmd, arg); \
- \
- TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
+#define _vm_ioctl(vm, cmd, name, arg) \
+({ \
+ int ret = __vm_ioctl(vm, cmd, arg); \
+ \
+ TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
})
-#define vm_ioctl(vm, cmd, arg) \
+#define vm_ioctl(vm, cmd, arg) \
_vm_ioctl(vm, cmd, #cmd, arg)
-#define __vcpu_ioctl(vcpu, cmd, arg) \
-({ \
- static_assert(sizeof(*(vcpu)) == sizeof(struct kvm_vcpu), ""); \
- kvm_do_ioctl((vcpu)->fd, cmd, arg); \
+
+static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { }
+
+#define __vcpu_ioctl(vcpu, cmd, arg) \
+({ \
+ static_assert_is_vcpu(vcpu); \
+ kvm_do_ioctl((vcpu)->fd, cmd, arg); \
})
-#define _vcpu_ioctl(vcpu, cmd, name, arg) \
-({ \
- int ret = __vcpu_ioctl(vcpu, cmd, arg); \
- \
- TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
+#define _vcpu_ioctl(vcpu, cmd, name, arg) \
+({ \
+ int ret = __vcpu_ioctl(vcpu, cmd, arg); \
+ \
+ TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
})
-#define vcpu_ioctl(vcpu, cmd, arg) \
+#define vcpu_ioctl(vcpu, cmd, arg) \
_vcpu_ioctl(vcpu, cmd, #cmd, arg)
/*