Skip to content

Commit 00939be

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/vt-d: Fold domain_exit() into intel_iommu_domain_free()
It has only one caller, no need for two functions. Correct the WARN_ON() error handling to leak the entire page table if the HW is still referencing it so we don't UAF during WARN_ON recovery. Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent cd0d0e4 commit 00939be

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,23 +1396,6 @@ void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu)
13961396
}
13971397
}
13981398

1399-
static void domain_exit(struct dmar_domain *domain)
1400-
{
1401-
if (domain->pgd) {
1402-
struct iommu_pages_list freelist =
1403-
IOMMU_PAGES_LIST_INIT(freelist);
1404-
1405-
domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw), &freelist);
1406-
iommu_put_pages_list(&freelist);
1407-
}
1408-
1409-
if (WARN_ON(!list_empty(&domain->devices)))
1410-
return;
1411-
1412-
kfree(domain->qi_batch);
1413-
kfree(domain);
1414-
}
1415-
14161399
/*
14171400
* For kdump cases, old valid entries may be cached due to the
14181401
* in-flight DMA and copied pgtable, but there is no unmapping
@@ -3406,9 +3389,24 @@ static void intel_iommu_domain_free(struct iommu_domain *domain)
34063389
{
34073390
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
34083391

3409-
WARN_ON(dmar_domain->nested_parent &&
3410-
!list_empty(&dmar_domain->s1_domains));
3411-
domain_exit(dmar_domain);
3392+
if (WARN_ON(dmar_domain->nested_parent &&
3393+
!list_empty(&dmar_domain->s1_domains)))
3394+
return;
3395+
3396+
if (WARN_ON(!list_empty(&dmar_domain->devices)))
3397+
return;
3398+
3399+
if (dmar_domain->pgd) {
3400+
struct iommu_pages_list freelist =
3401+
IOMMU_PAGES_LIST_INIT(freelist);
3402+
3403+
domain_unmap(dmar_domain, 0, DOMAIN_MAX_PFN(dmar_domain->gaw),
3404+
&freelist);
3405+
iommu_put_pages_list(&freelist);
3406+
}
3407+
3408+
kfree(dmar_domain->qi_batch);
3409+
kfree(dmar_domain);
34123410
}
34133411

34143412
int paging_domain_compatible(struct iommu_domain *domain, struct device *dev)

0 commit comments

Comments
 (0)