From patchwork Sun Sep 8 11:42:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13795416 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 B90692E634 for ; Sun, 8 Sep 2024 11:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725795781; cv=none; b=mQVtCNkQPUM5HtB9QayYX9An2VUy22k65r5etDsxEOsbR8SXCLWnRxaVitsz7Tl1D2cIdm8K0immu/8naxdhCF83XGxO5fXRFl2nTg3KncX+Hs9p5bCjTGcA0HsWJzKOp+/nLOLqzprDGgoKR8TRKc7JHQbFZI3CT0nDLy/nw1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725795781; c=relaxed/simple; bh=g/SSBnmxr6BtSLGzjLNz5QJEGxfg2sdMnLHrOgBNYGc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=brsQ1xvJYDRlHatyk/aJ8x/07n9Im9/M97Mex9MkGxsOchM+6xukScKF+nIsFUqPLL7jndJrol1FKXGOCw6yATc9WrWFxGLsDgB63VZRDZe2a7PPKzSuRpycEXf9iAOuxxccEVX3RfEcVRGk0MBRmYT7zlxmgLqalkTo9Okv/Vo= 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=gZrOrMxK; arc=none smtp.client-ip=192.198.163.13 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="gZrOrMxK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725795780; x=1757331780; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g/SSBnmxr6BtSLGzjLNz5QJEGxfg2sdMnLHrOgBNYGc=; b=gZrOrMxKDPQHTm6aVN9HY+662t0GR0hugaupIQPEK37ZSwOTx1x0MTzD 5xSm4a3y5loUCaLcSizXa0DafuGTe6TgeY1EfP0TYZksR1R4rTzSjfi1z gnnwvXTc6dHal3qPaHP/SvDBbplAxrDMklvMpuydtifolrAL3Yjv2jLtG f9WW4dOBs2NE2KfvUZ/CQOiGiHszNaoH05Ly7Wbaz/oUY5clL57gcIrLk MFqYrGBsfcsGWfqZqV6EJH76FMPZMzPVmI3hmYh8GOByP8SkUjYjSPouC szm9gPN6hEMbcf1rYr3YEbfQ4IbcYfb2HsGabpTC/ZkH72ryZP4aX9Nfq Q==; X-CSE-ConnectionGUID: ijXWAmO9TlyVjWu3rXf0NA== X-CSE-MsgGUID: hkONm03iRo+VLTYnsbUCdQ== X-IronPort-AV: E=McAfee;i="6700,10204,11188"; a="27418269" X-IronPort-AV: E=Sophos;i="6.10,212,1719903600"; d="scan'208";a="27418269" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2024 04:42:59 -0700 X-CSE-ConnectionGUID: GacXIldjSdiqbvs+224ZLQ== X-CSE-MsgGUID: Z//FvtdbT9K4tu+k/5j3Iw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,212,1719903600"; d="scan'208";a="89668164" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa002.fm.intel.com with ESMTP; 08 Sep 2024 04:42:58 -0700 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com Cc: nicolinc@nvidia.com, kvm@vger.kernel.org, yi.l.liu@intel.com, iommu@lists.linux.dev, baolu.lu@linux.intel.com Subject: [PATCH 1/2] iommufd: Avoid duplicated __iommu_group_set_core_domain() call Date: Sun, 8 Sep 2024 04:42:55 -0700 Message-Id: <20240908114256.979518-2-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240908114256.979518-1-yi.l.liu@intel.com> References: <20240908114256.979518-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 For the fault-capable hwpts, the iommufd_hwpt_detach_device() calls both iommufd_fault_domain_detach_dev() and iommu_detach_group(). This would have duplicated __iommu_group_set_core_domain() call since both functions call it in the end. This looks no harm as the __iommu_group_set_core_domain() returns if the new domain equals to the existing one. But it makes sense to avoid such duplicated calls in caller side. Signed-off-by: Yi Liu Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/iommufd_private.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 92efe30a8f0d..1141c0633dc9 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -490,8 +490,10 @@ static inline int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt, static inline void iommufd_hwpt_detach_device(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev) { - if (hwpt->fault) + if (hwpt->fault) { iommufd_fault_domain_detach_dev(hwpt, idev); + return; + } iommu_detach_group(hwpt->domain, idev->igroup->group); } From patchwork Sun Sep 8 11:42:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 13795415 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 EBA8B157A4D for ; Sun, 8 Sep 2024 11:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725795781; cv=none; b=g+1H+9SQ6i6KUrYjTNw0JDArMPdoHjxAn20896kDtuicckoPuQEzTtOsFzD79twCFucdk5bvL4dGqNL88HEIz3ba94c8WHNgocN85VcVFCdDs7iUBWRkrG4rx1wwN+TTEPEF+NpVgw/JArrnBJ8unItna/FBTkodaIwkomPJOAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725795781; c=relaxed/simple; bh=6D32PgrLosIh6OCfg0v2IHbZTTFBABwzW9sc9tl2E9s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DuaBLsbuBEv6kBcczXL26XmuUfvTkyVTtQIhpg9+9qEN6tXlH+KdOc1Gbltz9wNm2dwrRB4ViUcez5Hw48V5ndbX/TFOu6OubZb3dM2gYYaNabPxO6wssdReNA3JSCpRgC3hA54WSFuu5s4SY0anwR+x5dDQGiHAmtrrC8Zzs6k= 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=G5nlDl2g; arc=none smtp.client-ip=192.198.163.13 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="G5nlDl2g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725795780; x=1757331780; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6D32PgrLosIh6OCfg0v2IHbZTTFBABwzW9sc9tl2E9s=; b=G5nlDl2g+ZYwlbcQgoWDk0/3J9NgSJUfH8R+ctIPjYdswC2ynF7ReU+v fmrD6VySdGHUaE8Kt+ZSdIvszUb/MPLPAQ5WxiTBGA6yssm7qKU3Xl7ek 5k5quHtNH9r54mVHsDyp/04e1xWD2sfWamANXbZFlM8/pVd6ltyIfVnq/ xNjuA1aAq7F7kwpDiawTcMt8v57DH2lqQneyBvF1E6irkCSe5QK6fNRx+ zBwWt8+eLzDAY5mm03Mlv/tU60E2KZCfuKL2/wADRkdh6omm1x5KLNw3W 7tME0Vxvgr0FyeQs2qkNOt2FZnLhtoWPuAFDthcpJVgUyKpQ4QZLlfRkI w==; X-CSE-ConnectionGUID: IoBpp/mSQf2czxopQW5biQ== X-CSE-MsgGUID: 01owSwnjRiOI4j3/HSUO5g== X-IronPort-AV: E=McAfee;i="6700,10204,11188"; a="27418274" X-IronPort-AV: E=Sophos;i="6.10,212,1719903600"; d="scan'208";a="27418274" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2024 04:42:59 -0700 X-CSE-ConnectionGUID: b3L7dxTWQXG7yM1C1n4FVA== X-CSE-MsgGUID: S6ibyVC8Q5S2dKesRJIsVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,212,1719903600"; d="scan'208";a="89668168" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmviesa002.fm.intel.com with ESMTP; 08 Sep 2024 04:42:59 -0700 From: Yi Liu To: joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com Cc: nicolinc@nvidia.com, kvm@vger.kernel.org, yi.l.liu@intel.com, iommu@lists.linux.dev, baolu.lu@linux.intel.com Subject: [PATCH 2/2] iommu: Set iommu_attach_handle->domain in core Date: Sun, 8 Sep 2024 04:42:56 -0700 Message-Id: <20240908114256.979518-3-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240908114256.979518-1-yi.l.liu@intel.com> References: <20240908114256.979518-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 The IOMMU core sets the iommu_attach_handle->domain for the iommu_attach_group_handle() path, while the iommu_replace_group_handle() sets it on the caller side. Make the two paths aligned on it. Signed-off-by: Yi Liu Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 1 + drivers/iommu/iommufd/fault.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index ed6c5cb60c5a..83c8e617a2c5 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3578,6 +3578,7 @@ int iommu_replace_group_handle(struct iommu_group *group, ret = xa_reserve(&group->pasid_array, IOMMU_NO_PASID, GFP_KERNEL); if (ret) goto err_unlock; + handle->domain = new_domain; } ret = __iommu_group_set_domain(group, new_domain); diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index a643d5c7c535..c4715261f2c7 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -161,7 +161,6 @@ static int __fault_domain_replace_dev(struct iommufd_device *idev, if (!handle) return -ENOMEM; - handle->handle.domain = hwpt->domain; handle->idev = idev; ret = iommu_replace_group_handle(idev->igroup->group, hwpt->domain, &handle->handle);