Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
3ea9b809 d8ba3f14

+29 -24
+1 -1
tools/testing/selftests/kvm/aarch64/get-reg-list.c
··· 395 395 struct reg_sublist *s; 396 396 397 397 for_each_sublist(c, s) { 398 - if (s->capability && !kvm_check_cap(s->capability)) { 398 + if (s->capability && !kvm_has_cap(s->capability)) { 399 399 fprintf(stderr, "%s: %s not available, skipping tests\n", config_name(c), s->name); 400 400 exit(KSFT_SKIP); 401 401 }
+1 -1
tools/testing/selftests/kvm/aarch64/vcpu_width_config.c
··· 82 82 struct kvm_vm *vm; 83 83 int ret; 84 84 85 - if (!kvm_check_cap(KVM_CAP_ARM_EL1_32BIT)) { 85 + if (!kvm_has_cap(KVM_CAP_ARM_EL1_32BIT)) { 86 86 print_skip("KVM_CAP_ARM_EL1_32BIT is not supported"); 87 87 exit(KSFT_SKIP); 88 88 }
+2 -2
tools/testing/selftests/kvm/dirty_log_test.c
··· 210 210 211 211 static bool clear_log_supported(void) 212 212 { 213 - return kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); 213 + return kvm_has_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); 214 214 } 215 215 216 216 static void clear_log_create_vm_done(struct kvm_vm *vm) ··· 264 264 265 265 static bool dirty_ring_supported(void) 266 266 { 267 - return kvm_check_cap(KVM_CAP_DIRTY_LOG_RING); 267 + return kvm_has_cap(KVM_CAP_DIRTY_LOG_RING); 268 268 } 269 269 270 270 static void dirty_ring_create_vm_done(struct kvm_vm *vm)
+5
tools/testing/selftests/kvm/include/kvm_util_base.h
··· 169 169 int open_kvm_dev_path_or_exit(void); 170 170 unsigned int kvm_check_cap(long cap); 171 171 172 + static inline bool kvm_has_cap(long cap) 173 + { 174 + return kvm_check_cap(cap); 175 + } 176 + 172 177 #define __KVM_SYSCALL_ERROR(_name, _ret) \ 173 178 "%s failed, rc: %i errno: %i (%s)", (_name), (_ret), errno, strerror(errno) 174 179
+1 -1
tools/testing/selftests/kvm/kvm_binary_stats_test.c
··· 213 213 } 214 214 215 215 /* Check the extension for binary stats */ 216 - if (!kvm_check_cap(KVM_CAP_BINARY_STATS_FD)) { 216 + if (!kvm_has_cap(KVM_CAP_BINARY_STATS_FD)) { 217 217 print_skip("Binary form statistics interface is not supported"); 218 218 exit(KSFT_SKIP); 219 219 }
+2 -2
tools/testing/selftests/kvm/lib/kvm_util.c
··· 80 80 81 81 close(kvm_fd); 82 82 83 - return ret; 83 + return (unsigned int)ret; 84 84 } 85 85 86 86 void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size) ··· 93 93 { 94 94 vm->kvm_fd = _open_kvm_dev_path_or_exit(O_RDWR); 95 95 96 - if (!kvm_check_cap(KVM_CAP_IMMEDIATE_EXIT)) { 96 + if (!kvm_has_cap(KVM_CAP_IMMEDIATE_EXIT)) { 97 97 print_skip("immediate_exit not available"); 98 98 exit(KSFT_SKIP); 99 99 }
+1 -1
tools/testing/selftests/kvm/lib/s390x/diag318_test_handler.c
··· 61 61 * If KVM does not support diag318, then return 0 to 62 62 * ensure tests do not break. 63 63 */ 64 - if (!kvm_check_cap(KVM_CAP_S390_DIAG318)) { 64 + if (!kvm_has_cap(KVM_CAP_S390_DIAG318)) { 65 65 if (!printed_skip) { 66 66 fprintf(stdout, "KVM_CAP_S390_DIAG318 not supported. " 67 67 "Skipping diag318 test.\n");
+1 -1
tools/testing/selftests/kvm/x86_64/debug_regs.c
··· 95 95 1, /* cli */ 96 96 }; 97 97 98 - if (!kvm_check_cap(KVM_CAP_SET_GUEST_DEBUG)) { 98 + if (!kvm_has_cap(KVM_CAP_SET_GUEST_DEBUG)) { 99 99 print_skip("KVM_CAP_SET_GUEST_DEBUG not supported"); 100 100 return 0; 101 101 }
+1 -1
tools/testing/selftests/kvm/x86_64/emulator_error_test.c
··· 162 162 /* Tell stdout not to buffer its content */ 163 163 setbuf(stdout, NULL); 164 164 165 - if (!kvm_check_cap(KVM_CAP_SMALLER_MAXPHYADDR)) { 165 + if (!kvm_has_cap(KVM_CAP_SMALLER_MAXPHYADDR)) { 166 166 printf("module parameter 'allow_smaller_maxphyaddr' is not set. Skipping test.\n"); 167 167 return 0; 168 168 }
+2 -2
tools/testing/selftests/kvm/x86_64/evmcs_test.c
··· 209 209 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 210 210 211 211 if (!nested_vmx_supported() || 212 - !kvm_check_cap(KVM_CAP_NESTED_STATE) || 213 - !kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { 212 + !kvm_has_cap(KVM_CAP_NESTED_STATE) || 213 + !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { 214 214 print_skip("Enlightened VMCS is unsupported"); 215 215 exit(KSFT_SKIP); 216 216 }
+3 -3
tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
··· 137 137 /* Tell stdout not to buffer its content */ 138 138 setbuf(stdout, NULL); 139 139 140 - if (!kvm_check_cap(KVM_CAP_HYPERV_CPUID)) { 140 + if (!kvm_has_cap(KVM_CAP_HYPERV_CPUID)) { 141 141 print_skip("KVM_CAP_HYPERV_CPUID not supported"); 142 142 exit(KSFT_SKIP); 143 143 } ··· 152 152 free(hv_cpuid_entries); 153 153 154 154 if (!nested_vmx_supported() || 155 - !kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { 155 + !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { 156 156 print_skip("Enlightened VMCS is unsupported"); 157 157 goto do_sys; 158 158 } ··· 163 163 164 164 do_sys: 165 165 /* Test system ioctl version */ 166 - if (!kvm_check_cap(KVM_CAP_SYS_HYPERV_CPUID)) { 166 + if (!kvm_has_cap(KVM_CAP_SYS_HYPERV_CPUID)) { 167 167 print_skip("KVM_CAP_SYS_HYPERV_CPUID not supported"); 168 168 goto out; 169 169 }
+1 -1
tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
··· 204 204 struct kvm_vcpu *vcpu; 205 205 struct kvm_vm *vm; 206 206 207 - if (!kvm_check_cap(KVM_CAP_ENFORCE_PV_FEATURE_CPUID)) { 207 + if (!kvm_has_cap(KVM_CAP_ENFORCE_PV_FEATURE_CPUID)) { 208 208 print_skip("KVM_CAP_ENFORCE_PV_FEATURE_CPUID not supported"); 209 209 exit(KSFT_SKIP); 210 210 }
+1 -1
tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
··· 123 123 124 124 int main(int argc, char *argv[]) 125 125 { 126 - if (!kvm_check_cap(KVM_CAP_SET_BOOT_CPU_ID)) { 126 + if (!kvm_has_cap(KVM_CAP_SET_BOOT_CPU_ID)) { 127 127 print_skip("set_boot_cpu_id not available"); 128 128 return 0; 129 129 }
+2 -2
tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
··· 400 400 { 401 401 struct kvm_cpuid_entry2 *cpuid; 402 402 403 - if (!kvm_check_cap(KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM) && 404 - !kvm_check_cap(KVM_CAP_VM_COPY_ENC_CONTEXT_FROM)) { 403 + if (!kvm_has_cap(KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM) && 404 + !kvm_has_cap(KVM_CAP_VM_COPY_ENC_CONTEXT_FROM)) { 405 405 print_skip("Capabilities not available"); 406 406 exit(KSFT_SKIP); 407 407 }
+1 -1
tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c
··· 51 51 exit(KSFT_SKIP); 52 52 } 53 53 54 - if (!kvm_check_cap(KVM_CAP_X86_TRIPLE_FAULT_EVENT)) { 54 + if (!kvm_has_cap(KVM_CAP_X86_TRIPLE_FAULT_EVENT)) { 55 55 print_skip("KVM_CAP_X86_TRIPLE_FAULT_EVENT not supported"); 56 56 exit(KSFT_SKIP); 57 57 }
+1 -1
tools/testing/selftests/kvm/x86_64/tsc_scaling_sync.c
··· 93 93 94 94 int main(int argc, char *argv[]) 95 95 { 96 - if (!kvm_check_cap(KVM_CAP_VM_TSC_CONTROL)) { 96 + if (!kvm_has_cap(KVM_CAP_VM_TSC_CONTROL)) { 97 97 print_skip("KVM_CAP_VM_TSC_CONTROL not available"); 98 98 exit(KSFT_SKIP); 99 99 }
+1 -1
tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
··· 118 118 119 119 static void tsc_scaling_check_supported(void) 120 120 { 121 - if (!kvm_check_cap(KVM_CAP_TSC_CONTROL)) { 121 + if (!kvm_has_cap(KVM_CAP_TSC_CONTROL)) { 122 122 print_skip("TSC scaling not supported by the HW"); 123 123 exit(KSFT_SKIP); 124 124 }
+1 -1
tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c
··· 169 169 */ 170 170 nested_vmx_check_supported(); 171 171 172 - if (!kvm_check_cap(KVM_CAP_NESTED_STATE)) { 172 + if (!kvm_has_cap(KVM_CAP_NESTED_STATE)) { 173 173 print_skip("KVM_CAP_NESTED_STATE not supported"); 174 174 exit(KSFT_SKIP); 175 175 }
+1 -1
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c
··· 267 267 268 268 have_evmcs = kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS); 269 269 270 - if (!kvm_check_cap(KVM_CAP_NESTED_STATE)) { 270 + if (!kvm_has_cap(KVM_CAP_NESTED_STATE)) { 271 271 print_skip("KVM_CAP_NESTED_STATE not available"); 272 272 exit(KSFT_SKIP); 273 273 }