]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amdkfd: Fix mode1 reset crash issue
authorPhilip Yang <Philip.Yang@amd.com>
Thu, 6 Feb 2025 22:50:13 +0000 (17:50 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:19 +0000 (10:45 +0200)
[ Upstream commit f0b4440cdc1807bb6ec3dce0d6de81170803569b ]

If HW scheduler hangs and mode1 reset is used to recover GPU, KFD signal
user space to abort the processes. After process abort exit, user queues
still use the GPU to access system memory before h/w is reset while KFD
cleanup worker free system memory and free VRAM.

There is use-after-free race bug that KFD allocate and reuse the freed
system memory, and user queue write to the same system memory to corrupt
the data structure and cause driver crash.

To fix this race, KFD cleanup worker terminate user queues, then flush
reset_domain wq to wait for any GPU ongoing reset complete, and then
free outstanding BOs.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdkfd/kfd_process.c

index 64346c71c62a3001ed98863e5e0dc3052965f258..a6d08dee74f6ea1183e7363a2196ed7e6f3b1413 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/pm_runtime.h>
 #include "amdgpu_amdkfd.h"
 #include "amdgpu.h"
+#include "amdgpu_reset.h"
 
 struct mm_struct;
 
@@ -1110,6 +1111,17 @@ static void kfd_process_remove_sysfs(struct kfd_process *p)
        p->kobj = NULL;
 }
 
+/*
+ * If any GPU is ongoing reset, wait for reset complete.
+ */
+static void kfd_process_wait_gpu_reset_complete(struct kfd_process *p)
+{
+       int i;
+
+       for (i = 0; i < p->n_pdds; i++)
+               flush_workqueue(p->pdds[i]->dev->adev->reset_domain->wq);
+}
+
 /* No process locking is needed in this function, because the process
  * is not findable any more. We must assume that no other thread is
  * using it any more, otherwise we couldn't safely free the process
@@ -1123,6 +1135,11 @@ static void kfd_process_wq_release(struct work_struct *work)
        kfd_process_dequeue_from_all_devices(p);
        pqm_uninit(&p->pqm);
 
+       /*
+        * If GPU in reset, user queues may still running, wait for reset complete.
+        */
+       kfd_process_wait_gpu_reset_complete(p);
+
        /* Signal the eviction fence after user mode queues are
         * destroyed. This allows any BOs to be freed without
         * triggering pointless evictions or waiting for fences.