From patchwork Tue Sep 26 09:26:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 144888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1924340vqu; Tue, 26 Sep 2023 06:41:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPJbcyVwKgS1SRE0ycQQK/Pn68Ok7fpmhIklah4NTZ8SXIzaBeD/2uL8dt2MsF/0bN/jzL X-Received: by 2002:a17:90a:1197:b0:268:18e:9dfa with SMTP id e23-20020a17090a119700b00268018e9dfamr9003237pja.5.1695735661817; Tue, 26 Sep 2023 06:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695735661; cv=none; d=google.com; s=arc-20160816; b=S3oCbQf16hhjURoKzjDqpj/+i6mZkc/tr2Bfq0Yx0PPpK2ybbj0UdT1jRac4PZvQK4 n9+ylcLiLrOHckAk5JkzW4TVwIaezNSs/IdFW9UJs+u4vLbPDRkuJjlaOPIwMcmLhN6x WdKrD/Q4eqbg1NqaUT3HysqU0acCTZWDElXKMuHkjTIUv/gJMgVwqtZ2Q9Yvp+qj67M4 SYOG/N8xOit55w/4ohCC8Xu5/UbSlLjBYIMCwEtsQWn4UxzicofPHeffRZ5J6su8RCet DPEmAJFTE9E4LWKIkrQ7ivjKzJQ2klSaWlXglq4J0FSs+if6RpVw4f6ONM2lfoAt6NbE AuFA== 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=FGVz+cr0CEG4wG9gJuDTD+fyfB8jpiyXot+PXsWv5io=; fh=ncJBVmsnOSqrX1O37yfYEzicwaA2e7ARxnsU7aiysyE=; b=GjTpGvFhktufvoBcGf27mpLqqQSUmr7gzlF4auR1dmT9Zp15UbaeiX8yiGUntgBg+N dEX0ttrFK/r+1l06Aayuu2WbSiZXw2Qhv1f8hA1A3xSRfV8qxv9s9J6cfNfltmkbM6oB nFyPs7WVrF0mJaTESHF8lCAcVzj7C7xSHE/z66//9IN9pyxb1baB797gvioWKnwPlFP/ C0rcmPLL9KqRLChuGMIr/jGFYXE88F1y0MaLpyeOGMrlOlKKjggTYAhEBr0Wsu3JRBLc jDmyTrKCd2vExqmalbdoC00tCOP21Om0KanYSWKGBw3NakzEPcuUC9IkR0jjuJBU2O0O aiqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dVg55Z41; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id mi2-20020a17090b4b4200b00276b87c8b8esi1672441pjb.59.2023.09.26.06.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 06:41:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dVg55Z41; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4552781A7AD1; Tue, 26 Sep 2023 02:27:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234222AbjIZJ1M (ORCPT + 27 others); Tue, 26 Sep 2023 05:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234215AbjIZJ1I (ORCPT ); Tue, 26 Sep 2023 05:27:08 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 408B3EB; Tue, 26 Sep 2023 02:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695720421; x=1727256421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z/8xtA8gAK2sz+3XlyEPUKVKbvGdFNqEfJbcjCXtYIM=; b=dVg55Z41/VSGlO/gM9n7Z3KeFSBgLYQT07H271JJbEVu177T/lTcJvTv nUHs54I9OQYBzuHGHLrGE6htW1vEhmOxLAx6V5o4LRUCxuE9mGroldUhs uhel1ORB/EZUFyOAsskrfWZZuUu8ant19pZjwr8wh/fHrgilhz/EDdh8N JittMYwCUSUGRa5EhFsiTCYsDGyhqT0M6fBXdoZBzJ+FuG0UMcoKu3ZIr QH93eM9SgPvNT2+RH2/w3ZgNhgw5XGHXXDhK1J5r6DF6lrJw838Gvy6g+ 6HAma/HZT5zr6U4MuXPA1AXjeOrXI8U+zKklPDAadl21IkZ+bI1S4ERui Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="360905388" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="360905388" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 02:26:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="1079642559" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="1079642559" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga005.fm.intel.com with ESMTP; 26 Sep 2023 02:26:58 -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, joao.m.martins@oracle.com Subject: [RFC 5/8] iommufd/selftest: Add a helper to get test device Date: Tue, 26 Sep 2023 02:26:48 -0700 Message-Id: <20230926092651.17041-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926092651.17041-1-yi.l.liu@intel.com> References: <20230926092651.17041-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_NONE,SPF_NONE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 26 Sep 2023 02:27:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778107717379469437 X-GMAIL-MSGID: 1778107717379469437 There is need to get the selftest device (sobj->type == TYPE_IDEV) in multiple places, so have a helper to for 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 200c88387cd1..1f2ce4ffee4e 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -668,29 +668,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_self_test_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_self_test_device(ucmd->ictx, device_id); + if (IS_ERR(sobj)) + return PTR_ERR(sobj); rc = iommufd_device_replace(sobj->idev.idev, &pt_id); if (rc) @@ -700,7 +710,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; }