Skip to content

Commit 6542a00

Browse files
committed
KVM: selftests: Drop the single-underscore ioctl() helpers
Drop _kvm_ioctl(), _vm_ioctl(), and _vcpu_ioctl(), as they are no longer used by anything other than the no-underscores variants (and may have never been used directly). The single-underscore variants were never intended to be a "feature", they were a stopgap of sorts to ease the conversion to pretty printing ioctl() names when reporting errors. Opportunistically add a comment explaining when to use __KVM_IOCTL_ERROR() versus KVM_IOCTL_ERROR(). The single-underscore macros were subtly ensuring that the name of the ioctl() was printed on error, i.e. it's all too easy to overlook the fact that using __KVM_IOCTL_ERROR() is intentional. Link: https://lore.kernel.org/r/20231108010953.560824-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent fc6543b commit 6542a00

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

tools/testing/selftests/kvm/include/kvm_util_base.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ static inline bool kvm_has_cap(long cap)
267267
#define __KVM_SYSCALL_ERROR(_name, _ret) \
268268
"%s failed, rc: %i errno: %i (%s)", (_name), (_ret), errno, strerror(errno)
269269

270+
/*
271+
* Use the "inner", double-underscore macro when reporting errors from within
272+
* other macros so that the name of ioctl() and not its literal numeric value
273+
* is printed on error. The "outer" macro is strongly preferred when reporting
274+
* errors "directly", i.e. without an additional layer of macros, as it reduces
275+
* the probability of passing in the wrong string.
276+
*/
270277
#define __KVM_IOCTL_ERROR(_name, _ret) __KVM_SYSCALL_ERROR(_name, _ret)
271278
#define KVM_IOCTL_ERROR(_ioctl, _ret) __KVM_IOCTL_ERROR(#_ioctl, _ret)
272279

@@ -279,17 +286,13 @@ static inline bool kvm_has_cap(long cap)
279286
#define __kvm_ioctl(kvm_fd, cmd, arg) \
280287
kvm_do_ioctl(kvm_fd, cmd, arg)
281288

282-
283-
#define _kvm_ioctl(kvm_fd, cmd, name, arg) \
289+
#define kvm_ioctl(kvm_fd, cmd, arg) \
284290
({ \
285291
int ret = __kvm_ioctl(kvm_fd, cmd, arg); \
286292
\
287-
TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
293+
TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(#cmd, ret)); \
288294
})
289295

290-
#define kvm_ioctl(kvm_fd, cmd, arg) \
291-
_kvm_ioctl(kvm_fd, cmd, #cmd, arg)
292-
293296
static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { }
294297

295298
#define __vm_ioctl(vm, cmd, arg) \
@@ -298,17 +301,13 @@ static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { }
298301
kvm_do_ioctl((vm)->fd, cmd, arg); \
299302
})
300303

301-
#define _vm_ioctl(vm, cmd, name, arg) \
304+
#define vm_ioctl(vm, cmd, arg) \
302305
({ \
303306
int ret = __vm_ioctl(vm, cmd, arg); \
304307
\
305-
TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
308+
TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(#cmd, ret)); \
306309
})
307310

308-
#define vm_ioctl(vm, cmd, arg) \
309-
_vm_ioctl(vm, cmd, #cmd, arg)
310-
311-
312311
static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { }
313312

314313
#define __vcpu_ioctl(vcpu, cmd, arg) \
@@ -317,16 +316,13 @@ static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { }
317316
kvm_do_ioctl((vcpu)->fd, cmd, arg); \
318317
})
319318

320-
#define _vcpu_ioctl(vcpu, cmd, name, arg) \
319+
#define vcpu_ioctl(vcpu, cmd, arg) \
321320
({ \
322321
int ret = __vcpu_ioctl(vcpu, cmd, arg); \
323322
\
324-
TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \
323+
TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(#cmd, ret)); \
325324
})
326325

327-
#define vcpu_ioctl(vcpu, cmd, arg) \
328-
_vcpu_ioctl(vcpu, cmd, #cmd, arg)
329-
330326
/*
331327
* Looks up and returns the value corresponding to the capability
332328
* (KVM_CAP_*) given by cap.

0 commit comments

Comments
 (0)