All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] driver core: platform: Call iommu_release_device in dma_cleanup
@ 2024-08-29 12:05 Sachin Parekh
  2024-08-29 13:52 ` Greg KH
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Sachin Parekh @ 2024-08-29 12:05 UTC (permalink / raw)
  To: gregkh, rafael, will, robin.murphy
  Cc: sachinparekh, lokeshvutla, linux-kernel, iommu

Installing a kernel module that has an iommu node in its
device tree increments corresponding iommu kernel module
reference count during driver_register.
Removing the same kernel module doesn't decrement the
iommu reference count resulting in error while
removing the iommu kernel module

    $ modprobe arm-smmu-v3
    $ modprobe test_module
    $ modprobe -r test_module
    $ modprobe -r arm-smmu-v3
    modprobe: can't unload module arm_smmu_v3: Resource temporarily unavailable

Cause:
    platform_driver_register
        ...
        -> platform_dma_configure
            ...
            -> iommu_probe_device (Increments reference count)

    platform_driver_unregister
        ...
        -> platform_dma_cleanup
            ...
            -> No corresponding iommu_release_device call

Fix:
    Call iommu_release_device in platform_dma_cleanup to remove the
    iommu from the corresponding kernel module

Signed-off-by: Sachin Parekh <sachinparekh@google.com>
---
 drivers/base/platform.c | 3 +++
 drivers/iommu/iommu.c   | 3 +--
 include/linux/iommu.h   | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 4c3ee6521ba5..c8125325a5e9 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1467,6 +1467,9 @@ static void platform_dma_cleanup(struct device *dev)
 
 	if (!drv->driver_managed_dma)
 		iommu_device_unuse_default_domain(dev);
+
+	if (dev_of_node(dev))
+		iommu_release_device(dev);
 }
 
 static const struct dev_pm_ops platform_dev_pm_ops = {
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index ed6c5cb60c5a..495f548fd4b9 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -92,7 +92,6 @@ static const char * const iommu_group_resv_type_string[] = {
 
 static int iommu_bus_notifier(struct notifier_block *nb,
 			      unsigned long action, void *data);
-static void iommu_release_device(struct device *dev);
 static struct iommu_domain *
 __iommu_group_domain_alloc(struct iommu_group *group, unsigned int type);
 static int __iommu_attach_device(struct iommu_domain *domain,
@@ -663,7 +662,7 @@ static void __iommu_group_remove_device(struct device *dev)
 	iommu_group_put(group);
 }
 
-static void iommu_release_device(struct device *dev)
+void iommu_release_device(struct device *dev)
 {
 	struct iommu_group *group = dev->iommu_group;
 
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 04cbdae0052e..2f9cb7d9dadf 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -1049,6 +1049,7 @@ void dev_iommu_priv_set(struct device *dev, void *priv);
 
 extern struct mutex iommu_probe_device_lock;
 int iommu_probe_device(struct device *dev);
+void iommu_release_device(struct device *dev);
 
 int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f);
 int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features f);
-- 
2.46.0.295.g3b9ea8a38a-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-09-02  6:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29 12:05 [RFC PATCH] driver core: platform: Call iommu_release_device in dma_cleanup Sachin Parekh
2024-08-29 13:52 ` Greg KH
2024-09-02  6:44   ` Sachin Parekh
2024-08-29 13:58 ` Robin Murphy
2024-09-02  6:17   ` Sachin Parekh
2024-09-01 13:28 ` kernel test robot
2024-09-01 13:49 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.