From dc0d8009084d06f1d75962385fb052f2b42494d4 Mon Sep 17 00:00:00 2001 From: Mukul Joshi Date: Thu, 1 Sep 2022 16:12:46 -0400 Subject: [PATCH] libhsakmt: Fix memory leak on queue destroy for GFX9.4.3 Currently, on queue destroy, context save restore memory is freed only for a single XCC. Instead, we need to free the entire context save restore memory, which was allocated for all XCCs. Signed-off-by: Mukul Joshi Change-Id: I51ebb12fa8d5ebed41979d68e74f7c5392dca062 [ROCm/ROCR-Runtime commit: a713fb766ef0c55f51b7a229b5d5e4cce45c7500] --- projects/rocr-runtime/src/queues.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/rocr-runtime/src/queues.c b/projects/rocr-runtime/src/queues.c index 715ad853bc..9e29fe15f8 100644 --- a/projects/rocr-runtime/src/queues.c +++ b/projects/rocr-runtime/src/queues.c @@ -62,6 +62,7 @@ struct queue { uint32_t ctl_stack_size; uint32_t debug_memory_size; uint32_t eop_buffer_size; + uint32_t total_mem_alloc_size; uint32_t gfxv; bool use_ats; bool unified_ctx_save_restore; @@ -448,7 +449,7 @@ static void free_queue(struct queue *q) PAGE_ALIGN_UP(q->ctx_save_restore_size + q->debug_memory_size)); else if (q->ctx_save_restore) free_exec_aligned_memory(q->ctx_save_restore, - q->ctx_save_restore_size + q->debug_memory_size, + q->total_mem_alloc_size, PAGE_SIZE, q->use_ats); free_exec_aligned_memory((void *)q, sizeof(*q), PAGE_SIZE, q->use_ats); @@ -498,7 +499,6 @@ static int handle_concrete_asic(struct queue *q, ret = update_ctx_save_restore_size(NodeId, q); if (ret) { - uint32_t total_mem_alloc_size = 0; HsaNodeProperties node; bool svm_api; @@ -509,10 +509,10 @@ static int handle_concrete_asic(struct queue *q, args->ctl_stack_size = q->ctl_stack_size; /* Total memory to be allocated is = - * (Control Stack size + WG size) per XCC * num_xcc + - * Debug memory area size + * (Control Stack size + WG size + + * Debug memory area size) * num_xcc */ - total_mem_alloc_size = (q->ctx_save_restore_size + + q->total_mem_alloc_size = (q->ctx_save_restore_size + q->debug_memory_size) * node.NumXcc; svm_api = node.Capability.ui32.SVMAPISupported; @@ -521,7 +521,7 @@ static int handle_concrete_asic(struct queue *q, * area on dGPU. */ if (!q->use_ats && svm_api) { - uint32_t size = PAGE_ALIGN_UP(total_mem_alloc_size); + uint32_t size = PAGE_ALIGN_UP(q->total_mem_alloc_size); void *addr; HSAKMT_STATUS r = HSAKMT_STATUS_ERROR; @@ -556,7 +556,7 @@ static int handle_concrete_asic(struct queue *q, if (!q->unified_ctx_save_restore) { q->ctx_save_restore = allocate_exec_aligned_memory( - total_mem_alloc_size, + q->total_mem_alloc_size, q->use_ats, NodeId, false, false, false);