Skip to content

Commit e70b081

Browse files
pippy360joergroedel
authored andcommitted
iommu/vt-d: Remove IOVA handling code from the non-dma_ops path
There's no need for the non-dma_ops path to keep track of IOVAs. The whole point of the non-dma_ops path is that it allows the IOVAs to be handled separately. The IOVA handling code removed in this patch is pointless. Signed-off-by: Tom Murphy <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 7482fd5 commit e70b081

File tree

1 file changed

+32
-63
lines changed

1 file changed

+32
-63
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,11 +1892,6 @@ static int dmar_init_reserved_ranges(void)
18921892
return 0;
18931893
}
18941894

1895-
static void domain_reserve_special_ranges(struct dmar_domain *domain)
1896-
{
1897-
copy_reserved_iova(&reserved_iova_list, &domain->iovad);
1898-
}
1899-
19001895
static inline int guestwidth_to_adjustwidth(int gaw)
19011896
{
19021897
int agaw;
@@ -1918,7 +1913,8 @@ static void domain_exit(struct dmar_domain *domain)
19181913
domain_remove_dev_info(domain);
19191914

19201915
/* destroy iovas */
1921-
put_iova_domain(&domain->iovad);
1916+
if (domain->domain.type == IOMMU_DOMAIN_DMA)
1917+
put_iova_domain(&domain->iovad);
19221918

19231919
if (domain->pgd) {
19241920
struct page *freelist;
@@ -2627,19 +2623,9 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
26272623
}
26282624

26292625
static int iommu_domain_identity_map(struct dmar_domain *domain,
2630-
unsigned long long start,
2631-
unsigned long long end)
2626+
unsigned long first_vpfn,
2627+
unsigned long last_vpfn)
26322628
{
2633-
unsigned long first_vpfn = start >> VTD_PAGE_SHIFT;
2634-
unsigned long last_vpfn = end >> VTD_PAGE_SHIFT;
2635-
2636-
if (!reserve_iova(&domain->iovad, dma_to_mm_pfn(first_vpfn),
2637-
dma_to_mm_pfn(last_vpfn))) {
2638-
pr_err("Reserving iova failed\n");
2639-
return -ENOMEM;
2640-
}
2641-
2642-
pr_debug("Mapping reserved region %llx-%llx\n", start, end);
26432629
/*
26442630
* RMRR range might have overlap with physical memory range,
26452631
* clear it first
@@ -2677,7 +2663,8 @@ static int __init si_domain_init(int hw)
26772663

26782664
for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, NULL) {
26792665
ret = iommu_domain_identity_map(si_domain,
2680-
PFN_PHYS(start_pfn), PFN_PHYS(end_pfn));
2666+
mm_to_dma_pfn(start_pfn),
2667+
mm_to_dma_pfn(end_pfn));
26812668
if (ret)
26822669
return ret;
26832670
}
@@ -4547,58 +4534,37 @@ static int intel_iommu_memory_notifier(struct notifier_block *nb,
45474534
unsigned long val, void *v)
45484535
{
45494536
struct memory_notify *mhp = v;
4550-
unsigned long long start, end;
4551-
unsigned long start_vpfn, last_vpfn;
4537+
unsigned long start_vpfn = mm_to_dma_pfn(mhp->start_pfn);
4538+
unsigned long last_vpfn = mm_to_dma_pfn(mhp->start_pfn +
4539+
mhp->nr_pages - 1);
45524540

45534541
switch (val) {
45544542
case MEM_GOING_ONLINE:
4555-
start = mhp->start_pfn << PAGE_SHIFT;
4556-
end = ((mhp->start_pfn + mhp->nr_pages) << PAGE_SHIFT) - 1;
4557-
if (iommu_domain_identity_map(si_domain, start, end)) {
4558-
pr_warn("Failed to build identity map for [%llx-%llx]\n",
4559-
start, end);
4543+
if (iommu_domain_identity_map(si_domain,
4544+
start_vpfn, last_vpfn)) {
4545+
pr_warn("Failed to build identity map for [%lx-%lx]\n",
4546+
start_vpfn, last_vpfn);
45604547
return NOTIFY_BAD;
45614548
}
45624549
break;
45634550

45644551
case MEM_OFFLINE:
45654552
case MEM_CANCEL_ONLINE:
4566-
start_vpfn = mm_to_dma_pfn(mhp->start_pfn);
4567-
last_vpfn = mm_to_dma_pfn(mhp->start_pfn + mhp->nr_pages - 1);
4568-
while (start_vpfn <= last_vpfn) {
4569-
struct iova *iova;
4553+
{
45704554
struct dmar_drhd_unit *drhd;
45714555
struct intel_iommu *iommu;
45724556
struct page *freelist;
45734557

4574-
iova = find_iova(&si_domain->iovad, start_vpfn);
4575-
if (iova == NULL) {
4576-
pr_debug("Failed get IOVA for PFN %lx\n",
4577-
start_vpfn);
4578-
break;
4579-
}
4580-
4581-
iova = split_and_remove_iova(&si_domain->iovad, iova,
4582-
start_vpfn, last_vpfn);
4583-
if (iova == NULL) {
4584-
pr_warn("Failed to split IOVA PFN [%lx-%lx]\n",
4585-
start_vpfn, last_vpfn);
4586-
return NOTIFY_BAD;
4587-
}
4588-
4589-
freelist = domain_unmap(si_domain, iova->pfn_lo,
4590-
iova->pfn_hi);
4558+
freelist = domain_unmap(si_domain,
4559+
start_vpfn, last_vpfn);
45914560

45924561
rcu_read_lock();
45934562
for_each_active_iommu(iommu, drhd)
45944563
iommu_flush_iotlb_psi(iommu, si_domain,
4595-
iova->pfn_lo, iova_size(iova),
4564+
start_vpfn, mhp->nr_pages,
45964565
!freelist, 0);
45974566
rcu_read_unlock();
45984567
dma_free_pagelist(freelist);
4599-
4600-
start_vpfn = iova->pfn_hi + 1;
4601-
free_iova_mem(iova);
46024568
}
46034569
break;
46044570
}
@@ -4626,8 +4592,9 @@ static void free_all_cpu_cached_iovas(unsigned int cpu)
46264592
for (did = 0; did < cap_ndoms(iommu->cap); did++) {
46274593
domain = get_iommu_domain(iommu, (u16)did);
46284594

4629-
if (!domain)
4595+
if (!domain || domain->domain.type != IOMMU_DOMAIN_DMA)
46304596
continue;
4597+
46314598
free_cpu_cached_iovas(cpu, &domain->iovad);
46324599
}
46334600
}
@@ -5037,9 +5004,6 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width)
50375004
{
50385005
int adjust_width;
50395006

5040-
init_iova_domain(&domain->iovad, VTD_PAGE_SIZE, IOVA_START_PFN);
5041-
domain_reserve_special_ranges(domain);
5042-
50435007
/* calculate AGAW */
50445008
domain->gaw = guest_width;
50455009
adjust_width = guestwidth_to_adjustwidth(guest_width);
@@ -5058,11 +5022,21 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width)
50585022
return 0;
50595023
}
50605024

