From nobody Mon Sep 15 21:04:15 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04ECCC5479D for ; Tue, 10 Jan 2023 03:02:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231205AbjAJDCW (ORCPT ); Mon, 9 Jan 2023 22:02:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbjAJDCP (ORCPT ); Mon, 9 Jan 2023 22:02:15 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F1214102E for ; Mon, 9 Jan 2023 19:02:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673319734; x=1704855734; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LKTg2AhHtJU8Mk4diYz1OLa+rxghCz1GjIZU/8Rz5yw=; b=HPEJinNyMxewIla0psNrSKj2/01US/xY20AdDDqXwJLnWEcxRdoEgToH 5AzCQBhkwyOIHE+1yBGYL3WMfnJnDYbrdShE7P7C76wt00+AUB1ZIKNmb 4WuIBNM5USpmEY6TigmjgM87CaP9CETu9+93vhjXbQCSzBtQIbcIQNStS XndgDPCdkgn8uuybQHtRWRvtWntsRO2nFk3stZ+153LgRMqeQQgZZ6nZi zqLwCK/JHTDR+tyieI+WAuXn+NW/uQeYYSgB/7lFwfzG+Vo8xyVc27E7J oNNr9gQUutUAPL7AnewtOZ2ArDpyU6AQTcQzaRPRA8HMZZFo5hmo+0e0v A==; X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="324289072" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="324289072" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 19:02:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="830841923" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="830841923" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga005.jf.intel.com with ESMTP; 09 Jan 2023 19:02:06 -0800 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Will Deacon , Robin Murphy , Jean-Philippe Brucker Cc: Suravee Suthikulpanit , Vasant Hegde , Hector Martin , Sven Peter , Rob Clark , Marek Szyprowski , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Yong Wu , Matthias Brugger , Heiko Stuebner , Matthew Rosato , Orson Zhai , Baolin Wang , Chunyan Zhang , Chen-Yu Tsai , Thierry Reding , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v5 1/5] iommu: Remove detach_dev callbacks Date: Tue, 10 Jan 2023 10:54:04 +0800 Message-Id: <20230110025408.667767-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110025408.667767-1-baolu.lu@linux.intel.com> References: <20230110025408.667767-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The iommu core calls the driver's detach_dev domain op callback only when a device is finished assigning to user space and iommu_group_release_dma_owner() is called to return the device to the kernel, where iommu core wants to set the default domain to the device but the driver didn't provide one. In other words, if any iommu driver provides default domain support, the .detach_dev callback will never be called. This removes the detach_dev callbacks in those IOMMU drivers that support default domain. Reviewed-by: Jason Gunthorpe Reviewed-by: Sven Peter # apple-dart Acked-by: Chunyan Zhang # sprd Reviewed-by: Vasant Hegde # amd Signed-off-by: Lu Baolu --- drivers/iommu/amd/iommu.c | 26 ------------------------- drivers/iommu/apple-dart.c | 24 ----------------------- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 23 ---------------------- drivers/iommu/exynos-iommu.c | 1 - drivers/iommu/ipmmu-vmsa.c | 16 --------------- drivers/iommu/mtk_iommu.c | 9 --------- drivers/iommu/rockchip-iommu.c | 1 - drivers/iommu/sprd-iommu.c | 16 --------------- drivers/iommu/sun50i-iommu.c | 1 - 9 files changed, 117 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index cbeaab55c0db..92319c9b877c 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2126,31 +2126,6 @@ static void amd_iommu_domain_free(struct iommu_domai= n *dom) protection_domain_free(domain); } =20 -static void amd_iommu_detach_device(struct iommu_domain *dom, - struct device *dev) -{ - struct iommu_dev_data *dev_data =3D dev_iommu_priv_get(dev); - struct amd_iommu *iommu; - - if (!check_device(dev)) - return; - - if (dev_data->domain !=3D NULL) - detach_device(dev); - - iommu =3D rlookup_amd_iommu(dev); - if (!iommu) - return; - -#ifdef CONFIG_IRQ_REMAP - if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) && - (dom->type =3D=3D IOMMU_DOMAIN_UNMANAGED)) - dev_data->use_vapic =3D 0; -#endif - - iommu_completion_wait(iommu); -} - static int amd_iommu_attach_device(struct iommu_domain *dom, struct device *dev) { @@ -2416,7 +2391,6 @@ const struct iommu_ops amd_iommu_ops =3D { .def_domain_type =3D amd_iommu_def_domain_type, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D amd_iommu_attach_device, - .detach_dev =3D amd_iommu_detach_device, .map_pages =3D amd_iommu_map_pages, .unmap_pages =3D amd_iommu_unmap_pages, .iotlb_sync_map =3D amd_iommu_iotlb_sync_map, diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 4f4a323be0d0..96843d468801 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -486,13 +486,6 @@ static int apple_dart_domain_add_streams(struct apple_= dart_domain *domain, true); } =20 -static int apple_dart_domain_remove_streams(struct apple_dart_domain *doma= in, - struct apple_dart_master_cfg *cfg) -{ - return apple_dart_mod_streams(domain->stream_maps, cfg->stream_maps, - false); -} - static int apple_dart_attach_dev(struct iommu_domain *domain, struct device *dev) { @@ -535,22 +528,6 @@ static int apple_dart_attach_dev(struct iommu_domain *= domain, return ret; } =20 -static void apple_dart_detach_dev(struct iommu_domain *domain, - struct device *dev) -{ - int i; - struct apple_dart_stream_map *stream_map; - struct apple_dart_master_cfg *cfg =3D dev_iommu_priv_get(dev); - struct apple_dart_domain *dart_domain =3D to_dart_domain(domain); - - for_each_stream_map(i, cfg, stream_map) - apple_dart_hw_disable_dma(stream_map); - - if (domain->type =3D=3D IOMMU_DOMAIN_DMA || - domain->type =3D=3D IOMMU_DOMAIN_UNMANAGED) - apple_dart_domain_remove_streams(dart_domain, cfg); -} - static struct iommu_device *apple_dart_probe_device(struct device *dev) { struct apple_dart_master_cfg *cfg =3D dev_iommu_priv_get(dev); @@ -780,7 +757,6 @@ static const struct iommu_ops apple_dart_iommu_ops =3D { .owner =3D THIS_MODULE, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D apple_dart_attach_dev, - .detach_dev =3D apple_dart_detach_dev, .map_pages =3D apple_dart_map_pages, .unmap_pages =3D apple_dart_unmap_pages, .flush_iotlb_all =3D apple_dart_flush_iotlb_all, diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/ar= m-smmu/qcom_iommu.c index 270c3d9128ba..d7be3adee426 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -387,28 +387,6 @@ static int qcom_iommu_attach_dev(struct iommu_domain *= domain, struct device *dev return 0; } =20 -static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct devi= ce *dev) -{ - struct qcom_iommu_domain *qcom_domain =3D to_qcom_iommu_domain(domain); - struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); - struct qcom_iommu_dev *qcom_iommu =3D to_iommu(dev); - unsigned i; - - if (WARN_ON(!qcom_domain->iommu)) - return; - - pm_runtime_get_sync(qcom_iommu->dev); - for (i =3D 0; i < fwspec->num_ids; i++) { - struct qcom_iommu_ctx *ctx =3D to_ctx(qcom_domain, fwspec->ids[i]); - - /* Disable the context bank: */ - iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); - - ctx->domain =3D NULL; - } - pm_runtime_put_sync(qcom_iommu->dev); -} - static int qcom_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -583,7 +561,6 @@ static const struct iommu_ops qcom_iommu_ops =3D { .pgsize_bitmap =3D SZ_4K | SZ_64K | SZ_1M | SZ_16M, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D qcom_iommu_attach_dev, - .detach_dev =3D qcom_iommu_detach_dev, .map_pages =3D qcom_iommu_map, .unmap_pages =3D qcom_iommu_unmap, .flush_iotlb_all =3D qcom_iommu_flush_iotlb_all, diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index b0cde2211987..29ec713e8a21 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -1404,7 +1404,6 @@ static const struct iommu_ops exynos_iommu_ops =3D { .of_xlate =3D exynos_iommu_of_xlate, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D exynos_iommu_attach_device, - .detach_dev =3D exynos_iommu_detach_device, .map =3D exynos_iommu_map, .unmap =3D exynos_iommu_unmap, .iova_to_phys =3D exynos_iommu_iova_to_phys, diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index a003bd5fc65c..3112822ac7be 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -643,21 +643,6 @@ static int ipmmu_attach_device(struct iommu_domain *io= _domain, return 0; } =20 -static void ipmmu_detach_device(struct iommu_domain *io_domain, - struct device *dev) -{ - struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); - struct ipmmu_vmsa_domain *domain =3D to_vmsa_domain(io_domain); - unsigned int i; - - for (i =3D 0; i < fwspec->num_ids; ++i) - ipmmu_utlb_disable(domain, fwspec->ids[i]); - - /* - * TODO: Optimize by disabling the context when no device is attached. - */ -} - static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -876,7 +861,6 @@ static const struct iommu_ops ipmmu_ops =3D { .of_xlate =3D ipmmu_of_xlate, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D ipmmu_attach_device, - .detach_dev =3D ipmmu_detach_device, .map_pages =3D ipmmu_map, .unmap_pages =3D ipmmu_unmap, .flush_iotlb_all =3D ipmmu_flush_iotlb_all, diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 2badd6acfb23..d5a4955910ff 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -710,14 +710,6 @@ static int mtk_iommu_attach_device(struct iommu_domain= *domain, return ret; } =20 -static void mtk_iommu_detach_device(struct iommu_domain *domain, - struct device *dev) -{ - struct mtk_iommu_data *data =3D dev_iommu_priv_get(dev); - - mtk_iommu_config(data, dev, false, 0); -} - static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -946,7 +938,6 @@ static const struct iommu_ops mtk_iommu_ops =3D { .owner =3D THIS_MODULE, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D mtk_iommu_attach_device, - .detach_dev =3D mtk_iommu_detach_device, .map_pages =3D mtk_iommu_map, .unmap_pages =3D mtk_iommu_unmap, .flush_iotlb_all =3D mtk_iommu_flush_iotlb_all, diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index a68eadd64f38..f30db22ea5d7 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1192,7 +1192,6 @@ static const struct iommu_ops rk_iommu_ops =3D { .of_xlate =3D rk_iommu_of_xlate, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D rk_iommu_attach_device, - .detach_dev =3D rk_iommu_detach_device, .map =3D rk_iommu_map, .unmap =3D rk_iommu_unmap, .iova_to_phys =3D rk_iommu_iova_to_phys, diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index 219bfa11f7f4..ae94d74b73f4 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -255,21 +255,6 @@ static int sprd_iommu_attach_device(struct iommu_domai= n *domain, return 0; } =20 -static void sprd_iommu_detach_device(struct iommu_domain *domain, - struct device *dev) -{ - struct sprd_iommu_domain *dom =3D to_sprd_domain(domain); - struct sprd_iommu_device *sdev =3D dom->sdev; - size_t pgt_size =3D sprd_iommu_pgt_size(domain); - - if (!sdev) - return; - - dma_free_coherent(sdev->dev, pgt_size, dom->pgt_va, dom->pgt_pa); - sprd_iommu_hw_en(sdev, false); - dom->sdev =3D NULL; -} - static int sprd_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -414,7 +399,6 @@ static const struct iommu_ops sprd_iommu_ops =3D { .owner =3D THIS_MODULE, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D sprd_iommu_attach_device, - .detach_dev =3D sprd_iommu_detach_device, .map_pages =3D sprd_iommu_map, .unmap_pages =3D sprd_iommu_unmap, .iotlb_sync_map =3D sprd_iommu_sync_map, diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 5b585eace3d4..2d993d0cea7d 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -834,7 +834,6 @@ static const struct iommu_ops sun50i_iommu_ops =3D { .probe_device =3D sun50i_iommu_probe_device, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D sun50i_iommu_attach_device, - .detach_dev =3D sun50i_iommu_detach_device, .flush_iotlb_all =3D sun50i_iommu_flush_iotlb_all, .iotlb_sync_map =3D sun50i_iommu_iotlb_sync_map, .iotlb_sync =3D sun50i_iommu_iotlb_sync, --=20 2.34.1 From nobody Mon Sep 15 21:04:15 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F0A7C54EBD for ; Tue, 10 Jan 2023 03:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230272AbjAJDC3 (ORCPT ); Mon, 9 Jan 2023 22:02:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbjAJDCV (ORCPT ); Mon, 9 Jan 2023 22:02:21 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1436101F4 for ; Mon, 9 Jan 2023 19:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673319740; x=1704855740; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2Tijr/4QI/5wm5a8OGrbuYSXtQlU7vZNbvtCrm37JhA=; b=a7iRSMAYGR6w1X1A1mqz00umRy7EKj7+BqztFirhMqJl8K16oxN44pUG 9rEQq1Klj69kFXDKB7KJm7TbEWFDk2+DH6PH7yGHQTja8U57rNXcf0PYv SRH9Qil0cMRCvtDOmikPd/3X+6UxfuzBCX6kzjSNWQmANI9npJpcoOHHB DTHZbpBj02lk2CUftIF+EyRMD8crxXCKWZi0ExroMr1SXJNi2fNjt924L SRSY+wUwHl7OM67IdhmQ8Sbr98xG7ltA4jqYBReVjYux7hyNagC7YKj0N bV1xzmD3gBfz+z8r+1AXuh34odcCTkv3tZ3x2NRqwmyhRdSu1gTRirXYS Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="324289114" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="324289114" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 19:02:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="830841929" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="830841929" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga005.jf.intel.com with ESMTP; 09 Jan 2023 19:02:13 -0800 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Will Deacon , Robin Murphy , Jean-Philippe Brucker Cc: Suravee Suthikulpanit , Vasant Hegde , Hector Martin , Sven Peter , Rob Clark , Marek Szyprowski , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Yong Wu , Matthias Brugger , Heiko Stuebner , Matthew Rosato , Orson Zhai , Baolin Wang , Chunyan Zhang , Chen-Yu Tsai , Thierry Reding , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v5 2/5] iommu: Add set_platform_dma_ops iommu ops Date: Tue, 10 Jan 2023 10:54:05 +0800 Message-Id: <20230110025408.667767-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110025408.667767-1-baolu.lu@linux.intel.com> References: <20230110025408.667767-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When VFIO finishes assigning a device to user space and calls iommu_group_release_dma_owner() to return the device to kernel, the IOMMU core will attach the default domain to the device. Unfortunately, some IOMMU drivers don't support default domain, hence in the end, the core calls .detach_dev instead. This adds set_platform_dma_ops iommu ops to make it clear that what it does is returning control back to the platform DMA ops. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- include/linux/iommu.h | 4 ++++ drivers/iommu/iommu.c | 28 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 46e1347bfa22..7b3e3775b069 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -228,6 +228,9 @@ struct iommu_iotlb_gather { * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IO= MMU * group and attached to the groups domain + * @set_platform_dma_ops: Returning control back to the platform DMA ops. = This op + * is to support old IOMMU drivers, new drivers sho= uld use + * default domains, and the common IOMMU DMA ops. * @device_group: find iommu group for a particular device * @get_resv_regions: Request list of reserved regions for a device * @of_xlate: add OF master IDs to iommu grouping @@ -256,6 +259,7 @@ struct iommu_ops { struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); void (*probe_finalize)(struct device *dev); + void (*set_platform_dma_ops)(struct device *dev); struct iommu_group *(*device_group)(struct device *dev); =20 /* Request/Free a list of reserved regions for a device */ diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index de91dd88705b..1c8b2c7678f7 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2163,6 +2163,16 @@ static int iommu_group_do_detach_device(struct devic= e *dev, void *data) return 0; } =20 +static int iommu_group_do_set_platform_dma(struct device *dev, void *data) +{ + const struct iommu_ops *ops =3D dev_iommu_ops(dev); + + if (!WARN_ON(!ops->set_platform_dma_ops)) + ops->set_platform_dma_ops(dev); + + return 0; +} + static int __iommu_group_set_domain(struct iommu_group *group, struct iommu_domain *new_domain) { @@ -2177,10 +2187,20 @@ static int __iommu_group_set_domain(struct iommu_gr= oup *group, * platform specific behavior. */ if (!new_domain) { - if (WARN_ON(!group->domain->ops->detach_dev)) - return -EINVAL; - __iommu_group_for_each_dev(group, group->domain, - iommu_group_do_detach_device); + struct group_device *grp_dev; + + grp_dev =3D list_first_entry(&group->devices, + struct group_device, list); + + if (dev_iommu_ops(grp_dev->dev)->set_platform_dma_ops) + __iommu_group_for_each_dev(group, NULL, + iommu_group_do_set_platform_dma); + else if (group->domain->ops->detach_dev) + __iommu_group_for_each_dev(group, group->domain, + iommu_group_do_detach_device); + else + WARN_ON_ONCE(1); + group->domain =3D NULL; return 0; } --=20 2.34.1 From nobody Mon Sep 15 21:04:15 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD851C63797 for ; Tue, 10 Jan 2023 03:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235342AbjAJDDB (ORCPT ); Mon, 9 Jan 2023 22:03:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234992AbjAJDCa (ORCPT ); Mon, 9 Jan 2023 22:02:30 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B9C741A7C for ; Mon, 9 Jan 2023 19:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673319748; x=1704855748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nWlE5jqY0RFETPEIbA+ayORhmSr2X7ec+EjS3p4oMbk=; b=mYWTFIgciuA0eySSqfTSy3KH2Q7/SY5v964vvC8uLLyIO1kf1452av7K lgKNR57BBSFCXkSYTW8Z3iFPscNXhRTiwwlzClFThBEytE3UQ0xNbt/nN rYqRbYNz/BKQd9BjyHpQPJImeE/9GVa+UhGGVUORX/2kIJwxOGexpXQ87 R4ybt3uFecJ0CpmexThNVeNbx7uoejNATewZl+eecXdPHNnVsdu6cCJmD dgbXeXgL/2Akjh8HY8o/4yvd112iVkNR5fqO9b2HZ8CY3M4R68nu3P1/c 9A5IDOLviaILigjgKembzvnNTpQtI7Q7yEl7St71bVZstpAuNMy3pMZOZ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="324289147" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="324289147" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 19:02:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="830841954" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="830841954" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga005.jf.intel.com with ESMTP; 09 Jan 2023 19:02:20 -0800 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Will Deacon , Robin Murphy , Jean-Philippe Brucker Cc: Suravee Suthikulpanit , Vasant Hegde , Hector Martin , Sven Peter , Rob Clark , Marek Szyprowski , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Yong Wu , Matthias Brugger , Heiko Stuebner , Matthew Rosato , Orson Zhai , Baolin Wang , Chunyan Zhang , Chen-Yu Tsai , Thierry Reding , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v5 3/5] iommu: Add set_platform_dma_ops callbacks Date: Tue, 10 Jan 2023 10:54:06 +0800 Message-Id: <20230110025408.667767-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110025408.667767-1-baolu.lu@linux.intel.com> References: <20230110025408.667767-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For those IOMMU drivers that don't provide default domain support, add an implementation of set_platform_dma_ops callback so that the IOMMU core could return the DMA control to platform DMA ops. At the same time, with the set_platform_dma_ops implemented, there is no need for detach_dev. Remove it to avoid dead code. Reviewed-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- drivers/iommu/fsl_pamu_domain.c | 6 +++--- drivers/iommu/msm_iommu.c | 6 +++--- drivers/iommu/mtk_iommu_v1.c | 4 ++-- drivers/iommu/omap-iommu.c | 6 +++--- drivers/iommu/s390-iommu.c | 7 ++----- drivers/iommu/tegra-gart.c | 6 +++--- drivers/iommu/tegra-smmu.c | 5 +++-- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domai= n.c index 4408ac3c49b6..e123161c211a 100644 --- a/drivers/iommu/fsl_pamu_domain.c +++ b/drivers/iommu/fsl_pamu_domain.c @@ -283,9 +283,9 @@ static int fsl_pamu_attach_device(struct iommu_domain *= domain, return ret; } =20 -static void fsl_pamu_detach_device(struct iommu_domain *domain, - struct device *dev) +static void fsl_pamu_set_platform_dma(struct device *dev) { + struct iommu_domain *domain =3D iommu_get_domain_for_dev(dev); struct fsl_dma_domain *dma_domain =3D to_fsl_dma_domain(domain); const u32 *prop; int len; @@ -452,9 +452,9 @@ static const struct iommu_ops fsl_pamu_ops =3D { .domain_alloc =3D fsl_pamu_domain_alloc, .probe_device =3D fsl_pamu_probe_device, .device_group =3D fsl_pamu_device_group, + .set_platform_dma_ops =3D fsl_pamu_set_platform_dma; .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D fsl_pamu_attach_device, - .detach_dev =3D fsl_pamu_detach_device, .iova_to_phys =3D fsl_pamu_iova_to_phys, .free =3D fsl_pamu_domain_free, } diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index c60624910872..454f6331c889 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -443,9 +443,9 @@ static int msm_iommu_attach_dev(struct iommu_domain *do= main, struct device *dev) return ret; } =20 -static void msm_iommu_detach_dev(struct iommu_domain *domain, - struct device *dev) +static void msm_iommu_set_platform_dma(struct device *dev) { + struct iommu_domain *domain =3D iommu_get_domain_for_dev(dev); struct msm_priv *priv =3D to_msm_priv(domain); unsigned long flags; struct msm_iommu_dev *iommu; @@ -678,11 +678,11 @@ static struct iommu_ops msm_iommu_ops =3D { .domain_alloc =3D msm_iommu_domain_alloc, .probe_device =3D msm_iommu_probe_device, .device_group =3D generic_device_group, + .set_platform_dma_ops =3D msm_iommu_set_platform_dma, .pgsize_bitmap =3D MSM_IOMMU_PGSIZES, .of_xlate =3D qcom_iommu_of_xlate, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D msm_iommu_attach_dev, - .detach_dev =3D msm_iommu_detach_dev, .map_pages =3D msm_iommu_map, .unmap_pages =3D msm_iommu_unmap, /* diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 69682ee068d2..78d0a84c704f 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -319,7 +319,7 @@ static int mtk_iommu_v1_attach_device(struct iommu_doma= in *domain, struct device return 0; } =20 -static void mtk_iommu_v1_detach_device(struct iommu_domain *domain, struct= device *dev) +static void mtk_iommu_v1_set_platform_dma(struct device *dev) { struct mtk_iommu_v1_data *data =3D dev_iommu_priv_get(dev); =20 @@ -585,10 +585,10 @@ static const struct iommu_ops mtk_iommu_v1_ops =3D { .def_domain_type =3D mtk_iommu_v1_def_domain_type, .device_group =3D generic_device_group, .pgsize_bitmap =3D MT2701_IOMMU_PAGE_SIZE, + .set_platform_dma_ops =3D mtk_iommu_v1_set_platform_dma, .owner =3D THIS_MODULE, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D mtk_iommu_v1_attach_device, - .detach_dev =3D mtk_iommu_v1_detach_device, .map_pages =3D mtk_iommu_v1_map, .unmap_pages =3D mtk_iommu_v1_unmap, .iova_to_phys =3D mtk_iommu_v1_iova_to_phys, diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 2fd7702c6709..3ab078112a7c 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1556,9 +1556,9 @@ static void _omap_iommu_detach_dev(struct omap_iommu_= domain *omap_domain, omap_domain->dev =3D NULL; } =20 -static void omap_iommu_detach_dev(struct iommu_domain *domain, - struct device *dev) +static void omap_iommu_set_platform_dma(struct device *dev) { + struct iommu_domain *domain =3D iommu_get_domain_for_dev(dev); struct omap_iommu_domain *omap_domain =3D to_omap_domain(domain); =20 spin_lock(&omap_domain->lock); @@ -1737,10 +1737,10 @@ static const struct iommu_ops omap_iommu_ops =3D { .probe_device =3D omap_iommu_probe_device, .release_device =3D omap_iommu_release_device, .device_group =3D omap_iommu_device_group, + .set_platform_dma_ops =3D omap_iommu_set_platform_dma, .pgsize_bitmap =3D OMAP_IOMMU_PGSIZES, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D omap_iommu_attach_dev, - .detach_dev =3D omap_iommu_detach_dev, .map =3D omap_iommu_map, .unmap =3D omap_iommu_unmap, .iova_to_phys =3D omap_iommu_iova_to_phys, diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index ed33c6cce083..5591dab99446 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -144,13 +144,10 @@ static int s390_iommu_attach_device(struct iommu_doma= in *domain, return 0; } =20 -static void s390_iommu_detach_device(struct iommu_domain *domain, - struct device *dev) +static void s390_iommu_set_platform_dma(struct device *dev) { struct zpci_dev *zdev =3D to_zpci_dev(dev); =20 - WARN_ON(zdev->s390_domain !=3D to_s390_domain(domain)); - __s390_iommu_detach_device(zdev); zpci_dma_init_device(zdev); } @@ -435,11 +432,11 @@ static const struct iommu_ops s390_iommu_ops =3D { .probe_device =3D s390_iommu_probe_device, .release_device =3D s390_iommu_release_device, .device_group =3D generic_device_group, + .set_platform_dma_ops =3D s390_iommu_set_platform_dma, .pgsize_bitmap =3D SZ_4K, .get_resv_regions =3D s390_iommu_get_resv_regions, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D s390_iommu_attach_device, - .detach_dev =3D s390_iommu_detach_device, .map_pages =3D s390_iommu_map_pages, .unmap_pages =3D s390_iommu_unmap_pages, .flush_iotlb_all =3D s390_iommu_flush_iotlb_all, diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c index ed53279d1106..a482ff838b53 100644 --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -124,9 +124,9 @@ static int gart_iommu_attach_dev(struct iommu_domain *d= omain, return ret; } =20 -static void gart_iommu_detach_dev(struct iommu_domain *domain, - struct device *dev) +static void gart_iommu_set_platform_dma(struct device *dev) { + struct iommu_domain *domain =3D iommu_get_domain_for_dev(dev); struct gart_device *gart =3D gart_handle; =20 spin_lock(&gart->dom_lock); @@ -270,11 +270,11 @@ static const struct iommu_ops gart_iommu_ops =3D { .domain_alloc =3D gart_iommu_domain_alloc, .probe_device =3D gart_iommu_probe_device, .device_group =3D generic_device_group, + .set_platform_dma_ops =3D gart_iommu_set_platform_dma, .pgsize_bitmap =3D GART_IOMMU_PGSIZES, .of_xlate =3D gart_iommu_of_xlate, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D gart_iommu_attach_dev, - .detach_dev =3D gart_iommu_detach_dev, .map =3D gart_iommu_map, .unmap =3D gart_iommu_unmap, .iova_to_phys =3D gart_iommu_iova_to_phys, diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 5b1af40221ec..4c4ac22d5fb1 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -511,8 +511,9 @@ static int tegra_smmu_attach_dev(struct iommu_domain *d= omain, return err; } =20 -static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct devi= ce *dev) +static void tegra_smmu_set_platform_dma(struct device *dev) { + struct iommu_domain *domain =3D iommu_get_domain_for_dev(dev); struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); struct tegra_smmu_as *as =3D to_smmu_as(domain); struct tegra_smmu *smmu =3D as->smmu; @@ -965,11 +966,11 @@ static const struct iommu_ops tegra_smmu_ops =3D { .domain_alloc =3D tegra_smmu_domain_alloc, .probe_device =3D tegra_smmu_probe_device, .device_group =3D tegra_smmu_device_group, + .set_platform_dma_ops =3D tegra_smmu_set_platform_dma, .of_xlate =3D tegra_smmu_of_xlate, .pgsize_bitmap =3D SZ_4K, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D tegra_smmu_attach_dev, - .detach_dev =3D tegra_smmu_detach_dev, .map =3D tegra_smmu_map, .unmap =3D tegra_smmu_unmap, .iova_to_phys =3D tegra_smmu_iova_to_phys, --=20 2.34.1 From nobody Mon Sep 15 21:04:15 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DC04C5479D for ; Tue, 10 Jan 2023 03:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235128AbjAJDC6 (ORCPT ); Mon, 9 Jan 2023 22:02:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235387AbjAJDCg (ORCPT ); Mon, 9 Jan 2023 22:02:36 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D1C341A60 for ; Mon, 9 Jan 2023 19:02:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673319754; x=1704855754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MGY34VxzleiLMnPnhOwpqt2hdjvghotxVYMAmkUOnVs=; b=YgcchBqcc9oPwXfXIeodMWZVi9YzJvYRfzvXWXwVAyNMO6qM6dtasLek G/cBCdPTrOcqnbCmuLP89/6532F6HSGHkBIdVA0x81sFK+qoOcU2bJNN8 fsx2r8r5HAPYQC9lVFEOGVCCT5khTLao7oa1P7/dc94lyT8kgeNDD9/do IeCG3IJ4m7haQGYYk7FMzjawiW23pmpXcBByGpyDNbOQWMC4lKWxp6Ly7 zxuYY5wSeq7WIawf2su5CcsIAQFHF5dgEFfSjTK71bYQqlt6qGAO8WfU9 AqH385dZ723Hz769npLPPBABsFiaHADkdhmnjcgZS3M0NLd5JtefRhWdJ g==; X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="324289174" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="324289174" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 19:02:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="830841972" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="830841972" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga005.jf.intel.com with ESMTP; 09 Jan 2023 19:02:27 -0800 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Will Deacon , Robin Murphy , Jean-Philippe Brucker Cc: Suravee Suthikulpanit , Vasant Hegde , Hector Martin , Sven Peter , Rob Clark , Marek Szyprowski , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Yong Wu , Matthias Brugger , Heiko Stuebner , Matthew Rosato , Orson Zhai , Baolin Wang , Chunyan Zhang , Chen-Yu Tsai , Thierry Reding , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v5 4/5] iommu: Remove deferred attach check from __iommu_detach_device() Date: Tue, 10 Jan 2023 10:54:07 +0800 Message-Id: <20230110025408.667767-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110025408.667767-1-baolu.lu@linux.intel.com> References: <20230110025408.667767-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jason Gunthorpe At the current moment, __iommu_detach_device() is only called via call chains that are after the device driver is attached - eg via explicit attach APIs called by the device driver. Commit bd421264ed30 ("iommu: Fix deferred domain attachment") has removed deferred domain attachment check from __iommu_attach_device() path, so it should just unconditionally work in the __iommu_detach_device() path. It actually looks like a bug that we were blocking detach on these paths since the attach was unconditional and the caller is going to free the (probably) UNAMANGED domain once this returns. The only place we should be testing for deferred attach is during the initial point the dma device is linked to the group, and then again during the dma api calls. Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- include/linux/iommu.h | 2 ++ drivers/iommu/iommu.c | 70 ++++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 7b3e3775b069..0d10566b3cb2 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -405,6 +405,7 @@ struct iommu_fault_param { * @iommu_dev: IOMMU device this device is linked to * @priv: IOMMU Driver private data * @max_pasids: number of PASIDs this device can consume + * @attach_deferred: the dma domain attachment is deferred * * TODO: migrate other per device data pointers under iommu_dev_data, e.g. * struct iommu_group *iommu_group; @@ -417,6 +418,7 @@ struct dev_iommu { struct iommu_device *iommu_dev; void *priv; u32 max_pasids; + u32 attach_deferred:1; }; =20 int iommu_device_register(struct iommu_device *iommu, diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 1c8b2c7678f7..85ae20c8ff5e 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -371,6 +371,30 @@ static int __iommu_probe_device(struct device *dev, st= ruct list_head *group_list return ret; } =20 +static bool iommu_is_attach_deferred(struct device *dev) +{ + const struct iommu_ops *ops =3D dev_iommu_ops(dev); + + if (ops->is_attach_deferred) + return ops->is_attach_deferred(dev); + + return false; +} + +static int iommu_group_do_dma_first_attach(struct device *dev, void *data) +{ + struct iommu_domain *domain =3D data; + + lockdep_assert_held(&dev->iommu_group->mutex); + + if (iommu_is_attach_deferred(dev)) { + dev->iommu->attach_deferred =3D 1; + return 0; + } + + return __iommu_attach_device(domain, dev); +} + int iommu_probe_device(struct device *dev) { const struct iommu_ops *ops; @@ -401,7 +425,7 @@ int iommu_probe_device(struct device *dev) * attach the default domain. */ if (group->default_domain && !group->owner) { - ret =3D __iommu_attach_device(group->default_domain, dev); + ret =3D iommu_group_do_dma_first_attach(dev, group->default_domain); if (ret) { mutex_unlock(&group->mutex); iommu_group_put(group); @@ -947,16 +971,6 @@ static int iommu_create_device_direct_mappings(struct = iommu_group *group, return ret; } =20 -static bool iommu_is_attach_deferred(struct device *dev) -{ - const struct iommu_ops *ops =3D dev_iommu_ops(dev); - - if (ops->is_attach_deferred) - return ops->is_attach_deferred(dev); - - return false; -} - /** * iommu_group_add_device - add a device to an iommu group * @group: the group into which to add the device (reference should be hel= d) @@ -1009,8 +1023,8 @@ int iommu_group_add_device(struct iommu_group *group,= struct device *dev) =20 mutex_lock(&group->mutex); list_add_tail(&device->list, &group->devices); - if (group->domain && !iommu_is_attach_deferred(dev)) - ret =3D __iommu_attach_device(group->domain, dev); + if (group->domain) + ret =3D iommu_group_do_dma_first_attach(dev, group->domain); mutex_unlock(&group->mutex); if (ret) goto err_put_group; @@ -1776,21 +1790,10 @@ static void probe_alloc_default_domain(struct bus_t= ype *bus, =20 } =20 -static int iommu_group_do_dma_attach(struct device *dev, void *data) -{ - struct iommu_domain *domain =3D data; - int ret =3D 0; - - if (!iommu_is_attach_deferred(dev)) - ret =3D __iommu_attach_device(domain, dev); - - return ret; -} - -static int __iommu_group_dma_attach(struct iommu_group *group) +static int __iommu_group_dma_first_attach(struct iommu_group *group) { return __iommu_group_for_each_dev(group, group->default_domain, - iommu_group_do_dma_attach); + iommu_group_do_dma_first_attach); } =20 static int iommu_group_do_probe_finalize(struct device *dev, void *data) @@ -1855,7 +1858,7 @@ int bus_iommu_probe(struct bus_type *bus) =20 iommu_group_create_direct_mappings(group); =20 - ret =3D __iommu_group_dma_attach(group); + ret =3D __iommu_group_dma_first_attach(group); =20 mutex_unlock(&group->mutex); =20 @@ -1987,9 +1990,11 @@ static int __iommu_attach_device(struct iommu_domain= *domain, return -ENODEV; =20 ret =3D domain->ops->attach_dev(domain, dev); - if (!ret) - trace_attach_device_to_domain(dev); - return ret; + if (ret) + return ret; + dev->iommu->attach_deferred =3D 0; + trace_attach_device_to_domain(dev); + return 0; } =20 /** @@ -2034,7 +2039,7 @@ EXPORT_SYMBOL_GPL(iommu_attach_device); =20 int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain) { - if (iommu_is_attach_deferred(dev)) + if (dev->iommu && dev->iommu->attach_deferred) return __iommu_attach_device(domain, dev); =20 return 0; @@ -2043,9 +2048,6 @@ int iommu_deferred_attach(struct device *dev, struct = iommu_domain *domain) static void __iommu_detach_device(struct iommu_domain *domain, struct device *dev) { - if (iommu_is_attach_deferred(dev)) - return; - domain->ops->detach_dev(domain, dev); trace_detach_device_from_domain(dev); } --=20 2.34.1 From nobody Mon Sep 15 21:04:15 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71F1CC54EBD for ; Tue, 10 Jan 2023 03:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234368AbjAJDCz (ORCPT ); Mon, 9 Jan 2023 22:02:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235803AbjAJDCm (ORCPT ); Mon, 9 Jan 2023 22:02:42 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F2A10FEE for ; Mon, 9 Jan 2023 19:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673319761; x=1704855761; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UR5WZP9Av4XTBD2BfO5VWRKQ4DlrRvmKTgHn9rKCd1w=; b=FmfvwiOYYvRjGJMu/hFxksfuFnyc1bYd3zR90v883gvCs2NwQz88JS00 mi/8jumfOflCfyJ6NwbMf4fIqj1RYNyOTc1hX3cnk5W+UKo1zn+3S4Nky EPEEWM5Hic7VE0kLRWHns3jtkxjFLTP+vYDHsAJnt87ZoOwiW3Z8g9MMZ VL+/2Ha4qOwzyoX/0JLCZA6OFrOlFYTdLqmgfAiVX6ybv/ZuCk0Hs6PWV kpdE1+TFeR6JXXBJiOoCEX53o3d4UzjCqXvq9dl948W84bL7x5S7pbNMU TNfv+uG6ALuv4uvPUH9hT0Q69IpmQ+dWVJSgnjpW1Jp3OhNXoXfjKIMB+ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="324289201" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="324289201" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2023 19:02:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10585"; a="830842002" X-IronPort-AV: E=Sophos;i="5.96,313,1665471600"; d="scan'208";a="830842002" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga005.jf.intel.com with ESMTP; 09 Jan 2023 19:02:33 -0800 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Will Deacon , Robin Murphy , Jean-Philippe Brucker Cc: Suravee Suthikulpanit , Vasant Hegde , Hector Martin , Sven Peter , Rob Clark , Marek Szyprowski , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Yong Wu , Matthias Brugger , Heiko Stuebner , Matthew Rosato , Orson Zhai , Baolin Wang , Chunyan Zhang , Chen-Yu Tsai , Thierry Reding , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v5 5/5] iommu: Remove detach_dev callback Date: Tue, 10 Jan 2023 10:54:08 +0800 Message-Id: <20230110025408.667767-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110025408.667767-1-baolu.lu@linux.intel.com> References: <20230110025408.667767-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The detach_dev callback of domain ops is not called in the IOMMU core. Remove this callback to avoid dead code. The trace event for detaching domain from device is removed accordingly. Reviewed-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- include/linux/iommu.h | 2 -- include/trace/events/iommu.h | 7 ------- drivers/iommu/iommu-traces.c | 1 - drivers/iommu/iommu.c | 36 ++++-------------------------------- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 0d10566b3cb2..a8063f26ff69 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -299,7 +299,6 @@ struct iommu_ops { * * EBUSY - device is attached to a domain and cannot be changed * * ENODEV - device specific errors, not able to be attached * * - treated as ENODEV by the caller. Use is discouraged - * @detach_dev: detach an iommu domain from a device * @set_dev_pasid: set an iommu domain to a pasid of device * @map: map a physically contiguous memory region to an iommu domain * @map_pages: map a physically contiguous set of pages of the same size to @@ -320,7 +319,6 @@ struct iommu_ops { */ struct iommu_domain_ops { int (*attach_dev)(struct iommu_domain *domain, struct device *dev); - void (*detach_dev)(struct iommu_domain *domain, struct device *dev); int (*set_dev_pasid)(struct iommu_domain *domain, struct device *dev, ioasid_t pasid); =20 diff --git a/include/trace/events/iommu.h b/include/trace/events/iommu.h index 29096fe12623..70743db1fb75 100644 --- a/include/trace/events/iommu.h +++ b/include/trace/events/iommu.h @@ -76,13 +76,6 @@ DEFINE_EVENT(iommu_device_event, attach_device_to_domain, TP_ARGS(dev) ); =20 -DEFINE_EVENT(iommu_device_event, detach_device_from_domain, - - TP_PROTO(struct device *dev), - - TP_ARGS(dev) -); - TRACE_EVENT(map, =20 TP_PROTO(unsigned long iova, phys_addr_t paddr, size_t size), diff --git a/drivers/iommu/iommu-traces.c b/drivers/iommu/iommu-traces.c index 1e9ca7789de1..23416bf76df9 100644 --- a/drivers/iommu/iommu-traces.c +++ b/drivers/iommu/iommu-traces.c @@ -18,7 +18,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(remove_device_from_group); =20 /* iommu_device_event */ EXPORT_TRACEPOINT_SYMBOL_GPL(attach_device_to_domain); -EXPORT_TRACEPOINT_SYMBOL_GPL(detach_device_from_domain); =20 /* iommu_map_unmap */ EXPORT_TRACEPOINT_SYMBOL_GPL(map); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 85ae20c8ff5e..9135540d7d59 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2045,13 +2045,6 @@ int iommu_deferred_attach(struct device *dev, struct= iommu_domain *domain) return 0; } =20 -static void __iommu_detach_device(struct iommu_domain *domain, - struct device *dev) -{ - domain->ops->detach_dev(domain, dev); - trace_detach_device_from_domain(dev); -} - void iommu_detach_device(struct iommu_domain *domain, struct device *dev) { struct iommu_group *group; @@ -2156,15 +2149,6 @@ int iommu_attach_group(struct iommu_domain *domain, = struct iommu_group *group) } EXPORT_SYMBOL_GPL(iommu_attach_group); =20 -static int iommu_group_do_detach_device(struct device *dev, void *data) -{ - struct iommu_domain *domain =3D data; - - __iommu_detach_device(domain, dev); - - return 0; -} - static int iommu_group_do_set_platform_dma(struct device *dev, void *data) { const struct iommu_ops *ops =3D dev_iommu_ops(dev); @@ -2184,25 +2168,13 @@ static int __iommu_group_set_domain(struct iommu_gr= oup *group, return 0; =20 /* - * New drivers should support default domains and so the detach_dev() op - * will never be called. Otherwise the NULL domain represents some + * New drivers should support default domains, so set_platform_dma() + * op will never be called. Otherwise the NULL domain represents some * platform specific behavior. */ if (!new_domain) { - struct group_device *grp_dev; - - grp_dev =3D list_first_entry(&group->devices, - struct group_device, list); - - if (dev_iommu_ops(grp_dev->dev)->set_platform_dma_ops) - __iommu_group_for_each_dev(group, NULL, - iommu_group_do_set_platform_dma); - else if (group->domain->ops->detach_dev) - __iommu_group_for_each_dev(group, group->domain, - iommu_group_do_detach_device); - else - WARN_ON_ONCE(1); - + __iommu_group_for_each_dev(group, NULL, + iommu_group_do_set_platform_dma); group->domain =3D NULL; return 0; } --=20 2.34.1