Skip to content

Commit 9e74e1b

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Remove identity mappings from si_domain
As the driver has enforced DMA domains for devices managed by an IOMMU hardware that doesn't support passthrough translation mode, there is no need for static identity mappings in the si_domain. Remove the identity mapping code to avoid dead code. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 184bee3 commit 9e74e1b

File tree

1 file changed

+4
-118
lines changed

1 file changed

+4
-118
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 4 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,7 @@ static void device_rbtree_remove(struct device_domain_info *info)
167167
spin_unlock_irqrestore(&iommu->device_rbtree_lock, flags);
168168
}
169169

170-
/*
171-
* This domain is a statically identity mapping domain.
172-
* 1. This domain creats a static 1:1 mapping to all usable memory.
173-
* 2. It maps to each iommu if successful.
174-
* 3. Each iommu mapps to this domain if successful.
175-
*/
176170
static struct dmar_domain *si_domain;
177-
static int hw_pass_through = 1;
178171

179172
struct dmar_rmrr_unit {
180173
struct list_head list; /* list of rmrr units */
@@ -1647,7 +1640,7 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
16471640
struct context_entry *context;
16481641
int agaw, ret;
16491642

1650-
if (hw_pass_through && domain_type_is_si(domain))
1643+
if (domain_type_is_si(domain))
16511644
translation = CONTEXT_TT_PASS_THROUGH;
16521645

16531646
pr_debug("Set context mapping for %02x:%02x.%d\n",
@@ -1998,29 +1991,10 @@ static bool dev_is_real_dma_subdevice(struct device *dev)
19981991
pci_real_dma_dev(to_pci_dev(dev)) != to_pci_dev(dev);
19991992
}
20001993

2001-
static int iommu_domain_identity_map(struct dmar_domain *domain,
2002-
unsigned long first_vpfn,
2003-
unsigned long last_vpfn)
2004-
{
2005-
/*
2006-
* RMRR range might have overlap with physical memory range,
2007-
* clear it first
2008-
*/
2009-
dma_pte_clear_range(domain, first_vpfn, last_vpfn);
2010-
2011-
return __domain_mapping(domain, first_vpfn,
2012-
first_vpfn, last_vpfn - first_vpfn + 1,
2013-
DMA_PTE_READ|DMA_PTE_WRITE, GFP_KERNEL);
2014-
}
2015-
20161994
static int md_domain_init(struct dmar_domain *domain, int guest_width);
20171995

2018-
static int __init si_domain_init(int hw)
1996+
static int __init si_domain_init(void)
20191997
{
2020-
struct dmar_rmrr_unit *rmrr;
2021-
struct device *dev;
2022-
int i, nid, ret;
2023-
20241998
si_domain = alloc_domain(IOMMU_DOMAIN_IDENTITY);
20251999
if (!si_domain)
20262000
return -EFAULT;
@@ -2031,44 +2005,6 @@ static int __init si_domain_init(int hw)
20312005
return -EFAULT;
20322006
}
20332007

2034-
if (hw)
2035-
return 0;
2036-
2037-
for_each_online_node(nid) {
2038-
unsigned long start_pfn, end_pfn;
2039-
int i;
2040-
2041-
for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, NULL) {
2042-
ret = iommu_domain_identity_map(si_domain,
2043-
mm_to_dma_pfn_start(start_pfn),
2044-
mm_to_dma_pfn_end(end_pfn-1));
2045-
if (ret)
2046-
return ret;
2047-
}
2048-
}
2049-
2050-
/*
2051-
* Identity map the RMRRs so that devices with RMRRs could also use
2052-
* the si_domain.
2053-
*/
2054-
for_each_rmrr_units(rmrr) {
2055-
for_each_active_dev_scope(rmrr->devices, rmrr->devices_cnt,
2056-
i, dev) {
2057-
unsigned long long start = rmrr->base_address;
2058-
unsigned long long end = rmrr->end_address;
2059-
2060-
if (WARN_ON(end < start ||
2061-
end >> agaw_to_width(si_domain->agaw)))
2062-
continue;
2063-
2064-
ret = iommu_domain_identity_map(si_domain,
2065-
mm_to_dma_pfn_start(start >> PAGE_SHIFT),
2066-
mm_to_dma_pfn_end(end >> PAGE_SHIFT));
2067-
if (ret)
2068-
return ret;
2069-
}
2070-
}
2071-
20722008
return 0;
20732009
}
20742010

