Skip to content

Commit 781ca2d

Browse files
pippy360joergroedel
authored andcommitted
iommu: Add gfp parameter to iommu_ops::map
Add a gfp_t parameter to the iommu_ops::map function. Remove the needless locking in the AMD iommu driver. The iommu_ops::map function (or the iommu_map function which calls it) was always supposed to be sleepable (according to Joerg's comment in this thread: https://lore.kernel.org/patchwork/patch/977520/ ) and so should probably have had a "might_sleep()" since it was written. However currently the dma-iommu api can call iommu_map in an atomic context, which it shouldn't do. This doesn't cause any problems because any iommu driver which uses the dma-iommu api uses gfp_atomic in it's iommu_ops::map function. But doing this wastes the memory allocators atomic pools. Signed-off-by: Tom Murphy <murphyt7@tcd.ie> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 37ec8eb commit 781ca2d

19 files changed

Lines changed: 77 additions & 26 deletions

‎drivers/iommu/amd_iommu.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3106,7 +3106,8 @@ static int amd_iommu_attach_device(struct iommu_domain *dom,
31063106
}
31073107

31083108
static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
3109-
phys_addr_t paddr, size_t page_size, int iommu_prot)
3109+
phys_addr_t paddr, size_t page_size, int iommu_prot,
3110+
gfp_t gfp)
31103111
{
31113112
struct protection_domain *domain = to_pdomain(dom);
31123113
int prot = 0;

‎drivers/iommu/arm-smmu-v3.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
24482448
}
24492449

24502450
static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova,
2451-
phys_addr_t paddr, size_t size, int prot)
2451+
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
24522452
{
24532453
struct io_pgtable_ops *ops = to_smmu_domain(domain)->pgtbl_ops;
24542454

‎drivers/iommu/arm-smmu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11591159
}
11601160

