* [PATCH v3] drm/amdkfd: change kfd process kref count at creation
@ 2024-10-28 20:43 Xiaogang.Chen
2024-11-05 22:29 ` Chen, Xiaogang
2024-11-05 23:58 ` Felix Kuehling
0 siblings, 2 replies; 3+ messages in thread
From: Xiaogang.Chen @ 2024-10-28 20:43 UTC (permalink / raw)
To: amd-gfx; +Cc: felix.kuehling, philip.yang, Xiaogang Chen
From: Xiaogang Chen <xiaogang.chen@amd.com>
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 Xiaogang.Chen@amd.com
---
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d07acf1b2f93..d871d5320297 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -850,8 +850,10 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
goto out;
}
- /* A prior open of /dev/kfd could have already created the process. */
- process = find_process(thread, false);
+ /* A prior open of /dev/kfd could have already created the process.
+ * find_process will increase process kref in this case
+ */
+ process = find_process(thread, true);
if (process) {
pr_debug("Process already found\n");
} else {
@@ -899,8 +901,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
init_waitqueue_head(&process->wait_irq_drain);
}
out:
- if (!IS_ERR(process))
- kref_get(&process->ref);
mutex_unlock(&kfd_processes_mutex);
mmput(thread->mm);
@@ -1186,10 +1186,8 @@ static void kfd_process_ref_release(struct kref *ref)
static struct mmu_notifier *kfd_process_alloc_notifier(struct mm_struct *mm)
{
- int idx = srcu_read_lock(&kfd_processes_srcu);
- struct kfd_process *p = find_process_by_mm(mm);
-
- srcu_read_unlock(&kfd_processes_srcu, idx);
+ /* This increments p->ref counter if kfd process p exists */
+ struct kfd_process *p = kfd_lookup_process_by_mm(mm);
return p ? &p->mmu_notifier : ERR_PTR(-ESRCH);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] drm/amdkfd: change kfd process kref count at creation
2024-10-28 20:43 [PATCH v3] drm/amdkfd: change kfd process kref count at creation Xiaogang.Chen
@ 2024-11-05 22:29 ` Chen, Xiaogang
2024-11-05 23:58 ` Felix Kuehling
1 sibling, 0 replies; 3+ messages in thread
From: Chen, Xiaogang @ 2024-11-05 22:29 UTC (permalink / raw)
To: amd-gfx; +Cc: felix.kuehling, philip.yang
ping
On 10/28/2024 3:43 PM, Xiaogang.Chen wrote:
> From: Xiaogang Chen <xiaogang.chen@amd.com>
>
> 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 Xiaogang.Chen@amd.com
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_process.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index d07acf1b2f93..d871d5320297 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -850,8 +850,10 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
> goto out;
> }
>
> - /* A prior open of /dev/kfd could have already created the process. */
> - process = find_process(thread, false);
> + /* A prior open of /dev/kfd could have already created the process.
> + * find_process will increase process kref in this case
> + */
> + process = find_process(thread, true);
> if (process) {
> pr_debug("Process already found\n");
> } else {
> @@ -899,8 +901,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
> init_waitqueue_head(&process->wait_irq_drain);
> }
> out:
> - if (!IS_ERR(process))
> - kref_get(&process->ref);
> mutex_unlock(&kfd_processes_mutex);
> mmput(thread->mm);
>
> @@ -1186,10 +1186,8 @@ static void kfd_process_ref_release(struct kref *ref)
>
> static struct mmu_notifier *kfd_process_alloc_notifier(struct mm_struct *mm)
> {
> - int idx = srcu_read_lock(&kfd_processes_srcu);
> - struct kfd_process *p = find_process_by_mm(mm);
> -
> - srcu_read_unlock(&kfd_processes_srcu, idx);
> + /* This increments p->ref counter if kfd process p exists */
> + struct kfd_process *p = kfd_lookup_process_by_mm(mm);
>
> return p ? &p->mmu_notifier : ERR_PTR(-ESRCH);
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] drm/amdkfd: change kfd process kref count at creation
2024-10-28 20:43 [PATCH v3] drm/amdkfd: change kfd process kref count at creation Xiaogang.Chen
2024-11-05 22:29 ` Chen, Xiaogang
@ 2024-11-05 23:58 ` Felix Kuehling
1 sibling, 0 replies; 3+ messages in thread
From: Felix Kuehling @ 2024-11-05 23:58 UTC (permalink / raw)
To: Xiaogang.Chen, amd-gfx; +Cc: philip.yang
On 2024-10-28 16:43, Xiaogang.Chen wrote:
> From: Xiaogang Chen <xiaogang.chen@amd.com>
>
> 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 Xiaogang.Chen@amd.com
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_process.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index d07acf1b2f93..d871d5320297 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -850,8 +850,10 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
> goto out;
> }
>
> - /* A prior open of /dev/kfd could have already created the process. */
> - process = find_process(thread, false);
> + /* A prior open of /dev/kfd could have already created the process.
> + * find_process will increase process kref in this case
> + */
> + process = find_process(thread, true);
> if (process) {
> pr_debug("Process already found\n");
> } else {
> @@ -899,8 +901,6 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
> init_waitqueue_head(&process->wait_irq_drain);
> }
> out:
> - if (!IS_ERR(process))
> - kref_get(&process->ref);
> mutex_unlock(&kfd_processes_mutex);
> mmput(thread->mm);
>
> @@ -1186,10 +1186,8 @@ static void kfd_process_ref_release(struct kref *ref)
>
> static struct mmu_notifier *kfd_process_alloc_notifier(struct mm_struct *mm)
> {
> - int idx = srcu_read_lock(&kfd_processes_srcu);
> - struct kfd_process *p = find_process_by_mm(mm);
> -
> - srcu_read_unlock(&kfd_processes_srcu, idx);
> + /* This increments p->ref counter if kfd process p exists */
> + struct kfd_process *p = kfd_lookup_process_by_mm(mm);
>
> return p ? &p->mmu_notifier : ERR_PTR(-ESRCH);
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-05 23:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28 20:43 [PATCH v3] drm/amdkfd: change kfd process kref count at creation Xiaogang.Chen
2024-11-05 22:29 ` Chen, Xiaogang
2024-11-05 23:58 ` Felix Kuehling
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox