1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

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>
Tested-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/5-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
Jason Gunthorpe 2023-12-07 14:03:12 -04:00 committed by Joerg Roedel
parent 64945d1b0e
commit eda1a94caf
8 changed files with 10 additions and 12 deletions

View file

@ -551,8 +551,6 @@ static void amd_iommu_uninit_device(struct device *dev)
if (dev_data->domain) if (dev_data->domain)
detach_device(dev); detach_device(dev);
dev_iommu_priv_set(dev, NULL);
/* /*
* We keep dev_data around for unplugged devices and reuse it when the * We keep dev_data around for unplugged devices and reuse it when the
* device is re-plugged - not doing so would introduce a ton of races. * device is re-plugged - not doing so would introduce a ton of races.

View file

@ -740,7 +740,6 @@ static void apple_dart_release_device(struct device *dev)
{ {
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev); struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
dev_iommu_priv_set(dev, NULL);
kfree(cfg); kfree(cfg);
} }

View file

@ -2695,7 +2695,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
err_free_master: err_free_master:
kfree(master); kfree(master);
dev_iommu_priv_set(dev, NULL);
return ERR_PTR(ret); return ERR_PTR(ret);
} }

View file

@ -1420,7 +1420,6 @@ static void arm_smmu_release_device(struct device *dev)
arm_smmu_rpm_put(cfg->smmu); arm_smmu_rpm_put(cfg->smmu);
dev_iommu_priv_set(dev, NULL);
kfree(cfg); kfree(cfg);
} }

View file

@ -4461,7 +4461,6 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
ret = intel_pasid_alloc_table(dev); ret = intel_pasid_alloc_table(dev);
if (ret) { if (ret) {
dev_err(dev, "PASID table allocation failed\n"); dev_err(dev, "PASID table allocation failed\n");
dev_iommu_priv_set(dev, NULL);
kfree(info); kfree(info);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
@ -4479,7 +4478,6 @@ static void intel_iommu_release_device(struct device *dev)
dmar_remove_one_dev_info(dev); dmar_remove_one_dev_info(dev);
intel_pasid_free_table(dev); intel_pasid_free_table(dev);
intel_iommu_debugfs_remove_dev(info); intel_iommu_debugfs_remove_dev(info);
dev_iommu_priv_set(dev, NULL);
kfree(info); kfree(info);
set_dma_ops(dev, NULL); set_dma_ops(dev, NULL);
} }

View file

@ -387,6 +387,15 @@ static u32 dev_iommu_get_max_pasids(struct device *dev)
return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids); return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids);
} }
void dev_iommu_priv_set(struct device *dev, void *priv)
{
/* FSL_PAMU does something weird */
if (!IS_ENABLED(CONFIG_FSL_PAMU))
lockdep_assert_held(&iommu_probe_device_lock);
dev->iommu->priv = priv;
}
EXPORT_SYMBOL_GPL(dev_iommu_priv_set);
/* /*
* Init the dev->iommu and dev->iommu_group in the struct device and get the * Init the dev->iommu and dev->iommu_group in the struct device and get the
* driver probed * driver probed

View file

@ -1719,7 +1719,6 @@ static void omap_iommu_release_device(struct device *dev)
if (!dev->of_node || !arch_data) if (!dev->of_node || !arch_data)
return; return;
dev_iommu_priv_set(dev, NULL);
kfree(arch_data); kfree(arch_data);
} }

View file

@ -850,10 +850,7 @@ static inline void *dev_iommu_priv_get(struct device *dev)
return NULL; return NULL;
} }
static inline void dev_iommu_priv_set(struct device *dev, void *priv) void dev_iommu_priv_set(struct device *dev, void *priv);
{
dev->iommu->priv = priv;
}
extern struct mutex iommu_probe_device_lock; extern struct mutex iommu_probe_device_lock;
int iommu_probe_device(struct device *dev); int iommu_probe_device(struct device *dev);