iommu: Remove detach_dev callbacks
authorLu Baolu <baolu.lu@linux.intel.com>
Tue, 10 Jan 2023 02:54:04 +0000 (10:54 +0800)
committerJoerg Roedel <jroedel@suse.de>
Fri, 13 Jan 2023 15:39:14 +0000 (16:39 +0100)
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 <jgg@nvidia.com>
Reviewed-by: Sven Peter <sven@svenpeter.dev> # apple-dart
Acked-by: Chunyan Zhang <zhang.lyra@gmail.com> # sprd
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> # amd
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20230110025408.667767-2-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/iommu.c
drivers/iommu/apple-dart.c
drivers/iommu/arm/arm-smmu/qcom_iommu.c
drivers/iommu/exynos-iommu.c
drivers/iommu/ipmmu-vmsa.c
drivers/iommu/mtk_iommu.c
drivers/iommu/rockchip-iommu.c
drivers/iommu/sprd-iommu.c
drivers/iommu/sun50i-iommu.c

index cbeaab55c0dbccb3e3c4e0ad86839f6cd52a137d..92319c9b877c443b04d486d971a461358325389c 100644 (file)
@@ -2126,31 +2126,6 @@ static void amd_iommu_domain_free(struct iommu_domain *dom)
        protection_domain_free(domain);
 }
 
-static void amd_iommu_detach_device(struct iommu_domain *dom,
-                                   struct device *dev)
-{
-       struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
-       struct amd_iommu *iommu;
-
-       if (!check_device(dev))
-               return;
-
-       if (dev_data->domain != NULL)
-               detach_device(dev);
-
-       iommu = rlookup_amd_iommu(dev);
-       if (!iommu)
-               return;
-
-#ifdef CONFIG_IRQ_REMAP
-       if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) &&
-           (dom->type == IOMMU_DOMAIN_UNMANAGED))
-               dev_data->use_vapic = 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 = {
        .def_domain_type = amd_iommu_def_domain_type,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = amd_iommu_attach_device,
-               .detach_dev     = amd_iommu_detach_device,
                .map_pages      = amd_iommu_map_pages,
                .unmap_pages    = amd_iommu_unmap_pages,
                .iotlb_sync_map = amd_iommu_iotlb_sync_map,
index 4f4a323be0d0ffd5279d814c746f4cb3a432d73d..96843d4688012a38352511893820d1f31294d5a6 100644 (file)
@@ -486,13 +486,6 @@ static int apple_dart_domain_add_streams(struct apple_dart_domain *domain,
                                      true);
 }
 
-static int apple_dart_domain_remove_streams(struct apple_dart_domain *domain,
-                                           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;
 }
 
