10
10
#include <linux/iommu.h>
11
11
#include <linux/iommu-helper.h>
12
12
#include <linux/sizes.h>
13
+ #include <linux/rculist.h>
14
+ #include <linux/rcupdate.h>
13
15
#include <asm/pci_dma.h>
14
16
15
17
static const struct iommu_ops s390_iommu_ops ;
@@ -20,6 +22,7 @@ struct s390_domain {
20
22
unsigned long * dma_table ;
21
23
spinlock_t dma_table_lock ;
22
24
spinlock_t list_lock ;
25
+ struct rcu_head rcu ;
23
26
};
24
27
25
28
static struct s390_domain * to_s390_domain (struct iommu_domain * dom )
@@ -61,18 +64,28 @@ static struct iommu_domain *s390_domain_alloc(unsigned domain_type)
61
64
62
65
spin_lock_init (& s390_domain -> dma_table_lock );
63
66
spin_lock_init (& s390_domain -> list_lock );
64
- INIT_LIST_HEAD (& s390_domain -> devices );
67
+ INIT_LIST_HEAD_RCU (& s390_domain -> devices );
65
68
66
69
return & s390_domain -> domain ;
67
70
}
68
71
72
+ static void s390_iommu_rcu_free_domain (struct rcu_head * head )
73
+ {
74
+ struct s390_domain * s390_domain = container_of (head , struct s390_domain , rcu );
75
+
76
+ dma_cleanup_tables (s390_domain -> dma_table );
77
+ kfree (s390_domain );
78
+ }
79
+
69
80
static void s390_domain_free (struct iommu_domain * domain )
70
81
{
71
82
struct s390_domain * s390_domain = to_s390_domain (domain );
72
83
84
+ rcu_read_lock ();
73
85
WARN_ON (!list_empty (& s390_domain -> devices ));
74
- dma_cleanup_tables (s390_domain -> dma_table );
75
- kfree (s390_domain );
86
+ rcu_read_unlock ();
87
+
88
+ call_rcu (& s390_domain -> rcu , s390_iommu_rcu_free_domain );
76
89
}
77
90
78
91
static void __s390_iommu_detach_device (struct zpci_dev * zdev )
@@ -84,7 +97,7 @@ static void __s390_iommu_detach_device(struct zpci_dev *zdev)
84
97
return ;
85
98
86
99
spin_lock_irqsave (& s390_domain -> list_lock , flags );
87
- list_del_init (& zdev -> iommu_list );
100
+ list_del_rcu (& zdev -> iommu_list );
88
101
spin_unlock_irqrestore (& s390_domain -> list_lock , flags );
89
102
90
103
zpci_unregister_ioat (zdev , 0 );
@@ -127,7 +140,7 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
127
140
zdev -> s390_domain = s390_domain ;
128
141
129
142
spin_lock_irqsave (& s390_domain -> list_lock , flags );
130
- list_add (& zdev -> iommu_list , & s390_domain -> devices );
143
+ list_add_rcu (& zdev -> iommu_list , & s390_domain -> devices );
131
144
spin_unlock_irqrestore (& s390_domain -> list_lock , flags );
132
145
133
146
return 0 ;
@@ -203,14 +216,13 @@ static void s390_iommu_flush_iotlb_all(struct iommu_domain *domain)
203
216
{
204
217
struct s390_domain * s390_domain = to_s390_domain (domain );
205
218
struct zpci_dev * zdev ;
206
- unsigned long flags ;
207
219
208
- spin_lock_irqsave ( & s390_domain -> list_lock , flags );
209
- list_for_each_entry (zdev , & s390_domain -> devices , iommu_list ) {
220
+ rcu_read_lock ( );
221
+ list_for_each_entry_rcu (zdev , & s390_domain -> devices , iommu_list ) {
210
222
zpci_refresh_trans ((u64 )zdev -> fh << 32 , zdev -> start_dma ,
211
223
zdev -> end_dma - zdev -> start_dma + 1 );
212
224
}
213
- spin_unlock_irqrestore ( & s390_domain -> list_lock , flags );
225
+ rcu_read_unlock ( );
214
226
}
215
227
216
228
static void s390_iommu_iotlb_sync (struct iommu_domain * domain ,
@@ -219,35 +231,33 @@ static void s390_iommu_iotlb_sync(struct iommu_domain *domain,
219
231
struct s390_domain * s390_domain = to_s390_domain (domain );
220
232
size_t size = gather -> end - gather -> start + 1 ;
221
233
struct zpci_dev * zdev ;
222
- unsigned long flags ;
223
234
224
235
/* If gather was never added to there is nothing to flush */
225
236
if (!gather -> end )
226
237
return ;
227
238
228
- spin_lock_irqsave ( & s390_domain -> list_lock , flags );
229
- list_for_each_entry (zdev , & s390_domain -> devices , iommu_list ) {
239
+ rcu_read_lock ( );
240
+ list_for_each_entry_rcu (zdev , & s390_domain -> devices , iommu_list ) {
230
241
zpci_refresh_trans ((u64 )zdev -> fh << 32 , gather -> start ,
231
242
size );
232
243
}
233
- spin_unlock_irqrestore ( & s390_domain -> list_lock , flags );
244
+ rcu_read_unlock ( );
234
245
}
235
246
236
247
static void s390_iommu_iotlb_sync_map (struct iommu_domain * domain ,
237
248
unsigned long iova , size_t size )
238
249
{
239
250
struct s390_domain * s390_domain = to_s390_domain (domain );
240
251
struct zpci_dev * zdev ;
241
- unsigned long flags ;
242
252
243
- spin_lock_irqsave ( & s390_domain -> list_lock , flags );
244
- list_for_each_entry (zdev , & s390_domain -> devices , iommu_list ) {
253
+ rcu_read_lock ( );
254
+ list_for_each_entry_rcu (zdev , & s390_domain -> devices , iommu_list ) {
245
255
if (!zdev -> tlb_refresh )
246
256
continue ;
247
257
zpci_refresh_trans ((u64 )zdev -> fh << 32 ,
248
258
iova , size );
249
259
}
250
- spin_unlock_irqrestore ( & s390_domain -> list_lock , flags );
260
+ rcu_read_unlock ( );
251
261
}
252
262
253
263
static int s390_iommu_update_trans (struct s390_domain * s390_domain ,
0 commit comments