From patchwork Fri Aug 4 00:42:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13341034 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE3B9C00528 for ; Fri, 4 Aug 2023 00:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SZyOfFJA3de2Sl54Fh9cwPvI2oSB1X53PJziIWZgYMY=; b=Px50gZU06hWuKH xd4PpD2nGwCtprI/5e0IzpztSPhkBB80JTJQvZQlFDuhnyCSxFnKAr9pn8vKWFNJKS4KAMHuSP6nZ TQ/+OJwjzgLPLgF3O98Mj/o9veDslen9lOEPprII4CzH2NyCzotsQkf9NQ8DfWDO2iG6q1Mm0M8zo eWZeK6iQl+QfpnCLwRtAPI1lvpcKw1cbOLH6+ELMu95FxM81zqDVwb42wVKQtP4Aa+G00jckLCURM owfulnow2WRMUmDjnkL7VHGKM+BD5LGvSxKMbY2+Vfe5cyDqZCYPN5hFhH07yjoc4kn1j9weDnzJs UjaXkpOSPF6BdwZBaekQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRitn-00BBQj-2v; Fri, 04 Aug 2023 00:42:35 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRitk-00BBQ5-1M for linux-arm-kernel@lists.infradead.org; Fri, 04 Aug 2023 00:42:33 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1bba7a32a40so12217395ad.0 for ; Thu, 03 Aug 2023 17:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691109750; x=1691714550; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=TPdXiND7N94yuFEwSbECpKkQfmAanLh9RZ+A6BrvR7M=; b=2tZIajDGiYM8LOP6oRS7sIm2pcBnaXfZ7Wymplbdn69KUU8q53NcZ7y0HFK8pN3rJv XsgnlEdOHLu6ZqLedVwaja+dve26SOtilLHroxOKcn1gMKyUuqCKj30/Z97mg+qQ0A5R 3Ikj3Cg1e6W0kaLu9miTZWiHb9zsHokxrA3qv+mc/lCMvO6k2YOsSQj0EFs1erqLxsGU 3tJpi1uPKeG7pLmg5VlnYlIpw8x0qWFmi2sg4OydjUAuuqTERt756yyvc0gyoig//M6H 5fTKOOVxD2iGkXDjRyyWPE5G1u+8j6kSj/3rqzdeuj9Xdr5V2hQG6q1B7q16VMnrsqdk zf2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691109750; x=1691714550; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TPdXiND7N94yuFEwSbECpKkQfmAanLh9RZ+A6BrvR7M=; b=F7xfNgSxKbsFui9Hkt7tVhdoYZKrIkLTeZb8W5MlVHfLMAhwJklnMU9t8gULIPbt2o hfd8/aLWx37p21r4xd/aepiD7sYrx2mP4RWBmiFiaIGa74g+Y1jWp6sY/nXbrNXb9x4Q p3ifHEWxAZcTMz/u0ALup9Fv8AhrYeEEfLlOl+GwTXnocjL0QkQHk/DNqNga7xhG7pOt NojNXIRKBG9fxtH1GIwKfiAPMvpHf8xCaRg4jDy8WQSQeSB9MWRkK+eRfkMrSum8syH8 sn5iq3bZNppQhKFAUhbPpM59e3zenj/E38+U5tpMoVR/C+8liCQzgYCzOw3zL+8WUl0Z HQIw== X-Gm-Message-State: AOJu0Ywb9o48yP6D/5100WjlNEtqD95vXGbDU/aekXXdG8RANDECMpgb OrkPd7c1P8q7jsjmkgm+qT5vrmMA7CY= X-Google-Smtp-Source: AGHT+IGxPWjxkWB9Y/JG84vlZ7jPt3zPsnr0k+1ejtlvOppoogL05sX+e7/sQkS50kBaur8MYBj5ozDKMXE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:32d2:b0:1b8:5541:9d4d with SMTP id i18-20020a17090332d200b001b855419d4dmr1307plr.6.1691109750368; Thu, 03 Aug 2023 17:42:30 -0700 (PDT) Date: Thu, 3 Aug 2023 17:42:23 -0700 In-Reply-To: <20230804004226.1984505-1-seanjc@google.com> Mime-Version: 1.0 References: <20230804004226.1984505-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.585.gd2178a4bd4-goog Message-ID: <20230804004226.1984505-2-seanjc@google.com> Subject: [PATCH 1/4] KVM: selftests: Drop the single-underscore ioctl() helpers From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , Michal Luczaj X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230803_174232_480385_20CC6968 X-CRM114-Status: GOOD ( 13.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 07732a157ccd..90b7739ca204 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -227,6 +227,13 @@ static inline bool kvm_has_cap(long cap) #define __KVM_SYSCALL_ERROR(_name, _ret) \ "%s failed, rc: %i errno: %i (%s)", (_name), (_ret), errno, strerror(errno) +/* + * Use the "inner", double-underscore macro when reporting errors from within + * other macros so that the name of ioctl() and not its literal numeric value + * is printed on error. The "outer" macro is strongly preferred when reporting + * errors "directly", i.e. without an additional layer of macros, as it reduces + * the probability of passing in the wrong string. + */ #define __KVM_IOCTL_ERROR(_name, _ret) __KVM_SYSCALL_ERROR(_name, _ret) #define KVM_IOCTL_ERROR(_ioctl, _ret) __KVM_IOCTL_ERROR(#_ioctl, _ret) @@ -239,17 +246,13 @@ static inline bool kvm_has_cap(long cap) #define __kvm_ioctl(kvm_fd, cmd, arg) \ kvm_do_ioctl(kvm_fd, cmd, arg) - -#define _kvm_ioctl(kvm_fd, cmd, name, arg) \ +#define kvm_ioctl(kvm_fd, cmd, arg) \ ({ \ int ret = __kvm_ioctl(kvm_fd, cmd, arg); \ \ - TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(#cmd, ret)); \ }) -#define kvm_ioctl(kvm_fd, cmd, arg) \ - _kvm_ioctl(kvm_fd, cmd, #cmd, arg) - static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { } #define __vm_ioctl(vm, cmd, arg) \ @@ -258,16 +261,12 @@ static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { } kvm_do_ioctl((vm)->fd, cmd, arg); \ }) -#define _vm_ioctl(vm, cmd, name, arg) \ -({ \ - int ret = __vm_ioctl(vm, cmd, arg); \ - \ - TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ -}) - #define vm_ioctl(vm, cmd, arg) \ - _vm_ioctl(vm, cmd, #cmd, arg) - +({ \ + int ret = __vm_ioctl(vm, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(#cmd, ret)); \ +}) static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { } @@ -277,15 +276,12 @@ static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { } kvm_do_ioctl((vcpu)->fd, cmd, arg); \ }) -#define _vcpu_ioctl(vcpu, cmd, name, arg) \ -({ \ - int ret = __vcpu_ioctl(vcpu, cmd, arg); \ - \ - TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ -}) - #define vcpu_ioctl(vcpu, cmd, arg) \ - _vcpu_ioctl(vcpu, cmd, #cmd, arg) +({ \ + int ret = __vcpu_ioctl(vcpu, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(#cmd, ret)); \ +}) /* * Looks up and returns the value corresponding to the capability