Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp777516pxp; Fri, 11 Mar 2022 14:53:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJz68ptj6BEO0Emc8imuGtuP3+tRkut5YdhXcCjmpS0rgvQFOO5Wohqhcdex96JI7vsngEeo X-Received: by 2002:a17:902:c1d4:b0:151:b56c:41ef with SMTP id c20-20020a170902c1d400b00151b56c41efmr12592830plc.77.1647039200341; Fri, 11 Mar 2022 14:53:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647039200; cv=none; d=google.com; s=arc-20160816; b=R3EDbP6YwdnzpT/ggHIrdSwev8HyP7thGhFR6OoKd8qVyQWExBEX19WHIpZO6svFru 2ziDYamVh40fi+KJpO8AaoIo7VpCB7naPvtCVVaB7l7qnBLSuSzyWcxYsgxgOYKA1pPN B7cam5v5WTcpIzJ16pGzrNkOte11YwuiNq75c/unR3FyCcWTmVmUBMjelIVSc874ICW5 QvfV3bnaHQEU+RRlgavq3TTpfKaPRl4E5WJb6rZyHFXQUwu7TgN2KOVH7GidWgCiJm5z u1fTVKGo/8PK3bx5qH66TZVDW/tXZZu2qBePrVM4oHOHeSiLe2QmzI4zev8ofxE7UxE5 sHzw== 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=ZrVDE6mEcY5E3SWlXhRtIq5EGnZtg/5TxJ+2uaelnxs=; b=aDGb4THkq39brwmg3jM8e+F/nQ6uS9LrQLOl2BW/rohX7YNugwK7RS7cm77a3NUsnz MKmWunuBuR1ZTzV6b/RH+SJ05mY5rar3pZH91bhC6rM8pOsGcyXpRd+4GzTF2LWpeSJS zLVsEq00RNtVJDDuqLigL52XvQMzqtC3Y257QC++WvBOKBTiX9yTWPlE9NUwUKqN8Mxy YClE5g/DH20s99Qlp+tcEkheBj1r76ERkqpFF8FLr59Fl87mLPJb+7BsYoQW+4kyu6o+ TD3EAman/xlwQ9+4odMJKLLzv+socfKpvkY/62wrlibwID+0s2yduCjD2Omjup2Dodtb vrBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fwoMk9st; 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 y6-20020a623206000000b004c30d5f9e47si8228095pfy.103.2022.03.11.14.53.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:53:20 -0800 (PST) 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=fwoMk9st; 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 A3C81359ED1; Fri, 11 Mar 2022 13:51:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239973AbiCKFyh (ORCPT + 99 others); Fri, 11 Mar 2022 00:54:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346617AbiCKFwo (ORCPT ); Fri, 11 Mar 2022 00:52:44 -0500 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 3D5C9FCB63 for ; Thu, 10 Mar 2022 21:51:41 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id mt1-20020a17090b230100b001beef010919so7268619pjb.7 for ; Thu, 10 Mar 2022 21:51:41 -0800 (PST) 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=ZrVDE6mEcY5E3SWlXhRtIq5EGnZtg/5TxJ+2uaelnxs=; b=fwoMk9stqQumCkI+juM15MEBjcVi3SEB6oSKXwMIaPC50YCJdKIfRGwHfDd4nSDC6i uMBKYguPm0f+Q+Fx6h0XcOd5+G0o5o6osSWPXweh0KYrQk4pwNckfpBETQ0nlfrFal4y m53IYRIhx5jwNpMjJls8iYkaiCFzrD0Ov5lJxYe1m6tNaMcylrOfh856O6cm/7vRzk+B ZbhHIOm8V2scU3fhKHbSl7v1Zrjrg0mh755pbs0wLv1pwVDwm+zLXLM+3hZgwexd87JL nCOJ3kip0CYqY5iPv0/hj7AF9EjVkGrWrth99PkUqGz1EV3aVA+Gd2K2jlnL88dFzJ1j i54w== 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=ZrVDE6mEcY5E3SWlXhRtIq5EGnZtg/5TxJ+2uaelnxs=; b=Ky5LtU1e0eDks4M+ri+oJnmO48An/1FD0bayL/n0CLtsipCj8sGq1IU6owjy96nBjr gkqbq/74QbVbMW3ao7VXGzjBf09o9ysX++slLp/43wHthY4V/lvKjwz8UaFRR8hqKxBt xTZiO43YulCio2sYAE8cq+C09fJ5n2pADPvm85ejecdwaULRI8WmMHtZxyVxwISU2AeU N2hcKrg6ILuvFGv4QNvOCAO5dOXLtDFMBgZaHa22Th5UXeYVJfIYwG/KGfTdgpNxJA00 F4CTjIp8u+w/A5MIYSK8PK6bPhx8h8SFVwE5rFVOV0auYkvZycCkXe5Zp1/wR+VtF7rd X5OQ== X-Gm-Message-State: AOAM533x2WCIyhtOp8w06lgiX15+DzrO4JIxgWcu2sh4jVpJQl5fNKyz IleFdpMejeq5bf/ZYSYuGpx5u+NNsKDNn3dVkVnEmwFPg32M8ZOcA2X9+3Au209Y9386h/lVG47 36gjLqiq+inCNrTEGUaPoyqXNp6COBV4l3yAUTMaHu/ICCCqSq3E45n7Q5eMFi/UkWmDnEQ== X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:7883:b0:1bd:2372:c990 with SMTP id x3-20020a17090a788300b001bd2372c990mr19863533pjk.55.1646977900532; Thu, 10 Mar 2022 21:51:40 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 11 Mar 2022 05:49:32 +0000 In-Reply-To: <20220311055056.57265-1-seanjc@google.com> Message-Id: <20220311055056.57265-22-seanjc@google.com> Mime-Version: 1.0 References: <20220311055056.57265-1-seanjc@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [RFC PATCH 021/105] KVM: selftests: Move KVM_CREATE_DEVICE_TEST code to separate helper From: Sean Christopherson To: linux-kernel@vger.kernel.org Cc: Sean Christopherson 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 Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/aarch64/vgic_init.c | 10 ++++---- .../selftests/kvm/include/kvm_util_base.h | 3 ++- tools/testing/selftests/kvm/lib/kvm_util.c | 23 ++++++++++++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/vgic_init.c b/tools/testing/selftests/kvm/aarch64/vgic_init.c index 9cd58f22f5bd..18d1d0335108 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_init.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_init.c @@ -648,24 +648,24 @@ int test_kvm_device(uint32_t gic_dev_type) v.vm = vm_create_default_with_vcpus(NR_VCPUS, 0, 0, guest_code, NULL); /* try to create a non existing KVM device */ - ret = _kvm_create_device(v.vm, 0, true, &fd); + ret = __kvm_test_create_device(v.vm, 0); TEST_ASSERT(ret && errno == ENODEV, "unsupported device"); /* trial mode */ - ret = _kvm_create_device(v.vm, gic_dev_type, true, &fd); + ret = __kvm_test_create_device(v.vm, gic_dev_type); if (ret) return ret; v.gic_fd = kvm_create_device(v.vm, gic_dev_type); - ret = _kvm_create_device(v.vm, gic_dev_type, false, &fd); + ret = __kvm_create_device(v.vm, gic_dev_type, &fd); TEST_ASSERT(ret && errno == EEXIST, "create GIC device twice"); /* try to create the other gic_dev_type */ other = VGIC_DEV_IS_V2(gic_dev_type) ? KVM_DEV_TYPE_ARM_VGIC_V3 : KVM_DEV_TYPE_ARM_VGIC_V2; - if (!_kvm_create_device(v.vm, other, true, &fd)) { - ret = _kvm_create_device(v.vm, other, false, &fd); + if (!__kvm_test_create_device(v.vm, other)) { + ret = __kvm_test_create_device(v.vm, other); TEST_ASSERT(ret && errno == EINVAL, "create GIC device while other version exists"); } diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 03575063ee13..081ba04e5df3 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -479,7 +479,8 @@ void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...); int _kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr); int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr); -int _kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test, int *fd); +int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type); +int __kvm_create_device(struct kvm_vm *vm, uint64_t type, int *fd); int kvm_create_device(struct kvm_vm *vm, uint64_t type); int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr, void *val, bool write); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index bfa7174a7892..f0a08de67f0f 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1600,14 +1600,25 @@ int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr) return ret; } -int _kvm_create_device(struct kvm_vm *vm, uint64_t type, bool test, int *fd) +int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type) { - struct kvm_create_device create_dev; + struct kvm_create_device create_dev = { + .type = type, + .flags = KVM_CREATE_DEVICE_TEST, + }; + + return __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev); +} + +int __kvm_create_device(struct kvm_vm *vm, uint64_t type, int *fd) +{ + struct kvm_create_device create_dev = { + .type = type, + .fd = -1, + .flags = 0, + }; int ret; - create_dev.type = type; - create_dev.fd = -1; - create_dev.flags = test ? KVM_CREATE_DEVICE_TEST : 0; ret = __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev); *fd = create_dev.fd; return ret; @@ -1617,7 +1628,7 @@ int kvm_create_device(struct kvm_vm *vm, uint64_t type) { int fd, ret; - ret = _kvm_create_device(vm, type, false, &fd); + ret = __kvm_create_device(vm, type, &fd); TEST_ASSERT(!ret, "KVM_CREATE_DEVICE IOCTL failed, rc: %i errno: %i", ret, errno); return fd; -- 2.35.1.723.g4982287a31-goog