From: Xiang Chen <[email protected]>

When rmmod the driver of the last device in the domain, cached iovas are
not used and it is better to free them to save memories.

Signed-off-by: Xiang Chen <[email protected]>
---
 drivers/iommu/iommu.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 808ab70..d318d80 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -9,6 +9,7 @@
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/bug.h>
+#include <linux/dma-iommu.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/export.h>
@@ -16,6 +17,7 @@
 #include <linux/errno.h>
 #include <linux/iommu.h>
 #include <linux/idr.h>
+#include <linux/iova.h>
 #include <linux/notifier.h>
 #include <linux/err.h>
 #include <linux/pci.h>
@@ -1667,6 +1669,11 @@ static int iommu_bus_notifier(struct notifier_block *nb,
                group_action = IOMMU_GROUP_NOTIFY_UNBIND_DRIVER;
                break;
        case BUS_NOTIFY_UNBOUND_DRIVER:
+               if (iommu_group_device_count(group) == 1) {
+                       struct iommu_domain *domain = group->domain;
+
+                       free_rcache_cached_iovas(iommu_domain_to_iova(domain));
+               }
                group_action = IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER;
                break;
        }
-- 
2.8.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to