msm: kgsl: Check the address range before mapping to GPU

Validate the GPU address range for memory mapping request
for user allocated buffers before setting the bitmap.

This is applicable to the memory mapping specifically
when user have used USE_CPU_MAP flag.

Change-Id: I7fd30789329939f89b5486d59bdee920616cc6df
Signed-off-by: Sunil Khatri <sunilkh@codeaurora.org>
This commit is contained in:
Sunil Khatri 2016-04-27 18:08:08 +05:30 committed by Gerrit - the friendly Code Review server
parent 944077f264
commit cda78f04e6
1 changed files with 15 additions and 0 deletions

View File

@ -728,6 +728,10 @@ kgsl_mmu_get_gpuaddr(struct kgsl_pagetable *pagetable,
if (kgsl_memdesc_has_guard_page(memdesc))
size += kgsl_memdesc_guard_page_size(memdesc);
if (size < memdesc->size) {
memdesc->size = 0;
return -EINVAL;
}
/*
* Allocate aligned virtual addresses for iommu. This allows
* more efficient pagetable entries if the physical memory
@ -735,8 +739,19 @@ kgsl_mmu_get_gpuaddr(struct kgsl_pagetable *pagetable,
*/
if (kgsl_memdesc_use_cpu_map(memdesc)) {
uint64_t end = memdesc->gpuaddr + size;
if (memdesc->gpuaddr == 0)
return -EINVAL;
/*
* Validate the GPU address range for memory mapping request
* for user allocated buffers before setting the bitmap.
*/
if ((end >= (KGSL_MMU_GLOBAL_MEM_BASE - SZ_1M)) ||
(end < memdesc->gpuaddr)) {
memdesc->gpuaddr = 0;
return -EINVAL;
}
bitmap_set(pagetable->mem_bitmap,
(int) (memdesc->gpuaddr >> PAGE_SHIFT),
(int) (size >> PAGE_SHIFT));