forked from Minki/linux
selftests: KVM: Add helpers for vCPU device attributes
vCPU file descriptors are abstracted away from test code in KVM selftests, meaning that tests cannot directly access a vCPU's device attributes. Add helpers that tests can use to get at vCPU device attributes. Reviewed-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Oliver Upton <oupton@google.com> Message-Id: <20210916181555.973085-5-oupton@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
c1901feef5
commit
c895513453
@ -240,6 +240,15 @@ int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
|
||||
int kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
|
||||
void *val, bool write);
|
||||
|
||||
int _vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr);
|
||||
int vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr);
|
||||
int _vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr, void *val, bool write);
|
||||
int vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr, void *val, bool write);
|
||||
|
||||
const char *exit_reason_str(unsigned int exit_reason);
|
||||
|
||||
void virt_pgd_alloc(struct kvm_vm *vm);
|
||||
|
@ -2040,6 +2040,44 @@ int kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr)
|
||||
{
|
||||
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
|
||||
|
||||
TEST_ASSERT(vcpu, "nonexistent vcpu id: %d", vcpuid);
|
||||
|
||||
return _kvm_device_check_attr(vcpu->fd, group, attr);
|
||||
}
|
||||
|
||||
int vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr)
|
||||
{
|
||||
int ret = _vcpu_has_device_attr(vm, vcpuid, group, attr);
|
||||
|
||||
TEST_ASSERT(!ret, "KVM_HAS_DEVICE_ATTR IOCTL failed, rc: %i errno: %i", ret, errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr, void *val, bool write)
|
||||
{
|
||||
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
|
||||
|
||||
TEST_ASSERT(vcpu, "nonexistent vcpu id: %d", vcpuid);
|
||||
|
||||
return _kvm_device_access(vcpu->fd, group, attr, val, write);
|
||||
}
|
||||
|
||||
int vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group,
|
||||
uint64_t attr, void *val, bool write)
|
||||
{
|
||||
int ret = _vcpu_access_device_attr(vm, vcpuid, group, attr, val, write);
|
||||
|
||||
TEST_ASSERT(!ret, "KVM_SET|GET_DEVICE_ATTR IOCTL failed, rc: %i errno: %i", ret, errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* VM Dump
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user