From bf374b779fbb71280fafcefeb3bb3d68f047b304 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Tue, 6 Mar 2018 15:47:39 -0800 Subject: gpu: nvgpu: Pass correct va_allocated field in .gmmu_unmap() When nvgpu maps an nvgpu_mem struct the nvgpu driver has a choice of either using a fixed or non-fixed mapping. For non-fixed mappings the GMMU APIs allocate a VA space for the caller. In that case the GMMU APIs must also free that VA range when nvgpu unmaps the nvgpu_mem. For fixed mappings the GMMU APIs must instead not manage the life time of the VA space. To support these two possibilities add a field to nvgpu_mem that specifies whether the GMMU APIs must or must not free the GPU VA range during the GMMU unmap operation. Also fix a case in the nvgpu vm_area code that would double free a VA allocation in some cases (sparse allocs). Change-Id: Idc32dbb8208fa7c1c05823e67b54707fea51c6b7 Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1669920 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/gmmu.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'drivers/gpu/nvgpu/common/mm/gmmu.c') diff --git a/drivers/gpu/nvgpu/common/mm/gmmu.c b/drivers/gpu/nvgpu/common/mm/gmmu.c index 44e540dc..89d71b3b 100644 --- a/drivers/gpu/nvgpu/common/mm/gmmu.c +++ b/drivers/gpu/nvgpu/common/mm/gmmu.c @@ -86,6 +86,18 @@ static u64 __nvgpu_gmmu_map(struct vm_gk20a *vm, if (nvgpu_is_enabled(g, NVGPU_USE_COHERENT_SYSMEM)) flags |= NVGPU_VM_MAP_IO_COHERENT; + /* + * Later on, when we free this nvgpu_mem's GPU mapping, we are going to + * potentially have to free the GPU VA space. If the address passed in + * is non-zero then this API is not expected to manage the VA space and + * therefor we should not try and free it. But otherwise, if we do + * manage the VA alloc, we obviously must free it. + */ + if (addr != 0) + mem->free_gpu_va = false; + else + mem->free_gpu_va = true; + nvgpu_mutex_acquire(&vm->update_gmmu_lock); vaddr = g->ops.mm.gmmu_map(vm, addr, sgt, /* sg list */ @@ -152,7 +164,7 @@ void nvgpu_gmmu_unmap(struct vm_gk20a *vm, struct nvgpu_mem *mem, u64 gpu_va) gpu_va, mem->size, gmmu_page_size_kernel, - true, /*va_allocated */ + mem->free_gpu_va, gk20a_mem_flag_none, false, NULL); -- cgit v1.2.2