]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
iommu/vt-d: Refactor find_domain() helper
authorLu Baolu <baolu.lu@linux.intel.com>
Tue, 6 Apr 2021 17:12:00 +0000 (19:12 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Apr 2021 16:32:03 +0000 (18:32 +0200)
BugLink: https://bugs.launchpad.net/bugs/1922738
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 <ashok.raj@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 1ee0186b9a128a872887e16e2d1520ea37a95dc4)
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Acked-by: Guilherme G. Piccoli <gpiccoli@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/iommu/intel-iommu.c

index 953d86ca6d2b253cb02ae793e5d814da4677667c..ebdccc72dc465c7892c035a03c7afcf5a920d884 100644 (file)
@@ -2427,14 +2427,24 @@ static void domain_remove_dev_info(struct dmar_domain *domain)
        spin_unlock_irqrestore(&device_domain_lock, flags);
 }
 
-/*
- * find_domain
- * Note: we use struct device->archdata.iommu stores the info
- */
 static struct dmar_domain *find_domain(struct device *dev)
 {
        struct device_domain_info *info;
 
+       if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO ||
+                    dev->archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO))
+               return NULL;
+
+       /* No lock here, assumes no domain exit in normal case */
+       info = dev->archdata.iommu;
+       if (likely(info))
+               return info->domain;
+
+       return NULL;
+}
+
+static struct dmar_domain *deferred_attach_domain(struct device *dev)
+{
        if (unlikely(dev->archdata.iommu == DEFER_DEVICE_DOMAIN_INFO)) {
                struct iommu_domain *domain;
 
@@ -2444,12 +2454,7 @@ static struct dmar_domain *find_domain(struct device *dev)
                        intel_iommu_attach_device(domain, dev);
        }
 
-       /* No lock here, assumes no domain exit in normal case */
-       info = dev->archdata.iommu;
-
-       if (likely(info))
-               return info->domain;
-       return NULL;
+       return find_domain(dev);
 }
 
 static inline struct device_domain_info *
@@ -3515,7 +3520,7 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
 
        BUG_ON(dir == DMA_NONE);
 
-       domain = find_domain(dev);
+       domain = deferred_attach_domain(dev);
        if (!domain)
                return DMA_MAPPING_ERROR;
 
@@ -3735,7 +3740,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
        if (!iommu_need_mapping(dev))
                return dma_direct_map_sg(dev, sglist, nelems, dir, attrs);
 
-       domain = find_domain(dev);
+       domain = deferred_attach_domain(dev);
        if (!domain)
                return 0;
 
@@ -3830,7 +3835,7 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
        int prot = 0;
        int ret;
 
-       domain = find_domain(dev);
+       domain = deferred_attach_domain(dev);
        if (WARN_ON(dir == DMA_NONE || !domain))
                return DMA_MAPPING_ERROR;