diff options
-rw-r--r-- | arch/x86/include/asm/amd_iommu_types.h | 2 | ||||
-rw-r--r-- | arch/x86/kernel/amd_iommu.c | 12 |
2 files changed, 11 insertions, 3 deletions
diff --git a/arch/x86/include/asm/amd_iommu_types.h b/arch/x86/include/asm/amd_iommu_types.h index ab3e7bf1af71..e68b14811380 100644 --- a/arch/x86/include/asm/amd_iommu_types.h +++ b/arch/x86/include/asm/amd_iommu_types.h | |||
@@ -238,7 +238,9 @@ struct protection_domain { | |||
238 | unsigned long flags; /* flags to find out type of domain */ | 238 | unsigned long flags; /* flags to find out type of domain */ |
239 | bool updated; /* complete domain flush required */ | 239 | bool updated; /* complete domain flush required */ |
240 | unsigned dev_cnt; /* devices assigned to this domain */ | 240 | unsigned dev_cnt; /* devices assigned to this domain */ |
241 | unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */ | ||
241 | void *priv; /* private data */ | 242 | void *priv; /* private data */ |
243 | |||
242 | }; | 244 | }; |
243 | 245 | ||
244 | /* | 246 | /* |
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c index 7fe28be3b548..8c38f0085403 100644 --- a/arch/x86/kernel/amd_iommu.c +++ b/arch/x86/kernel/amd_iommu.c | |||
@@ -1175,7 +1175,9 @@ static void __attach_device(struct amd_iommu *iommu, | |||
1175 | /* update DTE entry */ | 1175 | /* update DTE entry */ |
1176 | set_dte_entry(devid, domain); | 1176 | set_dte_entry(devid, domain); |
1177 | 1177 | ||
1178 | domain->dev_cnt += 1; | 1178 | /* Do reference counting */ |
1179 | domain->dev_iommu[iommu->index] += 1; | ||
1180 | domain->dev_cnt += 1; | ||
1179 | 1181 | ||
1180 | /* ready */ | 1182 | /* ready */ |
1181 | spin_unlock(&domain->lock); | 1183 | spin_unlock(&domain->lock); |
@@ -1209,6 +1211,9 @@ static void attach_device(struct amd_iommu *iommu, | |||
1209 | */ | 1211 | */ |
1210 | static void __detach_device(struct protection_domain *domain, u16 devid) | 1212 | static void __detach_device(struct protection_domain *domain, u16 devid) |
1211 | { | 1213 | { |
1214 | struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; | ||
1215 | |||
1216 | BUG_ON(!iommu); | ||
1212 | 1217 | ||
1213 | /* lock domain */ | 1218 | /* lock domain */ |
1214 | spin_lock(&domain->lock); | 1219 | spin_lock(&domain->lock); |
@@ -1223,8 +1228,9 @@ static void __detach_device(struct protection_domain *domain, u16 devid) | |||
1223 | 1228 | ||
1224 | amd_iommu_apply_erratum_63(devid); | 1229 | amd_iommu_apply_erratum_63(devid); |
1225 | 1230 | ||
1226 | /* decrease reference counter */ | 1231 | /* decrease reference counters */ |
1227 | domain->dev_cnt -= 1; | 1232 | domain->dev_iommu[iommu->index] -= 1; |
1233 | domain->dev_cnt -= 1; | ||
1228 | 1234 | ||
1229 | /* ready */ | 1235 | /* ready */ |
1230 | spin_unlock(&domain->lock); | 1236 | spin_unlock(&domain->lock); |