Much as I'd like to remove iommu_present(), the final remaining users
are proving stubbornly difficult to clean up, so kick that can down
the road and just rework it to preserve the current behaviour without
depending on bus ops.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
v2: No change
drivers/iommu/iommu.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 42591766266d..b27f5d3453bb 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1871,9 +1871,24 @@ int bus_iommu_probe(struct bus_type *bus)
return ret;
}
+static int __iommu_present(struct device *dev, void *unused)
+{
+ return device_iommu_mapped(dev);
+}
+
+/**
+ * iommu_present() - make platform-specific assumptions about an IOMMU
+ * @bus: bus to check
+ *
+ * Do not use this function. You want device_iommu_mapped() instead.
+ *
+ * Return: true if some IOMMU is present for some device on the given bus. In
+ * general it may not be the only IOMMU, and it may not be for the device you
+ * are ultimately interested in.
+ */
bool iommu_present(struct bus_type *bus)
{
- return bus->iommu_ops != NULL;
+ return bus_for_each_dev(bus, NULL, NULL, __iommu_present) > 0;
}
EXPORT_SYMBOL_GPL(iommu_present);
--
2.36.1.dirty
On Thu, Jan 26, 2023 at 06:26:16PM +0000, Robin Murphy wrote: > Much as I'd like to remove iommu_present(), the final remaining users > are proving stubbornly difficult to clean up, so kick that can down > the road and just rework it to preserve the current behaviour without > depending on bus ops. > > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > --- Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> This below might help. You might need to ask Thierry for help on the problematic stuff in tegra. Really we should finish the series here and organize things so that the domain allocation is defered until a client is present. https://lore.kernel.org/linux-iommu/20220106022053.2406748-1-baolu.lu@linux.intel.com/ diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c index cd5b18ef79512c..e5c257e41f4933 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -353,9 +353,6 @@ static int mtk_drm_kms_init(struct drm_device *drm) if (drm_firmware_drivers_only()) return -ENODEV; - if (!iommu_present(&platform_bus_type)) - return -EPROBE_DEFER; - pdev = of_find_device_by_node(private->mutex_node); if (!pdev) { dev_err(drm->dev, "Waiting for disp-mutex device %pOF\n", @@ -709,6 +706,9 @@ static int mtk_drm_probe(struct platform_device *pdev) int ret; int i; + if (!device_iommu_mapped(dev)) + return -EPROBE_DEFER; + private = devm_kzalloc(dev, sizeof(*private), GFP_KERNEL); if (!private) return -ENOMEM;
On 2023-01-30 17:31, Jason Gunthorpe wrote: > On Thu, Jan 26, 2023 at 06:26:16PM +0000, Robin Murphy wrote: >> Much as I'd like to remove iommu_present(), the final remaining users >> are proving stubbornly difficult to clean up, so kick that can down >> the road and just rework it to preserve the current behaviour without >> depending on bus ops. >> >> Signed-off-by: Robin Murphy <robin.murphy@arm.com> >> --- > > Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> > > This below might help. You might need to ask Thierry for help on the > problematic stuff in tegra. Really we should finish the series here > and organize things so that the domain allocation is defered until a > client is present. mrk_drm doesn't even allocate, it relies on the DMA API domain; it also only runs on DT systems where IOMMU dependency ordering has been enforced by core code for a very long time now. I sent a patch simply removing that check back at the time of the rest of my iommu_present() cleanup, and it just got resoundingly ignored :( Thanks, Robin. > https://lore.kernel.org/linux-iommu/20220106022053.2406748-1-baolu.lu@linux.intel.com/ > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > index cd5b18ef79512c..e5c257e41f4933 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > @@ -353,9 +353,6 @@ static int mtk_drm_kms_init(struct drm_device *drm) > if (drm_firmware_drivers_only()) > return -ENODEV; > > - if (!iommu_present(&platform_bus_type)) > - return -EPROBE_DEFER; > - > pdev = of_find_device_by_node(private->mutex_node); > if (!pdev) { > dev_err(drm->dev, "Waiting for disp-mutex device %pOF\n", > @@ -709,6 +706,9 @@ static int mtk_drm_probe(struct platform_device *pdev) > int ret; > int i; > > + if (!device_iommu_mapped(dev)) > + return -EPROBE_DEFER; > + > private = devm_kzalloc(dev, sizeof(*private), GFP_KERNEL); > if (!private) > return -ENOMEM;
On 2023/1/27 2:26, Robin Murphy wrote: > Much as I'd like to remove iommu_present(), the final remaining users > are proving stubbornly difficult to clean up, so kick that can down > the road and just rework it to preserve the current behaviour without > depending on bus ops. > > Signed-off-by: Robin Murphy<robin.murphy@arm.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Best regards, baolu
© 2016 - 2025 Red Hat, Inc.