<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <pre class="moz-quote-pre" wrap="">Reviewed-by: Philip Yang <a class="moz-txt-link-rfc2396E" href="mailto:philip.yang@amd.com"><philip.yang@amd.com></a> for the series.</pre>
    <div class="moz-cite-prefix">On 2021-02-12 1:40 a.m., Felix Kuehling
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:20210212064034.29912-2-Felix.Kuehling@amd.com">
      <pre class="moz-quote-pre" wrap="">If init_cwsr_apu fails, we currently leave the kfd_process structure in
place anyway. The next kfd_open will then succeed, using the existing
kfd_process structure. Fix that by cleaning up the kfd_process after a
failure in init_cwsr_apu.

Signed-off-by: Felix Kuehling <a class="moz-txt-link-rfc2396E" href="mailto:Felix.Kuehling@amd.com"><Felix.Kuehling@amd.com></a>
---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 145cd0a17d50..a4d7682289bb 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -775,10 +775,8 @@ struct kfd_process *kfd_create_process(struct file *filep)
                        goto out;
 
                ret = kfd_process_init_cwsr_apu(process, filep);
-               if (ret) {
-                       process = ERR_PTR(ret);
-                       goto out;
-               }
+               if (ret)
+                       goto out_destroy;
 
                if (!procfs.kobj)
                        goto out;
@@ -826,6 +824,14 @@ struct kfd_process *kfd_create_process(struct file *filep)
        mutex_unlock(&kfd_processes_mutex);
 
        return process;
+
+out_destroy:
+       hash_del_rcu(&process->kfd_processes);
+       mutex_unlock(&kfd_processes_mutex);
+       synchronize_srcu(&kfd_processes_srcu);
+       /* kfd_process_free_notifier will trigger the cleanup */
+       mmu_notifier_put(&process->mmu_notifier);
+       return ERR_PTR(ret);
 }
 
 struct kfd_process *kfd_get_process(const struct task_struct *thread)
</pre>
    </blockquote>
  </body>
</html>