iommu: arm-smmu: Move most memory allocations to GFP_KERNEL

Order 0 allocation failures were being seen rarely during camera
usecases, which were estimated to require 800Mb of memory. This
corresponds to ~1.6 Mb of memory allocated via GFP_ATOMIC.

page allocation failure: order:0, mode:0x2088020(GFP_ATOMIC|__GFP_ZERO)
warn_alloc+0x114/0x134
__alloc_pages_nodemask+0x3e8/0xd30
alloc_pages_exact+0x4c/0xa4
arm_smmu_alloc_pages_exact+0x128/0x15c
io_pgtable_alloc_pages_exact+0x30/0xa0
__arm_lpae_alloc_pages+0x40/0x1c8
__arm_lpae_map+0x224/0x3b4
__arm_lpae_map+0x108/0x3b4
arm_lpae_map_sg+0x1f8/0x314
arm_smmu_map_sg+0x108/0x204
iommu_map_sg+0x30/0xfc
arm_iommu_map_sg+0x1e0/0x3d0
msm_dma_map_sg_attrs+0x2ec/0x660
cam_smmu_map_buffer_validate+0xc4/0x698
cam_smmu_map_user_iova+0x154/0x304
cam_mem_util_map_hw_va+0xf8/0x1f8
cam_mem_mgr_map+0xa8/0x350
cam_private_ioctl+0x494/0x6f0
__video_do_ioctl+0xb8/0x2bc
video_usercopy+0x28c/0x658
video_ioctl2+0x18/0x28

Node 0 active_anon:521428kB inactive_anon:385400kB active_file:499900kB
inactive_file:459444kB unevictable:9532kB isolated(anon):0kB
isolated(file):128kB mapped:648252kB dirty:0kB writeback:0kB shmem:2544kB
writeback_tmp:0kB unstable:0kB all_unreclaimable? no

DMA free:12332kB min:2752kB low:24992kB high:26276kB active_anon:279808kB
inactive_anon:118280kB active_file:148280kB inactive_file:169896kB
unevictable:0kB writepending:0kB present:1729188kB managed:1286960kB
mlocked:0kB slab_reclaimable:14940kB slab_unreclaimable:57784kB
kernel_stack:20752kB pagetables:36284kB bounce:0kB free_pcp:4972kB
local_pcp:620kB free_cma:432kB lowmem_reserve[]: 0 1906 1906

Normal free:7460kB min:4260kB low:38640kB high:40628kB
active_anon:242612kB inactive_anon:266492kB active_file:351456kB
inactive_file:290540kB unevictable:9568kB writepending:0kB
present:2067200kB managed:1989364kB mlocked:128kB slab_reclaimable:46708kB
slab_unreclaimable:116340kB kernel_stack:23520kB pagetables:36948kB
bounce:0kB free_pcp:4580kB local_pcp:80kB free_cma:0kB lowmem_reserve[]: 0
0 0

DMA: 603*4kB (UMCH) 469*8kB (UMCH) 258*16kB (UCH) 69*32kB (CH) 0*64kB
0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 12500kB

Normal: 320*4kB (H) 426*8kB (H) 142*16kB (H) 19*32kB (H) 0*64kB 0*128kB
0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 7568kB

For iommu domains which allow blocking, estimate the amount of pagetable
memory required by a particular operation, and preallocate it with the
GFP_KERNEL flag. The behavior for iommu domains which cannot block remains
the same, and they may encounter the same error as above.

Change-Id: I16804ef0876ab6e7acb76560f7398baacd3a30a8
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
diff --git a/drivers/iommu/msm_dma_iommu_mapping.c b/drivers/iommu/msm_dma_iommu_mapping.c
index 3f739a2..180edf3 100644
--- a/drivers/iommu/msm_dma_iommu_mapping.c
+++ b/drivers/iommu/msm_dma_iommu_mapping.c
@@ -1,4 +1,4 @@
-/* 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
@@ -183,7 +183,7 @@
 	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;