]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
amd/amdkfd: sync all devices to wait all processes being evicted
authorZhigang Luo <Zhigang.Luo@amd.com>
Mon, 18 Mar 2024 18:13:10 +0000 (14:13 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 May 2024 10:14:46 +0000 (12:14 +0200)
[ Upstream commit d06af584be5a769d124b7302b32a033e9559761d ]

If there are more than one device doing reset in parallel, the first
device will call kfd_suspend_all_processes() to evict all processes
on all devices, this call takes time to finish. other device will
start reset and recover without waiting. if the process has not been
evicted before doing recover, it will be restored, then caused page
fault.

Signed-off-by: Zhigang Luo <Zhigang.Luo@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_device.c

index 0a9cf9dfc22435dd003088159d673a06bc0e165e..fcf6558d019e554419c38627497ae0d5fb53b0d9 100644 (file)
@@ -944,7 +944,6 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 {
        struct kfd_node *node;
        int i;
-       int count;
 
        if (!kfd->init_complete)
                return;
@@ -952,12 +951,10 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
        /* for runtime suspend, skip locking kfd */
        if (!run_pm) {
                mutex_lock(&kfd_processes_mutex);
-               count = ++kfd_locked;
-               mutex_unlock(&kfd_processes_mutex);
-
                /* For first KFD device suspend all the KFD processes */
-               if (count == 1)
+               if (++kfd_locked == 1)
                        kfd_suspend_all_processes();
+               mutex_unlock(&kfd_processes_mutex);
        }
 
        for (i = 0; i < kfd->num_nodes; i++) {
@@ -968,7 +965,7 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)
 
 int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
 {
-       int ret, count, i;
+       int ret, i;
 
        if (!kfd->init_complete)
                return 0;
@@ -982,12 +979,10 @@ int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)
        /* for runtime resume, skip unlocking kfd */
        if (!run_pm) {
                mutex_lock(&kfd_processes_mutex);
-               count = --kfd_locked;
-               mutex_unlock(&kfd_processes_mutex);
-
-               WARN_ONCE(count < 0, "KFD suspend / resume ref. error");
-               if (count == 0)
+               if (--kfd_locked == 0)
                        ret = kfd_resume_all_processes();
+               WARN_ONCE(kfd_locked < 0, "KFD suspend / resume ref. error");
+               mutex_unlock(&kfd_processes_mutex);
        }
 
        return ret;