From 098ce2acb49ef7c936b01f0fefc365bd71297e3b Mon Sep 17 00:00:00 2001 From: Philip Yang Date: Fri, 10 Sep 2021 12:58:13 -0400 Subject: [PATCH] libhsakmt: register and deregister userptr in parallel For userptr, after taking aperture lock, decrease registration_count and ensure object registration_count equal to 0 to release KFD and thunk object. Move decrementing of registration count from fmm_deregister_memory into __fmm_release to avoid a race condition when dropping the aperture lock in fmm_deregister_memory. Change-Id: I5381fa6b8a77a1516af2554e5174e91969c338c4 Signed-off-by: Philip Yang [ROCm/ROCR-Runtime commit: f82927ad655c89d4f7f9942f2669ab3e1c3e8539] --- projects/rocr-runtime/src/fmm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index 33a1075dc1..6154606786 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -1676,6 +1676,14 @@ static int __fmm_release(vm_object_t *object, manageable_aperture_t *aperture) pthread_mutex_lock(&aperture->fmm_mutex); + if (object->userptr) { + object->registration_count--; + if (object->registration_count > 0) { + pthread_mutex_unlock(&aperture->fmm_mutex); + return 0; + } + } + /* If memory is user memory and it's still GPU mapped, munmap * would cause an eviction. If the restore happens quickly * enough, restore would also fail with an error message. So @@ -3404,12 +3412,6 @@ HSAKMT_STATUS fmm_deregister_memory(void *address) return HSAKMT_STATUS_SUCCESS; } - if (object->registration_count > 1) { - --object->registration_count; - pthread_mutex_unlock(&aperture->fmm_mutex); - return HSAKMT_STATUS_SUCCESS; - } - if (object->metadata || object->userptr || object->is_imported_kfd_bo) { /* An object with metadata is an imported graphics * buffer. Deregistering imported graphics buffers or