Commit 3ea9b809 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

KVM: selftests: Add kvm_has_cap() to provide syntactic sugar



Add kvm_has_cap() to wrap kvm_check_cap() and return a bool for the use
cases where the caller only wants check if a capability is supported,
i.e. doesn't care about the value beyond whether or not it's non-zero.
The "check" terminology is somewhat ambiguous as the non-boolean return
suggests that '0' might mean "success", i.e. suggests that the ioctl uses
the 0/-errno pattern.  Provide a wrapper instead of trying to find a new
name for the raw helper; the "check" terminology is derived from the name
of the ioctl, so using e.g. "get" isn't a clear win.

Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent d8ba3f14
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -395,7 +395,7 @@ static void check_supported(struct vcpu_config *c)
	struct reg_sublist *s;

	for_each_sublist(c, s) {
		if (s->capability && !kvm_check_cap(s->capability)) {
		if (s->capability && !kvm_has_cap(s->capability)) {
			fprintf(stderr, "%s: %s not available, skipping tests\n", config_name(c), s->name);
			exit(KSFT_SKIP);
		}
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ int main(void)
	struct kvm_vm *vm;
	int ret;

	if (!kvm_check_cap(KVM_CAP_ARM_EL1_32BIT)) {
	if (!kvm_has_cap(KVM_CAP_ARM_EL1_32BIT)) {
		print_skip("KVM_CAP_ARM_EL1_32BIT is not supported");
		exit(KSFT_SKIP);
	}
+2 −2
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ static void sem_wait_until(sem_t *sem)

static bool clear_log_supported(void)
{
	return kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
	return kvm_has_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
}

static void clear_log_create_vm_done(struct kvm_vm *vm)
@@ -264,7 +264,7 @@ static void default_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err)

static bool dirty_ring_supported(void)
{
	return kvm_check_cap(KVM_CAP_DIRTY_LOG_RING);
	return kvm_has_cap(KVM_CAP_DIRTY_LOG_RING);
}

static void dirty_ring_create_vm_done(struct kvm_vm *vm)
+5 −0
Original line number Diff line number Diff line
@@ -169,6 +169,11 @@ int open_path_or_exit(const char *path, int flags);
int open_kvm_dev_path_or_exit(void);
unsigned int kvm_check_cap(long cap);

static inline bool kvm_has_cap(long cap)
{
	return kvm_check_cap(cap);
}

#define __KVM_SYSCALL_ERROR(_name, _ret) \
	"%s failed, rc: %i errno: %i (%s)", (_name), (_ret), errno, strerror(errno)

+1 −1
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ int main(int argc, char *argv[])
	}

	/* Check the extension for binary stats */
	if (!kvm_check_cap(KVM_CAP_BINARY_STATS_FD)) {
	if (!kvm_has_cap(KVM_CAP_BINARY_STATS_FD)) {
		print_skip("Binary form statistics interface is not supported");
		exit(KSFT_SKIP);
	}
Loading