@@ -2081,80 +2081,42 @@ static void pdom_detach_iommu(struct amd_iommu *iommu,
2081
2081
spin_unlock_irqrestore (& pdom -> lock , flags );
2082
2082
}
2083
2083
2084
- static int do_attach (struct iommu_dev_data * dev_data ,
2085
- struct protection_domain * domain )
2084
+ /*
2085
+ * If a device is not yet associated with a domain, this function makes the
2086
+ * device visible in the domain
2087
+ */
2088
+ static int attach_device (struct device * dev ,
2089
+ struct protection_domain * domain )
2086
2090
{
2091
+ struct iommu_dev_data * dev_data = dev_iommu_priv_get (dev );
2087
2092
struct amd_iommu * iommu = get_amd_iommu_from_dev_data (dev_data );
2088
2093
int ret = 0 ;
2089
2094
2095
+ spin_lock (& dev_data -> lock );
2096
+
2097
+ if (dev_data -> domain != NULL ) {
2098
+ ret = - EBUSY ;
2099
+ goto out ;
2100
+ }
2101
+
2090
2102
/* Update data structures */
2091
2103
dev_data -> domain = domain ;
2092
2104
list_add (& dev_data -> list , & domain -> dev_list );
2093
2105
2094
2106
/* Do reference counting */
2095
2107
ret = pdom_attach_iommu (iommu , domain );
2096
2108
if (ret )
2097
- return ret ;
2109
+ goto out ;
2098
2110
2099
2111
/* Setup GCR3 table */
2100
2112
if (pdom_is_sva_capable (domain )) {
2101
2113
ret = init_gcr3_table (dev_data , domain );
2102
2114
if (ret ) {
2103
2115
pdom_detach_iommu (iommu , domain );
2104
- return ret ;
2116
+ goto out ;
2105
2117
}
2106
2118
}
2107
2119
2108
- return ret ;
2109
- }
2110
-
2111
- static void do_detach (struct iommu_dev_data * dev_data )
2112
- {
2113
- struct protection_domain * domain = dev_data -> domain ;
2114
- struct amd_iommu * iommu = get_amd_iommu_from_dev_data (dev_data );
2115
- unsigned long flags ;
2116
-
2117
- /* Clear DTE and flush the entry */
2118
- dev_update_dte (dev_data , false);
2119
-
2120
- /* Flush IOTLB and wait for the flushes to finish */
2121
- spin_lock_irqsave (& domain -> lock , flags );
2122
- amd_iommu_domain_flush_all (domain );
2123
- spin_unlock_irqrestore (& domain -> lock , flags );
2124
-
2125
- /* Clear GCR3 table */
2126
- if (pdom_is_sva_capable (domain ))
2127
- destroy_gcr3_table (dev_data , domain );
2128
-
2129
- /* Update data structures */
2130
- dev_data -> domain = NULL ;
2131
- list_del (& dev_data -> list );
2132
-
2133
- /* decrease reference counters - needs to happen after the flushes */
2134
- pdom_detach_iommu (iommu , domain );
2135
- }
2136
-
2137
- /*
2138
- * If a device is not yet associated with a domain, this function makes the
2139
- * device visible in the domain
2140
- */
2141
- static int attach_device (struct device * dev ,
2142
- struct protection_domain * domain )
2143
- {
2144
- struct iommu_dev_data * dev_data ;
2145
- int ret = 0 ;
2146
-
2147
- dev_data = dev_iommu_priv_get (dev );
2148
-
2149
- spin_lock (& dev_data -> lock );
2150
-
2151
- if (dev_data -> domain != NULL ) {
2152
- ret = - EBUSY ;
2153
- goto out ;
2154
- }
2155
-
2156
- ret = do_attach (dev_data , domain );
2157
-
2158
2120
out :
2159
2121
spin_unlock (& dev_data -> lock );
2160
2122
@@ -2168,7 +2130,9 @@ static void detach_device(struct device *dev)
2168
2130
{
2169
2131
struct iommu_dev_data * dev_data = dev_iommu_priv_get (dev );
2170
2132
struct amd_iommu * iommu = get_amd_iommu_from_dev_data (dev_data );
2133
+ struct protection_domain * domain = dev_data -> domain ;
2171
2134
bool ppr = dev_data -> ppr ;
2135
+ unsigned long flags ;
2172
2136
2173
2137
spin_lock (& dev_data -> lock );
2174
2138
@@ -2188,7 +2152,24 @@ static void detach_device(struct device *dev)
2188
2152
dev_data -> ppr = false;
2189
2153
}
2190
2154
2191
- do_detach (dev_data );
2155
+ /* Clear DTE and flush the entry */
2156
+ dev_update_dte (dev_data , false);
2157
+
2158
+ /* Flush IOTLB and wait for the flushes to finish */
2159
+ spin_lock_irqsave (& domain -> lock , flags );
2160
+ amd_iommu_domain_flush_all (domain );
2161
+ spin_unlock_irqrestore (& domain -> lock , flags );
2162
+
2163
+ /* Clear GCR3 table */
2164
+ if (pdom_is_sva_capable (domain ))
2165
+ destroy_gcr3_table (dev_data , domain );
2166
+
2167
+ /* Update data structures */
2168
+ dev_data -> domain = NULL ;
2169
+ list_del (& dev_data -> list );
2170
+
2171
+ /* decrease reference counters - needs to happen after the flushes */
2172
+ pdom_detach_iommu (iommu , domain );
2192
2173
2193
2174
out :
2194
2175
spin_unlock (& dev_data -> lock );
0 commit comments