From: Zhu Lingshan Date: Thu, 21 Aug 2025 06:41:31 +0000 (+0800) Subject: amdkfd: introduce new helper kfd_lookup_process_by_id X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07506945e138c191e913aba86030111a93a5b119;p=thirdparty%2Fkernel%2Flinux.git amdkfd: introduce new helper kfd_lookup_process_by_id 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 Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher --- diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index e424551d14b2..44629ce96832 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -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, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 06986f629b87..47cbd700f908 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -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