From 6d856ebbff4453f073ec45cf6e3246bdea3d4ccd Mon Sep 17 00:00:00 2001 From: Felix Kuehling Date: Fri, 15 Jan 2016 22:05:28 -0500 Subject: [PATCH] Fix memory leaks due to stale CPU mappings Use the aligned size of the buffer objects for CPU unmapping in __fmm_release instead of relying on the unaligned size passed in by the caller. Change-Id: If986ec24e9a05d32981549fddbf143221fc40bac [ROCm/ROCR-Runtime commit: 7a383f9d8861b2c4fdb986354a10a730a0227a73] --- projects/rocr-runtime/src/fmm.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index 6b3926aa75..9e9b0a05e7 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -922,6 +922,13 @@ static void __fmm_release(void *address, if (object->device_ids_array_size > 0) free(object->device_ids_array); + if (address >= dgpu_shared_aperture_base && + address <= dgpu_shared_aperture_limit) { + /* Remove any CPU mapping, but keep the address range reserved */ + mmap(address, object->size, PROT_NONE, + MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE | MAP_FIXED, -1, 0); + } + args.handle = object->handle; kmtIoctl(kfd_fd, AMDKFD_IOC_FREE_MEMORY_OF_GPU, &args); @@ -971,14 +978,6 @@ void fmm_release(void *address, uint64_t MemorySizeInBytes) } } - if (found && - address >= dgpu_shared_aperture_base && - address <= dgpu_shared_aperture_limit) { - /* Remove any CPU mapping, but keep the address range reserved */ - mmap(address, MemorySizeInBytes, PROT_NONE, - MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE | MAP_FIXED, -1, 0); - } - /* * If memory address isn't inside of any defined aperture - it refers * to the system memory