Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp132461iof; Sun, 5 Jun 2022 23:19:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+lHzL+7B9TmEcAfwPDFbI4qtXPk2MpBCi7BaA0dnfJ3HstTWRaIi+Rnk5VXfGWE1LOZaB X-Received: by 2002:a17:90b:c85:b0:1e2:e645:a8c9 with SMTP id o5-20020a17090b0c8500b001e2e645a8c9mr24605421pjz.185.1654496371491; Sun, 05 Jun 2022 23:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654496371; cv=none; d=google.com; s=arc-20160816; b=eagd3ce6p+p8dQycQiMjfKkcu3FeS31Wp46iO25RsvCLEUgIIVKsCMRTAMpZ0brOCh rtVGByO4+odN9p1TSGrrpXNyVoS+n+4PCZSC+aotA1cpimhciXr6z/71CY7+t/G2X0jL xRal+wLsPD4jOHA4KT4RGsreGpfpfJZPdOPd425cYjqe8/I2amxVrCDyVP9C3BXU1F3L ErUDRLQgWc08lCGcgTPQyo6NQBXq2+xjALEB31uxE54fG4ITNILL+Tk6luxtF1wW8Q1i MhDn7+Re0b6arIsjhPqhiHdYtg+j5fNc3ZOE5OZIdqHFTf+cWpqtXGPBIEnVJilr2hzd AhQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=36XEOpYEohNCR+Q01vTzoi5csXjLmHgWiPTQjP0f6so=; b=zFYabUDwgi++aCzD4TSzfaW/07Cro/bT+4E/tONezB5NHRBRxdC2grSoAr8gIlDCLw ZFI9QlC3HDvv0rZXlENPf+AgSJaZ5IHJkacdl2j+DKE0Avvotmx75clkj+HfhuK+GB44 E3VX7C+oTfaFZAiNLZpIkif62FWs/2rC68HUu/yhbi8DsLQXNr2UPEfbeyD1rP5gqoeD DUiT8I3Ot/nQyFtLi+sARsCVs76HqSX/QnEE3tgizoN8smkrZwvEpdH/7GSc4Yww50tT LijkQ41Awl21leYkHzni/virbHFsF0yy4DpLafPeFPhji0p+XHOorB+ZQpDC9MJEhJTW 9x+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DPkxiw2U; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b4-20020a63eb44000000b003f5d31f8e36si19107477pgk.672.2022.06.05.23.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 23:19:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DPkxiw2U; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 124581078AC; Sun, 5 Jun 2022 21:58:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240472AbiFCAr2 (ORCPT + 99 others); Thu, 2 Jun 2022 20:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240013AbiFCAoE (ORCPT ); Thu, 2 Jun 2022 20:44:04 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB7642250E for ; Thu, 2 Jun 2022 17:44:03 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id u1-20020a17090a2b8100b001d9325a862fso3516868pjd.6 for ; Thu, 02 Jun 2022 17:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=36XEOpYEohNCR+Q01vTzoi5csXjLmHgWiPTQjP0f6so=; b=DPkxiw2UxFi8eI9M47WQApqgocwHJV3aKzzdUq70auJn5gJ2hNpfwD46/NLb0EpB++ lRbsjiWihAy9Iw+Ij5xFss7Zpy6qqf5HuIdHL4jg6YE6ipxBRe5iCKK0DmniMFY7a+6i eNGT2D7WbjM98RplHYgTuPU93X1F5K02mJojLc4hmWULxIpMGollFkG90litawmtIU9U iC0+YN60QmQap5LyZSmjItpYZFJJ9oIAfLqQw/bvhf0ppZW/GOxls5xS8wMTcq361Khf LAFBw4FqIEmHmOgXjWli9hbXdLOhSEM+6RMdduLnIyId6p1Ut2rURktkTNyPAabWM1Vi Xw4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=36XEOpYEohNCR+Q01vTzoi5csXjLmHgWiPTQjP0f6so=; b=YvE8g0xMM08n6UiJJNxodZ2zCJyXmPMrHVXqHxVR2kfHAhy1AXfih6Ogp1BqBaPXhE Ek7ZzXpG/Cwaws2tz/8V23pOVckpZ0WNnubd8m2uXENcPJ1AtPoAnUacSqKkrBpioMh4 5SD8trINp7+1e9bmoPQ4qTcGWd0XmpZsYhnhkDIPSA0Ufzql7CV+uohu9uRtlDsvATT9 487YlGBEilfe6fbycJf9xlUSZ9NdFkkRdZFO8IR0/HSmdPB7BBKw4rL8PhmfXz0BDLAI TLpGPwWEPCxY0Qb6Fbl1+5J5XZK+mMKx/BkbWRMPwElJtvdKa5kKfkxFnm4Lg/tqFQQ+ fuqg== X-Gm-Message-State: AOAM531K0E2QQRnruPsVOvaCyTiTTrvzM2INrX4oTEQlhh7qeIFqcNGT P/hR1ves2R8oKNAD5iJ3fsSK7GCo1nE= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:9a2:b0:505:974f:9fd6 with SMTP id u34-20020a056a0009a200b00505974f9fd6mr7734316pfg.12.1654217043072; Thu, 02 Jun 2022 17:44:03 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 3 Jun 2022 00:41:22 +0000 In-Reply-To: <20220603004331.1523888-1-seanjc@google.com> Message-Id: <20220603004331.1523888-16-seanjc@google.com> Mime-Version: 1.0 References: <20220603004331.1523888-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v2 015/144] KVM: selftests: Make vm_ioctl() a wrapper to pretty print ioctl name From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , Andrew Jones , David Matlack , Ben Gardon , Oliver Upton , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make vm_ioctl() a macro wrapper and print the _name_ of the ioctl on failure instead of the number. 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 --- .../selftests/kvm/include/kvm_util_base.h | 38 ++++++++++--------- tools/testing/selftests/kvm/lib/kvm_util.c | 28 ++++---------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index c2dfc4341b31..39e1971e5d65 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -105,6 +105,27 @@ int open_kvm_dev_path_or_exit(void); int kvm_check_cap(long cap); int vm_check_cap(struct kvm_vm *vm, long cap); int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap); + +#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) + +int __kvm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg); +void kvm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg); + +int __vm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg); +void _vm_ioctl(struct kvm_vm *vm, unsigned long cmd, const char *name, void *arg); +#define vm_ioctl(vm, cmd, arg) _vm_ioctl(vm, cmd, #cmd, arg) + +int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long cmd, + void *arg); +void _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long cmd, + const char *name, void *arg); +#define vcpu_ioctl(vm, vcpuid, cmd, arg) \ + _vcpu_ioctl(vm, vcpuid, cmd, #cmd, arg) + void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size); const char *vm_guest_mode_string(uint32_t i); @@ -156,23 +177,6 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, uint64_t guest_paddr, uint32_t slot, uint64_t npages, uint32_t flags); -#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); -int __kvm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg); void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags); void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa); void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 940decfaa633..7eedd9ff20fa 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1690,32 +1690,18 @@ void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid) return vcpu->dirty_gfns; } -/* - * VM Ioctl - * - * Input Args: - * vm - Virtual Machine - * cmd - Ioctl number - * arg - Argument to pass to the ioctl - * - * Return: None - * - * Issues an arbitrary ioctl on a VM fd. - */ -void vm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg) -{ - int ret; - - ret = __vm_ioctl(vm, cmd, arg); - TEST_ASSERT(ret == 0, "vm ioctl %lu failed, rc: %i errno: %i (%s)", - cmd, ret, errno, strerror(errno)); -} - int __vm_ioctl(struct kvm_vm *vm, unsigned long cmd, void *arg) { return ioctl(vm->fd, cmd, arg); } +void _vm_ioctl(struct kvm_vm *vm, unsigned long cmd, const char *name, void *arg) +{ + int ret = __vm_ioctl(vm, cmd, arg); + + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); +} + /* * KVM system ioctl * -- 2.36.1.255.ge46751e96f-goog