From bb4291dcace941cdcd511727276d03bffff6d5fe Mon Sep 17 00:00:00 2001 From: Philip Yang Date: Tue, 6 Aug 2019 15:15:03 -0400 Subject: [PATCH] hsaKmtCloseKFD destroy objects in all apertures Otherwise the parent call hsaKmtCloseKFD and then fork child process, child process will duplicate the vm_objects from the parent. Change-Id: Ia6ffc51cbae983b6a7cdc58ccf3b11ebe4087d97 Signed-off-by: Philip Yang [ROCm/ROCR-Runtime commit: 632ad3a749d81f4e9ab21f36f309679bf6673a38] --- projects/rocr-runtime/src/fmm.c | 54 +++++++++++++++------------------ 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index 660ff234b3..5336af6973 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -2345,14 +2345,37 @@ sysfs_parse_failed: return ret; } +static void fmm_clear_aperture(manageable_aperture_t *app) +{ + rbtree_node_t *n; + + while ((n = rbtree_node_any(&app->tree, MID))) + vm_remove_object(app, vm_object_entry(n, 0)); + + while (app->vm_ranges) + vm_remove_area(app, app->vm_ranges); +} + void fmm_destroy_process_apertures(void) { + unsigned int i; + release_mmio(); + + fmm_clear_aperture(&cpuvm_aperture); + fmm_clear_aperture(&svm.apertures[SVM_DEFAULT]); + fmm_clear_aperture(&svm.apertures[SVM_COHERENT]); + if (gpu_mem) { + for (i = 0; i < gpu_mem_count; i++) { + fmm_clear_aperture(&gpu_mem[i].gpuvm_aperture); + fmm_clear_aperture(&gpu_mem[i].scratch_physical); + } + free(gpu_mem); gpu_mem = NULL; + gpu_mem_count = 0; } - gpu_mem_count = 0; } HSAKMT_STATUS fmm_get_aperture_base_and_limit(aperture_type_e aperture_type, HSAuint32 gpu_id, @@ -3531,18 +3554,6 @@ HSAKMT_STATUS fmm_set_mem_user_data(const void *mem, void *usr_data) return HSAKMT_STATUS_SUCCESS; } -static void fmm_clear_aperture(manageable_aperture_t *app) -{ - rbtree_node_t *n; - - while ((n = rbtree_node_any(&app->tree, MID))) - vm_remove_object(app, vm_object_entry(n, 0)); - - while (app->vm_ranges) - vm_remove_area(app, app->vm_ranges); - -} - /* This is a special funcion that should be called only from the child process * after a fork(). This will clear all vm_objects and mmaps duplicated from * the parent. @@ -3559,19 +3570,7 @@ void fmm_clear_all_mem(void) drm_render_fds[i] = 0; } - /* Nothing is initialized. */ - if (!gpu_mem) - return; - - fmm_clear_aperture(&cpuvm_aperture); - - for (i = 0; i < gpu_mem_count; i++) { - fmm_clear_aperture(&gpu_mem[i].gpuvm_aperture); - fmm_clear_aperture(&gpu_mem[i].scratch_physical); - } - - fmm_clear_aperture(&svm.apertures[SVM_DEFAULT]); - fmm_clear_aperture(&svm.apertures[SVM_COHERENT]); + fmm_destroy_process_apertures(); if (dgpu_shared_aperture_limit) { /* Use the same dgpu range as the parent. If failed, then set @@ -3597,7 +3596,4 @@ void fmm_clear_all_mem(void) all_gpu_id_array_size = 0; all_gpu_id_array = NULL; - - gpu_mem_count = 0; - free(gpu_mem); }