diff options
author | Alex Waterman <alexw@nvidia.com> | 2017-10-09 18:06:26 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-10-10 19:26:55 -0400 |
commit | 50975dcf2afe7b8111d228e1520f652ac7ebe061 (patch) | |
tree | 27bbbed6f1c79d4dc3cd4018cea915ad2f225f5d /drivers/gpu/nvgpu/common/linux | |
parent | fc5c78733931b6267ff7af7e6aa732c5deb6c601 (diff) |
gpu: nvgpu: memset alloced buffers on free
When freeing kmalloc and vmalloc buffers memset them to zero
before freeing them with the kernel APIs. This is only done if
CONFIG_NVGPU_TRACK_MEM_USAGE is set since this adds obvious
overhead to the driver. However, it is an incredibly useful
debug tool, so it's nice to have.
This could be done by enabling Linux kernel configs as well,
but not all OSes may have such a feature so building it into
nvgpu may prove quite useful.
Change-Id: I7a6a9a6ab4f3606a73a90b354c5a4a7b9cd4d947
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1575565
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com>
Reviewed-by: Konsta Holtta <kholtta@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/kmem.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/kmem.c b/drivers/gpu/nvgpu/common/linux/kmem.c index 04df552c..a492fb35 100644 --- a/drivers/gpu/nvgpu/common/linux/kmem.c +++ b/drivers/gpu/nvgpu/common/linux/kmem.c | |||
@@ -301,6 +301,8 @@ static int __nvgpu_free_kmem_alloc(struct nvgpu_mem_alloc_tracker *tracker, | |||
301 | return -EINVAL; | 301 | return -EINVAL; |
302 | } | 302 | } |
303 | 303 | ||
304 | memset((void *)alloc->addr, 0, alloc->size); | ||
305 | |||
304 | tracker->nr_frees++; | 306 | tracker->nr_frees++; |
305 | tracker->bytes_freed += alloc->size; | 307 | tracker->bytes_freed += alloc->size; |
306 | tracker->bytes_freed_real += alloc->real_size; | 308 | tracker->bytes_freed_real += alloc->real_size; |
@@ -415,9 +417,9 @@ void __nvgpu_track_vfree(struct gk20a *g, void *addr) | |||
415 | if (!addr) | 417 | if (!addr) |
416 | return; | 418 | return; |
417 | 419 | ||
418 | vfree(addr); | ||
419 | |||
420 | __nvgpu_free_kmem_alloc(g->vmallocs, (u64)(uintptr_t)addr); | 420 | __nvgpu_free_kmem_alloc(g->vmallocs, (u64)(uintptr_t)addr); |
421 | |||
422 | vfree(addr); | ||
421 | } | 423 | } |
422 | 424 | ||
423 | void __nvgpu_track_kfree(struct gk20a *g, void *addr) | 425 | void __nvgpu_track_kfree(struct gk20a *g, void *addr) |
@@ -425,9 +427,9 @@ void __nvgpu_track_kfree(struct gk20a *g, void *addr) | |||
425 | if (!addr) | 427 | if (!addr) |
426 | return; | 428 | return; |
427 | 429 | ||
428 | kfree(addr); | ||
429 | |||
430 | __nvgpu_free_kmem_alloc(g->kmallocs, (u64)(uintptr_t)addr); | 430 | __nvgpu_free_kmem_alloc(g->kmallocs, (u64)(uintptr_t)addr); |
431 | |||
432 | kfree(addr); | ||
431 | } | 433 | } |
432 | 434 | ||
433 | static int __do_check_for_outstanding_allocs( | 435 | static int __do_check_for_outstanding_allocs( |