-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 = dev_iommu_priv_get(dev);
-       struct apple_dart_domain *dart_domain = to_dart_domain(domain);
-
-       for_each_stream_map(i, cfg, stream_map)
-               apple_dart_hw_disable_dma(stream_map);
-
-       if (domain->type == IOMMU_DOMAIN_DMA ||
-           domain->type == 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 = dev_iommu_priv_get(dev);
@@ -780,7 +757,6 @@ static const struct iommu_ops apple_dart_iommu_ops = {
        .owner = THIS_MODULE,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = apple_dart_attach_dev,
-               .detach_dev     = apple_dart_detach_dev,
                .map_pages      = apple_dart_map_pages,
                .unmap_pages    = apple_dart_unmap_pages,
                .flush_iotlb_all = apple_dart_flush_iotlb_all,
index 270c3d9128bab874585f9e90a46ad09c524acc41..d7be3adee426d73d09ca520b87220e992dcafc93 100644 (file)
@@ -387,28 +387,6 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
        return 0;
 }
 
-static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct device *dev)
-{
-       struct qcom_iommu_domain *qcom_domain = to_qcom_iommu_domain(domain);
-       struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
-       struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
-       unsigned i;
-
-       if (WARN_ON(!qcom_domain->iommu))
-               return;
-
-       pm_runtime_get_sync(qcom_iommu->dev);
-       for (i = 0; i < fwspec->num_ids; i++) {
-               struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
-
-               /* Disable the context bank: */
-               iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
-
-               ctx->domain = 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 = {
        .pgsize_bitmap  = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = qcom_iommu_attach_dev,
-               .detach_dev     = qcom_iommu_detach_dev,
                .map_pages      = qcom_iommu_map,
                .unmap_pages    = qcom_iommu_unmap,
                .flush_iotlb_all = qcom_iommu_flush_iotlb_all,
index b0cde22119875eadcfb36cbc637d2a48133a70b6..29ec713e8a210586dda8d52ec009904880b50b1f 100644 (file)
@@ -1404,7 +1404,6 @@ static const struct iommu_ops exynos_iommu_ops = {
        .of_xlate = exynos_iommu_of_xlate,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = exynos_iommu_attach_device,
-               .detach_dev     = exynos_iommu_detach_device,
                .map            = exynos_iommu_map,
                .unmap          = exynos_iommu_unmap,
                .iova_to_phys   = exynos_iommu_iova_to_phys,
index a003bd5fc65c135a7a358e0553af0db8adab7652..3112822ac7be83437d155d05fb40fd3dc0d6de16 100644 (file)
@@ -643,21 +643,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
        return 0;
 }
 
-static void ipmmu_detach_device(struct iommu_domain *io_domain,
-                               struct device *dev)
-{
-       struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
-       struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain);
-       unsigned int i;
-
-       for (i = 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 = {
        .of_xlate = ipmmu_of_xlate,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = ipmmu_attach_device,
-               .detach_dev     = ipmmu_detach_device,
                .map_pages      = ipmmu_map,
                .unmap_pages    = ipmmu_unmap,
                .flush_iotlb_all = ipmmu_flush_iotlb_all,
index 2badd6acfb23d68f0fc0656b75f18c85cb910ca4..d5a4955910ff51acac5c8cb2fcf52bd08923a891 100644 (file)
@@ -710,14 +710,6 @@ err_unlock:
        return ret;
 }
 
-static void mtk_iommu_detach_device(struct iommu_domain *domain,
-                                   struct device *dev)
-{
-       struct mtk_iommu_data *data = 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 = {
        .owner          = THIS_MODULE,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = mtk_iommu_attach_device,
-               .detach_dev     = mtk_iommu_detach_device,
                .map_pages      = mtk_iommu_map,
                .unmap_pages    = mtk_iommu_unmap,
                .flush_iotlb_all = mtk_iommu_flush_iotlb_all,
index a68eadd64f38db5fd2401164456d0a55c9750f02..f30db22ea5d7a72906c5a5f41ab233df791e9ce2 100644 (file)
@@ -1192,7 +1192,6 @@ static const struct iommu_ops rk_iommu_ops = {
        .of_xlate = rk_iommu_of_xlate,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = rk_iommu_attach_device,
-               .detach_dev     = rk_iommu_detach_device,
                .map            = rk_iommu_map,
                .unmap          = rk_iommu_unmap,
                .iova_to_phys   = rk_iommu_iova_to_phys,
index 219bfa11f7f48fbb6444c60a00761f28204f25b8..ae94d74b73f46f369b54a15c053305d4aa1f781b 100644 (file)
@@ -255,21 +255,6 @@ static int sprd_iommu_attach_device(struct iommu_domain *domain,
        return 0;
 }
 
-static void sprd_iommu_detach_device(struct iommu_domain *domain,
-                                            struct device *dev)
-{
-       struct sprd_iommu_domain *dom = to_sprd_domain(domain);
-       struct sprd_iommu_device *sdev = dom->sdev;
-       size_t pgt_size = 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 = 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 = {
        .owner          = THIS_MODULE,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = sprd_iommu_attach_device,
-               .detach_dev     = sprd_iommu_detach_device,
                .map_pages      = sprd_iommu_map,
                .unmap_pages    = sprd_iommu_unmap,
                .iotlb_sync_map = sprd_iommu_sync_map,
index 5b585eace3d46f8381e4feda764e0804064ece5f..2d993d0cea7d00ca81566676c7506c8c50bbb413 100644 (file)
@@ -834,7 +834,6 @@ static const struct iommu_ops sun50i_iommu_ops = {
        .probe_device   = sun50i_iommu_probe_device,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = sun50i_iommu_attach_device,
-               .detach_dev     = sun50i_iommu_detach_device,
                .flush_iotlb_all = sun50i_iommu_flush_iotlb_all,
                .iotlb_sync_map = sun50i_iommu_iotlb_sync_map,
                .iotlb_sync     = sun50i_iommu_iotlb_sync,