>From 0df12098d4f86354eea458497f171e77f6cf9dee Mon Sep 17 00:00:00 2001 From: Lu Baolu Date: Thu, 7 Mar 2019 16:28:57 +0800 Subject: [PATCH 09/12] return si_domain directly --- drivers/iommu/intel-iommu.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 9641d75cbfa3..b380818878c7 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -4875,12 +4875,10 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) case IOMMU_DOMAIN_UNMANAGED: flags |= DOMAIN_FLAG_VIRTUAL_MACHINE | DOMAIN_FLAG_INITIALISED; dmar_domain = alloc_domain(flags); - if (!dmar_domain) { - pr_err("Can't allocate dmar_domain\n"); + if (!dmar_domain) return NULL; - } + if (md_domain_init(dmar_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) { - pr_err("Domain initialization failed\n"); domain_exit(dmar_domain); return NULL; } @@ -4892,30 +4890,15 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) break; case IOMMU_DOMAIN_DMA: dmar_domain = alloc_domain(flags); - if (!dmar_domain) { - pr_err("Can't allocate dmar_domain\n"); + if (!dmar_domain) return NULL; - } - // init domain in device attach when we know IOMMU capabilities break; case IOMMU_DOMAIN_IDENTITY: - flags |= DOMAIN_FLAG_STATIC_IDENTITY | DOMAIN_FLAG_INITIALISED; - dmar_domain = alloc_domain(flags); - if (!dmar_domain) { - pr_err("Can't allocate dmar_domain\n"); - return NULL; - } - if (si_domain_init(dmar_domain, 0)) { - pr_err("Domain initialization failed\n"); - domain_exit(dmar_domain); - return NULL; - } - break; + return &si_domain->domain; default: return NULL; } - dmar_domain->domain.type = type; return &dmar_domain->domain; } @@ -5009,6 +4992,10 @@ static int intel_iommu_map(struct iommu_domain *domain, int prot = 0; int ret; + /* Don't bother if hardware passthrough used. */ + if (dmar_domain == si_domain && hw_pass_through) + return 0; + if (iommu_prot & IOMMU_READ) prot |= DMA_PTE_READ; if (iommu_prot & IOMMU_WRITE) -- 2.17.1