From patchwork Mon Jul 24 11:03:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 124837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1726535vqg; Mon, 24 Jul 2023 04:18:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlFgD274V8S7VIk8M+ucpskMSTlg6Gv1FlR2ogZusMyp5BeJ+8IGT1DSO9IcDKWf0F7QiYNw X-Received: by 2002:a05:6402:70c:b0:522:2f8c:8953 with SMTP id w12-20020a056402070c00b005222f8c8953mr1584790edx.39.1690197485566; Mon, 24 Jul 2023 04:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690197485; cv=none; d=google.com; s=arc-20160816; b=iGy03PIdI4bkViz3S4bZqG3heJEaE1AgR9XSHXawbegb+ExSHlkVx5ET375pzLs+pY 1mMUkAy7JBdUwHktcQY4yl6RAor94jO6htgqxoD/jV681Gae+WF3Oqxlke9pqBRTD0tY MtbZGU1zlvwrYNliE8nMZGGH98hjxY54n1bOqJOGdBD//BEoUZB5W+DK3Dxf+v27YK1i qFKcGrXz0pl9CoUE4plyFtibl1Wo9L82pNcK9ymgrlgslgegajt+efY1pP4KQguc76S5 c8gLCqhZVulWjqd0qPJyzbcm8ss8/3QgwSyxJ4kJw4o1YwnZ1Pd5MXhrcttgpMJR+hV/ eS5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Tbr/Fws9MYIRI9KY5ITTxex1HNUBjBJfTqtKjKk+dMY=; fh=25kVo4cotgMzE250R6E3K5ES7E7C2JawiavlW0h5mKU=; b=rOwc4iLTCoYTwrIGX2TMP1CrC7WvAcbgcc8RhXi3ldOX5XRqXZW2Uk2P56kmuiGNXm Hi5NEVxXG7AR2eELTZtxfdyAUHIrlgR7Eo8sT4GakZNE0mU7+N1Sjac+N2Kc3SwIo8j1 zFr2NtZyqIqaJ7NqeQqNeZ++31IFVSu639xf4pQ+vBRhSoU0yHS6zIECDWJ+CcVe/ykR u6q9wAbKtS/UfE+vJdWB7KbpO+xcGoFxlDVBHe/7ezrK/fvGHgZ/AajWvR5O3kVdIzBc ZHBzvBT2TNnF2L5IxO+ZGPolJh9WioAxA2TCCWsdtcLKFPrKpyRfi3uab662cdRQ8ygV bbDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZmvauX4X; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z9-20020aa7cf89000000b00521029a8eeesi6831535edx.313.2023.07.24.04.17.41; Mon, 24 Jul 2023 04:18:05 -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=@intel.com header.s=Intel header.b=ZmvauX4X; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231432AbjGXLEw (ORCPT + 99 others); Mon, 24 Jul 2023 07:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbjGXLEh (ORCPT ); Mon, 24 Jul 2023 07:04:37 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A06139; Mon, 24 Jul 2023 04:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690196667; x=1721732667; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KYIs7M+eJopUTxJV4cpg9FxLziL1nbNIFCuxJQtO2rA=; b=ZmvauX4X9v+lLzgaAoMNKOtuebkV+GXuHuhiWLqUwX1F1iSgKubKKvOI C+0DTDkrlmiRTr6w/TIWbEV/YoBn1IL83MCigL0Fn+V8+hbGMDmdCD+Ih R7kKgXXEKpNNft0MneS+sAEBNCL/kYjvpgJapJTRoc4T7DJRVe6OjYlpw mCd+ZjS7QK+b3MXzx32/1GceO+rQc5gOui1Ba5gy4pN5yUC7k3COifiMs oFCFLA1t5mODEeIQ8h3EguZoDMMypK5ova2QAbYmsJPk2qlleSdHWD4j+ 4948IhjHX1sO2Lr5PmQ/3vNViyfjXodAhqGBRFNtp0IJ3uhdv6oYwqnO3 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="347013310" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="347013310" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 04:04:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="815775830" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="815775830" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by FMSMGA003.fm.intel.com with ESMTP; 24 Jul 2023 04:04:20 -0700 From: Yi Liu To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, zhenzhong.duan@intel.com Subject: [PATCH v3 10/17] iommufd/selftest: Add a helper to get test device Date: Mon, 24 Jul 2023 04:03:59 -0700 Message-Id: <20230724110406.107212-11-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724110406.107212-1-yi.l.liu@intel.com> References: <20230724110406.107212-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772300518328967594 X-GMAIL-MSGID: 1772300518328967594 There is need to get the selftest device (sobj->type == TYPE_IDEV) in multiple places, so have a helper to get it. Signed-off-by: Yi Liu --- drivers/iommu/iommufd/selftest.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index af7459e211ad..72d0c37e0b5e 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -472,29 +472,39 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd, return rc; } -/* Replace the mock domain with a manually allocated hw_pagetable */ -static int iommufd_test_mock_domain_replace(struct iommufd_ucmd *ucmd, - unsigned int device_id, u32 pt_id, - struct iommu_test_cmd *cmd) +static struct selftest_obj *iommufd_test_get_device(struct iommufd_ctx *ictx, + u32 id) { struct iommufd_object *dev_obj; struct selftest_obj *sobj; - int rc; /* * Prefer to use the OBJ_SELFTEST because the destroy_rwsem will ensure * it doesn't race with detach, which is not allowed. */ - dev_obj = - iommufd_get_object(ucmd->ictx, device_id, IOMMUFD_OBJ_SELFTEST); + dev_obj = iommufd_get_object(ictx, id, IOMMUFD_OBJ_SELFTEST); if (IS_ERR(dev_obj)) - return PTR_ERR(dev_obj); + return (struct selftest_obj *)dev_obj; sobj = container_of(dev_obj, struct selftest_obj, obj); if (sobj->type != TYPE_IDEV) { - rc = -EINVAL; - goto out_dev_obj; + iommufd_put_object(dev_obj); + return ERR_PTR(-EINVAL); } + return sobj; +} + +/* Replace the mock domain with a manually allocated hw_pagetable */ +static int iommufd_test_mock_domain_replace(struct iommufd_ucmd *ucmd, + unsigned int device_id, u32 pt_id, + struct iommu_test_cmd *cmd) +{ + struct selftest_obj *sobj; + int rc; + + sobj = iommufd_test_get_device(ucmd->ictx, device_id); + if (IS_ERR(sobj)) + return PTR_ERR(sobj); rc = iommufd_device_replace(sobj->idev.idev, &pt_id); if (rc) @@ -504,7 +514,7 @@ static int iommufd_test_mock_domain_replace(struct iommufd_ucmd *ucmd, rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); out_dev_obj: - iommufd_put_object(dev_obj); + iommufd_put_object(&sobj->obj); return rc; }