diff options
author | Alex Waterman <alexw@nvidia.com> | 2017-10-17 18:54:31 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-11-01 22:06:27 -0400 |
commit | a8bd154f7907c7054f8668c5995c1b5a7f748edc (patch) | |
tree | c218183ea2b815141d3aa2eedbf3928610612ab1 /drivers | |
parent | d13c256d5ee11da1664377481543005142d9bd30 (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')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/cde.c | 1 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/vm.c | 39 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/mm/vm.c | 8 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/vm.h | 1 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/vm.h | 3 |
5 files changed, 16 insertions, 36 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/cde.c b/drivers/gpu/nvgpu/common/linux/cde.c index 2f2e886f..6600fe42 100644 --- a/drivers/gpu/nvgpu/common/linux/cde.c +++ b/drivers/gpu/nvgpu/common/linux/cde.c | |||
@@ -1050,7 +1050,6 @@ __releases(&l->cde_app->mutex) | |||
1050 | NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL, | 1050 | NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL, |
1051 | NV_KIND_INVALID, | 1051 | NV_KIND_INVALID, |
1052 | compbits_kind, /* incompressible kind */ | 1052 | compbits_kind, /* incompressible kind */ |
1053 | true, | ||
1054 | gk20a_mem_flag_none, | 1053 | gk20a_mem_flag_none, |
1055 | map_offset, map_size, | 1054 | map_offset, map_size, |
1056 | NULL); | 1055 | NULL); |
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 | } |
diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index 3d10ff48..2ce62e75 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c | |||
@@ -672,11 +672,9 @@ int nvgpu_vm_get_buffers(struct vm_gk20a *vm, | |||
672 | nvgpu_rbtree_enum_start(0, &node, vm->mapped_buffers); | 672 | nvgpu_rbtree_enum_start(0, &node, vm->mapped_buffers); |
673 | while (node) { | 673 | while (node) { |
674 | mapped_buffer = mapped_buffer_from_rbtree_node(node); | 674 | mapped_buffer = mapped_buffer_from_rbtree_node(node); |
675 | if (mapped_buffer->user_mapped) { | 675 | buffer_list[i] = mapped_buffer; |
676 | buffer_list[i] = mapped_buffer; | 676 | nvgpu_ref_get(&mapped_buffer->ref); |
677 | nvgpu_ref_get(&mapped_buffer->ref); | 677 | i++; |
678 | i++; | ||
679 | } | ||
680 | nvgpu_rbtree_enum_next(&node, node); | 678 | nvgpu_rbtree_enum_next(&node, node); |
681 | } | 679 | } |
682 | 680 | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h index 3d9f9ea6..3794706c 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h | |||
@@ -72,7 +72,6 @@ u64 nvgpu_vm_map_linux(struct vm_gk20a *vm, | |||
72 | */ | 72 | */ |
73 | s16 incompr_kind, | 73 | s16 incompr_kind, |
74 | 74 | ||
75 | bool user_mapped, | ||
76 | int rw_flag, | 75 | int rw_flag, |
77 | u64 buffer_offset, | 76 | u64 buffer_offset, |
78 | u64 mapping_size, | 77 | u64 mapping_size, |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm.h b/drivers/gpu/nvgpu/include/nvgpu/vm.h index 84c7e0c7..7370a8e3 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/vm.h +++ b/drivers/gpu/nvgpu/include/nvgpu/vm.h | |||
@@ -96,8 +96,7 @@ struct nvgpu_mapped_buf { | |||
96 | struct dma_buf *dmabuf; | 96 | struct dma_buf *dmabuf; |
97 | struct sg_table *sgt; | 97 | struct sg_table *sgt; |
98 | struct nvgpu_ref ref; | 98 | struct nvgpu_ref ref; |
99 | u32 user_mapped; | 99 | |
100 | bool own_mem_ref; | ||
101 | u32 pgsz_idx; | 100 | u32 pgsz_idx; |
102 | u32 ctag_offset; | 101 | u32 ctag_offset; |
103 | u32 ctag_lines; | 102 | u32 ctag_lines; |