From patchwork Mon Nov 27 06:34:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 170011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp2888290vqx; Sun, 26 Nov 2023 22:35:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVxyfmXSDHfwQ1KRynwdZsXNwSMcufuy96YMEJOAmpyQn+YVL7MzCgKjsiJGDm+A3fzO1x X-Received: by 2002:a05:6358:720f:b0:16e:283:665d with SMTP id h15-20020a056358720f00b0016e0283665dmr12384497rwa.15.1701066907786; Sun, 26 Nov 2023 22:35:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701066907; cv=none; d=google.com; s=arc-20160816; b=hkr1jt8Kd18AdhUUXJiOLBOq5HOr4xPvuhYxK1BVLDr0cPtgpuMG1KXh36bQZAIRu2 imInJhSQzE3cIJADn+W8E8jA0vzb5x5DeJQL2uvimKd1jORiOu6g4cO2yvPsW0s7KOaP OsRXEFMQsG+SPHSLpxTeEJX9vlkmXDYu17VrYzzgQdIPwmVhH21IaW4O0wGmlPl59t6G nsibBTs4IHeTJWyEShL+OoYXrt8EuUKTarprq82K44WyfaCOi8c9c5KHyOhJ/y1Cw5JM 8FOZBisovILwA6/VzfJV73c1aZFdq/tEKpD+5e/lNJ7pW4ep9KvUNGbtqcjwt40LOjVN b5Mg== 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=R4sPmwV8XN38Irvhka+pArRxq+0ERq+E6GXgZbCpYAY=; fh=gm0A6EtasJwovXfz1TpeYfkY+4H0EN5E4rSCpite+Dk=; b=A0A35WlzZMOg8q/g9/1FTo8petE6wwU/iXYhe0TcwFDYkagCn9LaIiHQy3JmXzP7p+ eDP1vluP151xKsfts97fAOVE0HnZY8Vt3MMY2kgoiM32S9zsUXN9Rs5CJToRjDU6WSpI ebWZcftQao4zTjl75oP1p3wMCHfkx7PgBqYb5SwO6IPSNMfprrFjkyR9weoPyIQu/7TK dpZeHZpE6bd/AAV79zl9yrH2b2fcl4l2Haboc00dF/pVYacI+NQoIvltRXBUj0ZkKkmV z/Y6GlyIO5aJVHFUl08YHXXG6YrIsyHMNZNZcCTkXeeKnDW+nnCO5R3XP6kDYxbtlpuC LJng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LtvPq8MB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bw28-20020a056a02049c00b005b88dfa676esi9617329pgb.158.2023.11.26.22.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 22:35:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LtvPq8MB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 02E9780984AA; Sun, 26 Nov 2023 22:35:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232164AbjK0Geo (ORCPT + 99 others); Mon, 27 Nov 2023 01:34:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbjK0Ged (ORCPT ); Mon, 27 Nov 2023 01:34:33 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7692F9E; Sun, 26 Nov 2023 22:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701066879; x=1732602879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PYK6CzX/KC3fA+NEP1moXvit0m+FqGYstm2SuVEzKLg=; b=LtvPq8MBe4rpIufswOYZOkrJN9Ugq7QdLbiJlMNdsKTYcDZmdlJAcptg J+IdD9r2Q+GrYjZVni0Ju5KAxMACC2SpG7Sp67KDV5TGCmdS9sKpBVr6z 2MNPH0uCWsA6TkZfFRexkima83rX6BdRP7X/ah0T+3QoQyVXOcRkvxriU aOzO4YUBAGTPzJhgS2+oRWyzZEISJRM09LkfS87ynJjV4jeyoH5xW8faT LCkwZaOWfdf5QyVOMKnsvwLheV+dP+PmBt1THmQCbWH9IT5D6KvcsTdFF RSIMsKIevsatTmb3BosYjVztVMwMlPk4OaOTbNT9BTkeeriXHx3quCX2+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="391518187" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="391518187" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2023 22:34:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="838608944" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="838608944" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga004.fm.intel.com with ESMTP; 26 Nov 2023 22:34:38 -0800 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, xin.zeng@intel.com, yan.y.zhao@intel.com Subject: [PATCH 5/8] iommufd/selftest: Add a helper to get test device Date: Sun, 26 Nov 2023 22:34:25 -0800 Message-Id: <20231127063428.127436-6-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127063428.127436-1-yi.l.liu@intel.com> References: <20231127063428.127436-1-yi.l.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 26 Nov 2023 22:35:05 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783697933936291479 X-GMAIL-MSGID: 1783697933936291479 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 221a206bf38f..9b9fd3f50264 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -720,29 +720,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) @@ -752,7 +762,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; }