If active queue buffer is freed, kfd_lookup_process_by_mm return NULL,
means process exited and mm is gone, it is fine to evict queue then
free queue buffer CPU mapping and memory from do_exit.

Only show warning message if process mm is still alive when queue
buffer is freed.

Fixes: b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")
Signed-off-by: Philip Yang <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 48c9a211e415..9174f718482a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -2487,17 +2487,26 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct 
svm_range *prange,
        bool unmap_parent;
        uint32_t i;
 
+       p = kfd_lookup_process_by_mm(mm);
+
        if (atomic_read(&prange->queue_refcount)) {
                int r;
 
-               pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
-                       prange->start << PAGE_SHIFT);
+               /*
+                * Evict queue if queue buffer freed with warning message.
+                * If process is not found, this is free CPU mapping from
+                * do_exit, then it is fine to free queue buffer.
+                */
+               if (p) {
+                       pr_warn("Freeing queue vital buffer 0x%lx, queue 
evicted\n",
+                               prange->start << PAGE_SHIFT);
+               }
+
                r = kgd2kfd_quiesce_mm(mm, KFD_QUEUE_EVICTION_TRIGGER_SVM);
                if (r)
                        pr_debug("failed %d to quiesce KFD queues\n", r);
        }
 
-       p = kfd_lookup_process_by_mm(mm);
        if (!p)
                return;
        svms = &p->svms;
-- 
2.49.0

Reply via email to