]> Git Repo - linux.git/blobdiff - drivers/iommu/dma-iommu.c
Merge tag 'dma-mapping-5.20-2022-08-06' of git://git.infradead.org/users/hch/dma...
[linux.git] / drivers / iommu / dma-iommu.c
index 8a0d16d320efcda0ae0e9d56c460cbcd08df2492..376c4e3ae0e63ed50ea3150b8a72fab537b1b718 100644 (file)
@@ -65,10 +65,11 @@ struct iommu_dma_cookie {
 
        /* Domain for flush queue callback; NULL if flush queue not in use */
        struct iommu_domain             *fq_domain;
+       struct mutex                    mutex;
 };
 
 static DEFINE_STATIC_KEY_FALSE(iommu_deferred_attach_enabled);
-bool iommu_dma_forcedac __read_mostly;
+bool iommu_dma_forcedac __read_mostly = !IS_ENABLED(CONFIG_IOMMU_DMA_PCI_SAC);
 
 static int __init iommu_dma_forcedac_setup(char *str)
 {
@@ -311,6 +312,7 @@ int iommu_get_dma_cookie(struct iommu_domain *domain)
        if (!domain->iova_cookie)
                return -ENOMEM;
 
+       mutex_init(&domain->iova_cookie->mutex);
        return 0;
 }
 
@@ -386,7 +388,7 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
 {
 
        if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode))
-               iort_iommu_msi_get_resv_regions(dev, list);
+               iort_iommu_get_resv_regions(dev, list);
 
 }
 EXPORT_SYMBOL(iommu_dma_get_resv_regions);
@@ -561,26 +563,33 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
        }
 
        /* start_pfn is always nonzero for an already-initialised domain */
+       mutex_lock(&cookie->mutex);
        if (iovad->start_pfn) {
                if (1UL << order != iovad->granule ||
                    base_pfn != iovad->start_pfn) {
                        pr_warn("Incompatible range for DMA domain\n");
-                       return -EFAULT;
+                       ret = -EFAULT;
+                       goto done_unlock;
                }
 
-               return 0;
+               ret = 0;
+               goto done_unlock;
        }
 
        init_iova_domain(iovad, 1UL << order, base_pfn);
        ret = iova_domain_init_rcaches(iovad);
        if (ret)
-               return ret;
+               goto done_unlock;
 
        /* If the FQ fails we can simply fall back to strict mode */
        if (domain->type == IOMMU_DOMAIN_DMA_FQ && iommu_dma_init_fq(domain))
                domain->type = IOMMU_DOMAIN_DMA;
 
-       return iova_reserve_iommu_regions(dev, domain);
+       ret = iova_reserve_iommu_regions(dev, domain);
+
+done_unlock:
+       mutex_unlock(&cookie->mutex);
+       return ret;
 }
 
 /**
This page took 0.035848 seconds and 4 git commands to generate.