Skip to content

Commit 319720f

Browse files
committed
Merge tag 'iommu-fixes-for-v3.13-rc4' of git://github.com/awilliam/linux-vfio
Pull iommu fixes from Alex Williamson: "arm/smmu driver updates via Will Deacon fixing locking around page table walks and a couple other issues" * tag 'iommu-fixes-for-v3.13-rc4' of git://github.com/awilliam/linux-vfio: iommu/arm-smmu: fix error return code in arm_smmu_device_dt_probe() iommu/arm-smmu: remove potential NULL dereference on mapping path iommu/arm-smmu: use mutex instead of spinlock for locking page tables
2 parents 5dec682 + 239a870 commit 319720f

1 file changed

Lines changed: 28 additions & 38 deletions

File tree

‎drivers/iommu/arm-smmu.c‎

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ struct arm_smmu_domain {
392392
struct arm_smmu_cfg root_cfg;
393393
phys_addr_t output_mask;
394394

395-
spinlock_t lock;
395+
struct mutex lock;
396396
};
397397

398398
static DEFINE_SPINLOCK(arm_smmu_devices_lock);
@@ -900,7 +900,7 @@ static int arm_smmu_domain_init(struct iommu_domain *domain)
900900
goto out_free_domain;
901901
smmu_domain->root_cfg.pgd = pgd;
902902

903-
spin_lock_init(&smmu_domain->lock);
903+
mutex_init(&smmu_domain->lock);
904904
domain->priv = smmu_domain;
905905
return 0;
906906

@@ -1137,7 +1137,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11371137
* Sanity check the domain. We don't currently support domains
11381138
* that cross between different SMMU chains.
11391139
*/
1140-
spin_lock(&smmu_domain->lock);
1140+
mutex_lock(&smmu_domain->lock);
11411141
if (!smmu_domain->leaf_smmu) {
11421142
/* Now that we have a master, we can finalise the domain */
11431143
ret = arm_smmu_init_domain_context(domain, dev);
@@ -1152,7 +1152,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11521152
dev_name(device_smmu->dev));
11531153
goto err_unlock;
11541154
}
1155-
spin_unlock(&smmu_domain->lock);
1155+
mutex_unlock(&smmu_domain->lock);
11561156

11571157
/* Looks ok, so add the device to the domain */
11581158
master = find_smmu_master(smmu_domain->leaf_smmu, dev->of_node);
@@ -1162,7 +1162,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11621162
return arm_smmu_domain_add_master(smmu_domain, master);
11631163

11641164
err_unlock:
1165-
spin_unlock(&smmu_domain->lock);
1165+
mutex_unlock(&smmu_domain->lock);
11661166
return ret;
11671167
}
11681168

@@ -1394,7 +1394,7 @@ static int arm_smmu_handle_mapping(struct arm_smmu_domain *smmu_domain,
13941394
if (paddr & ~output_mask)
13951395
return -ERANGE;
13961396

1397-
spin_lock(&smmu_domain->lock);
1397+
mutex_lock(&smmu_domain->lock);
13981398
pgd += pgd_index(iova);
13991399
end = iova + size;
14001400
do {
@@ -1410,7 +1410,7 @@ static int arm_smmu_handle_mapping(struct arm_smmu_domain *smmu_domain,
14101410
} while (pgd++, iova != end);
14111411

14121412
out_unlock:
1413-
spin_unlock(&smmu_domain->lock);
1413+
mutex_unlock(&smmu_domain->lock);
14141414

14151415
/* Ensure new page tables are visible to the hardware walker */
14161416
if (smmu->features & ARM_SMMU_FEAT_COHERENT_WALK)
@@ -1423,9 +1423,8 @@ static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova,
14231423
phys_addr_t paddr, size_t size, int flags)
14241424
{
14251425
struct arm_smmu_domain *smmu_domain = domain->priv;
1426-
struct arm_smmu_device *smmu = smmu_domain->leaf_smmu;
14271426

1428-
if (!smmu_domain || !smmu)
1427+
if (!smmu_domain)
14291428
return -ENODEV;
14301429

14311430
/* Check for silent address truncation up the SMMU chain. */
@@ -1449,44 +1448,34 @@ static size_t arm_smmu_unmap(struct iommu_domain *domain, unsigned long iova,
14491448
static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
14501449
dma_addr_t iova)
14511450
{
1452-
pgd_t *pgd;
1453-
pud_t *pud;
1454-
pmd_t *pmd;
1455-
pte_t *pte;
1451+
pgd_t *pgdp, pgd;
1452+
pud_t pud;
1453+
pmd_t pmd;
1454+
pte_t pte;
14561455
struct arm_smmu_domain *smmu_domain = domain->priv;
14571456
struct arm_smmu_cfg *root_cfg = &smmu_domain->root_cfg;
1458-
struct arm_smmu_device *smmu = root_cfg->smmu;
14591457

1460-
spin_lock(&smmu_domain->lock);
1461-
pgd = root_cfg->pgd;
1462-
if (!pgd)
1463-
goto err_unlock;
1458+
pgdp = root_cfg->pgd;
1459+
if (!pgdp)
1460+
return 0;
14641461

1465-
pgd += pgd_index(iova);
1466-
if (pgd_none_or_clear_bad(pgd))
1467-
goto err_unlock;
1462+
pgd = *(pgdp + pgd_index(iova));
1463+
if (pgd_none(pgd))
1464+
return 0;
14681465

1469-
pud = pud_offset(pgd, iova);
1470-
if (pud_none_or_clear_bad(pud))
1471-
goto err_unlock;
1466+
pud = *pud_offset(&pgd, iova);
1467+
if (pud_none(pud))
1468+
return 0;
14721469

1473-
pmd = pmd_offset(pud, iova);
1474-
if (pmd_none_or_clear_bad(pmd))
1475-
goto err_unlock;
1470+
pmd = *pmd_offset(&pud, iova);
1471+
if (pmd_none(pmd))
1472+
return 0;
14761473

1477-
pte = pmd_page_vaddr(*pmd) + pte_index(iova);
1474+
pte = *(pmd_page_vaddr(pmd) + pte_index(iova));
14781475
if (pte_none(pte))
1479-
goto err_unlock;
1480-
1481-
spin_unlock(&smmu_domain->lock);
1482-
return __pfn_to_phys(pte_pfn(*pte)) | (iova & ~PAGE_MASK);
1476+
return 0;
14831477

1484-
err_unlock:
1485-
spin_unlock(&smmu_domain->lock);
1486-
dev_warn(smmu->dev,
1487-
"invalid (corrupt?) page tables detected for iova 0x%llx\n",
1488-
(unsigned long long)iova);
1489-
return -EINVAL;
1478+
return __pfn_to_phys(pte_pfn(pte)) | (iova & ~PAGE_MASK);
14901479
}
14911480

14921481
static int arm_smmu_domain_has_cap(struct iommu_domain *domain,
@@ -1863,6 +1852,7 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
18631852
dev_err(dev,
18641853
"found only %d context interrupt(s) but %d required\n",
18651854
smmu->num_context_irqs, smmu->num_context_banks);
1855+
err = -ENODEV;
18661856
goto out_put_parent;
18671857
}
18681858

0 commit comments

Comments
 (0)