5025+
static void intel_init_iova_domain(struct dmar_domain *dmar_domain)
5026+
{
5027+
init_iova_domain(&dmar_domain->iovad, VTD_PAGE_SIZE, IOVA_START_PFN);
5028+
copy_reserved_iova(&reserved_iova_list, &dmar_domain->iovad);
5029+
5030+
if (!intel_iommu_strict &&
5031+
init_iova_flush_queue(&dmar_domain->iovad,
5032+
iommu_flush_iova, iova_entry_free))
5033+
pr_info("iova flush queue initialization failed\n");
5034+
}
5035+
50615036
static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
50625037
{
50635038
struct dmar_domain *dmar_domain;
50645039
struct iommu_domain *domain;
5065-
int ret;
50665040

50675041
switch (type) {
50685042
case IOMMU_DOMAIN_DMA:
@@ -5079,13 +5053,8 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
50795053
return NULL;
50805054
}
50815055

5082-
if (!intel_iommu_strict && type == IOMMU_DOMAIN_DMA) {
5083-
ret = init_iova_flush_queue(&dmar_domain->iovad,
5084-
iommu_flush_iova,
5085-
iova_entry_free);
5086-
if (ret)
5087-
pr_info("iova flush queue initialization failed\n");
5088-
}
5056+
if (type == IOMMU_DOMAIN_DMA)
5057+
intel_init_iova_domain(dmar_domain);
50895058

50905059
domain_update_iommu_cap(dmar_domain);
50915060

0 commit comments

Comments
 (0)