@@ -2094,7 +2030,7 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
20942030

20952031
if (!sm_supported(iommu))
20962032
ret = domain_context_mapping(domain, dev);
2097-
else if (hw_pass_through && domain_type_is_si(domain))
2033+
else if (domain_type_is_si(domain))
20982034
ret = intel_pasid_setup_pass_through(iommu, dev, IOMMU_NO_PASID);
20992035
else if (domain->use_first_level)
21002036
ret = domain_setup_first_level(iommu, domain, dev, IOMMU_NO_PASID);
@@ -2449,8 +2385,6 @@ static int __init init_dmars(void)
24492385
}
24502386
}
24512387

2452-
if (!ecap_pass_through(iommu->ecap))
2453-
hw_pass_through = 0;
24542388
intel_svm_check(iommu);
24552389
}
24562390

@@ -2466,7 +2400,7 @@ static int __init init_dmars(void)
24662400

24672401
check_tylersburg_isoch();
24682402

2469-
ret = si_domain_init(hw_pass_through);
2403+
ret = si_domain_init();
24702404
if (ret)
24712405
goto free_iommu;
24722406

@@ -2893,12 +2827,6 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)
28932827
if (ret)
28942828
goto out;
28952829

2896-
if (hw_pass_through && !ecap_pass_through(iommu->ecap)) {
2897-
pr_warn("%s: Doesn't support hardware pass through.\n",
2898-
iommu->name);
2899-
return -ENXIO;
2900-
}
2901-
29022830
sp = domain_update_iommu_superpage(NULL, iommu) - 1;
29032831
if (sp >= 0 && !(cap_super_page_val(iommu->cap) & (1 << sp))) {
29042832
pr_warn("%s: Doesn't support large page.\n",
@@ -3149,43 +3077,6 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info)
31493077
return 0;
31503078
}
31513079

3152-
static int intel_iommu_memory_notifier(struct notifier_block *nb,
3153-
unsigned long val, void *v)
3154-
{
3155-
struct memory_notify *mhp = v;
3156-
unsigned long start_vpfn = mm_to_dma_pfn_start(mhp->start_pfn);
3157-
unsigned long last_vpfn = mm_to_dma_pfn_end(mhp->start_pfn +
3158-
mhp->nr_pages - 1);
3159-
3160-
switch (val) {
3161-
case MEM_GOING_ONLINE:
3162-
if (iommu_domain_identity_map(si_domain,
3163-
start_vpfn, last_vpfn)) {
3164-
pr_warn("Failed to build identity map for [%lx-%lx]\n",
3165-
start_vpfn, last_vpfn);
3166-
return NOTIFY_BAD;
3167-
}
3168-
break;
3169-
3170-
case MEM_OFFLINE:
3171-
case MEM_CANCEL_ONLINE:
3172-
{
3173-
LIST_HEAD(freelist);
3174-
3175-
domain_unmap(si_domain, start_vpfn, last_vpfn, &freelist);
3176-
iommu_put_pages_list(&freelist);
3177-
}
3178-
break;
3179-
}
3180-
3181-
return NOTIFY_OK;
3182-
}
3183-
3184-
static struct notifier_block intel_iommu_memory_nb = {
3185-
.notifier_call = intel_iommu_memory_notifier,
3186-
.priority = 0
3187-
};
3188-
31893080
static void intel_disable_iommus(void)
31903081
{
31913082
struct intel_iommu *iommu = NULL;
@@ -3482,12 +3373,7 @@ int __init intel_iommu_init(void)
34823373

34833374
iommu_pmu_register(iommu);
34843375
}
3485-
up_read(&dmar_global_lock);
3486-
3487-
if (si_domain && !hw_pass_through)
3488-
register_memory_notifier(&intel_iommu_memory_nb);
34893376

3490-
down_read(&dmar_global_lock);
34913377
if (probe_acpi_namespace_devices())
34923378
pr_warn("ACPI name space devices didn't probe correctly\n");
34933379

0 commit comments

Comments
 (0)