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 <Philip.Yang@amd.com>


[ROCm/ROCR-Runtime commit: f82927ad65]
This commit is contained in:
Philip Yang
2021-09-10 12:58:13 -04:00
rodzic f2d3dbb28e
commit 098ce2acb4
+8 -6
Wyświetl plik
@@ -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