From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94755226160 for ; Thu, 19 Dec 2024 13:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734614879; cv=none; b=kkTKLVkkQTRcdpin52F6UFx4/5UxKJs4wL0SbRbHDUZGrN5CKFRc1OGDXDpjvSrW1wpxtP3mq6CbfoE6qncmzCuOHrDPgNt5NxBSrcu8zFQ6vHrzeNEXrkBuGbXy4Q9dSncvoCKKC2YQpmpTINq4E4g5LZzifJKHcXqcgHMTW1w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734614879; c=relaxed/simple; bh=SdHs4gGZT0qErEtDlteBfOgZiUKIQbSAYNZESnXkR60=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O568C7Pwn3+MEq5PQe/kB0yaf8texQJZbykKL+r7ppPNspJNlBAyBqMAahEXU6DPuC7BkH5uPadYHt/c5nvOKYuRjxDgW8OYSA0EWnh1LGy4Q1VMvsPRTLdyF4gZ2Va89ZcLv4a6ezzt7vHQGrPrqdXzv4n3eUxiT3v5+K2Gvc8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gE/6Tgu8; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gE/6Tgu8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734614877; x=1766150877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SdHs4gGZT0qErEtDlteBfOgZiUKIQbSAYNZESnXkR60=; b=gE/6Tgu8J2XsrithHa19iReQ4aYOzjxNlHWysqs9nCUdZDTekfI6UQg4 MKxuyoRE2+y0Y2WkMllJb5tYtobBxwnXPjsMoDjzk4nSJ1siybIIBnUj1 J9oKK/OHRuhu3a9AByvyCkCOrS0Wb83QX53tNCYNv9SySDZrQgUC/MIFZ Di8sElHO7pu6pz663zrMf3/axocGQfTEA3tC8E199e55/A5hGwtHP9jJu CgIPk50zS/AUzYfa8cJJWu9kIZ2ahSg3NhN7dRMXqwRbmkF6aXkoLMN1S RVwHOEtyR/dfYS3pwXcfI+c/N1yHFgUoiRxoDh2HYdSDR6bOlWQt8gMnR Q==; X-CSE-ConnectionGUID: DzHwnojoQ8yICQm1Dvk3aA== X-CSE-MsgGUID: 7YKXbcJFQh6ebvt5SY947A== X-IronPort-AV: E=McAfee;i="6700,10204,11290"; a="46542316" X-IronPort-AV: E=Sophos;i="6.12,247,1728975600"; d="scan'208";a="46542316" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2024 05:27:51 -0800 X-CSE-ConnectionGUID: sLNilapZRCWbjKpGNPQ9VA== X-CSE-MsgGUID: c2RJE8cPQlWtK9Pao31pMA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,247,1728975600"; d="scan'208";a="103177342" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa004.jf.intel.com with ESMTP; 19 Dec 2024 05:27:51 -0800 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: eric.auger@redhat.com, nicolinc@nvidia.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, vasant.hegde@amd.com, will@kernel.org Subject: [PATCH v6 12/14] iommufd/selftest: Add a helper to get test device Date: Thu, 19 Dec 2024 05:27:44 -0800 Message-Id: <20241219132746.16193-13-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241219132746.16193-1-yi.l.liu@intel.com> References: <20241219132746.16193-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 3f49ef72ba91..515435640e35 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -982,29 +982,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 ERR_CAST(dev_obj); sobj = to_selftest_obj(dev_obj); if (sobj->type != TYPE_IDEV) { - rc = -EINVAL; - goto out_dev_obj; + iommufd_put_object(ictx, 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) @@ -1014,7 +1024,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(ucmd->ictx, dev_obj); + iommufd_put_object(ucmd->ictx, &sobj->obj); return rc; } -- 2.34.1