From: "Kuehling, Felix" <felix.kuehling@amd.com>
To: "Xiaogang.Chen" <xiaogang.chen@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdkfd: Check if there are kfd porcesses using adev by kfd_processes_count
Date: Wed, 29 Apr 2026 19:04:33 -0400 [thread overview]
Message-ID: <58de85fc-3774-440d-87a8-e8adc1bba263@amd.com> (raw)
In-Reply-To: <20260424191107.2146398-1-xiaogang.chen@amd.com>
On 2026-04-24 15:11, Xiaogang.Chen wrote:
> From: Xiaogang Chen <xiaogang.chen@amd.com>
>
> Fixes: 6cca686dfce7("drm/amdkfd: kfd driver supports hot unplug/replug
> amdgpu devices")
>
> During gpu hot-unplug need check if there are kfd porcesses still using the
> being removed gpu before clean resources of the device. Current driver checks
> if kfd_processes_table is empty. kfd processes are not terminated after
> removed from kfd_processes_table immediately. They are still alive and may
> access the device until kfd_process_wq work queue got ran.
>
> Check kfd->kfd_processes_count value that is updated after kfd process got
> uninitialized when its ref becomes zero.
>
> Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_device.c | 33 +------------------------
> 1 file changed, 1 insertion(+), 32 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> index 9a66ee661e57..71fd3b1d0b3a 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> @@ -1737,37 +1737,6 @@ bool kgd2kfd_vmfault_fast_path(struct amdgpu_device *adev, struct amdgpu_iv_entr
> return false;
> }
>
> -/* check if there is kfd process still uses adev */
> -static bool kgd2kfd_check_device_idle(struct amdgpu_device *adev)
> -{
> - struct kfd_process *p;
> - struct hlist_node *p_temp;
> - unsigned int temp;
> - struct kfd_node *dev;
> -
> - mutex_lock(&kfd_processes_mutex);
> -
> - if (hash_empty(kfd_processes_table)) {
> - mutex_unlock(&kfd_processes_mutex);
> - return true;
> - }
> -
> - /* check if there is device still use adev */
> - hash_for_each_safe(kfd_processes_table, temp, p_temp, p, kfd_processes) {
> - for (int i = 0; i < p->n_pdds; i++) {
> - dev = p->pdds[i]->dev;
> - if (dev->adev == adev) {
> - mutex_unlock(&kfd_processes_mutex);
> - return false;
> - }
> - }
> - }
> -
> - mutex_unlock(&kfd_processes_mutex);
> -
> - return true;
> -}
> -
> /** kgd2kfd_teardown_processes - gracefully tear down existing
> * kfd processes that use adev
> *
> @@ -1800,7 +1769,7 @@ void kgd2kfd_teardown_processes(struct amdgpu_device *adev)
> mutex_unlock(&kfd_processes_mutex);
>
> /* wait all kfd processes use adev terminate */
> - while (!kgd2kfd_check_device_idle(adev))
> + while (!!atomic_read(&adev->kfd.dev->kfd_processes_count))
> cond_resched();
> }
>
prev parent reply other threads:[~2026-04-29 23:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 19:11 [PATCH] drm/amdkfd: Check if there are kfd porcesses using adev by kfd_processes_count Xiaogang.Chen
2026-04-29 23:04 ` Kuehling, Felix [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58de85fc-3774-440d-87a8-e8adc1bba263@amd.com \
--to=felix.kuehling@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=xiaogang.chen@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox