]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
amdkfd: introduce new helper kfd_lookup_process_by_id
authorZhu Lingshan <lingshan.zhu@amd.com>
Thu, 21 Aug 2025 06:41:31 +0000 (14:41 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 8 Dec 2025 18:56:43 +0000 (13:56 -0500)
This commit introduces a new helper function
kfd_lookup_process_by_id which can find a
kfd process that identified by its context id from
the kfd process table

Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
drivers/gpu/drm/amd/amdkfd/kfd_process.c

index e424551d14b23eb7dbd645d36e6b3b53f431d060..44629ce96832e1a0b5a0ab859837fcddeac2d22e 100644 (file)
@@ -1061,6 +1061,7 @@ int kfd_create_process_sysfs(struct kfd_process *process);
 struct kfd_process *kfd_lookup_process_by_pasid(u32 pasid,
                                                 struct kfd_process_device **pdd);
 struct kfd_process *kfd_lookup_process_by_mm(const struct mm_struct *mm);
+struct kfd_process *kfd_lookup_process_by_id(const struct mm_struct *mm, u16 id);
 
 int kfd_process_gpuidx_from_gpuid(struct kfd_process *p, uint32_t gpu_id);
 int kfd_process_gpuid_from_node(struct kfd_process *p, struct kfd_node *node,
index 06986f629b87274d735dc70dd1c16f60f4a7774b..47cbd700f9082ee2e52d14fff61d3bbc66b6595e 100644 (file)
@@ -1959,6 +1959,27 @@ struct kfd_process *kfd_lookup_process_by_mm(const struct mm_struct *mm)
        return p;
 }
 
+/* This increments the process->ref counter. */
+struct kfd_process *kfd_lookup_process_by_id(const struct mm_struct *mm, u16 id)
+{
+       struct kfd_process *p, *ret_p = NULL;
+       unsigned int temp;
+
+       int idx = srcu_read_lock(&kfd_processes_srcu);
+
+       hash_for_each_rcu(kfd_processes_table, temp, p, kfd_processes) {
+               if (p->mm == mm && p->context_id == id) {
+                       kref_get(&p->ref);
+                       ret_p = p;
+                       break;
+               }
+       }
+
+       srcu_read_unlock(&kfd_processes_srcu, idx);
+
+       return ret_p;
+}
+
 /* kfd_process_evict_queues - Evict all user queues of a process
  *
  * Eviction is reference-counted per process-device. This means multiple