Skip to content

Commit 1c0490c

Browse files
committed
Merge tag 'iommu-fixes-v5.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull IOMMU fixes from Joerg Roedel: "A few more fixes this time: - Two patches to fix the error path of the map_sg implementation of the AMD IOMMU driver. - Also a missing IOTLB flush is fixed in the AMD IOMMU driver. - Memory leak fix for the Intel IOMMU driver. - Fix a regression in the Mediatek IOMMU driver which caused device initialization to fail (seen as broken HDMI output)" * tag 'iommu-fixes-v5.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: iommu/amd: Fix IOMMU page flush when detach device from a domain iommu/mediatek: Use correct fwspec in mtk_iommu_add_device() iommu/vt-d: Fix memory leak in intel_iommu_put_resv_regions() iommu/amd: Unmap all mapped pages in error path of map_sg iommu/amd: Call free_iova_fast with pfn in map_sg
2 parents 877ef51 + 9825bd9 commit 1c0490c

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,16 +1991,13 @@ static void do_attach(struct iommu_dev_data *dev_data,
19911991

19921992
static void do_detach(struct iommu_dev_data *dev_data)
19931993
{
1994+
struct protection_domain *domain = dev_data->domain;
19941995
struct amd_iommu *iommu;
19951996
u16 alias;
19961997

19971998
iommu = amd_iommu_rlookup_table[dev_data->devid];
19981999
alias = dev_data->alias;
19992000

2000-
/* decrease reference counters */
2001-
dev_data->domain->dev_iommu[iommu->index] -= 1;
2002-
dev_data->domain->dev_cnt -= 1;
2003-
20042001
/* Update data structures */
20052002
dev_data->domain = NULL;
20062003
list_del(&dev_data->list);
@@ -2010,6 +2007,16 @@ static void do_detach(struct iommu_dev_data *dev_data)
20102007

20112008
/* Flush the DTE entry */
20122009
device_flush_dte(dev_data);
2010+
2011+
/* Flush IOTLB */
2012+
domain_flush_tlb_pde(domain);
2013+
2014+
/* Wait for the flushes to finish */
2015+
domain_flush_complete(domain);
2016+
2017+
/* decrease reference counters - needs to happen after the flushes */
2018+
domain->dev_iommu[iommu->index] -= 1;
2019+
domain->dev_cnt -= 1;
20132020
}
20142021

20152022
/*
@@ -2617,13 +2624,13 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
26172624
bus_addr = address + s->dma_address + (j << PAGE_SHIFT);
26182625
iommu_unmap_page(domain, bus_addr, PAGE_SIZE);
26192626

2620-
if (--mapped_pages)
2627+
if (--mapped_pages == 0)
26212628
goto out_free_iova;
26222629
}
26232630
}
26242631

26252632
out_free_iova:
2626-
free_iova_fast(&dma_dom->iovad, address, npages);
2633+
free_iova_fast(&dma_dom->iovad, address >> PAGE_SHIFT, npages);
26272634

26282635
out_err:
26292636
return 0;

drivers/iommu/intel-iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5294,7 +5294,7 @@ static void intel_iommu_put_resv_regions(struct device *dev,
52945294
struct iommu_resv_region *entry, *next;
52955295

52965296
list_for_each_entry_safe(entry, next, head, list) {
5297-
if (entry->type == IOMMU_RESV_RESERVED)
5297+
if (entry->type == IOMMU_RESV_MSI)
52985298
kfree(entry);
52995299
}
53005300
}

drivers/iommu/mtk_iommu_v1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ static int mtk_iommu_add_device(struct device *dev)
441441
iommu_spec.args_count = count;
442442

443443
mtk_iommu_create_mapping(dev, &iommu_spec);
444+
445+
/* dev->iommu_fwspec might have changed */
446+
fwspec = dev_iommu_fwspec_get(dev);
447+
444448
of_node_put(iommu_spec.np);
445449
}
446450

0 commit comments

Comments
 (0)