From patchwork Fri Apr 12 08:15:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13627135 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 DCC2F50A63 for ; Fri, 12 Apr 2024 08:15:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712909738; cv=none; b=k3MqG6H7N/ON2NlSj159onK7G6JYgxNsZ9Bo+pISy7kx8reiGxPRSBF9fE8ORc68SSBmY+5hdiemfI5ch3EllWUWczlcA+OQ5ZxykDHw64jxFgDxTfGKcULcKZx3lI05+qfR/CpH8YO4DFoRQLKtyAQDTN+ttmdD/3kOokiVE6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712909738; c=relaxed/simple; bh=Am3pIE7+ge5z26u2xgPKEdvdLsxsgHeEHDf+EeiVypU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AhepG1X1rVaJEcpASLOu6F61dlssFyO4eucM34Pp4T6O29kf3vfCRGlZMnw+dNyj6giKI173VydbLeQCU2iFlO0gX31JQ0OhuAfXrWkFC0KJQl9e8YQzuXYfEjocbGh9JbFwETsX4EC7bRhBMuZqh2xhzqW84/XbFzPEeMM2Bhg= 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=ZOPbCCM0; arc=none smtp.client-ip=198.175.65.17 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="ZOPbCCM0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712909736; x=1744445736; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Am3pIE7+ge5z26u2xgPKEdvdLsxsgHeEHDf+EeiVypU=; b=ZOPbCCM0y+W/lP5pXNuFofmUeVk++PEHMvZw65HuDnzjD1t+okPKwAOI 3MrU2D3mTTKrIaVRgmivR0Ii0MWWGtVETdByF5ZmuHYCv0FeuY53EwPlz Htwb4mLDJ9bs94/3TmTHhtyHfJE23xspCQQW1R/wP3LDUpwf45pLfRzWm nChbqlpaT+3KLoC6ewfr5YdgorZXtFnM334XQT7pt4NaOcgqrvV68TjDs B452VeOQEldUJrYXw3IkvSEOHqxIPC5w/RF/qx+47Z7RMwebVZp9xVTfA Fk7n7JJuW+5o0vgpOKaAXlQceK8Dw/OWe2VvS+J8ImHE03bfj93rBFJDL w==; X-CSE-ConnectionGUID: wMB8jrfrT+GEGlE6g/CtyA== X-CSE-MsgGUID: +ZdQWbyCSaebc4vEhoFTkg== X-IronPort-AV: E=McAfee;i="6600,9927,11041"; a="8465086" X-IronPort-AV: E=Sophos;i="6.07,195,1708416000"; d="scan'208";a="8465086" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 01:15:35 -0700 X-CSE-ConnectionGUID: 9pbjeWMFTCyhhXnnI6CGTg== X-CSE-MsgGUID: h7Cc+wATT966wf6EROEluw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,195,1708416000"; d="scan'208";a="52137857" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by orviesa002.jf.intel.com with ESMTP; 12 Apr 2024 01:15:34 -0700 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com, baolu.lu@linux.intel.com Cc: alex.williamson@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, iommu@lists.linux.dev, zhenzhong.duan@intel.com, jacob.jun.pan@intel.com Subject: [PATCH v2 07/12] iommufd/selftest: Add a helper to get test device Date: Fri, 12 Apr 2024 01:15:11 -0700 Message-Id: <20240412081516.31168-8-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412081516.31168-1-yi.l.liu@intel.com> References: <20240412081516.31168-1-yi.l.liu@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 45e1328f0f5d..e21b076b2223 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -794,29 +794,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(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) @@ -826,7 +836,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; }