Loading drivers/iommu/arm-smmu.c +64 −1 Original line number Diff line number Diff line Loading @@ -535,6 +535,8 @@ struct arm_smmu_domain { struct list_head unassign_list; struct mutex assign_lock; struct list_head secure_pool_list; /* nonsecure pool protected by pgtbl_lock */ struct list_head nonsecure_pool; struct iommu_domain domain; bool qsmmuv500_errata1_init; Loading Loading @@ -1313,8 +1315,19 @@ static void *arm_smmu_alloc_pages_exact(void *cookie, void *page; struct arm_smmu_domain *smmu_domain = cookie; if (!arm_smmu_is_master_side_secure(smmu_domain)) if (!arm_smmu_is_master_side_secure(smmu_domain)) { struct page *pg; /* size is expected to be 4K with current configuration */ if (size == PAGE_SIZE) { pg = list_first_entry_or_null( &smmu_domain->nonsecure_pool, struct page, lru); if (pg) { list_del_init(&pg->lru); return page_address(pg); } } return alloc_pages_exact(size, gfp_mask); } page = arm_smmu_secure_pool_remove(smmu_domain, size); if (page) Loading Loading @@ -2080,6 +2093,7 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) INIT_LIST_HEAD(&smmu_domain->unassign_list); mutex_init(&smmu_domain->assign_lock); INIT_LIST_HEAD(&smmu_domain->secure_pool_list); INIT_LIST_HEAD(&smmu_domain->nonsecure_pool); arm_smmu_domain_reinit(smmu_domain); return &smmu_domain->domain; Loading Loading @@ -2432,6 +2446,50 @@ static int arm_smmu_prepare_pgtable(void *addr, void *cookie) return 0; } static void arm_smmu_prealloc_memory(struct arm_smmu_domain *smmu_domain, struct scatterlist *sgl, int nents, struct list_head *pool) { u32 nr = 0; int i; size_t size = 0; struct scatterlist *sg; struct page *page; if ((smmu_domain->attributes & (1 << DOMAIN_ATTR_ATOMIC)) || arm_smmu_has_secure_vmid(smmu_domain)) return; for_each_sg(sgl, sg, nents, i) size += sg->length; /* number of 2nd level pagetable entries */ nr += round_up(size, SZ_1G) >> 30; /* number of 3rd level pagetabel entries */ nr += round_up(size, SZ_2M) >> 21; /* Retry later with atomic allocation on error */ for (i = 0; i < nr; i++) { page = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0); if (!page) break; list_add(&page->lru, pool); } } static void arm_smmu_release_prealloc_memory( struct arm_smmu_domain *smmu_domain, struct list_head *list) { struct page *page, *tmp; u32 remaining = 0; list_for_each_entry_safe(page, tmp, list, lru) { list_del(&page->lru); __free_pages(page, 0); remaining++; } } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret; Loading Loading @@ -2589,10 +2647,12 @@ static size_t arm_smmu_map_sg(struct iommu_domain *domain, unsigned long iova, unsigned int idx_start, idx_end; struct scatterlist *sg_start, *sg_end; unsigned long __saved_iova_start; LIST_HEAD(nonsecure_pool); if (!ops) return -ENODEV; arm_smmu_prealloc_memory(smmu_domain, sg, nents, &nonsecure_pool); arm_smmu_secure_domain_lock(smmu_domain); __saved_iova_start = iova; Loading @@ -2611,8 +2671,10 @@ static size_t arm_smmu_map_sg(struct iommu_domain *domain, unsigned long iova, } spin_lock_irqsave(&smmu_domain->pgtbl_lock, flags); list_splice_init(&nonsecure_pool, &smmu_domain->nonsecure_pool); ret = ops->map_sg(ops, iova, sg_start, idx_end - idx_start, prot, &size); list_splice_init(&smmu_domain->nonsecure_pool, &nonsecure_pool); spin_unlock_irqrestore(&smmu_domain->pgtbl_lock, flags); /* Returns 0 on error */ if (!ret) { Loading @@ -2633,6 +2695,7 @@ static size_t arm_smmu_map_sg(struct iommu_domain *domain, unsigned long iova, iova = __saved_iova_start; } arm_smmu_secure_domain_unlock(smmu_domain); arm_smmu_release_prealloc_memory(smmu_domain, &nonsecure_pool); return iova - __saved_iova_start; } Loading drivers/iommu/msm_dma_iommu_mapping.c +2 −2 Original line number Diff line number Diff line /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -183,7 +183,7 @@ static inline int __msm_dma_map_sg(struct device *dev, struct scatterlist *sg, mutex_lock(&iommu_meta->lock); iommu_map = msm_iommu_lookup(iommu_meta, dev); if (!iommu_map) { iommu_map = kmalloc(sizeof(*iommu_map), GFP_ATOMIC); iommu_map = kmalloc(sizeof(*iommu_map), GFP_KERNEL); if (!iommu_map) { ret = -ENOMEM; Loading Loading
drivers/iommu/arm-smmu.c +64 −1 Original line number Diff line number Diff line Loading @@ -535,6 +535,8 @@ struct arm_smmu_domain { struct list_head unassign_list; struct mutex assign_lock; struct list_head secure_pool_list; /* nonsecure pool protected by pgtbl_lock */ struct list_head nonsecure_pool; struct iommu_domain domain; bool qsmmuv500_errata1_init; Loading Loading @@ -1313,8 +1315,19 @@ static void *arm_smmu_alloc_pages_exact(void *cookie, void *page; struct arm_smmu_domain *smmu_domain = cookie; if (!arm_smmu_is_master_side_secure(smmu_domain)) if (!arm_smmu_is_master_side_secure(smmu_domain)) { struct page *pg; /* size is expected to be 4K with current configuration */ if (size == PAGE_SIZE) { pg = list_first_entry_or_null( &smmu_domain->nonsecure_pool, struct page, lru); if (pg) { list_del_init(&pg->lru); return page_address(pg); } } return alloc_pages_exact(size, gfp_mask); } page = arm_smmu_secure_pool_remove(smmu_domain, size); if (page) Loading Loading @@ -2080,6 +2093,7 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) INIT_LIST_HEAD(&smmu_domain->unassign_list); mutex_init(&smmu_domain->assign_lock); INIT_LIST_HEAD(&smmu_domain->secure_pool_list); INIT_LIST_HEAD(&smmu_domain->nonsecure_pool); arm_smmu_domain_reinit(smmu_domain); return &smmu_domain->domain; Loading Loading @@ -2432,6 +2446,50 @@ static int arm_smmu_prepare_pgtable(void *addr, void *cookie) return 0; } static void arm_smmu_prealloc_memory(struct arm_smmu_domain *smmu_domain, struct scatterlist *sgl, int nents, struct list_head *pool) { u32 nr = 0; int i; size_t size = 0; struct scatterlist *sg; struct page *page; if ((smmu_domain->attributes & (1 << DOMAIN_ATTR_ATOMIC)) || arm_smmu_has_secure_vmid(smmu_domain)) return; for_each_sg(sgl, sg, nents, i) size += sg->length; /* number of 2nd level pagetable entries */ nr += round_up(size, SZ_1G) >> 30; /* number of 3rd level pagetabel entries */ nr += round_up(size, SZ_2M) >> 21; /* Retry later with atomic allocation on error */ for (i = 0; i < nr; i++) { page = alloc_pages(GFP_KERNEL | __GFP_ZERO, 0); if (!page) break; list_add(&page->lru, pool); } } static void arm_smmu_release_prealloc_memory( struct arm_smmu_domain *smmu_domain, struct list_head *list) { struct page *page, *tmp; u32 remaining = 0; list_for_each_entry_safe(page, tmp, list, lru) { list_del(&page->lru); __free_pages(page, 0); remaining++; } } static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret; Loading Loading @@ -2589,10 +2647,12 @@ static size_t arm_smmu_map_sg(struct iommu_domain *domain, unsigned long iova, unsigned int idx_start, idx_end; struct scatterlist *sg_start, *sg_end; unsigned long __saved_iova_start; LIST_HEAD(nonsecure_pool); if (!ops) return -ENODEV; arm_smmu_prealloc_memory(smmu_domain, sg, nents, &nonsecure_pool); arm_smmu_secure_domain_lock(smmu_domain); __saved_iova_start = iova; Loading @@ -2611,8 +2671,10 @@ static size_t arm_smmu_map_sg(struct iommu_domain *domain, unsigned long iova, } spin_lock_irqsave(&smmu_domain->pgtbl_lock, flags); list_splice_init(&nonsecure_pool, &smmu_domain->nonsecure_pool); ret = ops->map_sg(ops, iova, sg_start, idx_end - idx_start, prot, &size); list_splice_init(&smmu_domain->nonsecure_pool, &nonsecure_pool); spin_unlock_irqrestore(&smmu_domain->pgtbl_lock, flags); /* Returns 0 on error */ if (!ret) { Loading @@ -2633,6 +2695,7 @@ static size_t arm_smmu_map_sg(struct iommu_domain *domain, unsigned long iova, iova = __saved_iova_start; } arm_smmu_secure_domain_unlock(smmu_domain); arm_smmu_release_prealloc_memory(smmu_domain, &nonsecure_pool); return iova - __saved_iova_start; } Loading
drivers/iommu/msm_dma_iommu_mapping.c +2 −2 Original line number Diff line number Diff line /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -183,7 +183,7 @@ static inline int __msm_dma_map_sg(struct device *dev, struct scatterlist *sg, mutex_lock(&iommu_meta->lock); iommu_map = msm_iommu_lookup(iommu_meta, dev); if (!iommu_map) { iommu_map = kmalloc(sizeof(*iommu_map), GFP_ATOMIC); iommu_map = kmalloc(sizeof(*iommu_map), GFP_KERNEL); if (!iommu_map) { ret = -ENOMEM; Loading