Skip to content

Commit 79d82ce

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Check device list of domain in domain free path
When the IOMMU domain is about to be freed, it should not be set on any device. Instead of silently dealing with some bug cases, it's better to trigger a warning to report and fix any potential bugs at the first time. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20220706025524.2904370-9-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 8430fd3 commit 79d82ce

1 file changed

Lines changed: 3 additions & 15 deletions

File tree

drivers/iommu/intel/iommu.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ static LIST_HEAD(dmar_satc_units);
294294
/* bitmap for indexing intel_iommus */
295295
static int g_num_of_iommus;
296296

297-
static void domain_remove_dev_info(struct dmar_domain *domain);
298297
static void dmar_remove_one_dev_info(struct device *dev);
299298
static void __dmar_remove_one_dev_info(struct device_domain_info *info);
300299

@@ -1841,17 +1840,16 @@ static inline int guestwidth_to_adjustwidth(int gaw)
18411840

18421841
static void domain_exit(struct dmar_domain *domain)
18431842
{
1844-
1845-
/* Remove associated devices and clear attached or cached domains */
1846-
domain_remove_dev_info(domain);
1847-
18481843
if (domain->pgd) {
18491844
LIST_HEAD(freelist);
18501845

18511846
domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw), &freelist);
18521847
put_pages_list(&freelist);
18531848
}
18541849

1850+
if (WARN_ON(!list_empty(&domain->devices)))
1851+
return;
1852+
18551853
kfree(domain);
18561854
}
18571855

@@ -2333,16 +2331,6 @@ static void domain_context_clear_one(struct device_domain_info *info, u8 bus, u8
23332331
__iommu_flush_dev_iotlb(info, 0, MAX_AGAW_PFN_WIDTH);
23342332
}
23352333

2336-
static void domain_remove_dev_info(struct dmar_domain *domain)
2337-
{
2338-
struct device_domain_info *info, *tmp;
2339-
2340-
spin_lock(&device_domain_lock);
2341-
list_for_each_entry_safe(info, tmp, &domain->devices, link)
2342-
__dmar_remove_one_dev_info(info);
2343-
spin_unlock(&device_domain_lock);
2344-
}
2345-
23462334
static int domain_setup_first_level(struct intel_iommu *iommu,
23472335
struct dmar_domain *domain,
23482336
struct device *dev,

0 commit comments

Comments
 (0)