11611161
static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova,
1162-
phys_addr_t paddr, size_t size, int prot)
1162+
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
11631163
{
11641164
struct io_pgtable_ops *ops = to_smmu_domain(domain)->pgtbl_ops;
11651165
struct arm_smmu_device *smmu = to_smmu_domain(domain)->smmu;

‎drivers/iommu/dma-iommu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
476476
if (!iova)
477477
return DMA_MAPPING_ERROR;
478478

479-
if (iommu_map(domain, iova, phys - iova_off, size, prot)) {
479+
if (iommu_map_atomic(domain, iova, phys - iova_off, size, prot)) {
480480
iommu_dma_free_iova(cookie, iova, size);
481481
return DMA_MAPPING_ERROR;
482482
}
@@ -611,7 +611,7 @@ static void *iommu_dma_alloc_remap(struct device *dev, size_t size,
611611
arch_dma_prep_coherent(sg_page(sg), sg->length);
612612
}
613613

614-
if (iommu_map_sg(domain, iova, sgt.sgl, sgt.orig_nents, ioprot)
614+
if (iommu_map_sg_atomic(domain, iova, sgt.sgl, sgt.orig_nents, ioprot)
615615
< size)
616616
goto out_free_sg;
617617

@@ -871,7 +871,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
871871
* We'll leave any physical concatenation to the IOMMU driver's
872872
* implementation - it knows better than we do.
873873
*/
874-
if (iommu_map_sg(domain, iova, sg, nents, prot) < iova_len)
874+
if (iommu_map_sg_atomic(domain, iova, sg, nents, prot) < iova_len)
875875
goto out_free_iova;
876876

877877
return __finalise_sg(dev, sg, nents, iova);

‎drivers/iommu/exynos-iommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ static int lv2set_page(sysmmu_pte_t *pent, phys_addr_t paddr, size_t size,
10731073
*/
10741074
static int exynos_iommu_map(struct iommu_domain *iommu_domain,
10751075
unsigned long l_iova, phys_addr_t paddr, size_t size,
1076-
int prot)
1076+
int prot, gfp_t gfp)
10771077
{
10781078
struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
10791079
sysmmu_pte_t *entry;

‎drivers/iommu/intel-iommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5432,7 +5432,7 @@ static void intel_iommu_aux_detach_device(struct iommu_domain *domain,
54325432

54335433
static int intel_iommu_map(struct iommu_domain *domain,
54345434
unsigned long iova, phys_addr_t hpa,
5435-
size_t size, int iommu_prot)
5435+
size_t size, int iommu_prot, gfp_t gfp)
54365436
{
54375437
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
54385438
u64 max_addr;

‎drivers/iommu/iommu.c‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,8 +1854,8 @@ static size_t iommu_pgsize(struct iommu_domain *domain,
18541854
return pgsize;
18551855
}
18561856

1857-
int iommu_map(struct iommu_domain *domain, unsigned long iova,
1858-
phys_addr_t paddr, size_t size, int prot)
1857+
int __iommu_map(struct iommu_domain *domain, unsigned long iova,
1858+
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
18591859
{
18601860
const struct iommu_ops *ops = domain->ops;
18611861
unsigned long orig_iova = iova;
@@ -1892,8 +1892,8 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
18921892

18931893
pr_debug("mapping: iova 0x%lx pa %pa pgsize 0x%zx\n",
18941894
iova, &paddr, pgsize);
1895+
ret = ops->map(domain, iova, paddr, pgsize, prot, gfp);
18951896

1896-
ret = ops->map(domain, iova, paddr, pgsize, prot);
18971897
if (ret)
18981898
break;
18991899

@@ -1913,8 +1913,22 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
19131913

19141914
return ret;
19151915
}
1916+
1917+
int iommu_map(struct iommu_domain *domain, unsigned long iova,
1918+
phys_addr_t paddr, size_t size, int prot)
1919+
{
1920+
might_sleep();
1921+
return __iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL);
1922+
}
19161923
EXPORT_SYMBOL_GPL(iommu_map);
19171924

1925+
int iommu_map_atomic(struct iommu_domain *domain, unsigned long iova,
1926+
phys_addr_t paddr, size_t size, int prot)
1927+
{
1928+
return __iommu_map(domain, iova, paddr, size, prot, GFP_ATOMIC);
1929+
}
1930+
EXPORT_SYMBOL_GPL(iommu_map_atomic);
1931+
19181932
static size_t __iommu_unmap(struct iommu_domain *domain,
19191933
unsigned long iova, size_t size,
19201934
struct iommu_iotlb_gather *iotlb_gather)
@@ -1991,8 +2005,9 @@ size_t iommu_unmap_fast(struct iommu_domain *domain,
19912005
}
19922006
EXPORT_SYMBOL_GPL(iommu_unmap_fast);
19932007

1994-
size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
1995-
struct scatterlist *sg, unsigned int nents, int prot)
2008+
size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
2009+
struct scatterlist *sg, unsigned int nents, int prot,
2010+
gfp_t gfp)
19962011
{
19972012
size_t len = 0, mapped = 0;
19982013
phys_addr_t start;
@@ -2003,7 +2018,9 @@ size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
20032018
phys_addr_t s_phys = sg_phys(sg);
20042019

20052020
if (len && s_phys != start + len) {
2006-
ret = iommu_map(domain, iova + mapped, start, len, prot);
2021+
ret = __iommu_map(domain, iova + mapped, start,
2022+
len, prot, gfp);
2023+
20072024
if (ret)
20082025
goto out_err;
20092026

@@ -2031,8 +2048,22 @@ size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
20312048
return 0;
20322049

20332050
}
2051+
2052+
size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
2053+
struct scatterlist *sg, unsigned int nents, int prot)
2054+
{
2055+
might_sleep();
2056+
return __iommu_map_sg(domain, iova, sg, nents, prot, GFP_KERNEL);
2057+
}
20342058
EXPORT_SYMBOL_GPL(iommu_map_sg);
20352059

2060+
size_t iommu_map_sg_atomic(struct iommu_domain *domain, unsigned long iova,
2061+
struct scatterlist *sg, unsigned int nents, int prot)
2062+
{
2063+
return __iommu_map_sg(domain, iova, sg, nents, prot, GFP_ATOMIC);
2064+
}
2065+
EXPORT_SYMBOL_GPL(iommu_map_sg_atomic);
2066+
20362067
int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
20372068
phys_addr_t paddr, u64 size, int prot)
20382069
{

‎drivers/iommu/ipmmu-vmsa.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static void ipmmu_detach_device(struct iommu_domain *io_domain,
724724
}
725725

726726
static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova,
727-
phys_addr_t paddr, size_t size, int prot)
727+
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
728728
{
729729
struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain);
730730

‎drivers/iommu/msm_iommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ static void msm_iommu_detach_dev(struct iommu_domain *domain,
504504
}
505505

506506
static int msm_iommu_map(struct iommu_domain *domain, unsigned long iova,
507-
phys_addr_t pa, size_t len, int prot)
507+
phys_addr_t pa, size_t len, int prot, gfp_t gfp)
508508
{
509509
struct msm_priv *priv = to_msm_priv(domain);
510510
unsigned long flags;

‎drivers/iommu/mtk_iommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static void mtk_iommu_detach_device(struct iommu_domain *domain,
412412
}
413413

414414
static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova,
415-
phys_addr_t paddr, size_t size, int prot)
415+
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
416416
{
417417
struct mtk_iommu_domain *dom = to_mtk_domain(domain);
418418
struct mtk_iommu_data *data = mtk_iommu_get_m4u_data();

0 commit comments

Comments
 (0)