From 7486e8e29ff644153919a6790b56b2880a59ff10 Mon Sep 17 00:00:00 2001 From: Oak Zeng Date: Mon, 20 Nov 2017 10:57:37 -0500 Subject: [PATCH] Fix unconditional unmap in fmm_map_to_gpu_nodes _fmm_unmap_from_gpu is called in fmm_map_to_gpu_nodes to unmap buffer from nodes that is already mapped to but not in the new map nodes list. Previously, the unmap was called unconditionally even though the size of the array to unmap is 0. This fixes the issue by calling the unmap func only when the unmap array size is not 0. Also releases the fmm_mutex on error returns Change-Id: Iadd8383caf7ebb92f02618798c5efd138a352aaa Signed-off-by: Oak Zeng [ROCm/ROCR-Runtime commit: 061db45fe2447a616ab3e8dcf88e95437a331fff] --- projects/rocr-runtime/src/fmm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index b375b776fe..1313566c3c 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -3022,11 +3022,16 @@ HSAKMT_STATUS fmm_map_to_gpu_nodes(void *address, uint64_t size, } temp_node_id_array_size *= sizeof(uint32_t); - ret = _fmm_unmap_from_gpu(aperture, address, - temp_node_id_array, temp_node_id_array_size, - object); - if (ret != HSAKMT_STATUS_SUCCESS) - return ret; + if (temp_node_id_array_size) { + ret = _fmm_unmap_from_gpu(aperture, address, + temp_node_id_array, + temp_node_id_array_size, + object); + if (ret != HSAKMT_STATUS_SUCCESS) { + pthread_mutex_unlock(&aperture->fmm_mutex); + return ret; + } + } } retcode = _fmm_map_to_gpu_gtt(aperture, address, size, object,