drm/amdkfd: Reuse function to find a process through pasid
authorEdward O'Callaghan <funfunctor@folklore1984.net>
Sat, 17 Sep 2016 05:01:42 +0000 (15:01 +1000)
committerOded Gabbay <oded.gabbay@gmail.com>
Mon, 19 Sep 2016 17:58:35 +0000 (20:58 +0300)
The kfd_lookup_process_by_pasid() is just for that purpose,
so use it instead of repeating the code.

v2: return on the condition (p == NULL) instead of BUG_ON(!p).

Signed-off-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
drivers/gpu/drm/amd/amdkfd/kfd_process.c

index 4f3849ac8c0770d1dbde09f9d6e371fb24c01e94..ef7c8de7060e2dab64b7f7739b8c8286ea741711 100644 (file)
@@ -404,58 +404,47 @@ void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid)
 {
        struct kfd_process *p;
        struct kfd_process_device *pdd;
-       int idx, i;
 
        BUG_ON(dev == NULL);
 
-       idx = srcu_read_lock(&kfd_processes_srcu);
-
        /*
         * Look for the process that matches the pasid. If there is no such
         * process, we either released it in amdkfd's own notifier, or there
         * is a bug. Unfortunately, there is no way to tell...
         */
-       hash_for_each_rcu(kfd_processes_table, i, p, kfd_processes)
-               if (p->pasid == pasid) {
-
-                       srcu_read_unlock(&kfd_processes_srcu, idx);
-
-                       pr_debug("Unbinding process %d from IOMMU\n", pasid);
+       p = kfd_lookup_process_by_pasid(pasid);
+       if (!p)
+               return;
 
-                       mutex_lock(&p->mutex);
-
-                       if ((dev->dbgmgr) && (dev->dbgmgr->pasid == p->pasid))
-                               kfd_dbgmgr_destroy(dev->dbgmgr);
-
-                       pqm_uninit(&p->pqm);
+       pr_debug("Unbinding process %d from IOMMU\n", pasid);
 
-                       pdd = kfd_get_process_device_data(dev, p);
+       if ((dev->dbgmgr) && (dev->dbgmgr->pasid == p->pasid))
+               kfd_dbgmgr_destroy(dev->dbgmgr);
 
-                       if (!pdd) {
-                               mutex_unlock(&p->mutex);
-                               return;
-                       }
+       pqm_uninit(&p->pqm);
 
-                       if (pdd->reset_wavefronts) {
-                               dbgdev_wave_reset_wavefronts(pdd->dev, p);
-                               pdd->reset_wavefronts = false;
-                       }
+       pdd = kfd_get_process_device_data(dev, p);
 
-                       /*
-                        * Just mark pdd as unbound, because we still need it
-                        * to call amd_iommu_unbind_pasid() in when the
-                        * process exits.
-                        * We don't call amd_iommu_unbind_pasid() here
-                        * because the IOMMU called us.
-                        */
-                       pdd->bound = false;
+       if (!pdd) {
+               mutex_unlock(&p->mutex);
+               return;
+       }
 
-                       mutex_unlock(&p->mutex);
+       if (pdd->reset_wavefronts) {
+               dbgdev_wave_reset_wavefronts(pdd->dev, p);
+               pdd->reset_wavefronts = false;
+       }
 
-                       return;
-               }
+       /*
+        * Just mark pdd as unbound, because we still need it
+        * to call amd_iommu_unbind_pasid() in when the
+        * process exits.
+        * We don't call amd_iommu_unbind_pasid() here
+        * because the IOMMU called us.
+        */
+       pdd->bound = false;
 
-       srcu_read_unlock(&kfd_processes_srcu, idx);
+       mutex_unlock(&p->mutex);
 }
 
 struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p)