From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41457CCA47B for ; Fri, 3 Jun 2022 00:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240080AbiFCAof (ORCPT ); Thu, 2 Jun 2022 20:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239960AbiFCAoB (ORCPT ); Thu, 2 Jun 2022 20:44:01 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16987344D8 for ; Thu, 2 Jun 2022 17:43:50 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 84-20020a630057000000b003f9caa5bccfso3047879pga.9 for ; Thu, 02 Jun 2022 17:43:50 -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=nL2B8kY14hSwejw9RxK3Pa8QE1mSuDfrelWBw2aEYGA=; b=D/m73JaC0OEO3d5k9DGtAXjLDms0wLG5WNUOiEPwskP6Uftzig68QJPQ081eeGCOKm vaBZy/CwY3qo9xXUdARuyb9F1wMRwic7D4OCFo1YKGELMyUauKC6KF730oEZlhf1ABaA qw8tgh/F9uIgV730jNtYnjl+SyhEApeGOh02u8E1sjBvp5abr39OUhuGNJqE9VhglML5 HMevj0xIqTd9CUgWlK0LGF1lCMixoNG/YUNFUUVlURLrJrt6Xs6OiL7CDcwDfIVlg7U1 ys1XRlXe0ExarhQ2lQP+/MjbJXeF56vMQY2Vy2TXvMwMKhFp4p8bQL+uF37DBelUy4ks MPYg== 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=nL2B8kY14hSwejw9RxK3Pa8QE1mSuDfrelWBw2aEYGA=; b=AyVHij/nYWrxa9EUJyINGke1knQ55CxPC1yCXABl3lH/rFrZUg9vfc8SVUwP0JUB2Q wBfkCi5fe0hmIJ/2/1YfAXLZAk3mAiuZW39rNVGdb93/srGMMp3Tsnht/DX/WQBUzkMQ BwKYPppkSlw4Oqh1yuMQOsQbdKweyIyeyIrk7z5md3GUeOpmVihEnXKY9HRPToeO9Wwu ZeCJtJWPydzRbwnMfaAeHIwt2CkUV0t0bi/t63Ma1iRSCkTfUFcdN9LkNQZFKVnVaLNl hDnfb3X0uYY1Rp/fwZigWE4KMbC6hq40ABy6Xm5+OcP+jwhG/DcEXHnLG5XH7CJbmO5t TObg== X-Gm-Message-State: AOAM533OVxYG+sWziXrUbIYw7yU6R3j1M7emRB9lbnQiVnRBFkFkn/4a nNPUcQlLl5ZVsdPi9ILyaufc9bmXiHc= X-Google-Smtp-Source: ABdhPJzZeEHnmZWp0xNEa8TRWZbJ84+KIiGHjcsHJYw+FsOMdpDJ2uIL3OaCSRhhD9EsujNUj49DsUP1rr0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:b396:b0:1e4:d7de:ea3d with SMTP id e22-20020a17090ab39600b001e4d7deea3dmr8358835pjr.222.1654217029475; Thu, 02 Jun 2022 17:43:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 3 Jun 2022 00:41:14 +0000 In-Reply-To: <20220603004331.1523888-1-seanjc@google.com> Message-Id: <20220603004331.1523888-8-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 007/144] KVM: selftests: Make vcpu_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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make vcpu_ioctl() a macro wrapper and pretty the _name_ of the ioctl on failure instead of the number. Add inner macros to allow handling cases where the name of the ioctl needs to be resolved higher up the stack, and to allow using the formatting for non-ioctl syscalls without being technically wrong. 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 | 13 ++++++-- tools/testing/selftests/kvm/lib/kvm_util.c | 31 +++++-------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 662579a6358b..00f3103dc85e 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -157,10 +157,19 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, uint64_t guest_paddr, uint32_t slot, uint64_t npages, uint32_t flags); -void vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl, - void *arg); +#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); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 03c1f885a98b..fdcaf74b5959 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1937,29 +1937,6 @@ void vcpu_set_reg(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_one_reg *reg) ret, errno, strerror(errno)); } -/* - * VCPU Ioctl - * - * Input Args: - * vm - Virtual Machine - * vcpuid - VCPU ID - * cmd - Ioctl number - * arg - Argument to pass to the ioctl - * - * Return: None - * - * Issues an arbitrary ioctl on a VCPU fd. - */ -void vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, - unsigned long cmd, void *arg) -{ - int ret; - - ret = __vcpu_ioctl(vm, vcpuid, cmd, arg); - TEST_ASSERT(ret == 0, "vcpu ioctl %lu failed, rc: %i errno: %i (%s)", - cmd, ret, errno, strerror(errno)); -} - int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long cmd, void *arg) { @@ -1973,6 +1950,14 @@ int __vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, return ret; } +void _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long cmd, + const char *name, void *arg) +{ + int ret = __vcpu_ioctl(vm, vcpuid, cmd, arg); + + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); +} + void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid) { struct vcpu *vcpu; -- 2.36.1.255.ge46751e96f-goog