@@ -2079,27 +2079,13 @@ static void do_detach(struct iommu_dev_data *dev_data)
2079
2079
static int __attach_device (struct iommu_dev_data * dev_data ,
2080
2080
struct protection_domain * domain )
2081
2081
{
2082
- unsigned long flags ;
2083
- int ret ;
2084
-
2085
- /* lock domain */
2086
- spin_lock_irqsave (& domain -> lock , flags );
2087
-
2088
- ret = - EBUSY ;
2089
2082
if (dev_data -> domain != NULL )
2090
- goto out_unlock ;
2083
+ return - EBUSY ;
2091
2084
2092
2085
/* Attach alias group root */
2093
2086
do_attach (dev_data , domain );
2094
2087
2095
- ret = 0 ;
2096
-
2097
- out_unlock :
2098
-
2099
- /* ready */
2100
- spin_unlock_irqrestore (& domain -> lock , flags );
2101
-
2102
- return ret ;
2088
+ return 0 ;
2103
2089
}
2104
2090
2105
2091
@@ -2181,21 +2167,25 @@ static int attach_device(struct device *dev,
2181
2167
{
2182
2168
struct pci_dev * pdev ;
2183
2169
struct iommu_dev_data * dev_data ;
2170
+ unsigned long flags ;
2184
2171
int ret ;
2185
2172
2173
+ spin_lock_irqsave (& domain -> lock , flags );
2174
+
2186
2175
dev_data = get_dev_data (dev );
2187
2176
2188
2177
if (!dev_is_pci (dev ))
2189
2178
goto skip_ats_check ;
2190
2179
2191
2180
pdev = to_pci_dev (dev );
2192
2181
if (domain -> flags & PD_IOMMUV2_MASK ) {
2182
+ ret = - EINVAL ;
2193
2183
if (!dev_data -> passthrough )
2194
- return - EINVAL ;
2184
+ goto out ;
2195
2185
2196
2186
if (dev_data -> iommu_v2 ) {
2197
2187
if (pdev_iommuv2_enable (pdev ) != 0 )
2198
- return - EINVAL ;
2188
+ goto out ;
2199
2189
2200
2190
dev_data -> ats .enabled = true;
2201
2191
dev_data -> ats .qdep = pci_ats_queue_depth (pdev );
@@ -2219,24 +2209,10 @@ static int attach_device(struct device *dev,
2219
2209
2220
2210
domain_flush_complete (domain );
2221
2211
2222
- return ret ;
2223
- }
2224
-
2225
- /*
2226
- * Removes a device from a protection domain (unlocked)
2227
- */
2228
- static void __detach_device (struct iommu_dev_data * dev_data )
2229
- {
2230
- struct protection_domain * domain ;
2231
- unsigned long flags ;
2232
-
2233
- domain = dev_data -> domain ;
2234
-
2235
- spin_lock_irqsave (& domain -> lock , flags );
2236
-
2237
- do_detach (dev_data );
2238
-
2212
+ out :
2239
2213
spin_unlock_irqrestore (& domain -> lock , flags );
2214
+
2215
+ return ret ;
2240
2216
}
2241
2217
2242
2218
/*
@@ -2246,30 +2222,36 @@ static void detach_device(struct device *dev)
2246
2222
{
2247
2223
struct protection_domain * domain ;
2248
2224
struct iommu_dev_data * dev_data ;
2225
+ unsigned long flags ;
2249
2226
2250
2227
dev_data = get_dev_data (dev );
2251
2228
domain = dev_data -> domain ;
2252
2229
2230
+ spin_lock_irqsave (& domain -> lock , flags );
2231
+
2253
2232
/*
2254
2233
* First check if the device is still attached. It might already
2255
2234
* be detached from its domain because the generic
2256
2235
* iommu_detach_group code detached it and we try again here in
2257
2236
* our alias handling.
2258
2237
*/
2259
2238
if (WARN_ON (!dev_data -> domain ))
2260
- return ;
2239
+ goto out ;
2261
2240
2262
- __detach_device (dev_data );
2241
+ do_detach (dev_data );
2263
2242
2264
2243
if (!dev_is_pci (dev ))
2265
- return ;
2244
+ goto out ;
2266
2245
2267
2246
if (domain -> flags & PD_IOMMUV2_MASK && dev_data -> iommu_v2 )
2268
2247
pdev_iommuv2_disable (to_pci_dev (dev ));
2269
2248
else if (dev_data -> ats .enabled )
2270
2249
pci_disable_ats (to_pci_dev (dev ));
2271
2250
2272
2251
dev_data -> ats .enabled = false;
2252
+
2253
+ out :
2254
+ spin_unlock_irqrestore (& domain -> lock , flags );
2273
2255
}
2274
2256
2275
2257
static int amd_iommu_add_device (struct device * dev )
@@ -2904,13 +2886,18 @@ int __init amd_iommu_init_dma_ops(void)
2904
2886
static void cleanup_domain (struct protection_domain * domain )
2905
2887
{
2906
2888
struct iommu_dev_data * entry ;
2889
+ unsigned long flags ;
2890
+
2891
+ spin_lock_irqsave (& domain -> lock , flags );
2907
2892
2908
2893
while (!list_empty (& domain -> dev_list )) {
2909
2894
entry = list_first_entry (& domain -> dev_list ,
2910
2895
struct iommu_dev_data , list );
2911
2896
BUG_ON (!entry -> domain );
2912
- __detach_device (entry );
2897
+ do_detach (entry );
2913
2898
}
2899
+
2900
+ spin_unlock_irqrestore (& domain -> lock , flags );
2914
2901
}
2915
2902
2916
2903
static void protection_domain_free (struct protection_domain * domain )
0 commit comments