Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp753947iog; Mon, 13 Jun 2022 12:11:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tOuwGQM6aeb2atP9OvV6RnaUdK6Y/pBXW0pFX5aeQHpKCDW7+4Vp2SE5wDphyF7+X2kwzq X-Received: by 2002:a17:90a:86c8:b0:1e3:52ee:953d with SMTP id y8-20020a17090a86c800b001e352ee953dmr198746pjv.171.1655147484413; Mon, 13 Jun 2022 12:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655147484; cv=none; d=google.com; s=arc-20160816; b=ACFCQX2DrtC6eGmuAgAAXq3KvAEBXMjyZxehNasPtMW+BEVwU+Tagh+OF6B7qhe13c ghzxkpte18d83QeknMVfN+Xf+5DQcVa0ax/L5f28Zrs6UrDM3Muydhicxj5QmCSjLxkh 8aFHtLNXRXcqIduev3Q5FYICBilJhMTagJZxbDWhUQSCCdH3tm1atqW4UDcBAmqDM0Ea veGrChXx5S+19XjqCwRD6/ntxlKUV1fBUH3Hlsf6NyL6FMndfNX4raVpi+eecRIYxpVe S+saCe9c4B8ejsVdS9IwqL/FoHM5i6o8NvUa9Mfc9q8tIk6eJH6E1T3QagLdraYKTXxf QvaQ== 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=WzGiy8MvhiIUMi0s+wtsSIHmWc5cSwuMnyGQLZRW9iE=; b=W/Kq3A4LwUnyLWhCsON545kUQE0ICRuV7LStgxK1bBQQ+XaTxC0rqEz/RdcZ8hOHVo pzFcVaNcLHMAysO+RGPlQYwI9MOuYSxImA7cmiM3xHUXmyUloKWS+uGGU8hOhkgbZFCk AYhohs/dhbLR7XOYnDBwKbP/ktuwtqRF01fzLjNY3N0hYPaudWULkCwCDb3NhBQglsgA yugH3sVPvhtxZc9lcLinNVkMwWtk9huHW8yy1sIBoUG8qlZfKJmNOeWnIsOHuuaTEVQ2 QQcm/UquPl3nZsWsixZQmL0T/+3iDRBnVyAd+oFBoPhxHRrZAX++uLyrbHkzW7mYrTvH jjWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TmRZ8aVm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo14-20020a17090b1c8e00b001e28e2f497fsi12451437pjb.161.2022.06.13.12.11.12; Mon, 13 Jun 2022 12:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TmRZ8aVm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346727AbiFMTBA (ORCPT + 99 others); Mon, 13 Jun 2022 15:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346266AbiFMTAV (ORCPT ); Mon, 13 Jun 2022 15:00:21 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43A539969A for ; Mon, 13 Jun 2022 09:19:49 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id x19-20020aa78f13000000b0051bdda60a06so2547734pfr.2 for ; Mon, 13 Jun 2022 09:19:49 -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=WzGiy8MvhiIUMi0s+wtsSIHmWc5cSwuMnyGQLZRW9iE=; b=TmRZ8aVm8k7OvscC44C/b2jeDc4I79KMJqDidpu3fidjaRCDoHLjhsWb/Vr5AiMZTf cYPhbxDt12l+cE3KFcvcEa5obW/XZsdbPKAx+2BliPFQIyKy0DePwMuknXTWQMVRf6Ed QJw6IZfHxdVp+FEa2WnNHrxENVPpEzIH9VjXFoZZf+wPZH221AWWvXkvQv4YHeG+Ek44 bV8JTq23EsoRQyFSXipy4q7+fnGnu62yHj3vPpOCKUxgyJ8th5exzKEnDGvmoDc5arLu JXgJLz6cmOKwTiyYPTkjsG80WWC99rp/aWetKZjQ6LK9KpqGhuP0AWxY6XgkEMzTYIWA Onlg== 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=WzGiy8MvhiIUMi0s+wtsSIHmWc5cSwuMnyGQLZRW9iE=; b=mG0Yl5ry13ENxrafmaIzH+GDEdcivtJONjgbkiHTvCzdvSAa52yNTWPYepbLSAneY7 q2BBhPWEjg5oCPDUkVoyB7lBUv6CZUozoy4UfvC8iaNHZg7gCWCy0EXgdHRLAwqvyyo1 ReZn4xFfMUkGM+qhGjccrrIrduc9TZG8Xz99IVmIHNesNsI6cCMlXxg/kLvilhYlRt0V iKOK/nb8y3CRrwQjmY29G2IW6K0fE0OZlWR0YwwYcaGi+RLVskmWjLfBqbZNIkR9hQnv 2uf3L79CcJbKMfLtEPtzDgIx+MDzNLzlQyZpLb7v0SRbSY4h3IgfmQGCZ+UmP3SuOXl+ EW1g== X-Gm-Message-State: AJIora83Ko79LTOfF0OpEVVxzZyn72kBye38WzsovtIfLmZL7eveB4fV wNWnm5eMq/iyth5ECXRc6XOGwnTlZDg= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:d551:b0:168:93b6:a94a with SMTP id z17-20020a170902d55100b0016893b6a94amr77699plf.149.1655137188739; Mon, 13 Jun 2022 09:19:48 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 13 Jun 2022 16:19:40 +0000 In-Reply-To: <20220613161942.1586791-1-seanjc@google.com> Message-Id: <20220613161942.1586791-3-seanjc@google.com> Mime-Version: 1.0 References: <20220613161942.1586791-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH 2/4] KVM: selftests: Call a dummy helper in VM/vCPU ioctls() to enforce type From: Sean Christopherson To: Paolo Bonzini Cc: Andrew Jones , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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 Replace the goofy static_assert on the size of the @vm/@vcpu parameters with a call to a dummy helper, i.e. let the compiler naturally complain about an incompatible type instead of homebrewing a poor replacement. Reported-by: Andrew Jones Fixes: fcba483e8246 ("KVM: selftests: Sanity check input to ioctls() at build time") Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index cdaea2383543..7ebfc8c7de17 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -186,50 +186,55 @@ static inline bool kvm_has_cap(long cap) ioctl(fd, cmd, arg); \ }) -#define __kvm_ioctl(kvm_fd, cmd, arg) \ +#define __kvm_ioctl(kvm_fd, cmd, arg) \ kvm_do_ioctl(kvm_fd, cmd, arg) -#define _kvm_ioctl(kvm_fd, cmd, name, arg) \ -({ \ - int ret = __kvm_ioctl(kvm_fd, cmd, arg); \ - \ - TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ +#define _kvm_ioctl(kvm_fd, cmd, name, arg) \ +({ \ + int ret = __kvm_ioctl(kvm_fd, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ }) #define kvm_ioctl(kvm_fd, cmd, arg) \ _kvm_ioctl(kvm_fd, cmd, #cmd, arg) -#define __vm_ioctl(vm, cmd, arg) \ -({ \ - static_assert(sizeof(*(vm)) == sizeof(struct kvm_vm), ""); \ - kvm_do_ioctl((vm)->fd, cmd, arg); \ +static __always_inline void static_assert_is_vm(struct kvm_vm *vm) { } + +#define __vm_ioctl(vm, cmd, arg) \ +({ \ + static_assert_is_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, name, arg) \ +({ \ + int ret = __vm_ioctl(vm, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ }) -#define vm_ioctl(vm, cmd, arg) \ +#define vm_ioctl(vm, cmd, arg) \ _vm_ioctl(vm, cmd, #cmd, arg) -#define __vcpu_ioctl(vcpu, cmd, arg) \ -({ \ - static_assert(sizeof(*(vcpu)) == sizeof(struct kvm_vcpu), ""); \ - kvm_do_ioctl((vcpu)->fd, cmd, arg); \ + +static __always_inline void static_assert_is_vcpu(struct kvm_vcpu *vcpu) { } + +#define __vcpu_ioctl(vcpu, cmd, arg) \ +({ \ + static_assert_is_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, name, arg) \ +({ \ + int ret = __vcpu_ioctl(vcpu, cmd, arg); \ + \ + TEST_ASSERT(!ret, __KVM_IOCTL_ERROR(name, ret)); \ }) -#define vcpu_ioctl(vcpu, cmd, arg) \ +#define vcpu_ioctl(vcpu, cmd, arg) \ _vcpu_ioctl(vcpu, cmd, #cmd, arg) /* -- 2.36.1.476.g0c4daa206d-goog