iommu: Streamline iommu_iova_to_phys()
authorRobin Murphy <robin.murphy@arm.com>
Thu, 15 Jul 2021 13:04:24 +0000 (14:04 +0100)
committerJoerg Roedel <jroedel@suse.de>
Mon, 26 Jul 2021 11:37:51 +0000 (13:37 +0200)
If people are going to insist on calling iommu_iova_to_phys()
pointlessly and expecting it to work, we can at least do ourselves a
favour by handling those cases in the core code, rather than repeatedly
across an inconsistent handful of drivers.

Since all the existing drivers implement the internal callback, and any
future ones are likely to want to work with iommu-dma which relies on
iova_to_phys a fair bit, we may as well remove that currently-redundant
check as well and consider it mandatory.

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/f564f3f6ff731b898ff7a898919bf871c2c7745a.1626354264.git.robin.murphy@arm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/io_pgtable.c
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
drivers/iommu/arm/arm-smmu/arm-smmu.c
drivers/iommu/iommu.c

index bb0ee5c9fde7cf61ecc6f0c45a74c5aa46e2b8f2..182c93a43efd85a825faf6f6c548715998afe016 100644 (file)
@@ -493,9 +493,6 @@ static phys_addr_t iommu_v1_iova_to_phys(struct io_pgtable_ops *ops, unsigned lo
        unsigned long offset_mask, pte_pgsize;
        u64 *pte, __pte;
 
-       if (pgtable->mode == PAGE_MODE_NONE)
-               return iova;
-
        pte = fetch_pte(pgtable, iova, &pte_pgsize);
 
        if (!pte || !IOMMU_PTE_PRESENT(*pte))
index 235f9bdaeaf223ba5086da2a00b40214426d5708..6346f21726f40c8aed057c55885ca17ec626d5d4 100644 (file)
@@ -2488,9 +2488,6 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
 {
        struct io_pgtable_ops *ops = to_smmu_domain(domain)->pgtbl_ops;
 
-       if (domain->type == IOMMU_DOMAIN_IDENTITY)
-               return iova;
-
        if (!ops)
                return 0;
 
index 5ed4408d4b28905815f21d7ec8362c3142f9449d..ac21170fa2084efa4b71c283427243e9449313b9 100644 (file)
@@ -1322,9 +1322,6 @@ static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
        struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
        struct io_pgtable_ops *ops = smmu_domain->pgtbl_ops;
 
-       if (domain->type == IOMMU_DOMAIN_IDENTITY)
-               return iova;
-
        if (!ops)
                return 0;
 
index eeea5e5c4d102919608efcbe9a22ebb4db278b78..f2cda9950bd5d987f647c75f302680ebd8ce92b5 100644 (file)
@@ -2372,7 +2372,10 @@ EXPORT_SYMBOL_GPL(iommu_detach_group);
 
 phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
 {
-       if (unlikely(domain->ops->iova_to_phys == NULL))
+       if (domain->type == IOMMU_DOMAIN_IDENTITY)
+               return iova;
+
+       if (domain->type == IOMMU_DOMAIN_BLOCKED)
                return 0;
 
        return domain->ops->iova_to_phys(domain, iova);