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: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Sean Christopherson 2022-02-15 10:15:00 -08:00 committed by Paolo Bonzini
parent 2b38a7398f
commit 02e04c15ca
2 changed files with 19 additions and 25 deletions

View File

@ -157,10 +157,19 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
uint64_t guest_paddr, uint32_t slot, uint64_t npages,
uint32_t flags);
void vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl,
void *arg);
#define __KVM_SYSCALL_ERROR(_name, _ret) \
"%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,
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);
int __vm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg);
void kvm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);

View File

@ -1937,29 +1937,6 @@ void vcpu_set_reg(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_one_reg *reg)
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,
unsigned long cmd, void *arg)
{
@ -1973,6 +1950,14 @@ int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid,
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)
{
struct vcpu *vcpu;