Skip to content

Commit 6cb6d43

Browse files
xiaogang-chen-amdalexdeucher
authored andcommitted
drm/amdkfd: change kfd process kref count at creation
kfd process kref count(process->ref) is initialized to 1 by kref_init. After it is created not need to increase its kref. Instad add kfd process kref at kfd process mmu notifier allocation since we already decrease the kref at free_notifier of mmu_notifier_ops, so pair them. When user process opens kfd node multiple times the kfd process kref is increased each time to balance with kfd node close operation. Signed-off-by: Xiaogang Chen <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 408d208 commit 6cb6d43

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_process.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,10 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
854854
goto out;
855855
}
856856

857-
/* A prior open of /dev/kfd could have already created the process. */
858-
process = find_process(thread, false);
857+
/* A prior open of /dev/kfd could have already created the process.
858+
* find_process will increase process kref in this case
859+
*/
860+
process = find_process(thread, true);
859861
if (process) {
860862
pr_debug("Process already found\n");
861863
} else {
@@ -903,8 +905,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
903905
init_waitqueue_head(&process->wait_irq_drain);
904906
}
905907
out:
906-
if (!IS_ERR(process))
907-
kref_get(&process->ref);
908908
mutex_unlock(&kfd_processes_mutex);
909909
mmput(thread->mm);
910910

@@ -1190,10 +1190,8 @@ static void kfd_process_ref_release(struct kref *ref)
11901190

11911191
static struct mmu_notifier *kfd_process_alloc_notifier(struct mm_struct *mm)
11921192
{
1193-
int idx = srcu_read_lock(&kfd_processes_srcu);
1194-
struct kfd_process *p = find_process_by_mm(mm);
1195-
1196-
srcu_read_unlock(&kfd_processes_srcu, idx);
1193+
/* This increments p->ref counter if kfd process p exists */
1194+
struct kfd_process *p = kfd_lookup_process_by_mm(mm);
11971195

11981196
return p ? &p->mmu_notifier : ERR_PTR(-ESRCH);
11991197
}

0 commit comments

Comments
 (0)