OSDN Git Service

drm/amdkfd: fix KFDSVMRangeTest.PartialUnmapSysMemTest fails
authorYifan Zhang <yifan1.zhang@amd.com>
Sat, 14 Aug 2021 09:53:14 +0000 (17:53 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 13 Oct 2021 18:14:34 +0000 (14:14 -0400)
[ RUN      ] KFDSVMRangeTest.PartialUnmapSysMemTest
/home/yifan/brahma/libhsakmt/tests/kfdtest/src/KFDTestUtil.cpp:245: Failure
Value of: (hsaKmtAllocMemory(m_Node, m_Size, m_Flags, &m_pBuf))
  Actual: 1
Expected: HSAKMT_STATUS_SUCCESS
Which is: 0
/home/yifan/brahma/libhsakmt/tests/kfdtest/src/KFDTestUtil.cpp:248: Failure
Value of: (hsaKmtMapMemoryToGPUNodes(m_pBuf, m_Size, __null, mapFlags, 1, &m_Node))
  Actual: 1
Expected: HSAKMT_STATUS_SUCCESS
Which is: 0
/home/yifan/brahma/libhsakmt/tests/kfdtest/src/KFDTestUtil.cpp:306: Failure
Expected: ((void *)__null) != (ptr), actual: NULL vs NULL
Segmentation fault (core dumped)
[          ] Profile: Full Test
[          ] HW capabilities: 0x9

kernel log:

[  102.029150]  ret_from_fork+0x22/0x30
[  102.029158] ---[ end trace 15c34e782714f9a3 ]---
[ 3613.603598] amdgpu: Address: 0x7f7149ccc000 already allocated by SVM
[ 3613.610620] show_signal_msg: 27 callbacks suppressed

These is race with deferred actions from previous memory map
changes (e.g. munmap).Flush pending deffered work to avoid such case.

Signed-off-by: Yifan Zhang <yifan1.zhang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

index 3177c4a..4de907f 100644 (file)
@@ -1261,7 +1261,12 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
                return -EINVAL;
 
 #if IS_ENABLED(CONFIG_HSA_AMD_SVM)
+       /* Flush pending deferred work to avoid racing with deferred actions
+        * from previous memory map changes (e.g. munmap).
+        */
+       svm_range_list_lock_and_flush_work(svms, current->mm);
        mutex_lock(&svms->lock);
+       mmap_write_unlock(current->mm);
        if (interval_tree_iter_first(&svms->objects,
                                     args->va_addr >> PAGE_SHIFT,
                                     (args->va_addr + args->size - 1) >> PAGE_SHIFT)) {