Skip to content

Commit 1ee0186

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Refactor find_domain() helper
Current find_domain() helper checks and does the deferred domain attachment and return the domain in use. This isn't always the use case for the callers. Some callers only want to retrieve the current domain in use. This refactors find_domain() into two helpers: 1) find_domain() only returns the domain in use; 2) deferred_attach_domain() does the deferred domain attachment if required and return the domain in use. Cc: Ashok Raj <[email protected]> Cc: Jacob Pan <[email protected]> Cc: Kevin Tian <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 4f5cafb commit 1ee0186

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,14 +2420,24 @@ static void domain_remove_dev_info(struct dmar_domain *domain)
24202420
spin_unlock_irqrestore(&device_domain_lock, flags);
24212421
}
24222422

2423-
/*
2424-
* find_domain
2425-
* Note: we use struct device->archdata.iommu stores the info
2426-
*/
24272423
static struct dmar_domain *find_domain(struct device *dev)
24282424
{
24292425
struct device_domain_info *info;
24302426

2427+
if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO ||
2428+
dev->archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO))
2429+
return NULL;
2430+
2431+
/* No lock here, assumes no domain exit in normal case */
2432+
info = dev->archdata.iommu;
2433+
if (likely(info))
2434+
return info->domain;
2435+
2436+
return NULL;
2437+
}
2438+
2439+
static struct dmar_domain *deferred_attach_domain(struct device *dev)
2440+
{
24312441
if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO)) {
24322442
struct iommu_domain *domain;
24332443

@@ -2437,12 +2447,7 @@ static struct dmar_domain *find_domain(struct device *dev)
24372447
intel_iommu_attach_device(domain, dev);
24382448
}
24392449

2440-
/* No lock here, assumes no domain exit in normal case */
2441-
info = dev->archdata.iommu;
2442-
2443-
if (likely(info))
2444-
return info->domain;
2445-
return NULL;
2450+
return find_domain(dev);
24462451
}
24472452

24482453
static inline struct device_domain_info *
@@ -3512,7 +3517,7 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
35123517

35133518
BUG_ON(dir == DMA_NONE);
35143519

3515-
domain = find_domain(dev);
3520+
domain = deferred_attach_domain(dev);
35163521
if (!domain)
35173522
return DMA_MAPPING_ERROR;
35183523

@@ -3732,7 +3737,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
37323737
if (!iommu_need_mapping(dev))
37333738
return dma_direct_map_sg(dev, sglist, nelems, dir, attrs);
37343739

3735-
domain = find_domain(dev);
3740+
domain = deferred_attach_domain(dev);
37363741
if (!domain)
37373742
return 0;
37383743

@@ -3819,7 +3824,7 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
38193824
int prot = 0;
38203825
int ret;
38213826

3822-
domain = find_domain(dev);
3827+
domain = deferred_attach_domain(dev);
38233828
if (WARN_ON(dir == DMA_NONE || !domain))
38243829
return DMA_MAPPING_ERROR;
38253830

0 commit comments

Comments
 (0)