From 98c886193d867e48de0e3a5dc3b3864536d98c66 Mon Sep 17 00:00:00 2001 From: Felix Kuehling Date: Tue, 26 Jul 2016 17:22:46 -0400 Subject: [PATCH 1476/4131] drm/amdkfd: Get reference to lead_thread task struct Increment the kfd_process.lead_thread's reference counter to make it safe to dereference. This will be needed for getting a safe reference to the process' mm_struct. Change-Id: I2a38f5f2de989dd4f19115d21d31ea6df953806c Signed-off-by: Felix Kuehling --- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 ++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index f943e11..f540931 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -618,6 +618,8 @@ struct kfd_process { * In any process, the thread that started main() is the lead * thread and outlives the rest. * It is here because amd_iommu_bind_pasid wants a task_struct. + * It can also be used for safely getting a reference to the + * mm_struct of the process. */ struct task_struct *lead_thread; diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index ec066d8..889d165 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -466,6 +466,8 @@ static void kfd_process_ref_release(struct kref *ref) kfd_pasid_free(p->pasid); + put_task_struct(p->lead_thread); + kfree(p); } @@ -647,6 +649,7 @@ static struct kfd_process *create_process(const struct task_struct *thread) (uintptr_t)process->mm); process->lead_thread = thread->group_leader; + get_task_struct(process->lead_thread); INIT_LIST_HEAD(&process->per_device_data); -- 2.7.4