From a11cb2a63361a8efe92c2254694f050cf2caef42 Mon Sep 17 00:00:00 2001 From: Philip Yang Date: Tue, 20 Aug 2019 10:55:14 -0400 Subject: [PATCH] libhsakmt: child process destroy vm objects in all apertures child process clone vm objects from svm->apertures if parent process doesn't free memory before fork. fmm_clear_all_mem suppose to clear the apertures in forked child process but this only works if gpu_vm is not NULL. parent process call hsaKmtCloseKFD reset gpu_vm to NULL and then fork, then child process will not clear svm->apertures. As a result, the child process will allocate vm object with same address and add to aperture, there are duplicate vm objects with same address in aperture. Then mapping to GPU will find the wrong vm object and create incorrect GPU mapping cause rocrtst IPC test VM fault. The issue happened with HSA_USERPTR_FOR_PAGED_MEM=1. The fix is to clear vm objects in all apertures in clear_after_fork. Change-Id: I92e42a967075a634a3f475b915c8242d82077ecb Signed-off-by: Philip Yang --- src/fmm.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/fmm.c b/src/fmm.c index 660ff234b3..dc24b61bbc 100644 --- a/src/fmm.c +++ b/src/fmm.c @@ -3559,17 +3559,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]); @@ -3598,6 +3588,16 @@ void fmm_clear_all_mem(void) all_gpu_id_array_size = 0; all_gpu_id_array = NULL; + /* Nothing is initialized. */ + if (!gpu_mem) + return; + + for (i = 0; i < gpu_mem_count; i++) { + fmm_clear_aperture(&gpu_mem[i].gpuvm_aperture); + fmm_clear_aperture(&gpu_mem[i].scratch_physical); + } + gpu_mem_count = 0; free(gpu_mem); + gpu_mem = NULL; }