@@ -25,6 +25,17 @@ static void init_iova_rcaches(struct iova_domain *iovad);
25
25
static void free_iova_rcaches (struct iova_domain * iovad );
26
26
static void fq_destroy_all_entries (struct iova_domain * iovad );
27
27
static void fq_flush_timeout (struct timer_list * t );
28
+
29
+ static int iova_cpuhp_dead (unsigned int cpu , struct hlist_node * node )
30
+ {
31
+ struct iova_domain * iovad ;
32
+
33
+ iovad = hlist_entry_safe (node , struct iova_domain , cpuhp_dead );
34
+
35
+ free_cpu_cached_iovas (cpu , iovad );
36
+ return 0 ;
37
+ }
38
+
28
39
static void free_global_cached_iovas (struct iova_domain * iovad );
29
40
30
41
static struct iova * to_iova (struct rb_node * node )
@@ -56,6 +67,7 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule,
56
67
iovad -> anchor .pfn_lo = iovad -> anchor .pfn_hi = IOVA_ANCHOR ;
57
68
rb_link_node (& iovad -> anchor .node , NULL , & iovad -> rbroot .rb_node );
58
69
rb_insert_color (& iovad -> anchor .node , & iovad -> rbroot );
70
+ cpuhp_state_add_instance_nocalls (CPUHP_IOMMU_IOVA_DEAD , & iovad -> cpuhp_dead );
59
71
init_iova_rcaches (iovad );
60
72
}
61
73
EXPORT_SYMBOL_GPL (init_iova_domain );
@@ -299,10 +311,21 @@ int iova_cache_get(void)
299
311
{
300
312
mutex_lock (& iova_cache_mutex );
301
313
if (!iova_cache_users ) {
314
+ int ret ;
315
+
316
+ ret = cpuhp_setup_state_multi (CPUHP_IOMMU_IOVA_DEAD , "iommu/iova:dead" , NULL ,
317
+ iova_cpuhp_dead );
318
+ if (ret ) {
319
+ mutex_unlock (& iova_cache_mutex );
320
+ pr_err ("Couldn't register cpuhp handler\n" );
321
+ return ret ;
322
+ }
323
+
302
324
iova_cache = kmem_cache_create (
303
325
"iommu_iova" , sizeof (struct iova ), 0 ,
304
326
SLAB_HWCACHE_ALIGN , NULL );
305
327
if (!iova_cache ) {
328
+ cpuhp_remove_multi_state (CPUHP_IOMMU_IOVA_DEAD );
306
329
mutex_unlock (& iova_cache_mutex );
307
330
pr_err ("Couldn't create iova cache\n" );
308
331
return - ENOMEM ;
@@ -324,8 +347,10 @@ void iova_cache_put(void)
324
347
return ;
325
348
}
326
349
iova_cache_users -- ;
327
- if (!iova_cache_users )
350
+ if (!iova_cache_users ) {
351
+ cpuhp_remove_multi_state (CPUHP_IOMMU_IOVA_DEAD );
328
352
kmem_cache_destroy (iova_cache );
353
+ }
329
354
mutex_unlock (& iova_cache_mutex );
330
355
}
331
356
EXPORT_SYMBOL_GPL (iova_cache_put );
@@ -648,6 +673,9 @@ void put_iova_domain(struct iova_domain *iovad)
648
673
{
649
674
struct iova * iova , * tmp ;
650
675
676
+ cpuhp_state_remove_instance_nocalls (CPUHP_IOMMU_IOVA_DEAD ,
677
+ & iovad -> cpuhp_dead );
678
+
651
679
free_iova_flush_queue (iovad );
652
680
free_iova_rcaches (iovad );
653
681
rbtree_postorder_for_each_entry_safe (iova , tmp , & iovad -> rbroot , node )
0 commit comments