summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/vm.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-10-17 18:54:31 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-11-01 22:06:27 -0400
commita8bd154f7907c7054f8668c5995c1b5a7f748edc (patch)
treec218183ea2b815141d3aa2eedbf3928610612ab1 /drivers/gpu/nvgpu/common/linux/vm.c
parentd13c256d5ee11da1664377481543005142d9bd30 (diff)
gpu: nvgpu: Remove user_mapped from mapped_buf
Remove the always true field 'user_mapped' from the mapped_buf struct. All mapped_bufs are mapped by a user request since they always originate from a dma_buf (for Linux, that is). As such there is a fair amount of logic that could be deleted. Linux specific: the own_mem_ref field was also be deleted. The logic of only storing a dma_buf ref when the buffer is mapped for the first time by a user is easy: when the mapped buffer is found in the map cache release the outstanding dma_buf ref taken earlier on in the map path. If the map cache does not have the buffer simply let the higher level map code keep the dma_buf ref. The dma_buf ref is released when the nvgpu_vm_unmap_system() call-back is called by the unmap path. JIRA NVGPU-30 JIRA NVGPU-71 Change-Id: I229d136713812a7332bdadd5ebacd85d983bbbf0 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1583983 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/vm.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/vm.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/vm.c b/drivers/gpu/nvgpu/common/linux/vm.c
index feb124f8..40e3d6ea 100644
--- a/drivers/gpu/nvgpu/common/linux/vm.c
+++ b/drivers/gpu/nvgpu/common/linux/vm.c
@@ -227,7 +227,6 @@ static u64 __nvgpu_vm_find_mapping(struct vm_gk20a *vm,
227 u64 offset_align, 227 u64 offset_align,
228 u32 flags, 228 u32 flags,
229 int kind, 229 int kind,
230 bool user_mapped,
231 int rw_flag) 230 int rw_flag)
232{ 231{
233 struct gk20a *g = gk20a_from_vm(vm); 232 struct gk20a *g = gk20a_from_vm(vm);
@@ -251,22 +250,13 @@ static u64 __nvgpu_vm_find_mapping(struct vm_gk20a *vm,
251 if (mapped_buffer->flags != flags) 250 if (mapped_buffer->flags != flags)
252 return 0; 251 return 0;
253 252
254 /* mark the buffer as used */ 253 /*
255 if (user_mapped) { 254 * If we find the mapping here then that means we have mapped it already
256 if (mapped_buffer->user_mapped == 0) 255 * and already have a dma_buf ref to the underlying buffer. As such
257 vm->num_user_mapped_buffers++; 256 * release the ref taken earlier in the map path.
258 mapped_buffer->user_mapped++; 257 */
258 dma_buf_put(mapped_buffer->dmabuf);
259 259
260 /* If the mapping comes from user space, we own
261 * the handle ref. Since we reuse an
262 * existing mapping here, we need to give back those
263 * refs once in order not to leak.
264 */
265 if (mapped_buffer->own_mem_ref)
266 dma_buf_put(mapped_buffer->dmabuf);
267 else
268 mapped_buffer->own_mem_ref = true;
269 }
270 nvgpu_ref_get(&mapped_buffer->ref); 260 nvgpu_ref_get(&mapped_buffer->ref);
271 261
272 nvgpu_log(g, gpu_dbg_map, 262 nvgpu_log(g, gpu_dbg_map,
@@ -329,7 +319,6 @@ u64 nvgpu_vm_map_linux(struct vm_gk20a *vm,
329 u32 flags, 319 u32 flags,
330 s16 compr_kind, 320 s16 compr_kind,
331 s16 incompr_kind, 321 s16 incompr_kind,
332 bool user_mapped,
333 int rw_flag, 322 int rw_flag,
334 u64 buffer_offset, 323 u64 buffer_offset,
335 u64 mapping_size, 324 u64 mapping_size,
@@ -367,7 +356,7 @@ u64 nvgpu_vm_map_linux(struct vm_gk20a *vm,
367 map_key_kind = compr_kind; 356 map_key_kind = compr_kind;
368 } 357 }
369 358
370 if (user_mapped && vm->userspace_managed && 359 if (vm->userspace_managed &&
371 !(flags & NVGPU_AS_MAP_BUFFER_FLAGS_FIXED_OFFSET)) { 360 !(flags & NVGPU_AS_MAP_BUFFER_FLAGS_FIXED_OFFSET)) {
372 nvgpu_err(g, "non-fixed-offset mapping not available on " 361 nvgpu_err(g, "non-fixed-offset mapping not available on "
373 "userspace managed address spaces"); 362 "userspace managed address spaces");
@@ -380,8 +369,7 @@ u64 nvgpu_vm_map_linux(struct vm_gk20a *vm,
380 if (!vm->userspace_managed) { 369 if (!vm->userspace_managed) {
381 map_offset = __nvgpu_vm_find_mapping( 370 map_offset = __nvgpu_vm_find_mapping(
382 vm, dmabuf, offset_align, 371 vm, dmabuf, offset_align,
383 flags, map_key_kind, 372 flags, map_key_kind, rw_flag);
384 user_mapped, rw_flag);
385 if (map_offset) { 373 if (map_offset) {
386 nvgpu_mutex_release(&vm->update_gmmu_lock); 374 nvgpu_mutex_release(&vm->update_gmmu_lock);
387 return map_offset; 375 return map_offset;
@@ -545,8 +533,6 @@ u64 nvgpu_vm_map_linux(struct vm_gk20a *vm,
545 mapped_buffer->flags = flags; 533 mapped_buffer->flags = flags;
546 mapped_buffer->kind = map_key_kind; 534 mapped_buffer->kind = map_key_kind;
547 mapped_buffer->va_allocated = va_allocated; 535 mapped_buffer->va_allocated = va_allocated;
548 mapped_buffer->user_mapped = user_mapped ? 1 : 0;
549 mapped_buffer->own_mem_ref = user_mapped;
550 nvgpu_init_list_node(&mapped_buffer->buffer_list); 536 nvgpu_init_list_node(&mapped_buffer->buffer_list);
551 nvgpu_ref_init(&mapped_buffer->ref); 537 nvgpu_ref_init(&mapped_buffer->ref);
552 538
@@ -555,8 +541,8 @@ u64 nvgpu_vm_map_linux(struct vm_gk20a *vm,
555 nvgpu_err(g, "failed to insert into mapped buffer tree"); 541 nvgpu_err(g, "failed to insert into mapped buffer tree");
556 goto clean_up; 542 goto clean_up;
557 } 543 }
558 if (user_mapped) 544
559 vm->num_user_mapped_buffers++; 545 vm->num_user_mapped_buffers++;
560 546
561 if (vm_area) { 547 if (vm_area) {
562 nvgpu_list_add_tail(&mapped_buffer->buffer_list, 548 nvgpu_list_add_tail(&mapped_buffer->buffer_list,
@@ -626,7 +612,7 @@ int nvgpu_vm_map_buffer(struct vm_gk20a *vm,
626 } 612 }
627 613
628 ret_va = nvgpu_vm_map_linux(vm, dmabuf, *offset_align, 614 ret_va = nvgpu_vm_map_linux(vm, dmabuf, *offset_align,
629 flags, compr_kind, incompr_kind, true, 615 flags, compr_kind, incompr_kind,
630 gk20a_mem_flag_none, 616 gk20a_mem_flag_none,
631 buffer_offset, 617 buffer_offset,
632 mapping_size, 618 mapping_size,
@@ -655,6 +641,5 @@ void nvgpu_vm_unmap_system(struct nvgpu_mapped_buf *mapped_buffer)
655 gk20a_mm_unpin(dev_from_vm(vm), mapped_buffer->dmabuf, 641 gk20a_mm_unpin(dev_from_vm(vm), mapped_buffer->dmabuf,
656 mapped_buffer->sgt); 642 mapped_buffer->sgt);
657 643
658 if (mapped_buffer->own_mem_ref) 644 dma_buf_put(mapped_buffer->dmabuf);
659 dma_buf_put(mapped_buffer->dmabuf);
660} 645}