Commit ad125f30 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

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: default avatarAndrew Jones <drjones@redhat.com>
Fixes: fcba483e ("KVM: selftests: Sanity check input to ioctls() at build time")
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20220613161942.1586791-3-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 4f48e2e7
...@@ -200,9 +200,11 @@ static inline bool kvm_has_cap(long cap) ...@@ -200,9 +200,11 @@ static inline bool kvm_has_cap(long cap)
#define kvm_ioctl(kvm_fd, cmd, arg) \ #define kvm_ioctl(kvm_fd, cmd, arg) \
_kvm_ioctl(kvm_fd, cmd, #cmd, arg) _kvm_ioctl(kvm_fd, cmd, #cmd, arg)
static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { }
#define __vm_ioctl(vm, cmd, arg) \ #define __vm_ioctl(vm, cmd, arg) \
({ \ ({ \
static_assert(sizeof(*(vm)) == sizeof(struct kvm_vm), ""); \ static_assert_is_vm(vm); \
kvm_do_ioctl((vm)->fd, cmd, arg); \ kvm_do_ioctl((vm)->fd, cmd, arg); \
}) })
...@@ -216,9 +218,12 @@ static inline bool kvm_has_cap(long cap) ...@@ -216,9 +218,12 @@ static inline bool kvm_has_cap(long cap)
#define vm_ioctl(vm, cmd, arg) \ #define vm_ioctl(vm, cmd, arg) \
_vm_ioctl(vm, cmd, #cmd, arg) _vm_ioctl(vm, cmd, #cmd, arg)
static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { }
#define __vcpu_ioctl(vcpu, cmd, arg) \ #define __vcpu_ioctl(vcpu, cmd, arg) \
({ \ ({ \
static_assert(sizeof(*(vcpu)) == sizeof(struct kvm_vcpu), ""); \ static_assert_is_vcpu(vcpu); \
kvm_do_ioctl((vcpu)->fd, cmd, arg); \ kvm_do_ioctl((vcpu)->fd, cmd, arg); \
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment