Commit 02e04c15 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Make vcpu_ioctl() a wrapper to pretty print ioctl name

Make vcpu_ioctl() a macro wrapper and pretty the _name_ of the ioctl on
failure instead of the number.  Add inner macros to allow handling cases
where the name of the ioctl needs to be resolved higher up the stack, and
to allow using the formatting for non-ioctl syscalls without being
technically wrong.

Deliberately do not use __stringify(), as that will expand the ioctl all
the way down to its numerical sequence, again the intent is to print the
name of the macro.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2b38a739
...@@ -157,10 +157,19 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, ...@@ -157,10 +157,19 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
uint64_t guest_paddr, uint32_t slot, uint64_t npages, uint64_t guest_paddr, uint32_t slot, uint64_t npages,
uint32_t flags); uint32_t flags);
void vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl, #define __KVM_SYSCALL_ERROR(_name, _ret) \
void *arg); "%s failed, rc: %i errno: %i (%s)", (_name), (_ret), errno, strerror(errno)
#define __KVM_IOCTL_ERROR(_name, _ret) __KVM_SYSCALL_ERROR(_name, _ret)
#define KVM_IOCTL_ERROR(_ioctl, _ret) __KVM_IOCTL_ERROR(#_ioctl, _ret)
void _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
const char *name, void *arg);
int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl, int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
void *arg); void *arg);
#define vcpu_ioctl(vm, vcpuid, ioctl, arg) \
_vcpu_ioctl(vm, vcpuid, ioctl, #ioctl, arg)
void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg); void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
int __vm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg); int __vm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg);
void kvm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg); void kvm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
......
...@@ -1937,29 +1937,6 @@ void vcpu_set_reg(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_one_reg *reg) ...@@ -1937,29 +1937,6 @@ void vcpu_set_reg(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_one_reg *reg)
ret, errno, strerror(errno)); ret, errno, strerror(errno));
} }
/*
* VCPU Ioctl
*
* Input Args:
* vm - Virtual Machine
* vcpuid - VCPU ID
* cmd - Ioctl number
* arg - Argument to pass to the ioctl
*
* Return: None
*
* Issues an arbitrary ioctl on a VCPU fd.
*/
void vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid,
unsigned long cmd, void *arg)
{
int ret;
ret = __vcpu_ioctl(vm, vcpuid, cmd, arg);
TEST_ASSERT(ret == 0, "vcpu ioctl %lu failed, rc: %i errno: %i (%s)",
cmd, ret, errno, strerror(errno));
}
int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid,
unsigned long cmd, void *arg) unsigned long cmd, void *arg)
{ {
...@@ -1973,6 +1950,14 @@ int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, ...@@ -1973,6 +1950,14 @@ int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid,
return ret; return ret;
} }
void _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long cmd,
const char *name, void *arg)
{
int ret = __vcpu_ioctl(vm, vcpuid, cmd, arg);
TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret));
}
void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid) void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid)
{ {
struct vcpu *vcpu; struct vcpu *vcpu;
......
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