File tree 2 files changed +24
-6
lines changed
2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 14
14
#include <linux/types.h>
15
15
#include <linux/slab.h>
16
16
#include <linux/mm.h>
17
+ #include <linux/delay.h>
17
18
#include <linux/spinlock.h>
18
19
#include <linux/string.h>
19
20
#include <linux/dma-mapping.h>
@@ -803,6 +804,7 @@ bool iommu_table_in_use(struct iommu_table *tbl)
803
804
static void iommu_table_free (struct kref * kref )
804
805
{
805
806
struct iommu_table * tbl ;
807
+ unsigned long start_time ;
806
808
807
809
tbl = container_of (kref , struct iommu_table , it_kref );
808
810
@@ -817,8 +819,24 @@ static void iommu_table_free(struct kref *kref)
817
819
iommu_debugfs_del (tbl );
818
820
819
821
/* verify that table contains no entries */
820
- if (iommu_table_in_use (tbl ))
821
- pr_warn ("%s: Unexpected TCEs\n" , __func__ );
822
+ start_time = jiffies ;
823
+ while (iommu_table_in_use (tbl )) {
824
+ int sec ;
825
+
826
+ pr_info ("%s: Unexpected TCEs, wait for 50ms\n" , __func__ );
827
+ msleep (50 );
828
+
829
+ /* Come out of the loop if we have already waited for 120 seconds
830
+ * for the TCEs to be free'ed. TCE are being free'ed
831
+ * asynchronously by some DMA buffer management API - like
832
+ * page_pool.
833
+ */
834
+ sec = (s32 )((u32 )jiffies - (u32 )start_time ) / HZ ;
835
+ if (sec >= 120 ) {
836
+ pr_warn ("%s: TCEs still mapped even after 120 seconds\n" , __func__ );
837
+ break ;
838
+ }
839
+ }
822
840
823
841
/* free bitmap */
824
842
vfree (tbl -> it_map );
Original file line number Diff line number Diff line change @@ -2390,6 +2390,10 @@ static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long acti
2390
2390
2391
2391
switch (action ) {
2392
2392
case OF_RECONFIG_DETACH_NODE :
2393
+ if (pci && pci -> table_group )
2394
+ iommu_pseries_free_group (pci -> table_group ,
2395
+ np -> full_name );
2396
+
2393
2397
/*
2394
2398
* Removing the property will invoke the reconfig
2395
2399
* notifier again, which causes dead-lock on the
@@ -2400,10 +2404,6 @@ static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long acti
2400
2404
if (remove_dma_window_named (np , false, DIRECT64_PROPNAME , true))
2401
2405
remove_dma_window_named (np , false, DMA64_PROPNAME , true);
2402
2406
2403
- if (pci && pci -> table_group )
2404
- iommu_pseries_free_group (pci -> table_group ,
2405
- np -> full_name );
2406
-
2407
2407
spin_lock (& dma_win_list_lock );
2408
2408
list_for_each_entry (window , & dma_win_list , list ) {
2409
2409
if (window -> device == np ) {
You can’t perform that action at this time.
0 commit comments