Skip to content

Commit cb94843

Browse files
jgunthorpemarcan
authored andcommitted
iommu: Mark dev_iommu_priv_set() with a lockdep
A perfect driver would only call dev_iommu_priv_set() from its probe callback. We've made it functionally correct to call it from the of_xlate by adding a lock around that call. lockdep assert that iommu_probe_device_lock is held to discourage misuse. Exclude PPC kernels with CONFIG_FSL_PAMU turned on because FSL_PAMU uses a global static for its priv and abuses priv for its domain. Remove the pointless stores of NULL, all these are on paths where the core code will free dev->iommu after the op returns. Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 6f5cbd3 commit cb94843

8 files changed

Lines changed: 10 additions & 12 deletions

File tree

drivers/iommu/amd/iommu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,6 @@ static void amd_iommu_uninit_device(struct device *dev)
436436
if (dev_data->domain)
437437
detach_device(dev);
438438

439-
dev_iommu_priv_set(dev, NULL);
440-
441439
/*
442440
* We keep dev_data around for unplugged devices and reuse it when the
443441
* device is re-plugged - not doing so would introduce a ton of races.

drivers/iommu/apple-dart.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ static void apple_dart_release_device(struct device *dev)
713713
{
714714
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
715715

716-
dev_iommu_priv_set(dev, NULL);
717716
kfree(cfg);
718717
}
719718

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
27072707

27082708
err_free_master:
27092709
kfree(master);
2710-
dev_iommu_priv_set(dev, NULL);
27112710
return ERR_PTR(ret);
27122711
}
27132712

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,6 @@ static void arm_smmu_release_device(struct device *dev)
14231423

14241424
arm_smmu_rpm_put(cfg->smmu);
14251425

1426-
dev_iommu_priv_set(dev, NULL);
14271426
kfree(cfg);
14281427
}
14291428

drivers/iommu/intel/iommu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,7 +4403,6 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
44034403
ret = intel_pasid_alloc_table(dev);
44044404
if (ret) {
44054405
dev_err(dev, "PASID table allocation failed\n");
4406-
dev_iommu_priv_set(dev, NULL);
44074406
kfree(info);
44084407
return ERR_PTR(ret);
44094408
}
@@ -4418,7 +4417,6 @@ static void intel_iommu_release_device(struct device *dev)
44184417

44194418
dmar_remove_one_dev_info(dev);
44204419
intel_pasid_free_table(dev);
4421-
dev_iommu_priv_set(dev, NULL);
44224420
kfree(info);
44234421
set_dma_ops(dev, NULL);
44244422
}

drivers/iommu/iommu.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ static u32 dev_iommu_get_max_pasids(struct device *dev)
382382
return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids);
383383
}
384384

385+
void dev_iommu_priv_set(struct device *dev, void *priv)
386+
{
387+
/* FSL_PAMU does something weird */
388+
if (!IS_ENABLED(CONFIG_FSL_PAMU))
389+
lockdep_assert_held(&iommu_probe_device_lock);
390+
dev->iommu->priv = priv;
391+
}
392+
EXPORT_SYMBOL_GPL(dev_iommu_priv_set);
393+
385394
/*
386395
* Init the dev->iommu and dev->iommu_group in the struct device and get the
387396
* driver probed. Take ownership of fwspec, it always freed on error

drivers/iommu/omap-iommu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,6 @@ static void omap_iommu_release_device(struct device *dev)
17121712
if (!dev->of_node || !arch_data)
17131713
return;
17141714

1715-
dev_iommu_priv_set(dev, NULL);
17161715
kfree(arch_data);
17171716

17181717
}

include/linux/iommu.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,7 @@ static inline void *dev_iommu_priv_get(struct device *dev)
710710
return NULL;
711711
}
712712

713-
static inline void dev_iommu_priv_set(struct device *dev, void *priv)
714-
{
715-
dev->iommu->priv = priv;
716-
}
713+
void dev_iommu_priv_set(struct device *dev, void *priv);
717714

718715
int iommu_probe_device_fwspec(struct device *dev, struct iommu_fwspec *fwspec);
719716
static inline int iommu_probe_device(struct device *dev)

0 commit comments

Comments
 (0)